版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

1364 строки
47 KiB

  1. var __create = Object.create;
  2. var __defProp = Object.defineProperty;
  3. var __defProps = Object.defineProperties;
  4. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  5. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  6. var __getOwnPropNames = Object.getOwnPropertyNames;
  7. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  8. var __getProtoOf = Object.getPrototypeOf;
  9. var __hasOwnProp = Object.prototype.hasOwnProperty;
  10. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  11. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  12. var __spreadValues = (a, b) => {
  13. for (var prop in b || (b = {}))
  14. if (__hasOwnProp.call(b, prop))
  15. __defNormalProp(a, prop, b[prop]);
  16. if (__getOwnPropSymbols)
  17. for (var prop of __getOwnPropSymbols(b)) {
  18. if (__propIsEnum.call(b, prop))
  19. __defNormalProp(a, prop, b[prop]);
  20. }
  21. return a;
  22. };
  23. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  24. var __objRest = (source, exclude) => {
  25. var target = {};
  26. for (var prop in source)
  27. if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
  28. target[prop] = source[prop];
  29. if (source != null && __getOwnPropSymbols)
  30. for (var prop of __getOwnPropSymbols(source)) {
  31. if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
  32. target[prop] = source[prop];
  33. }
  34. return target;
  35. };
  36. var __commonJS = (cb, mod) => function __require() {
  37. return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  38. };
  39. var __export = (target, all) => {
  40. for (var name in all)
  41. __defProp(target, name, { get: all[name], enumerable: true });
  42. };
  43. var __copyProps = (to, from, except, desc) => {
  44. if (from && typeof from === "object" || typeof from === "function") {
  45. for (let key of __getOwnPropNames(from))
  46. if (!__hasOwnProp.call(to, key) && key !== except)
  47. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  48. }
  49. return to;
  50. };
  51. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  52. // If the importer is in node compatibility mode or this is not an ESM
  53. // file that has been converted to a CommonJS file using a Babel-
  54. // compatible transform (i.e. "__esModule" has not been set), then set
  55. // "default" to the CommonJS "module.exports" for node compatibility.
  56. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  57. mod
  58. ));
  59. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  60. // node_modules/.pnpm/picocolors@1.0.0/node_modules/picocolors/picocolors.js
  61. var require_picocolors = __commonJS({
  62. "node_modules/.pnpm/picocolors@1.0.0/node_modules/picocolors/picocolors.js"(exports, module2) {
  63. var tty2 = require("tty");
  64. var isColorSupported = !("NO_COLOR" in process.env || process.argv.includes("--no-color")) && ("FORCE_COLOR" in process.env || process.argv.includes("--color") || process.platform === "win32" || tty2.isatty(1) && process.env.TERM !== "dumb" || "CI" in process.env);
  65. var formatter = (open, close, replace = open) => (input) => {
  66. let string = "" + input;
  67. let index = string.indexOf(close, open.length);
  68. return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
  69. };
  70. var replaceClose = (string, close, replace, index) => {
  71. let start = string.substring(0, index) + replace;
  72. let end = string.substring(index + close.length);
  73. let nextIndex = end.indexOf(close);
  74. return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end;
  75. };
  76. var createColors = (enabled = isColorSupported) => ({
  77. isColorSupported: enabled,
  78. reset: enabled ? (s) => `\x1B[0m${s}\x1B[0m` : String,
  79. bold: enabled ? formatter("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m") : String,
  80. dim: enabled ? formatter("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m") : String,
  81. italic: enabled ? formatter("\x1B[3m", "\x1B[23m") : String,
  82. underline: enabled ? formatter("\x1B[4m", "\x1B[24m") : String,
  83. inverse: enabled ? formatter("\x1B[7m", "\x1B[27m") : String,
  84. hidden: enabled ? formatter("\x1B[8m", "\x1B[28m") : String,
  85. strikethrough: enabled ? formatter("\x1B[9m", "\x1B[29m") : String,
  86. black: enabled ? formatter("\x1B[30m", "\x1B[39m") : String,
  87. red: enabled ? formatter("\x1B[31m", "\x1B[39m") : String,
  88. green: enabled ? formatter("\x1B[32m", "\x1B[39m") : String,
  89. yellow: enabled ? formatter("\x1B[33m", "\x1B[39m") : String,
  90. blue: enabled ? formatter("\x1B[34m", "\x1B[39m") : String,
  91. magenta: enabled ? formatter("\x1B[35m", "\x1B[39m") : String,
  92. cyan: enabled ? formatter("\x1B[36m", "\x1B[39m") : String,
  93. white: enabled ? formatter("\x1B[37m", "\x1B[39m") : String,
  94. gray: enabled ? formatter("\x1B[90m", "\x1B[39m") : String,
  95. bgBlack: enabled ? formatter("\x1B[40m", "\x1B[49m") : String,
  96. bgRed: enabled ? formatter("\x1B[41m", "\x1B[49m") : String,
  97. bgGreen: enabled ? formatter("\x1B[42m", "\x1B[49m") : String,
  98. bgYellow: enabled ? formatter("\x1B[43m", "\x1B[49m") : String,
  99. bgBlue: enabled ? formatter("\x1B[44m", "\x1B[49m") : String,
  100. bgMagenta: enabled ? formatter("\x1B[45m", "\x1B[49m") : String,
  101. bgCyan: enabled ? formatter("\x1B[46m", "\x1B[49m") : String,
  102. bgWhite: enabled ? formatter("\x1B[47m", "\x1B[49m") : String
  103. });
  104. module2.exports = createColors();
  105. module2.exports.createColors = createColors;
  106. }
  107. });
  108. // src/cli/index.ts
  109. var cli_exports = {};
  110. __export(cli_exports, {
  111. main: () => main2
  112. });
  113. module.exports = __toCommonJS(cli_exports);
  114. // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/vendor/ansi-styles/index.js
  115. var ANSI_BACKGROUND_OFFSET = 10;
  116. var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
  117. var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
  118. var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
  119. var styles = {
  120. modifier: {
  121. reset: [0, 0],
  122. // 21 isn't widely supported and 22 does the same thing
  123. bold: [1, 22],
  124. dim: [2, 22],
  125. italic: [3, 23],
  126. underline: [4, 24],
  127. overline: [53, 55],
  128. inverse: [7, 27],
  129. hidden: [8, 28],
  130. strikethrough: [9, 29]
  131. },
  132. color: {
  133. black: [30, 39],
  134. red: [31, 39],
  135. green: [32, 39],
  136. yellow: [33, 39],
  137. blue: [34, 39],
  138. magenta: [35, 39],
  139. cyan: [36, 39],
  140. white: [37, 39],
  141. // Bright color
  142. blackBright: [90, 39],
  143. gray: [90, 39],
  144. // Alias of `blackBright`
  145. grey: [90, 39],
  146. // Alias of `blackBright`
  147. redBright: [91, 39],
  148. greenBright: [92, 39],
  149. yellowBright: [93, 39],
  150. blueBright: [94, 39],
  151. magentaBright: [95, 39],
  152. cyanBright: [96, 39],
  153. whiteBright: [97, 39]
  154. },
  155. bgColor: {
  156. bgBlack: [40, 49],
  157. bgRed: [41, 49],
  158. bgGreen: [42, 49],
  159. bgYellow: [43, 49],
  160. bgBlue: [44, 49],
  161. bgMagenta: [45, 49],
  162. bgCyan: [46, 49],
  163. bgWhite: [47, 49],
  164. // Bright color
  165. bgBlackBright: [100, 49],
  166. bgGray: [100, 49],
  167. // Alias of `bgBlackBright`
  168. bgGrey: [100, 49],
  169. // Alias of `bgBlackBright`
  170. bgRedBright: [101, 49],
  171. bgGreenBright: [102, 49],
  172. bgYellowBright: [103, 49],
  173. bgBlueBright: [104, 49],
  174. bgMagentaBright: [105, 49],
  175. bgCyanBright: [106, 49],
  176. bgWhiteBright: [107, 49]
  177. }
  178. };
  179. var modifierNames = Object.keys(styles.modifier);
  180. var foregroundColorNames = Object.keys(styles.color);
  181. var backgroundColorNames = Object.keys(styles.bgColor);
  182. var colorNames = [...foregroundColorNames, ...backgroundColorNames];
  183. function assembleStyles() {
  184. const codes = /* @__PURE__ */ new Map();
  185. for (const [groupName, group] of Object.entries(styles)) {
  186. for (const [styleName, style] of Object.entries(group)) {
  187. styles[styleName] = {
  188. open: `\x1B[${style[0]}m`,
  189. close: `\x1B[${style[1]}m`
  190. };
  191. group[styleName] = styles[styleName];
  192. codes.set(style[0], style[1]);
  193. }
  194. Object.defineProperty(styles, groupName, {
  195. value: group,
  196. enumerable: false
  197. });
  198. }
  199. Object.defineProperty(styles, "codes", {
  200. value: codes,
  201. enumerable: false
  202. });
  203. styles.color.close = "\x1B[39m";
  204. styles.bgColor.close = "\x1B[49m";
  205. styles.color.ansi = wrapAnsi16();
  206. styles.color.ansi256 = wrapAnsi256();
  207. styles.color.ansi16m = wrapAnsi16m();
  208. styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
  209. styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
  210. styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
  211. Object.defineProperties(styles, {
  212. rgbToAnsi256: {
  213. value(red, green, blue) {
  214. if (red === green && green === blue) {
  215. if (red < 8) {
  216. return 16;
  217. }
  218. if (red > 248) {
  219. return 231;
  220. }
  221. return Math.round((red - 8) / 247 * 24) + 232;
  222. }
  223. return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
  224. },
  225. enumerable: false
  226. },
  227. hexToRgb: {
  228. value(hex) {
  229. const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
  230. if (!matches) {
  231. return [0, 0, 0];
  232. }
  233. let [colorString] = matches;
  234. if (colorString.length === 3) {
  235. colorString = [...colorString].map((character) => character + character).join("");
  236. }
  237. const integer = Number.parseInt(colorString, 16);
  238. return [
  239. /* eslint-disable no-bitwise */
  240. integer >> 16 & 255,
  241. integer >> 8 & 255,
  242. integer & 255
  243. /* eslint-enable no-bitwise */
  244. ];
  245. },
  246. enumerable: false
  247. },
  248. hexToAnsi256: {
  249. value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
  250. enumerable: false
  251. },
  252. ansi256ToAnsi: {
  253. value(code) {
  254. if (code < 8) {
  255. return 30 + code;
  256. }
  257. if (code < 16) {
  258. return 90 + (code - 8);
  259. }
  260. let red;
  261. let green;
  262. let blue;
  263. if (code >= 232) {
  264. red = ((code - 232) * 10 + 8) / 255;
  265. green = red;
  266. blue = red;
  267. } else {
  268. code -= 16;
  269. const remainder = code % 36;
  270. red = Math.floor(code / 36) / 5;
  271. green = Math.floor(remainder / 6) / 5;
  272. blue = remainder % 6 / 5;
  273. }
  274. const value = Math.max(red, green, blue) * 2;
  275. if (value === 0) {
  276. return 30;
  277. }
  278. let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
  279. if (value === 2) {
  280. result += 60;
  281. }
  282. return result;
  283. },
  284. enumerable: false
  285. },
  286. rgbToAnsi: {
  287. value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
  288. enumerable: false
  289. },
  290. hexToAnsi: {
  291. value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
  292. enumerable: false
  293. }
  294. });
  295. return styles;
  296. }
  297. var ansiStyles = assembleStyles();
  298. var ansi_styles_default = ansiStyles;
  299. // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/vendor/supports-color/index.js
  300. var import_node_process = __toESM(require("process"), 1);
  301. var import_node_os = __toESM(require("os"), 1);
  302. var import_node_tty = __toESM(require("tty"), 1);
  303. function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) {
  304. const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
  305. const position = argv.indexOf(prefix + flag);
  306. const terminatorPosition = argv.indexOf("--");
  307. return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
  308. }
  309. var { env } = import_node_process.default;
  310. var flagForceColor;
  311. if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
  312. flagForceColor = 0;
  313. } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
  314. flagForceColor = 1;
  315. }
  316. function envForceColor() {
  317. if ("FORCE_COLOR" in env) {
  318. if (env.FORCE_COLOR === "true") {
  319. return 1;
  320. }
  321. if (env.FORCE_COLOR === "false") {
  322. return 0;
  323. }
  324. return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
  325. }
  326. }
  327. function translateLevel(level) {
  328. if (level === 0) {
  329. return false;
  330. }
  331. return {
  332. level,
  333. hasBasic: true,
  334. has256: level >= 2,
  335. has16m: level >= 3
  336. };
  337. }
  338. function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
  339. const noFlagForceColor = envForceColor();
  340. if (noFlagForceColor !== void 0) {
  341. flagForceColor = noFlagForceColor;
  342. }
  343. const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
  344. if (forceColor === 0) {
  345. return 0;
  346. }
  347. if (sniffFlags) {
  348. if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
  349. return 3;
  350. }
  351. if (hasFlag("color=256")) {
  352. return 2;
  353. }
  354. }
  355. if ("TF_BUILD" in env && "AGENT_NAME" in env) {
  356. return 1;
  357. }
  358. if (haveStream && !streamIsTTY && forceColor === void 0) {
  359. return 0;
  360. }
  361. const min = forceColor || 0;
  362. if (env.TERM === "dumb") {
  363. return min;
  364. }
  365. if (import_node_process.default.platform === "win32") {
  366. const osRelease = import_node_os.default.release().split(".");
  367. if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  368. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  369. }
  370. return 1;
  371. }
  372. if ("CI" in env) {
  373. if ("GITHUB_ACTIONS" in env) {
  374. return 3;
  375. }
  376. if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
  377. return 1;
  378. }
  379. return min;
  380. }
  381. if ("TEAMCITY_VERSION" in env) {
  382. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  383. }
  384. if (env.COLORTERM === "truecolor") {
  385. return 3;
  386. }
  387. if (env.TERM === "xterm-kitty") {
  388. return 3;
  389. }
  390. if ("TERM_PROGRAM" in env) {
  391. const version2 = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
  392. switch (env.TERM_PROGRAM) {
  393. case "iTerm.app": {
  394. return version2 >= 3 ? 3 : 2;
  395. }
  396. case "Apple_Terminal": {
  397. return 2;
  398. }
  399. }
  400. }
  401. if (/-256(color)?$/i.test(env.TERM)) {
  402. return 2;
  403. }
  404. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
  405. return 1;
  406. }
  407. if ("COLORTERM" in env) {
  408. return 1;
  409. }
  410. return min;
  411. }
  412. function createSupportsColor(stream, options = {}) {
  413. const level = _supportsColor(stream, __spreadValues({
  414. streamIsTTY: stream && stream.isTTY
  415. }, options));
  416. return translateLevel(level);
  417. }
  418. var supportsColor = {
  419. stdout: createSupportsColor({ isTTY: import_node_tty.default.isatty(1) }),
  420. stderr: createSupportsColor({ isTTY: import_node_tty.default.isatty(2) })
  421. };
  422. var supports_color_default = supportsColor;
  423. // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/utilities.js
  424. function stringReplaceAll(string, substring, replacer) {
  425. let index = string.indexOf(substring);
  426. if (index === -1) {
  427. return string;
  428. }
  429. const substringLength = substring.length;
  430. let endIndex = 0;
  431. let returnValue = "";
  432. do {
  433. returnValue += string.slice(endIndex, index) + substring + replacer;
  434. endIndex = index + substringLength;
  435. index = string.indexOf(substring, endIndex);
  436. } while (index !== -1);
  437. returnValue += string.slice(endIndex);
  438. return returnValue;
  439. }
  440. function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
  441. let endIndex = 0;
  442. let returnValue = "";
  443. do {
  444. const gotCR = string[index - 1] === "\r";
  445. returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
  446. endIndex = index + 1;
  447. index = string.indexOf("\n", endIndex);
  448. } while (index !== -1);
  449. returnValue += string.slice(endIndex);
  450. return returnValue;
  451. }
  452. // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/index.js
  453. var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
  454. var GENERATOR = Symbol("GENERATOR");
  455. var STYLER = Symbol("STYLER");
  456. var IS_EMPTY = Symbol("IS_EMPTY");
  457. var levelMapping = [
  458. "ansi",
  459. "ansi",
  460. "ansi256",
  461. "ansi16m"
  462. ];
  463. var styles2 = /* @__PURE__ */ Object.create(null);
  464. var applyOptions = (object, options = {}) => {
  465. if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
  466. throw new Error("The `level` option should be an integer from 0 to 3");
  467. }
  468. const colorLevel = stdoutColor ? stdoutColor.level : 0;
  469. object.level = options.level === void 0 ? colorLevel : options.level;
  470. };
  471. var chalkFactory = (options) => {
  472. const chalk2 = (...strings) => strings.join(" ");
  473. applyOptions(chalk2, options);
  474. Object.setPrototypeOf(chalk2, createChalk.prototype);
  475. return chalk2;
  476. };
  477. function createChalk(options) {
  478. return chalkFactory(options);
  479. }
  480. Object.setPrototypeOf(createChalk.prototype, Function.prototype);
  481. for (const [styleName, style] of Object.entries(ansi_styles_default)) {
  482. styles2[styleName] = {
  483. get() {
  484. const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
  485. Object.defineProperty(this, styleName, { value: builder });
  486. return builder;
  487. }
  488. };
  489. }
  490. styles2.visible = {
  491. get() {
  492. const builder = createBuilder(this, this[STYLER], true);
  493. Object.defineProperty(this, "visible", { value: builder });
  494. return builder;
  495. }
  496. };
  497. var getModelAnsi = (model, level, type, ...arguments_) => {
  498. if (model === "rgb") {
  499. if (level === "ansi16m") {
  500. return ansi_styles_default[type].ansi16m(...arguments_);
  501. }
  502. if (level === "ansi256") {
  503. return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
  504. }
  505. return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
  506. }
  507. if (model === "hex") {
  508. return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
  509. }
  510. return ansi_styles_default[type][model](...arguments_);
  511. };
  512. var usedModels = ["rgb", "hex", "ansi256"];
  513. for (const model of usedModels) {
  514. styles2[model] = {
  515. get() {
  516. const { level } = this;
  517. return function(...arguments_) {
  518. const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
  519. return createBuilder(this, styler, this[IS_EMPTY]);
  520. };
  521. }
  522. };
  523. const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
  524. styles2[bgModel] = {
  525. get() {
  526. const { level } = this;
  527. return function(...arguments_) {
  528. const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
  529. return createBuilder(this, styler, this[IS_EMPTY]);
  530. };
  531. }
  532. };
  533. }
  534. var proto = Object.defineProperties(() => {
  535. }, __spreadProps(__spreadValues({}, styles2), {
  536. level: {
  537. enumerable: true,
  538. get() {
  539. return this[GENERATOR].level;
  540. },
  541. set(level) {
  542. this[GENERATOR].level = level;
  543. }
  544. }
  545. }));
  546. var createStyler = (open, close, parent) => {
  547. let openAll;
  548. let closeAll;
  549. if (parent === void 0) {
  550. openAll = open;
  551. closeAll = close;
  552. } else {
  553. openAll = parent.openAll + open;
  554. closeAll = close + parent.closeAll;
  555. }
  556. return {
  557. open,
  558. close,
  559. openAll,
  560. closeAll,
  561. parent
  562. };
  563. };
  564. var createBuilder = (self, _styler, _isEmpty) => {
  565. const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
  566. Object.setPrototypeOf(builder, proto);
  567. builder[GENERATOR] = self;
  568. builder[STYLER] = _styler;
  569. builder[IS_EMPTY] = _isEmpty;
  570. return builder;
  571. };
  572. var applyStyle = (self, string) => {
  573. if (self.level <= 0 || !string) {
  574. return self[IS_EMPTY] ? "" : string;
  575. }
  576. let styler = self[STYLER];
  577. if (styler === void 0) {
  578. return string;
  579. }
  580. const { openAll, closeAll } = styler;
  581. if (string.includes("\x1B")) {
  582. while (styler !== void 0) {
  583. string = stringReplaceAll(string, styler.close, styler.open);
  584. styler = styler.parent;
  585. }
  586. }
  587. const lfIndex = string.indexOf("\n");
  588. if (lfIndex !== -1) {
  589. string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
  590. }
  591. return openAll + string + closeAll;
  592. };
  593. Object.defineProperties(createChalk.prototype, styles2);
  594. var chalk = createChalk();
  595. var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
  596. var source_default = chalk;
  597. // node_modules/.pnpm/is-unicode-supported@1.3.0/node_modules/is-unicode-supported/index.js
  598. var import_node_process2 = __toESM(require("process"), 1);
  599. function isUnicodeSupported() {
  600. if (import_node_process2.default.platform !== "win32") {
  601. return import_node_process2.default.env.TERM !== "linux";
  602. }
  603. return Boolean(import_node_process2.default.env.CI) || Boolean(import_node_process2.default.env.WT_SESSION) || Boolean(import_node_process2.default.env.TERMINUS_SUBLIME) || import_node_process2.default.env.ConEmuTask === "{cmd::Cmder}" || import_node_process2.default.env.TERM_PROGRAM === "Terminus-Sublime" || import_node_process2.default.env.TERM_PROGRAM === "vscode" || import_node_process2.default.env.TERM === "xterm-256color" || import_node_process2.default.env.TERM === "alacritty" || import_node_process2.default.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
  604. }
  605. // node_modules/.pnpm/log-symbols@5.1.0/node_modules/log-symbols/index.js
  606. var main = {
  607. info: source_default.blue("\u2139"),
  608. success: source_default.green("\u2714"),
  609. warning: source_default.yellow("\u26A0"),
  610. error: source_default.red("\u2716")
  611. };
  612. var fallback = {
  613. info: source_default.blue("i"),
  614. success: source_default.green("\u221A"),
  615. warning: source_default.yellow("\u203C"),
  616. error: source_default.red("\xD7")
  617. };
  618. var logSymbols = isUnicodeSupported() ? main : fallback;
  619. var log_symbols_default = logSymbols;
  620. // package.json
  621. var version = "9.1.0";
  622. // src/version-bump.ts
  623. var ezSpawn3 = __toESM(require("@jsdevtools/ez-spawn"));
  624. var import_picocolors2 = __toESM(require_picocolors());
  625. var import_prompts2 = __toESM(require("prompts"));
  626. // src/get-new-version.ts
  627. var import_picocolors = __toESM(require_picocolors());
  628. var import_prompts = __toESM(require("prompts"));
  629. var import_semver2 = __toESM(require("semver"));
  630. // src/release-type.ts
  631. var import_semver = require("semver");
  632. var prereleaseTypes = ["premajor", "preminor", "prepatch", "prerelease"];
  633. var releaseTypes = prereleaseTypes.concat(["major", "minor", "patch"]);
  634. function isPrerelease(value) {
  635. return prereleaseTypes.includes(value);
  636. }
  637. function isReleaseType(value) {
  638. return releaseTypes.includes(value);
  639. }
  640. // src/get-new-version.ts
  641. async function getNewVersion(operation) {
  642. const { release } = operation.options;
  643. const { oldVersion } = operation.state;
  644. switch (release.type) {
  645. case "prompt":
  646. return promptForNewVersion(operation);
  647. case "version":
  648. return operation.update({
  649. newVersion: new import_semver2.SemVer(release.version, true).version
  650. });
  651. default:
  652. return operation.update({
  653. release: release.type,
  654. newVersion: getNextVersion(oldVersion, release)
  655. });
  656. }
  657. }
  658. function getNextVersion(oldVersion, bump) {
  659. const oldSemVer = new import_semver2.SemVer(oldVersion);
  660. const newSemVer = oldSemVer.inc(bump.type, bump.preid);
  661. if (isPrerelease(bump.type) && newSemVer.prerelease.length === 2 && newSemVer.prerelease[0] === bump.preid && String(newSemVer.prerelease[1]) === "0") {
  662. newSemVer.prerelease[1] = "1";
  663. newSemVer.format();
  664. }
  665. return newSemVer.version;
  666. }
  667. function getNextVersions(oldVersion, preid) {
  668. var _a;
  669. const next = {};
  670. const parse = import_semver2.default.parse(oldVersion);
  671. if (typeof (parse == null ? void 0 : parse.prerelease[0]) === "string")
  672. preid = (parse == null ? void 0 : parse.prerelease[0]) || "preid";
  673. for (const type of releaseTypes)
  674. next[type] = import_semver2.default.inc(oldVersion, type, preid);
  675. next.next = ((_a = parse == null ? void 0 : parse.prerelease) == null ? void 0 : _a.length) ? import_semver2.default.inc(oldVersion, "prerelease", preid) : import_semver2.default.inc(oldVersion, "patch");
  676. return next;
  677. }
  678. async function promptForNewVersion(operation) {
  679. const { oldVersion } = operation.state;
  680. const release = operation.options.release;
  681. const next = getNextVersions(oldVersion, release.preid);
  682. const PADDING = 13;
  683. const answers = await (0, import_prompts.default)([
  684. {
  685. type: "autocomplete",
  686. name: "release",
  687. message: `Current version ${import_picocolors.default.green(oldVersion)}`,
  688. initial: "next",
  689. choices: [
  690. { value: "major", title: `${"major".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.major)}` },
  691. { value: "minor", title: `${"minor".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.minor)}` },
  692. { value: "patch", title: `${"patch".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.patch)}` },
  693. { value: "next", title: `${"next".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.next)}` },
  694. { value: "prepatch", title: `${"pre-patch".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.prepatch)}` },
  695. { value: "preminor", title: `${"pre-minor".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.preminor)}` },
  696. { value: "premajor", title: `${"pre-major".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.premajor)}` },
  697. { value: "none", title: `${"as-is".padStart(PADDING, " ")} ${import_picocolors.default.bold(oldVersion)}` },
  698. { value: "custom", title: "custom ...".padStart(PADDING + 4, " ") }
  699. ]
  700. },
  701. {
  702. type: (prev) => prev === "custom" ? "text" : null,
  703. name: "custom",
  704. message: "Enter the new version number:",
  705. initial: oldVersion,
  706. validate: (custom) => {
  707. return (0, import_semver2.valid)(custom) ? true : "That's not a valid version number";
  708. }
  709. }
  710. ]);
  711. const newVersion = answers.release === "none" ? oldVersion : answers.release === "custom" ? (0, import_semver2.clean)(answers.custom) : next[answers.release];
  712. if (!newVersion)
  713. process.exit(1);
  714. switch (answers.release) {
  715. case "custom":
  716. case "next":
  717. case "none":
  718. return operation.update({ newVersion });
  719. default:
  720. return operation.update({ release: answers.release, newVersion });
  721. }
  722. }
  723. // src/get-old-version.ts
  724. var import_semver3 = require("semver");
  725. // src/fs.ts
  726. var import_node_fs = __toESM(require("fs"));
  727. var import_node_path = __toESM(require("path"));
  728. // node_modules/.pnpm/detect-indent@7.0.1/node_modules/detect-indent/index.js
  729. var INDENT_REGEX = /^(?:( )+|\t+)/;
  730. var INDENT_TYPE_SPACE = "space";
  731. var INDENT_TYPE_TAB = "tab";
  732. function makeIndentsMap(string, ignoreSingleSpaces) {
  733. const indents = /* @__PURE__ */ new Map();
  734. let previousSize = 0;
  735. let previousIndentType;
  736. let key;
  737. for (const line of string.split(/\n/g)) {
  738. if (!line) {
  739. continue;
  740. }
  741. let indent;
  742. let indentType;
  743. let use;
  744. let weight;
  745. let entry;
  746. const matches = line.match(INDENT_REGEX);
  747. if (matches === null) {
  748. previousSize = 0;
  749. previousIndentType = "";
  750. } else {
  751. indent = matches[0].length;
  752. indentType = matches[1] ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
  753. if (ignoreSingleSpaces && indentType === INDENT_TYPE_SPACE && indent === 1) {
  754. continue;
  755. }
  756. if (indentType !== previousIndentType) {
  757. previousSize = 0;
  758. }
  759. previousIndentType = indentType;
  760. use = 1;
  761. weight = 0;
  762. const indentDifference = indent - previousSize;
  763. previousSize = indent;
  764. if (indentDifference === 0) {
  765. use = 0;
  766. weight = 1;
  767. } else {
  768. const absoluteIndentDifference = indentDifference > 0 ? indentDifference : -indentDifference;
  769. key = encodeIndentsKey(indentType, absoluteIndentDifference);
  770. }
  771. entry = indents.get(key);
  772. entry = entry === void 0 ? [1, 0] : [entry[0] + use, entry[1] + weight];
  773. indents.set(key, entry);
  774. }
  775. }
  776. return indents;
  777. }
  778. function encodeIndentsKey(indentType, indentAmount) {
  779. const typeCharacter = indentType === INDENT_TYPE_SPACE ? "s" : "t";
  780. return typeCharacter + String(indentAmount);
  781. }
  782. function decodeIndentsKey(indentsKey) {
  783. const keyHasTypeSpace = indentsKey[0] === "s";
  784. const type = keyHasTypeSpace ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
  785. const amount = Number(indentsKey.slice(1));
  786. return { type, amount };
  787. }
  788. function getMostUsedKey(indents) {
  789. let result;
  790. let maxUsed = 0;
  791. let maxWeight = 0;
  792. for (const [key, [usedCount, weight]] of indents) {
  793. if (usedCount > maxUsed || usedCount === maxUsed && weight > maxWeight) {
  794. maxUsed = usedCount;
  795. maxWeight = weight;
  796. result = key;
  797. }
  798. }
  799. return result;
  800. }
  801. function makeIndentString(type, amount) {
  802. const indentCharacter = type === INDENT_TYPE_SPACE ? " " : " ";
  803. return indentCharacter.repeat(amount);
  804. }
  805. function detectIndent(string) {
  806. if (typeof string !== "string") {
  807. throw new TypeError("Expected a string");
  808. }
  809. let indents = makeIndentsMap(string, true);
  810. if (indents.size === 0) {
  811. indents = makeIndentsMap(string, false);
  812. }
  813. const keyOfMostUsedIndent = getMostUsedKey(indents);
  814. let type;
  815. let amount = 0;
  816. let indent = "";
  817. if (keyOfMostUsedIndent !== void 0) {
  818. ({ type, amount } = decodeIndentsKey(keyOfMostUsedIndent));
  819. indent = makeIndentString(type, amount);
  820. }
  821. return {
  822. amount,
  823. type,
  824. indent
  825. };
  826. }
  827. // node_modules/.pnpm/detect-newline@4.0.0/node_modules/detect-newline/index.js
  828. function detectNewline(string) {
  829. if (typeof string !== "string") {
  830. throw new TypeError("Expected a string");
  831. }
  832. const newlines = string.match(/(?:\r?\n)/g) || [];
  833. if (newlines.length === 0) {
  834. return;
  835. }
  836. const crlf = newlines.filter((newline) => newline === "\r\n").length;
  837. const lf = newlines.length - crlf;
  838. return crlf > lf ? "\r\n" : "\n";
  839. }
  840. // src/fs.ts
  841. async function readJsonFile(name, cwd) {
  842. const file = await readTextFile(name, cwd);
  843. const data = JSON.parse(file.data);
  844. const indent = detectIndent(file.data).indent;
  845. const newline = detectNewline(file.data);
  846. return __spreadProps(__spreadValues({}, file), { data, indent, newline });
  847. }
  848. async function writeJsonFile(file) {
  849. let json = JSON.stringify(file.data, void 0, file.indent);
  850. if (file.newline)
  851. json += file.newline;
  852. return writeTextFile(__spreadProps(__spreadValues({}, file), { data: json }));
  853. }
  854. function readTextFile(name, cwd) {
  855. return new Promise((resolve, reject) => {
  856. const filePath = import_node_path.default.join(cwd, name);
  857. import_node_fs.default.readFile(filePath, "utf8", (err, text) => {
  858. if (err) {
  859. reject(err);
  860. } else {
  861. resolve({
  862. path: filePath,
  863. data: text
  864. });
  865. }
  866. });
  867. });
  868. }
  869. function writeTextFile(file) {
  870. return new Promise((resolve, reject) => {
  871. import_node_fs.default.writeFile(file.path, file.data, (err) => {
  872. if (err)
  873. reject(err);
  874. else
  875. resolve();
  876. });
  877. });
  878. }
  879. // src/manifest.ts
  880. function isManifest(obj) {
  881. return obj && typeof obj === "object" && isOptionalString(obj.name) && isOptionalString(obj.version) && isOptionalString(obj.description);
  882. }
  883. function isOptionalString(value) {
  884. const type = typeof value;
  885. return value === null || type === "undefined" || type === "string";
  886. }
  887. // src/get-old-version.ts
  888. async function getOldVersion(operation) {
  889. const { cwd, files } = operation.options;
  890. const filesToCheck = files.filter((file) => file.endsWith(".json"));
  891. if (!filesToCheck.includes("package.json"))
  892. filesToCheck.push("package.json");
  893. for (const file of filesToCheck) {
  894. const version2 = await readVersion(file, cwd);
  895. if (version2) {
  896. return operation.update({
  897. oldVersionSource: file,
  898. oldVersion: version2
  899. });
  900. }
  901. }
  902. throw new Error(
  903. `Unable to determine the current version number. Checked ${filesToCheck.join(", ")}.`
  904. );
  905. }
  906. async function readVersion(file, cwd) {
  907. try {
  908. const { data: manifest } = await readJsonFile(file, cwd);
  909. if (isManifest(manifest)) {
  910. if ((0, import_semver3.valid)(manifest.version))
  911. return manifest.version;
  912. }
  913. } catch (error) {
  914. return void 0;
  915. }
  916. }
  917. // src/git.ts
  918. var ezSpawn = __toESM(require("@jsdevtools/ez-spawn"));
  919. async function gitCommit(operation) {
  920. if (!operation.options.commit)
  921. return operation;
  922. const { all, noVerify, message } = operation.options.commit;
  923. const { updatedFiles, newVersion } = operation.state;
  924. let args = [];
  925. if (all) {
  926. args.push("--all");
  927. }
  928. if (noVerify) {
  929. args.push("--no-verify");
  930. }
  931. const commitMessage = formatVersionString(message, newVersion);
  932. args.push("--message", commitMessage);
  933. if (!all)
  934. args = args.concat(updatedFiles);
  935. await ezSpawn.async("git", ["commit", ...args]);
  936. return operation.update({ event: "git commit" /* GitCommit */, commitMessage });
  937. }
  938. async function gitTag(operation) {
  939. if (!operation.options.tag)
  940. return operation;
  941. const { commit, tag } = operation.options;
  942. const { newVersion } = operation.state;
  943. const args = [
  944. // Create an annotated tag, which is recommended for releases.
  945. // See https://git-scm.com/docs/git-tag
  946. "--annotate",
  947. // Use the same commit message for the tag
  948. "--message",
  949. formatVersionString(commit.message, newVersion)
  950. ];
  951. const tagName = formatVersionString(tag.name, newVersion);
  952. args.push(tagName);
  953. await ezSpawn.async("git", ["tag", ...args]);
  954. return operation.update({ event: "git tag" /* GitTag */, tagName });
  955. }
  956. async function gitPush(operation) {
  957. if (!operation.options.push)
  958. return operation;
  959. await ezSpawn.async("git", "push");
  960. if (operation.options.tag) {
  961. await ezSpawn.async("git", ["push", "--tags"]);
  962. }
  963. return operation.update({ event: "git push" /* GitPush */ });
  964. }
  965. function formatVersionString(template, newVersion) {
  966. if (template.includes("%s"))
  967. return template.replace(/%s/g, newVersion);
  968. else
  969. return template + newVersion;
  970. }
  971. // src/normalize-options.ts
  972. var import_fast_glob = __toESM(require("fast-glob"));
  973. async function normalizeOptions(raw) {
  974. var _a;
  975. const preid = typeof raw.preid === "string" ? raw.preid : "beta";
  976. const push = Boolean(raw.push);
  977. const all = Boolean(raw.all);
  978. const noVerify = Boolean(raw.noVerify);
  979. const cwd = raw.cwd || process.cwd();
  980. const ignoreScripts = Boolean(raw.ignoreScripts);
  981. const execute = raw.execute;
  982. let release;
  983. if (!raw.release || raw.release === "prompt")
  984. release = { type: "prompt", preid };
  985. else if (isReleaseType(raw.release))
  986. release = { type: raw.release, preid };
  987. else
  988. release = { type: "version", version: raw.release };
  989. let tag;
  990. if (typeof raw.tag === "string")
  991. tag = { name: raw.tag };
  992. else if (raw.tag)
  993. tag = { name: "v" };
  994. let commit;
  995. if (typeof raw.commit === "string")
  996. commit = { all, noVerify, message: raw.commit };
  997. else if (raw.commit || tag || push)
  998. commit = { all, noVerify, message: "chore: release v" };
  999. const files = await (0, import_fast_glob.default)(
  1000. ((_a = raw.files) == null ? void 0 : _a.length) ? raw.files : ["package.json", "package-lock.json"],
  1001. {
  1002. cwd,
  1003. onlyFiles: true,
  1004. ignore: [
  1005. "**/{.git,node_modules,bower_components,__tests__,fixtures,fixture}/**"
  1006. ]
  1007. }
  1008. );
  1009. let ui;
  1010. if (raw.interface === false) {
  1011. ui = { input: false, output: false };
  1012. } else if (raw.interface === true || !raw.interface) {
  1013. ui = { input: process.stdin, output: process.stdout };
  1014. } else {
  1015. let _b = raw.interface, { input, output } = _b, other = __objRest(_b, ["input", "output"]);
  1016. if (input === true || input !== false && !input)
  1017. input = process.stdin;
  1018. if (output === true || output !== false && !output)
  1019. output = process.stdout;
  1020. ui = __spreadValues({ input, output }, other);
  1021. }
  1022. if (release.type === "prompt" && !(ui.input && ui.output))
  1023. throw new Error("Cannot prompt for the version number because input or output has been disabled.");
  1024. return { release, commit, tag, push, files, cwd, interface: ui, ignoreScripts, execute };
  1025. }
  1026. // src/operation.ts
  1027. var Operation = class {
  1028. /**
  1029. * Private constructor. Use the `Operation.start()` static method instead.
  1030. */
  1031. constructor(options, progress2) {
  1032. /**
  1033. * The current state of the operation.
  1034. */
  1035. this.state = {
  1036. release: void 0,
  1037. oldVersion: "",
  1038. oldVersionSource: "",
  1039. newVersion: "",
  1040. commitMessage: "",
  1041. tagName: "",
  1042. updatedFiles: [],
  1043. skippedFiles: []
  1044. };
  1045. this.options = options;
  1046. this._progress = progress2;
  1047. }
  1048. /**
  1049. * The results of the operation.
  1050. */
  1051. get results() {
  1052. const options = this.options;
  1053. const state = this.state;
  1054. return {
  1055. release: state.release,
  1056. oldVersion: state.oldVersion,
  1057. newVersion: state.newVersion,
  1058. commit: options.commit ? state.commitMessage : false,
  1059. tag: options.tag ? state.tagName : false,
  1060. updatedFiles: state.updatedFiles.slice(),
  1061. skippedFiles: state.skippedFiles.slice()
  1062. };
  1063. }
  1064. /**
  1065. * Starts a new `versionBump()` operation.
  1066. */
  1067. static async start(input) {
  1068. const options = await normalizeOptions(input);
  1069. return new Operation(options, input.progress);
  1070. }
  1071. /**
  1072. * Updates the operation state and results, and reports the updated progress to the user.
  1073. */
  1074. update(_a) {
  1075. var _b = _a, { event, script } = _b, newState = __objRest(_b, ["event", "script"]);
  1076. Object.assign(this.state, newState);
  1077. if (event && this._progress) {
  1078. this._progress(__spreadValues({ event, script }, this.results));
  1079. }
  1080. return this;
  1081. }
  1082. };
  1083. // src/run-npm-script.ts
  1084. var ezSpawn2 = __toESM(require("@jsdevtools/ez-spawn"));
  1085. async function runNpmScript(script, operation) {
  1086. const { cwd, ignoreScripts } = operation.options;
  1087. if (!ignoreScripts) {
  1088. const { data: manifest } = await readJsonFile("package.json", cwd);
  1089. if (isManifest(manifest) && hasScript(manifest, script)) {
  1090. await ezSpawn2.async("npm", ["run", script, "--silent"], { stdio: "inherit" });
  1091. operation.update({ event: "npm script" /* NpmScript */, script });
  1092. }
  1093. }
  1094. return operation;
  1095. }
  1096. function hasScript(manifest, script) {
  1097. const scripts = manifest.scripts;
  1098. if (scripts && typeof scripts === "object")
  1099. return Boolean(scripts[script]);
  1100. return false;
  1101. }
  1102. // src/update-files.ts
  1103. var path2 = __toESM(require("path"));
  1104. async function updateFiles(operation) {
  1105. const { files } = operation.options;
  1106. for (const relPath of files) {
  1107. const modified = await updateFile(relPath, operation);
  1108. if (modified) {
  1109. operation.update({
  1110. event: "file updated" /* FileUpdated */,
  1111. updatedFiles: operation.state.updatedFiles.concat(relPath)
  1112. });
  1113. } else {
  1114. operation.update({
  1115. event: "file skipped" /* FileSkipped */,
  1116. skippedFiles: operation.state.skippedFiles.concat(relPath)
  1117. });
  1118. }
  1119. }
  1120. return operation;
  1121. }
  1122. async function updateFile(relPath, operation) {
  1123. const name = path2.basename(relPath).trim().toLowerCase();
  1124. switch (name) {
  1125. case "package.json":
  1126. case "package-lock.json":
  1127. case "bower.json":
  1128. case "component.json":
  1129. return updateManifestFile(relPath, operation);
  1130. default:
  1131. return updateTextFile(relPath, operation);
  1132. }
  1133. }
  1134. async function updateManifestFile(relPath, operation) {
  1135. const { cwd } = operation.options;
  1136. const { newVersion } = operation.state;
  1137. let modified = false;
  1138. const file = await readJsonFile(relPath, cwd);
  1139. if (isManifest(file.data) && file.data.version !== newVersion) {
  1140. file.data.version = newVersion;
  1141. await writeJsonFile(file);
  1142. modified = true;
  1143. }
  1144. return modified;
  1145. }
  1146. async function updateTextFile(relPath, operation) {
  1147. const { cwd } = operation.options;
  1148. const { oldVersion, newVersion } = operation.state;
  1149. const modified = false;
  1150. const file = await readTextFile(relPath, cwd);
  1151. if (file.data.includes(oldVersion)) {
  1152. const sanitizedVersion = oldVersion.replace(/(\W)/g, "\\$1");
  1153. const replacePattern = new RegExp(`(\\b|v)${sanitizedVersion}\\b`, "g");
  1154. file.data = file.data.replace(replacePattern, `$1${newVersion}`);
  1155. await writeTextFile(file);
  1156. return true;
  1157. }
  1158. return modified;
  1159. }
  1160. // src/version-bump.ts
  1161. async function versionBump(arg = {}) {
  1162. if (typeof arg === "string")
  1163. arg = { release: arg };
  1164. const operation = await Operation.start(arg);
  1165. await getOldVersion(operation);
  1166. await getNewVersion(operation);
  1167. if (arg.confirm) {
  1168. printSummary(operation);
  1169. if (!await (0, import_prompts2.default)({
  1170. name: "yes",
  1171. type: "confirm",
  1172. message: "Bump?",
  1173. initial: true
  1174. }).then((r) => r.yes))
  1175. process.exit(1);
  1176. }
  1177. await runNpmScript("preversion" /* PreVersion */, operation);
  1178. await updateFiles(operation);
  1179. if (operation.options.execute) {
  1180. console.log(log_symbols_default.info, "Executing script", operation.options.execute);
  1181. await ezSpawn3.async(operation.options.execute, { stdio: "inherit" });
  1182. console.log(log_symbols_default.success, "Script finished");
  1183. }
  1184. await runNpmScript("version" /* Version */, operation);
  1185. await gitCommit(operation);
  1186. await gitTag(operation);
  1187. await runNpmScript("postversion" /* PostVersion */, operation);
  1188. await gitPush(operation);
  1189. return operation.results;
  1190. }
  1191. function printSummary(operation) {
  1192. console.log();
  1193. console.log(` files ${operation.options.files.map((i) => import_picocolors2.default.bold(i)).join("\n ")}`);
  1194. if (operation.options.commit)
  1195. console.log(` commit ${import_picocolors2.default.bold(formatVersionString(operation.options.commit.message, operation.state.newVersion))}`);
  1196. if (operation.options.tag)
  1197. console.log(` tag ${import_picocolors2.default.bold(formatVersionString(operation.options.tag.name, operation.state.newVersion))}`);
  1198. if (operation.options.execute)
  1199. console.log(` execute ${import_picocolors2.default.bold(operation.options.execute)}`);
  1200. if (operation.options.push)
  1201. console.log(` push ${import_picocolors2.default.cyan(import_picocolors2.default.bold("yes"))}`);
  1202. console.log();
  1203. console.log(` from ${import_picocolors2.default.bold(operation.state.oldVersion)}`);
  1204. console.log(` to ${import_picocolors2.default.green(import_picocolors2.default.bold(operation.state.newVersion))}`);
  1205. console.log();
  1206. }
  1207. // src/cli/parse-args.ts
  1208. var import_semver4 = require("semver");
  1209. var import_cac = __toESM(require("cac"));
  1210. var import_picocolors3 = __toESM(require_picocolors());
  1211. // src/config.ts
  1212. var import_c12 = require("c12");
  1213. var bumpConfigDefaults = {
  1214. commit: true,
  1215. push: true,
  1216. tag: true,
  1217. recursive: false,
  1218. noVerify: false,
  1219. confirm: true,
  1220. ignoreScripts: false,
  1221. all: false,
  1222. files: []
  1223. };
  1224. async function loadBumpConfig(overrides, cwd = process.cwd()) {
  1225. const { config } = await (0, import_c12.loadConfig)({
  1226. name: "bump",
  1227. defaults: bumpConfigDefaults,
  1228. overrides: __spreadValues({}, overrides),
  1229. cwd
  1230. });
  1231. return config;
  1232. }
  1233. // src/cli/parse-args.ts
  1234. async function parseArgs() {
  1235. var _a;
  1236. try {
  1237. const cli = (0, import_cac.default)("bumpp");
  1238. 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();
  1239. const result = cli.parse();
  1240. const args = result.options;
  1241. const parsedArgs = {
  1242. help: args.help,
  1243. version: args.version,
  1244. quiet: args.quiet,
  1245. options: await loadBumpConfig({
  1246. preid: args.preid,
  1247. commit: args.commit,
  1248. tag: args.tag,
  1249. push: args.push,
  1250. all: args.all,
  1251. confirm: !args.yes,
  1252. noVerify: !args.verify,
  1253. files: [...args["--"] || [], ...result.args],
  1254. ignoreScripts: args.ignoreScripts,
  1255. execute: args.execute,
  1256. recursive: !!args.recursive
  1257. })
  1258. };
  1259. if (parsedArgs.options.files && parsedArgs.options.files.length > 0) {
  1260. const firstArg = parsedArgs.options.files[0];
  1261. if (firstArg === "prompt" || isReleaseType(firstArg) || (0, import_semver4.valid)(firstArg)) {
  1262. parsedArgs.options.release = firstArg;
  1263. parsedArgs.options.files.shift();
  1264. }
  1265. }
  1266. if (parsedArgs.options.recursive) {
  1267. if ((_a = parsedArgs.options.files) == null ? void 0 : _a.length)
  1268. console.log(import_picocolors3.default.yellow("The --recursive option is ignored when files are specified"));
  1269. else
  1270. parsedArgs.options.files = ["package.json", "package-lock.json", "packages/**/package.json"];
  1271. }
  1272. return parsedArgs;
  1273. } catch (error) {
  1274. return errorHandler(error);
  1275. }
  1276. }
  1277. function errorHandler(error) {
  1278. console.error(error.message);
  1279. return process.exit(9 /* InvalidArgument */);
  1280. }
  1281. // src/cli/index.ts
  1282. async function main2() {
  1283. try {
  1284. process.on("uncaughtException", errorHandler2);
  1285. process.on("unhandledRejection", errorHandler2);
  1286. const { help, version: version2, quiet, options } = await parseArgs();
  1287. if (help) {
  1288. process.exit(0 /* Success */);
  1289. } else if (version2) {
  1290. console.log(version);
  1291. process.exit(0 /* Success */);
  1292. } else {
  1293. if (!quiet)
  1294. options.progress = options.progress ? options.progress : progress;
  1295. await versionBump(options);
  1296. }
  1297. } catch (error) {
  1298. errorHandler2(error);
  1299. }
  1300. }
  1301. function progress({ event, script, updatedFiles, skippedFiles, newVersion }) {
  1302. switch (event) {
  1303. case "file updated" /* FileUpdated */:
  1304. console.log(log_symbols_default.success, `Updated ${updatedFiles.pop()} to ${newVersion}`);
  1305. break;
  1306. case "file skipped" /* FileSkipped */:
  1307. console.log(log_symbols_default.info, `${skippedFiles.pop()} did not need to be updated`);
  1308. break;
  1309. case "git commit" /* GitCommit */:
  1310. console.log(log_symbols_default.success, "Git commit");
  1311. break;
  1312. case "git tag" /* GitTag */:
  1313. console.log(log_symbols_default.success, "Git tag");
  1314. break;
  1315. case "git push" /* GitPush */:
  1316. console.log(log_symbols_default.success, "Git push");
  1317. break;
  1318. case "npm script" /* NpmScript */:
  1319. console.log(log_symbols_default.success, `Npm run ${script}`);
  1320. break;
  1321. }
  1322. }
  1323. function errorHandler2(error) {
  1324. let message = error.message || String(error);
  1325. if (process.env.DEBUG || process.env.NODE_ENV === "development")
  1326. message = error.stack || message;
  1327. console.error(message);
  1328. process.exit(1 /* FatalError */);
  1329. }
  1330. // Annotate the CommonJS export names for ESM import in node:
  1331. 0 && (module.exports = {
  1332. main
  1333. });