Skip to content

Commit

Permalink
feat: new --execute arg
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 7, 2021
1 parent 754d825 commit eb2bd5a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# bumpp

[![NPM version](https://img.shields.io/npm/v/bumpp?color=a1b858&label=)](https://www.npmjs.com/package/bumpp)

Forked from [`version-bump-prompt`](https://github.com/JS-DevTools/version-bump-prompt)

###### Changes in this fork

- Renamed to `bumpp` - so you can use `npx bumpp` directly
- Add a new argument `--execute` to execute the command before committing

<details>
<summary>Original README</summary>

# Version Bump Prompt

[![Cross-Platform Compatibility](https://jstools.dev/img/badges/os-badges.svg)](https://github.com/JS-DevTools/version-bump-prompt/actions)
Expand Down Expand Up @@ -265,3 +279,5 @@ Thanks to these awesome companies for their support of Open Source developers
[![Coveralls](https://jstools.dev/img/badges/coveralls.svg)](https://coveralls.io)
[![Travis CI](https://jstools.dev/img/badges/travis-ci.svg)](https://travis-ci.com)
[![SauceLabs](https://jstools.dev/img/badges/sauce-labs.svg)](https://saucelabs.com)

</details>
2 changes: 2 additions & 0 deletions src/cli/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ options:
-v, --version Show the version number
-x, --execute Excute additional command after bumping and before commiting
-q, --quiet Suppress unnecessary output
-h, --help Show usage information
Expand Down
2 changes: 2 additions & 0 deletions src/cli/parse-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function parseArgs(argv: string[]): ParsedArgs {
{ name: "version", alias: "v", type: Boolean },
{ name: "help", alias: "h", type: Boolean },
{ name: "ignore-scripts", type: Boolean },
{ name: "execute", alias: "x", type: String },
{ name: "files", type: String, multiple: true, defaultOption: true },
],
{ argv }
Expand All @@ -50,6 +51,7 @@ export function parseArgs(argv: string[]): ParsedArgs {
noVerify: args["no-verify"] as boolean,
files: args.files as string[],
ignoreScripts: args["ignore-scripts"] as boolean,
execute: args.execute as string | undefined,
}
};

Expand Down
4 changes: 3 additions & 1 deletion src/normalize-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface NormalizedOptions {
cwd: string;
interface: Interface;
ignoreScripts: boolean;
execute?: string;
}

/**
Expand All @@ -69,6 +70,7 @@ export async function normalizeOptions(raw: VersionBumpOptions): Promise<Normali
let noVerify = Boolean(raw.noVerify);
let cwd = raw.cwd || process.cwd();
let ignoreScripts = Boolean(raw.ignoreScripts);
let execute = raw.execute;

let release: Release;
if (!raw.release || raw.release === "prompt") {
Expand Down Expand Up @@ -133,7 +135,7 @@ export async function normalizeOptions(raw: VersionBumpOptions): Promise<Normali
throw new Error("Cannot prompt for the version number because input or output has been disabled.");
}

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

/**
Expand Down
6 changes: 6 additions & 0 deletions src/types/version-bump-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ export interface VersionBumpOptions {
* A callback that is provides information about the progress of the `versionBump()` function.
*/
progress?(progress: VersionBumpProgress): void;


/**
* Excute additional command after bumping and before commiting
*/
execute?: string;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/version-bump.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ezSpawn = require("@jsdevtools/ez-spawn");
import { getNewVersion } from "./get-new-version";
import { getOldVersion } from "./get-old-version";
import { gitCommit, gitPush, gitTag } from "./git";
Expand Down Expand Up @@ -54,6 +55,10 @@ export async function versionBump(arg: VersionBumpOptions | string = {}): Promis
// Update the version number in all files
await updateFiles(operation);

if (operation.options.execute) {
await ezSpawn.async(operation.options.execute, { stdio: "inherit" });
}

// Run npm version script, if any
await runNpmScript(NpmScript.Version, operation);

Expand Down

0 comments on commit eb2bd5a

Please sign in to comment.