Skip to content

Commit

Permalink
fix: support commands on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
manekinekko committed Oct 18, 2019
1 parent 6a8a652 commit d389249
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { az, Config, saveWorkspace } from "../core/utils";

module.exports = async function() {
let subscriptionsList = await az<AzureSubscription[]>(
`login --query '[].{name:name, state:state, id:id}'`,
`login --query "[].{name:name, state:state, id:id}"`,
`Loading subscriptions...`
);

Expand Down
22 changes: 21 additions & 1 deletion src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export const uuid = () => {
return guuid;
};

export const sanitize = (name: string) => name.replace(/[\W_]+/gim, "").trim().substr(0, 20);
export const sanitize = (name: string) =>
name
.replace(/[\W_]+/gim, "")
.trim()
.substr(0, 20);

export const Config = new Configstore(packageJson.name, {
version: packageJson.version
Expand Down Expand Up @@ -199,6 +203,22 @@ export function saveEnvFile(key: string, value: string) {
}

fs.writeFileSync(ENV_FILENAME, envValues.join("\n"));

const gitIgnoreFilename = `.gitignore`;
if (fileExists(gitIgnoreFilename)) {
const gitIgnoreFileContent = readFileFromDisk(gitIgnoreFilename) || "";
if (gitIgnoreFileContent.includes('.env')) {
debug(`${ENV_FILENAME} file already in ${gitIgnoreFilename}`);
}
else {
debug(`add ${ENV_FILENAME} to ${gitIgnoreFilename}`);
fs.writeFileSync(ENV_FILENAME, [gitIgnoreFileContent, ENV_FILENAME].join("\n"));
}
}
else {
debug(`add ${ENV_FILENAME} to ${gitIgnoreFilename}`);
fs.writeFileSync(gitIgnoreFilename, ENV_FILENAME);
}
}

export function isProjectFileExists() {
Expand Down
8 changes: 4 additions & 4 deletions src/features/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = async function() {
if (databaseType === "TABLE_STORAGE") {
// https://docs.microsoft.com/en-us/cli/azure/storage/table?view=azure-cli-latest#az-storage-table-list
const databasesInstancesList = await az<DatabaseInstance[]>(
`storage table list --account-name "${storage.name}" --subscription "${subscription.id}" --query '[].{name: name}'`,
`storage table list --account-name "${storage.name}" --subscription "${subscription.id}" --query "[].{name: name}"`,
`Checking Table Storage instances for Storage Account ${chalk.cyan(storage.name)}...`
);

Expand All @@ -43,7 +43,7 @@ module.exports = async function() {
} else {
// https://docs.microsoft.com/en-us/cli/azure/storage/table?view=azure-cli-latest#az-storage-table-create
databaseInstance = await az<DatabaseInstance>(
`storage table create --name ${databaseName} --account-name ${storage.name} --query '{created: created}'`,
`storage table create --name ${databaseName} --account-name ${storage.name} --query "{created: created}"`,
`Setting up Table Storage ${chalk.cyan(databaseName)}...`
);

Expand All @@ -63,7 +63,7 @@ module.exports = async function() {
} else if (databaseType === "COSMOSDB") {
// https://docs.microsoft.com/en-us/cli/azure/cosmosdb?view=azure-cli-latest#az-cosmosdb-list
const databasesInstancesList = await az<DatabaseInstance[]>(
`cosmosdb list --resource-group "${resourceGroup.name}" --subscription "${subscription.id}" --query '[].{id: id, name: name, tags: tags, documentEndpoint: documentEndpoint}'`,
`cosmosdb list --resource-group "${resourceGroup.name}" --subscription "${subscription.id}" --query "[].{id: id, name: name, tags: tags, documentEndpoint: documentEndpoint}"`,
`Checking CosmosDB instances for resource group ${chalk.cyan(resourceGroup.name)}...`
);

Expand All @@ -73,7 +73,7 @@ module.exports = async function() {
} else {
// https://docs.microsoft.com/en-us/cli/azure/cosmosdb?view=azure-cli-latest#az-cosmosdb-create
databaseInstance = await az<DatabaseInstance>(
`cosmosdb create --name ${databaseName} --resource-group ${resourceGroup.name} --tag 'x-created-by=hexa' --query '{id: id, name: name, tags: tags, endpoint: documentEndpoint}'`,
`cosmosdb create --name ${databaseName} --resource-group ${resourceGroup.name} --tag 'x-created-by=hexa' --query "{id: id, name: name, tags: tags, endpoint: documentEndpoint}"`,
`Setting up CosmosDB instance ${chalk.cyan(databaseName)} (this may take up to 5 minutes)...`
);
debug(`created cosmosdb instance ${chalk.green(databaseInstance.name)}`);
Expand Down
4 changes: 2 additions & 2 deletions src/features/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = async function() {

// https://docs.microsoft.com/en-us/cli/azure/functionapp?view=azure-cli-latest#az-functionapp-list
let functionAppsList = await az<AzureFunctionApp[]>(
`functionapp list --resource-group "${resourceGroup.name}" --subscription "${subscription.id}" --query '[].{id: id, name: name, appServicePlanId: appServicePlanId, hostName: defaultHostName, state: state, tags: tags}'`,
`functionapp list --resource-group "${resourceGroup.name}" --subscription "${subscription.id}" --query "[].{id: id, name: name, appServicePlanId: appServicePlanId, hostName: defaultHostName, state: state, tags: tags}"`,
`Checking storage accounts for resource group ${chalk.cyan(resourceGroup.name)}...`
);
functionAppsList = functionAppsList.sort((a, b) => (a.tags && a.tags["x-created-by"] === "hexa" ? -1 : 1));
Expand All @@ -32,7 +32,7 @@ module.exports = async function() {
} else {
// https://docs.microsoft.com/en-us/cli/azure/functionapp?view=azure-cli-latest#az-functionapp-create
functionApp = await az<AzureFunctionApp>(
`functionapp create --resource-group ${resourceGroup.name} --consumption-plan-location ${resourceGroup.location} --name ${functionAppName} --storage-account ${storage.name} --runtime node --disable-app-insights --tag 'x-created-by=hexa' --query '{id: id, name: name, appServicePlanId: appServicePlanId, hostName: defaultHostName, state: state, tags: tags}'`,
`functionapp create --resource-group ${resourceGroup.name} --consumption-plan-location ${resourceGroup.location} --name ${functionAppName} --storage-account ${storage.name} --runtime node --disable-app-insights --tag 'x-created-by=hexa' --query "{id: id, name: name, appServicePlanId: appServicePlanId, hostName: defaultHostName, state: state, tags: tags}"`,
`Enabling Functions (this may take few minutes)...`
);
debug(`created functionApp ${chalk.green(functionApp.name)}`);
Expand Down
2 changes: 1 addition & 1 deletion src/features/hosting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = async function() {

// https://docs.microsoft.com/en-us/cli/azure/storage/blob/service-properties?view=azure-cli-latest#az-storage-blob-service-properties-update
await az<string>(
`storage blob service-properties update --account-name "${storage.name}" --static-website --404-document 404.html --index-document index.html --query '{staticWebsite: staticWebsite}'`,
`storage blob service-properties update --account-name "${storage.name}" --static-website --404-document 404.html --index-document index.html --query "{staticWebsite: staticWebsite}"`,
`Enabling hosting for storage account ${chalk.cyan(storage.name)}...`
);

Expand Down
4 changes: 2 additions & 2 deletions src/features/resource-group/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ module.exports = async function(creationMode: CreationMode) {
if (creationMode === "MANUAL") {
// https://docs.microsoft.com/en-us/cli/azure/account?view=azure-cli-latest#az-account-list-locations
let regionsList = await az<AzureRegion[]>(
`account list-locations --query '[].{name:name, id:id, displayName:displayName}'`,
`account list-locations --query "[].{name:name, id:id, displayName:displayName}"`,
`Loading Azure regions (this may take few minutes)...`
);
({ name, region } = await askForResourceGroupDetails(regionsList, name, region));
}

// https://docs.microsoft.com/en-us/cli/azure/group?view=azure-cli-latest#az-group-create
let resourceGroup = await az<AzureResourceGroup>(
`group create -l ${region} -n ${name} --tag 'x-created-by=hexa' --query '{name:name, id:id, location:location}'`,
`group create -l ${region} -n ${name} --tag "x-created-by=hexa" --query "{name:name, id:id, location:location}"`,
`Setting resource group ${chalk.cyan(name)}`
);

Expand Down
2 changes: 1 addition & 1 deletion src/features/resource-group/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = async function() {

// https://docs.microsoft.com/en-us/cli/azure/group?view=azure-cli-latest#az-group-list
let resourceGroupsList = await az<AzureResourceGroup[]>(
`group list --query '[].{name:name, id:id, location:location, tags:tags}'`,
`group list --query "[].{name:name, id:id, location:location, tags:tags}"`,
`Loading resource groups...`
);

Expand Down
4 changes: 2 additions & 2 deletions src/features/storage/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = async function(creationMode: CreationMode) {

if (creationMode === "MANUAL") {
let regionsList = await az<AzureRegion[]>(
`account list-locations --query '[].{name:name, id:id, displayName:displayName}'`,
`account list-locations --query "[].{name:name, id:id, displayName:displayName}"`,
`Loading your regions (this may take few minutes)...`
);
({ name } = await askForStorageAccountDetails(regionsList, name));
Expand All @@ -28,7 +28,7 @@ module.exports = async function(creationMode: CreationMode) {
// https://docs.microsoft.com/en-us/cli/azure/storage/account?view=azure-cli-latest#az-storage-account-create
// --kind StorageV2 is required for static websites
let storage = await az<AzureStorage>(
`storage account create --location "${resourceGroup.location}" --name "${name}" --subscription "${subscription.id}" --resource-group "${resourceGroup.name}" --kind StorageV2 --tag 'x-created-by=hexa' --query '{name:name, id:id, location:location}'`,
`storage account create --location "${resourceGroup.location}" --name "${name}" --subscription "${subscription.id}" --resource-group "${resourceGroup.name}" --kind StorageV2 --tag "x-created-by=hexa" --query "{name:name, id:id, location:location}"`,
`Creating storage account ${chalk.cyan(name)} (this may take few minutes)...`
);

Expand Down
2 changes: 1 addition & 1 deletion src/features/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = async function() {

// https://docs.microsoft.com/en-us/cli/azure/storage/account?view=azure-cli-latest#az-storage-account-list
let storageAccountsList = await az<AzureStorage[]>(
`storage account list --resource-group "${resourceGroup.name}" --subscription "${subscription.id}" --query '[].{name:name, id:id, location:location, tags:tags}'`,
`storage account list --resource-group "${resourceGroup.name}" --subscription "${subscription.id}" --query "[].{name:name, id:id, location:location, tags:tags}"`,
`Checking storage accounts for resource group ${chalk.cyan(resourceGroup.name)}...`
);

Expand Down
2 changes: 1 addition & 1 deletion src/features/storage/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = async function() {
} else {
// https://docs.microsoft.com/en-us/cli/azure/storage/account?view=azure-cli-latest#az-storage-account-show-connection-string
let connectionString = await az<string>(
`storage account show-connection-string --name "${storage.name}" --resource-group "${resourceGroup.name}" --subscription "${subscription.name}" --query 'connectionString'`,
`storage account show-connection-string --name "${storage.name}" --resource-group "${resourceGroup.name}" --subscription "${subscription.name}" --query "connectionString"`,
`Fetching a connection string for storage account ${chalk.cyan(storage.name)}...`
);
saveEnvFile("AZURE_STORAGE_CONNECTION_STRING", connectionString);
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ console.log(prettyFont.string);
// set confiuration
// WARNING: order matters
if (program.yolo) {
program.force = true;
program.yes = true;
program.auto = true;
program.token = true;
process.env.HEXA_YOLO_MODE = "1";
Expand All @@ -61,7 +61,7 @@ console.log(prettyFont.string);
if (program.debug) {
process.env.DEBUG = "*";
}
if (program.force) {
if (program.yes) {
process.env.HEXA_FORCE_MODE = "1";
}
if (program.manual === false) {
Expand Down

0 comments on commit d389249

Please sign in to comment.