Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added warning when CLI build is pointing to non production environment #320

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.`,
),
);
};
Loading