diff --git a/.changeset/proud-socks-cry.md b/.changeset/proud-socks-cry.md new file mode 100644 index 00000000..1b30d597 --- /dev/null +++ b/.changeset/proud-socks-cry.md @@ -0,0 +1,6 @@ +--- +"@pantheon-systems/pcc-cli": patch +--- + +Added a warning message when CLI build is pointing to non-production +environment. diff --git a/packages/cli/src/cli/index.ts b/packages/cli/src/cli/index.ts index aa897dbe..dcb2a8fc 100755 --- a/packages/cli/src/cli/index.ts +++ b/packages/cli/src/cli/index.ts @@ -2,6 +2,7 @@ import ora from "ora"; import yargs from "yargs"; import { hideBin } from "yargs/helpers"; +import { checkEnvironment } from "../lib/checkEnvironment"; import checkUpdate, { getPackageDetails } from "../lib/checkUpdate"; import { isProgramInstalled } from "../lib/utils"; import { @@ -68,6 +69,7 @@ yargs(hideBin(process.argv)) .scriptName("pcc") .usage("$0 ") .middleware(configureMiddleware(checkUpdate)) + .middleware(configureMiddleware(checkEnvironment)) .strictCommands() .demandCommand() .version(false) diff --git a/packages/cli/src/lib/apiConfig.ts b/packages/cli/src/lib/apiConfig.ts index f21daa2c..7eb5f3f6 100644 --- a/packages/cli/src/lib/apiConfig.ts +++ b/packages/cli/src/lib/apiConfig.ts @@ -1,6 +1,6 @@ import { getLocalConfigDetails } from "./localStorage"; -enum TargetEnvironment { +export enum TargetEnvironment { production = "production", staging = "staging", test = "test", diff --git a/packages/cli/src/lib/checkEnvironment.ts b/packages/cli/src/lib/checkEnvironment.ts new file mode 100644 index 00000000..9c18243f --- /dev/null +++ b/packages/cli/src/lib/checkEnvironment.ts @@ -0,0 +1,17 @@ +import chalk from "chalk"; +import { TargetEnvironment } from "./apiConfig"; +import { getLocalConfigDetails } from "./localStorage"; + +export const checkEnvironment = async () => { + const config = await getLocalConfigDetails(); + const env = + config?.targetEnvironment || + (process.env.NODE_ENV as TargetEnvironment) || + "production"; + if (env !== TargetEnvironment.production) + console.log( + chalk.yellow( + `WARNING: This CLI build is pointing to "${env}" environment.`, + ), + ); +};