版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

343 lines
10 KiB

  1. import { ReleaseType } from 'semver';
  2. export { ReleaseType } from 'semver';
  3. /**
  4. * Information about the work that was performed by the `versionBump()` function.
  5. */
  6. interface VersionBumpResults {
  7. /**
  8. * The release type that was used, or `undefined` if an explicit version number was used.
  9. */
  10. release?: ReleaseType;
  11. /**
  12. * The previous version number in package.json.
  13. */
  14. oldVersion: string;
  15. /**
  16. * The new version number.
  17. */
  18. newVersion: string;
  19. /**
  20. * The commit message that was used for the git commit, or `false` if no git commit was created.
  21. *
  22. * NOTE: This will never be an empty string. It will always contain at least the new version number.
  23. */
  24. commit: string | false;
  25. /**
  26. * The tag name that was used for the git tag, or `false` if no git tag was created.
  27. *
  28. * NOTE: This will never be an empty string. It will always contain at least the new version number.
  29. */
  30. tag: string | false;
  31. /**
  32. * The files that were actually modified.
  33. */
  34. updatedFiles: string[];
  35. /**
  36. * The files that were not updated because they did not contain the old version number.
  37. */
  38. skippedFiles: string[];
  39. }
  40. /**
  41. * Progress events that indicate the progress of the `versionBump()` function.
  42. */
  43. declare const enum ProgressEvent {
  44. FileUpdated = "file updated",
  45. FileSkipped = "file skipped",
  46. GitCommit = "git commit",
  47. GitTag = "git tag",
  48. GitPush = "git push",
  49. NpmScript = "npm script"
  50. }
  51. /**
  52. * The NPM version scripts
  53. *
  54. * @see https://docs.npmjs.com/cli/version.html
  55. */
  56. declare const enum NpmScript {
  57. PreVersion = "preversion",
  58. Version = "version",
  59. PostVersion = "postversion"
  60. }
  61. /**
  62. * Information about the progress of the `versionBump()` function.
  63. */
  64. interface VersionBumpProgress extends VersionBumpResults {
  65. event: ProgressEvent;
  66. script?: NpmScript;
  67. }
  68. /**
  69. * Options for the `versionBump()` function.
  70. */
  71. interface VersionBumpOptions {
  72. /**
  73. * The release version or type. Can be one of the following:
  74. *
  75. * - The new version number (e.g. "1.23.456")
  76. * - A release type (e.g. "major", "minor", "patch", "prerelease", etc.)
  77. * - "prompt" to prompt the user for the version number
  78. *
  79. * Defaults to "prompt".
  80. */
  81. release?: string;
  82. /**
  83. * The prerelease type (e.g. "alpha", "beta", "next").
  84. *
  85. * Defaults to "beta".
  86. */
  87. preid?: string;
  88. /**
  89. * Indicates whether to create a git commit. Can be set to a custom commit message string
  90. * or `true` to use "release v". Any `%s` placeholders in the message string will be replaced
  91. * with the new version number. If the message string does _not_ contain any `%s` placeholders,
  92. * then the new version number will be appended to the message.
  93. *
  94. * Defaults to `false`.
  95. */
  96. commit?: boolean | string;
  97. /**
  98. * Indicates whether to tag the git commit. Can be set to a custom tag string
  99. * or `true` to use "v". Any `%s` placeholders in the tag string will be replaced
  100. * with the new version number. If the tag string does _not_ contain any `%s` placeholders,
  101. * then the new version number will be appended to the tag.
  102. *
  103. * Defaults to `false`.
  104. */
  105. tag?: boolean | string;
  106. /**
  107. * Indicates whether to push the git commit and tag.
  108. *
  109. * Defaults to `false`.
  110. */
  111. push?: boolean;
  112. /**
  113. * Indicates whether the git commit should include ALL files (`git commit --all`)
  114. * rather than just the files that were modified by `versionBump()`.
  115. *
  116. * Defaults to `false`.
  117. */
  118. all?: boolean;
  119. /**
  120. * Prompt for confirmation
  121. *
  122. * @default false
  123. */
  124. confirm?: boolean;
  125. /**
  126. * Indicates whether to bypass git commit hooks (`git commit --no-verify`).
  127. *
  128. * Defaults to `false`.
  129. */
  130. noVerify?: boolean;
  131. /**
  132. * The files to be updated. For certain known files ("package.json", "bower.json", etc.)
  133. * `versionBump()` will explicitly update the file's version number. For other files
  134. * (ReadMe files, config files, source code, etc.) it will simply do a global replacement
  135. * of the old version number with the new version number.
  136. *
  137. * Defaults to ["package.json", "package-lock.json"]
  138. */
  139. files?: string[];
  140. /**
  141. * The working directory, which is used as the basis for locating all files.
  142. *
  143. * Defaults to `process.cwd()`
  144. */
  145. cwd?: string;
  146. /**
  147. * Options for the command-line interface. Can be one of the following:
  148. *
  149. * - `true` - To default to `process.stdin` and `process.stdout`.
  150. * - `false` - To disable all CLI output. Cannot be used when `release` is "prompt".
  151. * - An object that will be passed to `readline.createInterface()`.
  152. *
  153. * Defaults to `true`.
  154. */
  155. interface?: boolean | InterfaceOptions;
  156. /**
  157. * Indicates whether to ignore version scripts.
  158. *
  159. * Defaults to `false`.
  160. */
  161. ignoreScripts?: boolean;
  162. /**
  163. * A callback that is provides information about the progress of the `versionBump()` function.
  164. */
  165. progress?(progress: VersionBumpProgress): void;
  166. /**
  167. * Excute additional command after bumping and before commiting
  168. */
  169. execute?: string;
  170. /**
  171. * Bump the files recursively for monorepo. Only works without `files` option.
  172. *
  173. * @default false
  174. */
  175. recursive?: boolean;
  176. }
  177. /**
  178. * Options for the command-line interface.
  179. */
  180. interface InterfaceOptions {
  181. /**
  182. * The stream that will be used to read user input. Can be one of the following:
  183. *
  184. * - `true` - To default to `process.stdin`
  185. * - `false` - To disable all CLI input
  186. * - Any readable stream
  187. *
  188. * Defaults to `true`.
  189. */
  190. input?: NodeJS.ReadableStream | NodeJS.ReadStream | boolean;
  191. /**
  192. * The stream that will be used to write output, such as prompts and progress.
  193. * Can be one of the following:
  194. *
  195. * - `true` - To default to `process.stdout`
  196. * - `false` - To disable all CLI output
  197. * - Any writable stream
  198. *
  199. * Defaults to `true`.
  200. */
  201. output?: NodeJS.WritableStream | NodeJS.WriteStream | boolean;
  202. /**
  203. * Any other properties will be passed directly to `readline.createInterface()`.
  204. * See the `ReadLineOptions` interface for possible options.
  205. */
  206. [key: string]: unknown;
  207. }
  208. interface Interface {
  209. input?: NodeJS.ReadableStream | NodeJS.ReadStream | false;
  210. output?: NodeJS.WritableStream | NodeJS.WriteStream | false;
  211. [key: string]: unknown;
  212. }
  213. /**
  214. * A specific version release.
  215. */
  216. interface VersionRelease {
  217. type: 'version';
  218. version: string;
  219. }
  220. /**
  221. * Prompt the user for the release number.
  222. */
  223. interface PromptRelease {
  224. type: 'prompt';
  225. preid: string;
  226. }
  227. /**
  228. * A bump release, relative to the current version number.
  229. */
  230. interface BumpRelease {
  231. type: ReleaseType;
  232. preid: string;
  233. }
  234. /**
  235. * One of the possible Release types.
  236. */
  237. type Release = VersionRelease | PromptRelease | BumpRelease;
  238. /**
  239. * Normalized and sanitized options
  240. */
  241. interface NormalizedOptions {
  242. release: Release;
  243. commit?: {
  244. message: string;
  245. noVerify: boolean;
  246. all: boolean;
  247. };
  248. tag?: {
  249. name: string;
  250. };
  251. push: boolean;
  252. files: string[];
  253. cwd: string;
  254. interface: Interface;
  255. ignoreScripts: boolean;
  256. execute?: string;
  257. }
  258. interface OperationState {
  259. release: ReleaseType | undefined;
  260. oldVersionSource: string;
  261. oldVersion: string;
  262. newVersion: string;
  263. commitMessage: string;
  264. tagName: string;
  265. updatedFiles: string[];
  266. skippedFiles: string[];
  267. }
  268. interface UpdateOperationState extends Partial<OperationState> {
  269. event?: ProgressEvent;
  270. script?: NpmScript;
  271. }
  272. /**
  273. * All of the inputs, outputs, and state of a single `versionBump()` call.
  274. */
  275. declare class Operation {
  276. /**
  277. * The options for this operation.
  278. */
  279. options: NormalizedOptions;
  280. /**
  281. * The current state of the operation.
  282. */
  283. readonly state: Readonly<OperationState>;
  284. /**
  285. * The results of the operation.
  286. */
  287. get results(): VersionBumpResults;
  288. /**
  289. * The callback that's used to report the progress of the operation.
  290. */
  291. private readonly _progress?;
  292. /**
  293. * Private constructor. Use the `Operation.start()` static method instead.
  294. */
  295. private constructor();
  296. /**
  297. * Starts a new `versionBump()` operation.
  298. */
  299. static start(input: VersionBumpOptions): Promise<Operation>;
  300. /**
  301. * Updates the operation state and results, and reports the updated progress to the user.
  302. */
  303. update({ event, script, ...newState }: UpdateOperationState): this;
  304. }
  305. /**
  306. * Prompts the user for a version number and updates package.json and package-lock.json.
  307. *
  308. * @returns - The new version number
  309. */
  310. declare function versionBump(): Promise<VersionBumpResults>;
  311. /**
  312. * Bumps the version number in package.json, package-lock.json.
  313. *
  314. * @param release
  315. * The release version or type. Can be one of the following:
  316. *
  317. * - The new version number (e.g. "1.23.456")
  318. * - A release type (e.g. "major", "minor", "patch", "prerelease", etc.)
  319. * - "prompt" to prompt the user for the version number
  320. */
  321. declare function versionBump(release: string): Promise<VersionBumpResults>;
  322. /**
  323. * Bumps the version number in one or more files, prompting the user if necessary.
  324. * Optionally also commits, tags, and pushes to git.
  325. */
  326. declare function versionBump(options: VersionBumpOptions): Promise<VersionBumpResults>;
  327. /**
  328. * Bumps the version number in one or more files, prompting users if necessary.
  329. */
  330. declare function versionBumpInfo(arg?: VersionBumpOptions | string): Promise<Operation>;
  331. declare const bumpConfigDefaults: VersionBumpOptions;
  332. declare function loadBumpConfig(overrides?: Partial<VersionBumpOptions>, cwd?: string): Promise<VersionBumpOptions>;
  333. declare function defineConfig(config: Partial<VersionBumpOptions>): Partial<VersionBumpOptions>;
  334. export { InterfaceOptions, NpmScript, ProgressEvent, VersionBumpOptions, VersionBumpProgress, VersionBumpResults, bumpConfigDefaults, versionBump as default, defineConfig, loadBumpConfig, versionBump, versionBumpInfo };