Skip to content

Commit

Permalink
Added warning when CLI build is pointing to non production environment
Browse files Browse the repository at this point in the history
  • Loading branch information
aumkar committed Oct 25, 2024
1 parent 5c40347 commit 692d622
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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 692d622

Please sign in to comment.