Skip to content

Commit

Permalink
refactor(@142vip/release-version): 结构与编码风格优化,配置bumpx命令
Browse files Browse the repository at this point in the history
  • Loading branch information
mmdapl committed Jul 17, 2024
1 parent 5092fe0 commit 3680d42
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/release-version/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* cli 工具入口
*/

import './dist/index.mjs'
import './dist/bumpx-cli.mjs'
2 changes: 1 addition & 1 deletion packages/release-version/src/core/git.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ezSpawn from '@jsdevtools/ez-spawn'
import { ProgressEvent } from '../types/version-bump-progress'
import { ProgressEvent } from '../types'
import type { Operation } from './operation'

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/release-version/src/core/normalize-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'node:fs/promises'
import fsSync from 'node:fs'
import fg from 'fast-glob'
import yaml from 'js-yaml'
import type { VersionBumpOptions } from '../types/version-bump-options'
import type { VersionBumpOptions } from '../types'
import type { ReleaseType } from './release-type'
import { isReleaseType } from './release-type'

Expand Down
6 changes: 2 additions & 4 deletions packages/release-version/src/core/operation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { VersionBumpOptions } from '../types/version-bump-options'
import type { NpmScript, ProgressEvent, VersionBumpProgress } from '../types/version-bump-progress'
import type { VersionBumpResults } from '../types/version-bump-results'
import type { NpmScript, ProgressEvent, VersionBumpOptions, VersionBumpProgress, VersionBumpResults } from '../types'
import type { NormalizedOptions } from './normalize-options'
import { normalizeOptions } from './normalize-options'
import type { ReleaseType } from './release-type'
Expand All @@ -24,7 +22,7 @@ interface UpdateOperationState extends Partial<OperationState> {
}

/**
* All of the inputs, outputs, and state of a single `versionBump()` call.
* All the inputs, outputs, and state of a single `versionBump()` call.
*/
export class Operation {
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/release-version/src/core/run-npm-script.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ezSpawn from '@jsdevtools/ez-spawn'
import type { NpmScript } from '../types/version-bump-progress'
import { ProgressEvent } from '../types/version-bump-progress'
import type { NpmScript } from '../types'
import { ProgressEvent } from '../types'
import { readJsonFile } from './fs'
import type { Manifest } from './manifest'
import { isManifest } from './manifest'
Expand Down
2 changes: 1 addition & 1 deletion packages/release-version/src/core/update-files.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'node:path'
import { ProgressEvent } from '../types/version-bump-progress'
import { ProgressEvent } from '../types'
import { readJsonFile, readTextFile, writeJsonFile, writeTextFile } from './fs'
import { isManifest, isPackageLockManifest } from './manifest'
import type { Operation } from './operation'
Expand Down
33 changes: 6 additions & 27 deletions packages/release-version/src/core/version-bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,13 @@ import { Operation } from './operation'
import { runNpmScript } from './run-npm-script'
import { updateFiles } from './update-files'

/**
* Prompts the user for a version number and updates package.json and package-lock.json.
*
* @returns - The new version number
*/
export async function versionBump(): Promise<VersionBumpResults>

/**
* Bumps the version number in package.json, package-lock.json.
*
* @param release
* The release version or type. Can be one of the following:
*
* - The new version number (e.g. "1.23.456")
* - A release type (e.g. "major", "minor", "patch", "prerelease", etc.)
* - "prompt" to prompt the user for the version number
*/
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>

/**
* Bumps the version number in one or more files, prompting the user if necessary.
* Optionally also commits, tags, and pushes to git.
*
* use:
* - versionBump():default to new version number
* - versionBump(release: string): explicit the new version number ,e.g: 0.1.10
* - versionBump(options: VersionBumpOptions):Optionally also commits, tags, and pushes to git
*/
export async function versionBump(arg: (VersionBumpOptions) | string = {}): Promise<VersionBumpResults | undefined> {
if (typeof arg === 'string')
Expand Down Expand Up @@ -86,7 +65,7 @@ export async function versionBump(arg: (VersionBumpOptions) | string = {}): Prom
// Run npm postversion script, if any
await runNpmScript(NpmScript.PostVersion, operation)

// Push the git commit and tag, if enabled
// 推送git信息和标记到远程
await gitPush(operation)

return operation.results
Expand Down

0 comments on commit 3680d42

Please sign in to comment.