版博士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.

преди 1 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import {
  2. __toESM,
  3. bumpConfigDefaults,
  4. isReleaseType,
  5. loadBumpConfig,
  6. log_symbols_default,
  7. require_picocolors,
  8. versionBump
  9. } from "../chunk-L3LY4KGC.mjs";
  10. // package.json
  11. var version = "9.1.0";
  12. // src/cli/parse-args.ts
  13. var import_picocolors = __toESM(require_picocolors());
  14. import { valid as isValidVersion } from "semver";
  15. import cac from "cac";
  16. async function parseArgs() {
  17. var _a;
  18. try {
  19. const cli = cac("bumpp");
  20. cli.version(version).usage("[...files]").option("--preid <preid>", "ID for prerelease").option("--all", `Include all files (default: ${bumpConfigDefaults.all})`).option("-c, --commit [msg]", `Commit message (default: ${bumpConfigDefaults.commit})`).option("-t, --tag [tag]", `Tag name (default: ${bumpConfigDefaults.tag})`).option("-p, --push", `Push to remote (default: ${bumpConfigDefaults.push})`).option("-y, --yes", `Skip confirmation (default: ${!bumpConfigDefaults.confirm})`).option("-r, --recursive", `Bump package.json files recursively (default: ${bumpConfigDefaults.recursive})`).option("--no-verify", "Skip git verification").option("--ignore-scripts", `Ignore scripts (default: ${bumpConfigDefaults.ignoreScripts})`).option("-q, --quiet", "Quiet mode").option("-v, --version <version>", "Tagert version").option("-x, --execute <command>", "Commands to execute after version bumps").help();
  21. const result = cli.parse();
  22. const args = result.options;
  23. const parsedArgs = {
  24. help: args.help,
  25. version: args.version,
  26. quiet: args.quiet,
  27. options: await loadBumpConfig({
  28. preid: args.preid,
  29. commit: args.commit,
  30. tag: args.tag,
  31. push: args.push,
  32. all: args.all,
  33. confirm: !args.yes,
  34. noVerify: !args.verify,
  35. files: [...args["--"] || [], ...result.args],
  36. ignoreScripts: args.ignoreScripts,
  37. execute: args.execute,
  38. recursive: !!args.recursive
  39. })
  40. };
  41. if (parsedArgs.options.files && parsedArgs.options.files.length > 0) {
  42. const firstArg = parsedArgs.options.files[0];
  43. if (firstArg === "prompt" || isReleaseType(firstArg) || isValidVersion(firstArg)) {
  44. parsedArgs.options.release = firstArg;
  45. parsedArgs.options.files.shift();
  46. }
  47. }
  48. if (parsedArgs.options.recursive) {
  49. if ((_a = parsedArgs.options.files) == null ? void 0 : _a.length)
  50. console.log(import_picocolors.default.yellow("The --recursive option is ignored when files are specified"));
  51. else
  52. parsedArgs.options.files = ["package.json", "package-lock.json", "packages/**/package.json"];
  53. }
  54. return parsedArgs;
  55. } catch (error) {
  56. return errorHandler(error);
  57. }
  58. }
  59. function errorHandler(error) {
  60. console.error(error.message);
  61. return process.exit(9 /* InvalidArgument */);
  62. }
  63. // src/cli/index.ts
  64. async function main() {
  65. try {
  66. process.on("uncaughtException", errorHandler2);
  67. process.on("unhandledRejection", errorHandler2);
  68. const { help, version: version2, quiet, options } = await parseArgs();
  69. if (help) {
  70. process.exit(0 /* Success */);
  71. } else if (version2) {
  72. console.log(version);
  73. process.exit(0 /* Success */);
  74. } else {
  75. if (!quiet)
  76. options.progress = options.progress ? options.progress : progress;
  77. await versionBump(options);
  78. }
  79. } catch (error) {
  80. errorHandler2(error);
  81. }
  82. }
  83. function progress({ event, script, updatedFiles, skippedFiles, newVersion }) {
  84. switch (event) {
  85. case "file updated" /* FileUpdated */:
  86. console.log(log_symbols_default.success, `Updated ${updatedFiles.pop()} to ${newVersion}`);
  87. break;
  88. case "file skipped" /* FileSkipped */:
  89. console.log(log_symbols_default.info, `${skippedFiles.pop()} did not need to be updated`);
  90. break;
  91. case "git commit" /* GitCommit */:
  92. console.log(log_symbols_default.success, "Git commit");
  93. break;
  94. case "git tag" /* GitTag */:
  95. console.log(log_symbols_default.success, "Git tag");
  96. break;
  97. case "git push" /* GitPush */:
  98. console.log(log_symbols_default.success, "Git push");
  99. break;
  100. case "npm script" /* NpmScript */:
  101. console.log(log_symbols_default.success, `Npm run ${script}`);
  102. break;
  103. }
  104. }
  105. function errorHandler2(error) {
  106. let message = error.message || String(error);
  107. if (process.env.DEBUG || process.env.NODE_ENV === "development")
  108. message = error.stack || message;
  109. console.error(message);
  110. process.exit(1 /* FatalError */);
  111. }
  112. export {
  113. main
  114. };