From 692d6224d7be896cf9445bf05d4af1a948eaa4f4 Mon Sep 17 00:00:00 2001 From: Omkar Date: Fri, 25 Oct 2024 15:18:09 +0530 Subject: [PATCH 1/2] Added warning when CLI build is pointing to non production environment --- packages/cli/src/cli/index.ts | 2 ++ packages/cli/src/lib/apiConfig.ts | 2 +- packages/cli/src/lib/checkEnvironment.ts | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 packages/cli/src/lib/checkEnvironment.ts 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.`, + ), + ); +}; From 39b76049343e079e69925fba23946485217e0238 Mon Sep 17 00:00:00 2001 From: Omkar Date: Fri, 25 Oct 2024 15:35:30 +0530 Subject: [PATCH 2/2] added changeset --- .changeset/proud-socks-cry.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/proud-socks-cry.md 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.