Skip to content

Commit

Permalink
feat: introduce -r option
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Feb 23, 2023
1 parent ce6badf commit c12b228
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ Forked from [`version-bump-prompt`](https://github.com/JS-DevTools/version-bump-
- Use current version's `preid` when avaliable.
- Confirmation before bumping.
- Enable `--commit` `--tag` `--push` by default. (opt-out by `--no-push`, etc.)
- `-r` or `--recursive` to bump all packages in the monorepo.
- Conventional Commits by default.
11 changes: 11 additions & 0 deletions src/cli/parse-args.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { valid as isValidVersion } from 'semver'
import cac from 'cac'
import c from 'picocolors'
import { isReleaseType } from '../release-type'
import type { VersionBumpOptions } from '../types/version-bump-options'
import { version } from '../../package.json'
Expand Down Expand Up @@ -31,6 +32,7 @@ export function parseArgs(): ParsedArgs {
.option('-t, --tag [tag]', 'Tag name', { default: true })
.option('-p, --push', 'Push to remote', { default: true })
.option('-y, --yes', 'Skip confirmation')
.option('-r, --recursive', 'Bump package.json files recursively', { default: false })
.option('--no-verify', 'Skip git verification')
.option('--ignore-scripts', 'Ignore scripts', { default: false })
.option('-q, --quiet', 'Quiet mode')
Expand All @@ -56,6 +58,7 @@ export function parseArgs(): ParsedArgs {
files: [...args['--'] || [], ...result.args],
ignoreScripts: args.ignoreScripts,
execute: args.execute,
recursive: !!args.recursive,
},
}

Expand All @@ -69,6 +72,14 @@ export function parseArgs(): ParsedArgs {
}
}

if (parsedArgs.options.recursive) {
if (parsedArgs.options.files?.length)
console.log(c.yellow('The --recursive option is ignored when files are specified'))

else
parsedArgs.options.files = ['package.json', 'package-lock.json', 'packages/**/package.json']

This comment has been minimized.

Copy link
@meteorlxy

meteorlxy Feb 27, 2023

@antfu What about reading the workspace config? Not all repo is using packages/**

This comment has been minimized.

Copy link
@antfu

antfu Feb 27, 2023

Author Member

For sure, great if you want to work on it. Or I will say you can always explicitly list the file :P

}

return parsedArgs
}
catch (error) {
Expand Down
8 changes: 7 additions & 1 deletion src/normalize-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ export async function normalizeOptions(raw: VersionBumpOptions): Promise<Normali
raw.files?.length
? raw.files
: ['package.json', 'package-lock.json'],
{ cwd, onlyFiles: true },
{
cwd,
onlyFiles: true,
ignore: [
'**/{.git,node_modules,bower_components,__tests__,fixtures,fixture}/**',
],
},
)

let ui: Interface
Expand Down
7 changes: 7 additions & 0 deletions src/types/version-bump-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ export interface VersionBumpOptions {
* Excute additional command after bumping and before commiting
*/
execute?: string

/**
* Bump the files recursively for monorepo. Only works without `files` option.
*
* @default false
*/
recursive?: boolean
}

/**
Expand Down

0 comments on commit c12b228

Please sign in to comment.