Skip to content

Commit

Permalink
Merge pull request #320 from pantheon-systems/od/pcc-1584/showing-war…
Browse files Browse the repository at this point in the history
…ning-for-stage-build

Added warning when CLI build is pointing to non production environment
  • Loading branch information
kevinstubbs authored Oct 25, 2024
2 parents 5c40347 + 39b7604 commit 1cf635c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/proud-socks-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pantheon-systems/pcc-cli": patch
---

Added a warning message when CLI build is pointing to non-production
environment.
2 changes: 2 additions & 0 deletions packages/cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -68,6 +69,7 @@ yargs(hideBin(process.argv))
.scriptName("pcc")
.usage("$0 <cmd>")
.middleware(configureMiddleware(checkUpdate))
.middleware(configureMiddleware(checkEnvironment))
.strictCommands()
.demandCommand()
.version(false)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/apiConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getLocalConfigDetails } from "./localStorage";

enum TargetEnvironment {
export enum TargetEnvironment {
production = "production",
staging = "staging",
test = "test",
Expand Down
17 changes: 17 additions & 0 deletions packages/cli/src/lib/checkEnvironment.ts
Original file line number Diff line number Diff line change
@@ -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.`,
),
);
};

0 comments on commit 1cf635c

Please sign in to comment.