Skip to content

Commit

Permalink
Fix skip auth arg to skip environment file steps
Browse files Browse the repository at this point in the history
  • Loading branch information
dremin committed Oct 25, 2023
1 parent 334bf58 commit c850ca7
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions scripts/setup-environment.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as constants from "./common/constants.mjs";
// example usage of all possible options:
// node scripts/setup-environment.mjs --skip-install --env=dev --packages=serverless-functions,serverless-schedule-manager

let skipAuthStep = false;
let skipEnvSetup = false;
let skipInstallStep = false;
let overwrite = false;
let uninstall = false;
Expand All @@ -29,8 +29,8 @@ for (let i = 2; i < process.argv.length; i++) {
overwrite = true;
} else if (process.argv[i].startsWith('--uninstall')) {
uninstall = true;
} else if (process.argv[i].startsWith('--skip-auth')) {
skipAuthStep = true;
} else if (process.argv[i].startsWith('--skip-env')) {
skipEnvSetup = true;
}
}

Expand All @@ -48,9 +48,9 @@ const execute = async () => {
console.log("");
}

const account = skipAuthStep ? {} : await getTwilioAccount();
const account = skipEnvSetup ? {} : await getTwilioAccount();

if (!account && !skipAuthStep) {
if (!account && !skipEnvSetup) {
// No account provided
outputEnd();
return;
Expand All @@ -73,28 +73,30 @@ const execute = async () => {
packages = defaultPackages;
}

// Fetch and save env files for each package
for (const path of packages) {
const envFile = `./${path}/.env${environment ? `.${environment}` : ''}`;
const exampleFile = `./${path}/.env.example`;
let environmentData = await fillReplacements(envFile, exampleFile, account, environment, overwrite);
allReplacements = { ...allReplacements, ...environmentData };
}

if (packages.includes(constants.flexConfigDir)) {
// We also need to populate flex-config
let configEnv = environment;
if (!environment) configEnv = 'local';
if (!skipEnvSetup) {
// Fetch and save env files for each package
for (const path of packages) {
const envFile = `./${path}/.env${environment ? `.${environment}` : ''}`;
const exampleFile = `./${path}/.env.example`;
let environmentData = await fillReplacements(envFile, exampleFile, account, environment, overwrite);
allReplacements = { ...allReplacements, ...environmentData };
}

const configFile = `./${constants.flexConfigDir}/ui_attributes.${configEnv}.json`;
const exampleFile = `./${constants.flexConfigDir}/ui_attributes.example.json`;
let configData = await fillReplacements(configFile, exampleFile, account, configEnv, overwrite);
allReplacements = { ...allReplacements, ...configData };
}

if (!environment) {
// When running locally, we need to generate appConfig.js
saveAppConfig(overwrite);
if (packages.includes(constants.flexConfigDir)) {
// We also need to populate flex-config
let configEnv = environment;
if (!environment) configEnv = 'local';

const configFile = `./${constants.flexConfigDir}/ui_attributes.${configEnv}.json`;
const exampleFile = `./${constants.flexConfigDir}/ui_attributes.example.json`;
let configData = await fillReplacements(configFile, exampleFile, account, configEnv, overwrite);
allReplacements = { ...allReplacements, ...configData };
}

if (!environment) {
// When running locally, we need to generate appConfig.js
saveAppConfig(overwrite);
}
}

if (!skipInstallStep || uninstall) {
Expand Down

0 comments on commit c850ca7

Please sign in to comment.