aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/packages/turbo-ignore/src/args.ts
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
commitdd84b9d64fb98746a230cd24233ff50a562c39c9 (patch)
treeb583261ef00b3afe72ec4d6dacb31e57779a6faf /packages/turbo-ignore/src/args.ts
parent0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff)
downloadHydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz
HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip
Diffstat (limited to 'packages/turbo-ignore/src/args.ts')
-rw-r--r--packages/turbo-ignore/src/args.ts89
1 files changed, 89 insertions, 0 deletions
diff --git a/packages/turbo-ignore/src/args.ts b/packages/turbo-ignore/src/args.ts
new file mode 100644
index 0000000..8d6015c
--- /dev/null
+++ b/packages/turbo-ignore/src/args.ts
@@ -0,0 +1,89 @@
+import pkg from "../package.json";
+import { TurboIgnoreArgs } from "./types";
+import {
+ skipAllCommits,
+ forceAllCommits,
+ skipWorkspaceCommits,
+ forceWorkspaceCommits,
+} from "./checkCommit";
+
+export const help = `
+turbo-ignore
+
+Automatically ignore builds that have no changes
+
+Usage:
+ $ npx turbo-ignore [<workspace>] [flags...]
+
+If <workspace> is not provided, it will be inferred from the "name"
+field of the "package.json" located at the current working directory.
+
+Flags:
+ --fallback=<ref> On Vercel, if no previously deployed SHA is available to compare against,
+ fallback to comparing against the provided ref
+ --help, -h Show this help message
+ --version, -v Show the version of this script
+
+---
+
+turbo-ignore will also check for special commit messages to indicate if a build should be skipped or not.
+
+Skip turbo-ignore check and automatically ignore:
+${[...skipAllCommits, ...skipWorkspaceCommits({ workspace: "<workspace>" })]
+ .map((msg) => ` - ${msg}`)
+ .join("\n")}
+
+Skip turbo-ignore check and automatically deploy:
+${[...forceAllCommits, ...forceWorkspaceCommits({ workspace: "<workspace>" })]
+ .map((msg) => ` - ${msg}`)
+ .join("\n")}
+`;
+
+// simple args parser because we don't want to pull in a dependency
+// and we don't need many features
+export default function parseArgs({
+ argv,
+}: {
+ argv: Array<string>;
+}): TurboIgnoreArgs {
+ const args: TurboIgnoreArgs = { directory: process.cwd() };
+
+ // find all flags
+ const flags = new Set(
+ argv
+ .filter((args) => args.startsWith("-"))
+ .map((flag) => flag.replace(/-/g, ""))
+ );
+
+ // handle help flag and exit
+ if (flags.has("help") || flags.has("h")) {
+ console.log(help);
+ process.exit(0);
+ }
+ // handle version flag and exit
+ if (flags.has("version") || flags.has("v")) {
+ console.log(pkg.version);
+ process.exit(0);
+ }
+
+ // set workspace (if provided)
+ if (argv.length && !argv[0].startsWith("-")) {
+ args.workspace = argv[0];
+ }
+
+ // set task (if provided)
+ const taskArgSentinel = "--task=";
+ const taskArg = argv.find((arg) => arg.startsWith(taskArgSentinel));
+ if (taskArg && taskArg.length > taskArgSentinel.length) {
+ args.task = taskArg.split("=")[1];
+ }
+
+ // set fallback (if provided)
+ const fallbackSentinel = "--fallback=";
+ const fallbackArg = argv.find((arg) => arg.startsWith(fallbackSentinel));
+ if (fallbackArg && fallbackArg.length > fallbackSentinel.length) {
+ args.fallback = fallbackArg.split("=")[1];
+ }
+
+ return args;
+}