Skip to content

Commit

Permalink
feat: add old version
Browse files Browse the repository at this point in the history
  • Loading branch information
murongg committed Oct 5, 2023
1 parent bf20fc7 commit b912e6e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
34 changes: 19 additions & 15 deletions src/cli/parse-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface ParsedArgs {
help?: boolean
version?: boolean
quiet?: boolean
options: VersionBumpOptions
options: VersionBumpOptions & { oldVersion?: string }
}

/**
Expand All @@ -42,28 +42,32 @@ export async function parseArgs(): Promise<ParsedArgs> {
.option('-q, --quiet', 'Quiet mode')
.option('-v, --version <version>', 'Tagert version')
.option('-x, --execute <command>', 'Commands to execute after version bumps')
.option('--old-version <version>', 'Old version to bump')
.help()

const result = cli.parse()
const args = result.options

console.log(args)
const parsedArgs: ParsedArgs = {
help: args.help as boolean,
version: args.version as boolean,
quiet: args.quiet as boolean,
options: await loadBumpConfig({
preid: args.preid,
commit: !args.noCommit && args.commit,
tag: !args.noTag && args.tag,
push: args.push,
all: args.all,
confirm: !args.yes,
noVerify: !args.verify,
files: [...(args['--'] || []), ...result.args],
ignoreScripts: args.ignoreScripts,
execute: args.execute,
recursive: !!args.recursive,
}),
options: {
...await loadBumpConfig({
preid: args.preid,
commit: !args.noCommit && args.commit,
tag: !args.noTag && args.tag,
push: args.push,
all: args.all,
confirm: !args.yes,
noVerify: !args.verify,
files: [...(args['--'] || []), ...result.args],
ignoreScripts: args.ignoreScripts,
execute: args.execute,
recursive: !!args.recursive,
}),
oldVersion: args.oldVersion,
},
}

// If a version number or release type was specified, then it will mistakenly be added to the "files" array
Expand Down
3 changes: 3 additions & 0 deletions src/get-old-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import type { Operation } from './operation'
* An error is thrown if no version number can be found.
*/
export async function getOldVersion(operation: Operation): Promise<Operation> {
if (operation.state.oldVersion)
return operation

const { cwd, files } = operation.options

// Check all JSON files in the files list
Expand Down
2 changes: 1 addition & 1 deletion src/normalize-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface NormalizedOptions {
/**
* Converts raw VersionBumpOptions to a normalized and sanitized Options object.
*/
export async function normalizeOptions(raw: VersionBumpOptions): Promise<NormalizedOptions> {
export async function normalizeOptions(raw: VersionBumpOptions & { oldVersion?: string }): Promise<NormalizedOptions> {
// Set the simple properties first
const preid = typeof raw.preid === 'string' ? raw.preid : 'beta'
const push = Boolean(raw.push)
Expand Down
12 changes: 9 additions & 3 deletions src/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,25 @@ export class Operation {
/**
* Private constructor. Use the `Operation.start()` static method instead.
*/
private constructor(options: NormalizedOptions, progress?: ProgressCallback) {
private constructor(options: NormalizedOptions, progress?: ProgressCallback, oldVersion?: string) {
this.options = options
this._progress = progress
if (oldVersion) {
this.update({
oldVersion,
oldVersionSource: 'user',
})
}
}

/**
* Starts a new `versionBump()` operation.
*/
public static async start(input: VersionBumpOptions): Promise<Operation> {
public static async start(input: VersionBumpOptions & { oldVersion?: string }): Promise<Operation> {
// Validate and normalize the options
const options = await normalizeOptions(input)

return new Operation(options, input.progress)
return new Operation(options, input.progress, input.oldVersion)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/version-bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ export async function versionBump(release: string): Promise<VersionBumpResults>
* Bumps the version number in one or more files, prompting the user if necessary.
* Optionally also commits, tags, and pushes to git.
*/
export async function versionBump(options: VersionBumpOptions): Promise<VersionBumpResults>
export async function versionBump(options: VersionBumpOptions & { oldVersion?: string }): Promise<VersionBumpResults>

/**
* Bumps the version number in one or more files, prompting the user if necessary.
* Optionally also commits, tags, and pushes to git.
*/
export async function versionBump(arg: VersionBumpOptions | string = {}): Promise<VersionBumpResults | undefined> {
export async function versionBump(arg: (VersionBumpOptions & { oldVersion?: string }) | string = {}): Promise<VersionBumpResults | undefined> {
if (typeof arg === 'string')
arg = { release: arg }

Expand Down

0 comments on commit b912e6e

Please sign in to comment.