Skip to content

Commit

Permalink
feat!: enable commit tag push by default
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jun 15, 2022
1 parent 5d795b2 commit 7e304cd
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 103 deletions.
6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,7 @@
{
"name": "bumpp",
"version": "7.2.0",
"packageManager": "pnpm@7.2.1",
"description": "Automatically (or with prompts) bump your version number, commit changes, tag, and push to Git",
"keywords": [
"version",
Expand Down Expand Up @@ -38,7 +39,7 @@
"lint": "eslint src test",
"build": "tsup src/index.ts src/cli/index.ts --format esm,cjs --dts --clean",
"watch": "npm run build -- --watch src",
"start": "esno src/cli/dev.ts",
"start": "esno src/cli/run.ts",
"test": "mocha && npm run lint",
"coverage": "nyc node_modules/mocha/bin/mocha",
"upgrade": "npm-check -u && npm audit fix",
Expand All @@ -50,7 +51,6 @@
"@jsdevtools/chai-exec": "^2.1.1",
"@jsdevtools/eslint-config": "^1.1.4",
"@types/chai": "^4.2.21",
"@types/command-line-args": "^5.2.0",
"@types/inquirer": "^7.3.3",
"@types/mocha": "^8.2.3",
"@types/node": "^14.17.14",
Expand All @@ -72,8 +72,8 @@
},
"dependencies": {
"@jsdevtools/ez-spawn": "^3.0.4",
"cac": "^6.7.12",
"chalk": "^4.1.2",
"command-line-args": "^5.2.0",
"globby": "^11.0.4",
"prompts": "^2.4.1",
"semver": "^7.3.5"
Expand Down
80 changes: 29 additions & 51 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions src/cli/dev.ts

This file was deleted.

74 changes: 32 additions & 42 deletions src/cli/parse-args.ts
@@ -1,9 +1,10 @@
import commandLineArgs from "command-line-args";
import { valid as isValidVersion } from "semver";
import { isReleaseType } from "../release-type";
import { VersionBumpOptions } from "../types/version-bump-options";
import { ExitCode } from "./exit-code";
import { usageText } from "./help";
import cac from 'cac'
import {version} from '../../package.json'

/**
* The parsed command-line arguments
Expand All @@ -20,56 +21,44 @@ export interface ParsedArgs {
*/
export function parseArgs(argv: string[]): ParsedArgs {
try {
let args = commandLineArgs(
[
{ name: "preid", type: String },
{ name: "commit", alias: "c", type: String },
{ name: "tag", alias: "t", type: String },
{ name: "push", alias: "p", type: Boolean },
{ name: "all", alias: "a", type: Boolean },
{ name: "no-verify", type: Boolean },
{ name: "quiet", alias: "q", type: Boolean },
{ 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 }
);

const cli = cac('bumpp')

cli
.version(version)
.usage('[...files]')
.option('--preid <preid>', 'ID for prerelease')
.option('--all', 'Include all files')
.option('-c, --commit [msg]', 'Commit message', {default: true})
.option('-t, --tag [tag]', 'Tag name', {default: true})
.option('-p, --push', 'Push to remote', {default: true})
.option('--no-verify', 'Skip git verification')
.option('--ignore-scripts', 'Ignore scripts', {default: false})
.option('-q, --quiet', 'Quiet mode')
.option('-v, --version <version>', 'Tagert version')
.option('-x, --execute <command>', 'Commands to execute after version bumps')
.help()

const args = cli.parse().options


let parsedArgs: ParsedArgs = {
help: args.help as boolean,
version: args.version as boolean,
quiet: args.quiet as boolean,
options: {
preid: args.preid as string,
commit: args.commit as string | boolean,
tag: args.tag as string | boolean,
push: args.push as boolean,
all: args.all as boolean,
noVerify: args["no-verify"] as boolean,
files: args.files as string[],
ignoreScripts: args["ignore-scripts"] as boolean,
execute: args.execute as string | undefined,
preid: args.preid,
commit: args.commit,
tag: args.tag,
push: args.push,
all: args.all,
noVerify: !args.verify,
files: args['--'],
ignoreScripts: args.ignoreScripts,
execute: args.execute,
}
};

// If --preid is used without an argument, then throw an error, since it's probably a mistake.
// If they want to use the default value ("beta"), then they should not pass the argument at all
if (args.preid === null) {
throw new Error("The --preid option requires a value, such as \"alpha\", \"beta\", etc.");
}

// If --commit is used without an argument, then treat it as a boolean flag
if (args.commit === null) {
parsedArgs.options.commit = true;
}

// If --tag is used without an argument, then treat it as a boolean flag
if (args.tag === null) {
parsedArgs.options.tag = true;
}

// If a version number or release type was specified, then it will mistakenly be added to the "files" array
if (parsedArgs.options.files && parsedArgs.options.files.length > 0) {
Expand All @@ -81,6 +70,7 @@ export function parseArgs(argv: string[]): ParsedArgs {
}
}


return parsedArgs;
}
catch (error) {
Expand Down

0 comments on commit 7e304cd

Please sign in to comment.