Skip to content

Commit 104a055

Browse files
committed
feat(skip version scripts): add argument to skip if specified
feature to skip specified version scripts from running by default with a new argument
1 parent 67fd701 commit 104a055

File tree

8 files changed

+43
-4
lines changed

8 files changed

+43
-4
lines changed

src/cli/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function main(args: string[]): Promise<void> {
4343
}
4444
}
4545

46-
function progress({ event, script, updatedFiles, skippedFiles, newVersion }: VersionBumpProgress): void {
46+
function progress({ event, script, updatedFiles, skippedFiles, newVersion, skippedScripts }: VersionBumpProgress): void {
4747
switch (event) {
4848
case ProgressEvent.FileUpdated:
4949
console.log(success, `Updated ${updatedFiles.pop()} to ${newVersion}`);
@@ -53,6 +53,10 @@ function progress({ event, script, updatedFiles, skippedFiles, newVersion }: Ver
5353
console.log(info, `${skippedFiles.pop()} did not need to be updated`);
5454
break;
5555

56+
case ProgressEvent.ScriptSkipped:
57+
console.log(success, `Script skipped ${skippedScripts.pop()}`);
58+
break;
59+
5660
case ProgressEvent.GitCommit:
5761
console.log(success, "Git commit");
5862
break;

src/cli/parse-args.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export function parseArgs(argv: string[]): ParsedArgs {
3131
{ name: "quiet", alias: "q", type: Boolean },
3232
{ name: "version", alias: "v", type: Boolean },
3333
{ name: "help", alias: "h", type: Boolean },
34+
{ name: "skip-version-scripts", type: String, multiple: true, defaultValue: []},
3435
{ name: "files", type: String, multiple: true, defaultOption: true },
3536
],
3637
{ argv }
@@ -48,6 +49,7 @@ export function parseArgs(argv: string[]): ParsedArgs {
4849
all: args.all as boolean,
4950
noVerify: args["no-verify"] as boolean,
5051
files: args.files as string[],
52+
skipVersionScripts: args["skip-version-scripts"] as string[],
5153
}
5254
};
5355

src/normalize-options.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface NormalizedOptions {
5555
files: string[];
5656
cwd: string;
5757
interface: Interface;
58+
skipVersionScripts: string[];
5859
}
5960

6061
/**
@@ -131,7 +132,9 @@ export async function normalizeOptions(raw: VersionBumpOptions): Promise<Normali
131132
throw new Error("Cannot prompt for the version number because input or output has been disabled.");
132133
}
133134

134-
return { release, commit, tag, push, files, cwd, interface: ui };
135+
let skipVersionScripts = raw.skipVersionScripts as string[];
136+
137+
return { release, commit, tag, push, files, cwd, interface: ui, skipVersionScripts };
135138
}
136139

137140
/**

src/operation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface OperationState {
1515
tagName: string;
1616
updatedFiles: string[];
1717
skippedFiles: string[];
18+
skippedScripts: string[];
1819
}
1920

2021
interface UpdateOperationState extends Partial<OperationState> {
@@ -43,6 +44,7 @@ export class Operation {
4344
tagName: "",
4445
updatedFiles: [],
4546
skippedFiles: [],
47+
skippedScripts: [],
4648
};
4749

4850
/**
@@ -60,6 +62,7 @@ export class Operation {
6062
tag: options.tag ? state.tagName : false,
6163
updatedFiles: state.updatedFiles.slice(),
6264
skippedFiles: state.skippedFiles.slice(),
65+
skippedScripts: state.skippedScripts.slice(),
6366
};
6467
}
6568

src/run-npm-script.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ export async function runNpmScript(script: NpmScript, operation: Operation): Pro
1313
let { data: manifest } = await readJsonFile("package.json", cwd);
1414

1515
if (isManifest(manifest) && hasScript(manifest, script)) {
16-
await ezSpawn.async("npm", ["run", script, "--silent"], { stdio: "inherit" });
17-
operation.update({ event: ProgressEvent.NpmScript, script });
16+
if (shouldSkipScript(script, operation.options.skipVersionScripts)) {
17+
operation.update({ event: ProgressEvent.ScriptSkipped, skippedScripts: operation.state.skippedScripts.concat(script) });
18+
}
19+
else {
20+
await ezSpawn.async("npm", ["run", script, "--silent"], { stdio: "inherit" });
21+
operation.update({ event: ProgressEvent.NpmScript, script });
22+
}
23+
1824
}
1925

2026
return operation;
@@ -32,3 +38,10 @@ function hasScript(manifest: Manifest, script: NpmScript): boolean {
3238

3339
return false;
3440
}
41+
42+
/**
43+
* Determines whether the specified script should be skipped.
44+
*/
45+
function shouldSkipScript(script: NpmScript, skipVersionScripts: string[]): boolean {
46+
return skipVersionScripts.includes(script);
47+
}

src/types/version-bump-options.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ export interface VersionBumpOptions {
9292
*/
9393
interface?: boolean | InterfaceOptions;
9494

95+
/**
96+
* The version scripts to be skipped
97+
* Options can be any or all of the following separated with space:
98+
* preversion, version and postversion
99+
* Defaults to []
100+
*/
101+
skipVersionScripts?: string[];
102+
95103
/**
96104
* A callback that is provides information about the progress of the `versionBump()` function.
97105
*/

src/types/version-bump-progress.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const enum ProgressEvent {
1010
GitTag = "git tag",
1111
GitPush = "git push",
1212
NpmScript = "npm script",
13+
ScriptSkipped = "script skipped",
1314
}
1415

1516
/**

src/types/version-bump-results.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@ export interface VersionBumpResults {
4242
* The files that were not updated because they did not contain the old version number.
4343
*/
4444
skippedFiles: string[];
45+
46+
/**
47+
* The version scripts which were skipped because they were explicitly specified to be skipped.
48+
*/
49+
skippedScripts: string[];
4550
}

0 commit comments

Comments
 (0)