From d389249cbae45cdf14133d8c32c2cfd22aa7a4e8 Mon Sep 17 00:00:00 2001 From: Wassim Chegham Date: Fri, 18 Oct 2019 12:33:57 +0200 Subject: [PATCH] fix: support commands on Windows --- src/commands/login.ts | 2 +- src/core/utils.ts | 22 +++++++++++++++++++++- src/features/database/index.ts | 8 ++++---- src/features/functions/index.ts | 4 ++-- src/features/hosting/index.ts | 2 +- src/features/resource-group/create.ts | 4 ++-- src/features/resource-group/index.ts | 2 +- src/features/storage/create.ts | 4 ++-- src/features/storage/index.ts | 2 +- src/features/storage/tokens.ts | 2 +- src/index.ts | 4 ++-- 11 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/commands/login.ts b/src/commands/login.ts index 71f8e61..3b1003a 100644 --- a/src/commands/login.ts +++ b/src/commands/login.ts @@ -3,7 +3,7 @@ import { az, Config, saveWorkspace } from "../core/utils"; module.exports = async function() { let subscriptionsList = await az( - `login --query '[].{name:name, state:state, id:id}'`, + `login --query "[].{name:name, state:state, id:id}"`, `Loading subscriptions...` ); diff --git a/src/core/utils.ts b/src/core/utils.ts index 05461a6..0810a81 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -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 @@ -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() { diff --git a/src/features/database/index.ts b/src/features/database/index.ts index ae7214d..fe7db06 100644 --- a/src/features/database/index.ts +++ b/src/features/database/index.ts @@ -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( - `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)}...` ); @@ -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( - `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)}...` ); @@ -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( - `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)}...` ); @@ -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( - `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)}`); diff --git a/src/features/functions/index.ts b/src/features/functions/index.ts index 07faad1..f77e691 100644 --- a/src/features/functions/index.ts +++ b/src/features/functions/index.ts @@ -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( - `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)); @@ -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( - `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)}`); diff --git a/src/features/hosting/index.ts b/src/features/hosting/index.ts index 5e58dbc..e58a634 100644 --- a/src/features/hosting/index.ts +++ b/src/features/hosting/index.ts @@ -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( - `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)}...` ); diff --git a/src/features/resource-group/create.ts b/src/features/resource-group/create.ts index 5f293fb..9a03751 100644 --- a/src/features/resource-group/create.ts +++ b/src/features/resource-group/create.ts @@ -11,7 +11,7 @@ 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( - `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)); @@ -19,7 +19,7 @@ module.exports = async function(creationMode: CreationMode) { // https://docs.microsoft.com/en-us/cli/azure/group?view=azure-cli-latest#az-group-create let resourceGroup = await az( - `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)}` ); diff --git a/src/features/resource-group/index.ts b/src/features/resource-group/index.ts index bb789f7..4e965cb 100644 --- a/src/features/resource-group/index.ts +++ b/src/features/resource-group/index.ts @@ -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( - `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...` ); diff --git a/src/features/storage/create.ts b/src/features/storage/create.ts index c6378cd..8894a2f 100644 --- a/src/features/storage/create.ts +++ b/src/features/storage/create.ts @@ -19,7 +19,7 @@ module.exports = async function(creationMode: CreationMode) { if (creationMode === "MANUAL") { let regionsList = await az( - `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)); @@ -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( - `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)...` ); diff --git a/src/features/storage/index.ts b/src/features/storage/index.ts index baf14a4..449b47c 100644 --- a/src/features/storage/index.ts +++ b/src/features/storage/index.ts @@ -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( - `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)}...` ); diff --git a/src/features/storage/tokens.ts b/src/features/storage/tokens.ts index 1c0933d..28c3d26 100644 --- a/src/features/storage/tokens.ts +++ b/src/features/storage/tokens.ts @@ -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( - `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); diff --git a/src/index.ts b/src/index.ts index 1ee666c..eea892b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"; @@ -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) {