Skip to content

Commit

Permalink
feat: validate pckgs before building
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-dane committed Dec 20, 2024
1 parent e30bfec commit 083ec2e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
18 changes: 17 additions & 1 deletion packages/scripts/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dotenv.config({
import { Command } from "commander";

import { runBuild } from "./commands/build";
import { ALL_PACKAGES, CATEGORY_VM } from "./common/cli.constants";
import { ALL_PACKAGES, CATEGORY_VM, PCKG } from "./common/cli.constants";
import { startDeleteFlow } from "./commands/delete";
import { log } from "./common/cli.utils";
import { Options_Cli } from "./common/cli.types";
Expand Down Expand Up @@ -58,6 +58,21 @@ const getCliOptions = (program: Command): Options_Cli => {
return options;
};

const validatePackages = (packages: string[] | undefined) => {
if (!packages) {
log.error("Packages must be defined");
}
if (!packages?.includes(PCKG.NODE) && !packages?.includes(PCKG.WEB)) {
log.error(
`One or more of these pckgs isn't supported: ${(
packages as string[]
)?.toString()}`
);

process.exit(1);
}
};

const runScript = async () => {
const program = createProgram();
program.parse(process.argv);
Expand All @@ -68,6 +83,7 @@ const runScript = async () => {
const cmd = program.args[0];
switch (true) {
case cmd === "build": {
validatePackages(options.packages);
await runBuild(options);
break;
}
Expand Down
17 changes: 7 additions & 10 deletions packages/scripts/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,21 @@ import {
} from "@scripts/common/cli.utils";

export const runBuild = async (options: Options_Cli) => {
const env = options["environment"];
const vmInfo = await getVmInfo(env);
const vmInfo = await getVmInfo(options.environment);

const pckgs =
options["packages"] === undefined
options?.packages?.length === 0
? await getPckgsTo("build")
: options["packages"];
: (options.packages as string[]);

if (pckgs.includes(PCKG.NODE)) {
await buildNodePckgs(vmInfo, options["skipEnv"]);
await buildNodePckgs(vmInfo, options.skipEnv);
}

if (pckgs.includes(PCKG.WEB)) {
await buildWeb(vmInfo);
}
};

// eslint-disable-next-line @typescript-eslint/require-await
const buildNodePckgs = async (vmInfo: Info_VM, skipEnv?: boolean) => {
removeOldBuildFor(PCKG.NODE);
createNodeDirs();
Expand Down Expand Up @@ -78,10 +75,10 @@ const buildWeb = async (vmInfo: Info_VM) => {
log.success(`Done building web files.`);
log.tip(`
Now you'll probably want to:
- zip the build/web dir
- zip the build dir
- copy it to your ${destination} server
- unzip it
- run it`);
- unzip it and serve as the static assets
`);
process.exit(0);
};

Expand Down

0 comments on commit 083ec2e

Please sign in to comment.