Skip to content

Commit

Permalink
fix: change to ignore scripts boolean instead of skip version scripts…
Browse files Browse the repository at this point in the history
… array.
  • Loading branch information
sidtagirisa committed Aug 9, 2020
1 parent 50670d8 commit 94b2961
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 41 deletions.
6 changes: 1 addition & 5 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function main(args: string[]): Promise<void> {
}
}

function progress({ event, script, updatedFiles, skippedFiles, newVersion, skippedScripts }: VersionBumpProgress): void {
function progress({ event, script, updatedFiles, skippedFiles, newVersion }: VersionBumpProgress): void {
switch (event) {
case ProgressEvent.FileUpdated:
console.log(success, `Updated ${updatedFiles.pop()} to ${newVersion}`);
Expand All @@ -53,10 +53,6 @@ function progress({ event, script, updatedFiles, skippedFiles, newVersion, skipp
console.log(info, `${skippedFiles.pop()} did not need to be updated`);
break;

case ProgressEvent.ScriptSkipped:
console.log(success, `Script skipped ${skippedScripts.pop()}`);
break;

case ProgressEvent.GitCommit:
console.log(success, "Git commit");
break;
Expand Down
4 changes: 2 additions & 2 deletions src/cli/parse-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function parseArgs(argv: string[]): ParsedArgs {
{ name: "quiet", alias: "q", type: Boolean },
{ name: "version", alias: "v", type: Boolean },
{ name: "help", alias: "h", type: Boolean },
{ name: "skip-version-scripts", type: String, multiple: true, defaultValue: []},
{ name: "ignore-scripts", type: Boolean },
{ name: "files", type: String, multiple: true, defaultOption: true },
],
{ argv }
Expand All @@ -49,7 +49,7 @@ export function parseArgs(argv: string[]): ParsedArgs {
all: args.all as boolean,
noVerify: args["no-verify"] as boolean,
files: args.files as string[],
skipVersionScripts: args["skip-version-scripts"] as string[],
ignoreScripts: args["ignore-scripts"] as boolean,
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/normalize-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface NormalizedOptions {
files: string[];
cwd: string;
interface: Interface;
skipVersionScripts: string[];
ignoreScripts: boolean;
}

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

let skipVersionScripts = raw.skipVersionScripts as string[];
let ignoreScripts = raw.ignoreScripts as boolean;

return { release, commit, tag, push, files, cwd, interface: ui, skipVersionScripts };
return { release, commit, tag, push, files, cwd, interface: ui, ignoreScripts };
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ interface OperationState {
tagName: string;
updatedFiles: string[];
skippedFiles: string[];
skippedScripts: string[];
}

interface UpdateOperationState extends Partial<OperationState> {
Expand Down Expand Up @@ -44,7 +43,6 @@ export class Operation {
tagName: "",
updatedFiles: [],
skippedFiles: [],
skippedScripts: [],
};

/**
Expand Down
13 changes: 1 addition & 12 deletions src/run-npm-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ export async function runNpmScript(script: NpmScript, operation: Operation): Pro
let { data: manifest } = await readJsonFile("package.json", cwd);

if (isManifest(manifest) && hasScript(manifest, script)) {
if (shouldSkipScript(script, operation.options.skipVersionScripts)) {
operation.update({ event: ProgressEvent.ScriptSkipped, skippedScripts: operation.state.skippedScripts.concat(script) });
}
else {
if (!operation.options.ignoreScripts) {
await ezSpawn.async("npm", ["run", script, "--silent"], { stdio: "inherit" });
operation.update({ event: ProgressEvent.NpmScript, script });
}

}

return operation;
Expand All @@ -38,10 +34,3 @@ function hasScript(manifest: Manifest, script: NpmScript): boolean {

return false;
}

/**
* Determines whether the specified script should be skipped.
*/
function shouldSkipScript(script: NpmScript, skipVersionScripts: string[]): boolean {
return skipVersionScripts.includes(script);
}
9 changes: 4 additions & 5 deletions src/types/version-bump-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,11 @@ export interface VersionBumpOptions {
interface?: boolean | InterfaceOptions;

/**
* The version scripts to be skipped
* Options can be any or all of the following separated with space:
* preversion, version and postversion
* Defaults to []
* Indicates whether to ignore version scripts.
*
* Defaults to `false`.
*/
skipVersionScripts?: string[];
ignoreScripts?: boolean;

/**
* A callback that is provides information about the progress of the `versionBump()` function.
Expand Down
1 change: 0 additions & 1 deletion src/types/version-bump-progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const enum ProgressEvent {
GitTag = "git tag",
GitPush = "git push",
NpmScript = "npm script",
ScriptSkipped = "script skipped",
}

/**
Expand Down
5 changes: 0 additions & 5 deletions src/types/version-bump-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,4 @@ export interface VersionBumpResults {
* The files that were not updated because they did not contain the old version number.
*/
skippedFiles: string[];

/**
* The version scripts which were skipped because they were explicitly specified to be skipped.
*/
skippedScripts: string[];
}
9 changes: 3 additions & 6 deletions test/specs/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ describe("versionBup() API", () => {
commit: false,
tag: false,
updatedFiles: ["package.json"],
skippedFiles: [],
skippedScripts: []
skippedFiles: []
});

// The package.json file should have been updated
Expand All @@ -54,8 +53,7 @@ describe("versionBup() API", () => {
commit: false,
tag: false,
updatedFiles: ["package.json"],
skippedFiles: [],
skippedScripts: []
skippedFiles: []
});

// The package.json file should have been updated
Expand Down Expand Up @@ -99,8 +97,7 @@ describe("versionBup() API", () => {
"README.md",
"subdir/deep/changelog.md"
],
skippedFiles: [],
skippedScripts: []
skippedFiles: []
});

// The CWD should not have changed
Expand Down

0 comments on commit 94b2961

Please sign in to comment.