Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: execute could receive a function #54

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Forked from [`version-bump-prompt`](https://github.com/JS-DevTools/version-bump-

- Renamed to `bumpp` - so you can use `npx bumpp` directly.
- Ships ESM and CJS bundles.
- Add a new argument `--execute` to execute the command before committing.
- Add a new argument `--execute` to execute the command, or execute a function before committing.
- Use the current version's `preid` when available.
- Confirmation before bumping.
- Enable `--commit` `--tag` `--push` by default. (opt-out by `--no-push`, etc.)
Expand All @@ -23,5 +23,8 @@ import { defineConfig } from 'bumpp'

export default defineConfig({
// ...options
execute(config) {
// ...`execute` could receive a function here
}
})
```
5 changes: 3 additions & 2 deletions src/normalize-options.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { Operation } from './operation'
import type { ReleaseType } from './release-type'
import type { VersionBumpOptions } from './types/version-bump-options'
import fsSync from 'node:fs'
import fs from 'node:fs/promises'
import process from 'node:process'
import { glob } from 'tinyglobby'
import yaml from 'js-yaml'
import { glob } from 'tinyglobby'
import { isReleaseType } from './release-type'

interface Interface {
Expand Down Expand Up @@ -61,7 +62,7 @@ export interface NormalizedOptions {
cwd: string
interface: Interface
ignoreScripts: boolean
execute?: string
execute?: string | ((config?: Operation) => void | PromiseLike<void>)
printCommits?: boolean
customVersion?: VersionBumpOptions['customVersion']
currentVersion?: string
Expand Down
3 changes: 2 additions & 1 deletion src/types/version-bump-options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type _semver from 'semver'
import type { Operation } from '../operation'
import type { VersionBumpProgress } from './version-bump-progress'

/**
Expand Down Expand Up @@ -135,7 +136,7 @@ export interface VersionBumpOptions {
/**
* Excute additional command after bumping and before commiting
*/
execute?: string
execute?: string | ((config?: Operation) => void | PromiseLike<void>)

/**
* Bump the files recursively for monorepo. Only works without `files` option.
Expand Down
13 changes: 9 additions & 4 deletions src/version-bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ export async function versionBump(arg: (VersionBumpOptions) | string = {}): Prom
await updateFiles(operation)

if (operation.options.execute) {
console.log(symbols.info, 'Executing script', operation.options.execute)
await ezSpawn.async(operation.options.execute, { stdio: 'inherit' })
console.log(symbols.success, 'Script finished')
if (typeof operation.options.execute === 'function') {
await operation.options.execute(operation)
}
else {
console.log(symbols.info, 'Executing script', operation.options.execute)
await ezSpawn.async(operation.options.execute, { stdio: 'inherit' })
console.log(symbols.success, 'Script finished')
}
}

// Run npm version script, if any
Expand All @@ -101,7 +106,7 @@ function printSummary(operation: Operation) {
if (operation.options.tag)
console.log(` tag ${c.bold(formatVersionString(operation.options.tag.name, operation.state.newVersion))}`)
if (operation.options.execute)
console.log(` execute ${c.bold(operation.options.execute)}`)
console.log(` execute ${c.bold(typeof operation.options.execute === 'function' ? 'function' : operation.options.execute)}`)
if (operation.options.push)
console.log(` push ${c.cyan(c.bold('yes'))}`)
console.log()
Expand Down