@coze-arch/cli 0.0.1-alpha.e8683e → 0.0.1-alpha.e9ff73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +25 -16
  2. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +9 -8
  3. package/lib/__templates__/expo/README.md +2 -2
  4. package/lib/__templates__/expo/client/app/+not-found.tsx +30 -0
  5. package/lib/__templates__/expo/client/app.config.ts +2 -2
  6. package/lib/__templates__/expo/client/eslint.config.mjs +17 -1
  7. package/lib/__templates__/expo/client/hooks/useSafeRouter.ts +152 -0
  8. package/lib/__templates__/expo/client/metro.config.js +3 -0
  9. package/lib/__templates__/expo/client/package.json +36 -34
  10. package/lib/__templates__/expo/client/screens/demo/index.tsx +3 -3
  11. package/lib/__templates__/expo/eslint-plugins/react-native/index.js +9 -0
  12. package/lib/__templates__/expo/eslint-plugins/react-native/rule.js +64 -0
  13. package/lib/__templates__/expo/package.json +3 -0
  14. package/lib/__templates__/expo/patches/expo@54.0.33.patch +45 -0
  15. package/lib/__templates__/expo/pnpm-lock.yaml +1318 -2636
  16. package/lib/__templates__/expo/server/package.json +9 -7
  17. package/lib/__templates__/expo/server/src/index.ts +1 -0
  18. package/lib/__templates__/expo/template.config.js +56 -0
  19. package/lib/__templates__/native-static/.coze +11 -0
  20. package/lib/__templates__/native-static/index.html +33 -0
  21. package/lib/__templates__/native-static/styles/main.css +136 -0
  22. package/lib/__templates__/native-static/template.config.js +22 -0
  23. package/lib/__templates__/nextjs/_gitignore +3 -0
  24. package/lib/__templates__/nextjs/next.config.ts +1 -1
  25. package/lib/__templates__/nextjs/package.json +4 -1
  26. package/lib/__templates__/nextjs/pnpm-lock.yaml +1066 -926
  27. package/lib/__templates__/nextjs/scripts/build.sh +4 -1
  28. package/lib/__templates__/nextjs/scripts/dev.sh +1 -1
  29. package/lib/__templates__/nextjs/scripts/start.sh +1 -1
  30. package/lib/__templates__/nextjs/server.ts +35 -0
  31. package/lib/__templates__/nextjs/src/app/page.tsx +18 -60
  32. package/lib/__templates__/nextjs/template.config.js +49 -14
  33. package/lib/__templates__/nuxt-app/.coze +12 -0
  34. package/lib/__templates__/nuxt-app/.nuxt/app.config.mjs +21 -0
  35. package/lib/__templates__/nuxt-app/.nuxt/components.d.ts +64 -0
  36. package/lib/__templates__/nuxt-app/.nuxt/imports.d.ts +31 -0
  37. package/lib/__templates__/nuxt-app/.nuxt/manifest/meta/f97812ec-f25e-427b-b45d-eab58fba39f9.json +1 -0
  38. package/lib/__templates__/nuxt-app/.nuxt/nuxt.d.ts +19 -0
  39. package/lib/__templates__/nuxt-app/.nuxt/nuxt.node.d.ts +14 -0
  40. package/lib/__templates__/nuxt-app/.nuxt/nuxt.shared.d.ts +6 -0
  41. package/lib/__templates__/nuxt-app/.nuxt/schema/nuxt.schema.d.ts +17 -0
  42. package/lib/__templates__/nuxt-app/.nuxt/schema/nuxt.schema.json +3 -0
  43. package/lib/__templates__/nuxt-app/.nuxt/tsconfig.app.json +201 -0
  44. package/lib/__templates__/nuxt-app/.nuxt/tsconfig.json +203 -0
  45. package/lib/__templates__/nuxt-app/.nuxt/tsconfig.node.json +110 -0
  46. package/lib/__templates__/nuxt-app/.nuxt/tsconfig.server.json +140 -0
  47. package/lib/__templates__/nuxt-app/.nuxt/tsconfig.shared.json +152 -0
  48. package/lib/__templates__/nuxt-app/.nuxt/types/app.config.d.ts +35 -0
  49. package/lib/__templates__/nuxt-app/.nuxt/types/build.d.ts +24 -0
  50. package/lib/__templates__/nuxt-app/.nuxt/types/builder-env.d.ts +1 -0
  51. package/lib/__templates__/nuxt-app/.nuxt/types/components.d.ts +69 -0
  52. package/lib/__templates__/nuxt-app/.nuxt/types/imports.d.ts +360 -0
  53. package/lib/__templates__/nuxt-app/.nuxt/types/middleware.d.ts +11 -0
  54. package/lib/__templates__/nuxt-app/.nuxt/types/modules.d.ts +79 -0
  55. package/lib/__templates__/nuxt-app/.nuxt/types/nitro-config.d.ts +14 -0
  56. package/lib/__templates__/nuxt-app/.nuxt/types/nitro-imports.d.ts +151 -0
  57. package/lib/__templates__/nuxt-app/.nuxt/types/nitro-layouts.d.ts +17 -0
  58. package/lib/__templates__/nuxt-app/.nuxt/types/nitro-nuxt.d.ts +64 -0
  59. package/lib/__templates__/nuxt-app/.nuxt/types/nitro-routes.d.ts +17 -0
  60. package/lib/__templates__/nuxt-app/.nuxt/types/nitro.d.ts +3 -0
  61. package/lib/__templates__/nuxt-app/.nuxt/types/plugins.d.ts +30 -0
  62. package/lib/__templates__/nuxt-app/.nuxt/types/runtime-config.d.ts +32 -0
  63. package/lib/__templates__/nuxt-app/.nuxt/types/shared-imports.d.ts +10 -0
  64. package/lib/__templates__/nuxt-app/.nuxt/types/vue-shim.d.ts +0 -0
  65. package/lib/__templates__/nuxt-app/README.md +83 -0
  66. package/lib/__templates__/nuxt-app/_gitignore +24 -0
  67. package/lib/__templates__/nuxt-app/_npmrc +23 -0
  68. package/lib/__templates__/nuxt-app/app/app.vue +193 -0
  69. package/lib/__templates__/nuxt-app/nuxt.config.ts +56 -0
  70. package/lib/__templates__/nuxt-app/package.json +28 -0
  71. package/lib/__templates__/nuxt-app/pnpm-lock.yaml +7202 -0
  72. package/lib/__templates__/nuxt-app/public/favicon.ico +0 -0
  73. package/lib/__templates__/nuxt-app/public/robots.txt +2 -0
  74. package/lib/__templates__/nuxt-app/scripts/build.sh +14 -0
  75. package/lib/__templates__/nuxt-app/scripts/dev.sh +33 -0
  76. package/lib/__templates__/nuxt-app/scripts/prepare.sh +14 -0
  77. package/lib/__templates__/nuxt-app/scripts/start.sh +15 -0
  78. package/lib/__templates__/nuxt-app/template.config.js +78 -0
  79. package/lib/__templates__/nuxt-app/tsconfig.json +18 -0
  80. package/lib/__templates__/taro/.coze +14 -0
  81. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +19 -0
  82. package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +14 -0
  83. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +2 -0
  84. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +151 -0
  85. package/lib/__templates__/taro/.cozeproj/scripts/init_env.sh +5 -0
  86. package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -0
  87. package/lib/__templates__/taro/README.md +751 -0
  88. package/lib/__templates__/taro/_gitignore +40 -0
  89. package/lib/__templates__/taro/_npmrc +18 -0
  90. package/lib/__templates__/taro/babel.config.js +12 -0
  91. package/lib/__templates__/taro/config/dev.ts +9 -0
  92. package/lib/__templates__/taro/config/index.ts +223 -0
  93. package/lib/__templates__/taro/config/prod.ts +34 -0
  94. package/lib/__templates__/taro/eslint.config.mjs +80 -0
  95. package/lib/__templates__/taro/key/private.appid.key +0 -0
  96. package/lib/__templates__/taro/package.json +107 -0
  97. package/lib/__templates__/taro/patches/@tarojs__plugin-mini-ci@4.1.9.patch +30 -0
  98. package/lib/__templates__/taro/pnpm-lock.yaml +23100 -0
  99. package/lib/__templates__/taro/pnpm-workspace.yaml +2 -0
  100. package/lib/__templates__/taro/project.config.json +15 -0
  101. package/lib/__templates__/taro/server/nest-cli.json +10 -0
  102. package/lib/__templates__/taro/server/package.json +40 -0
  103. package/lib/__templates__/taro/server/src/app.controller.ts +23 -0
  104. package/lib/__templates__/taro/server/src/app.module.ts +10 -0
  105. package/lib/__templates__/taro/server/src/app.service.ts +8 -0
  106. package/lib/__templates__/taro/server/src/interceptors/http-status.interceptor.ts +23 -0
  107. package/lib/__templates__/taro/server/src/main.ts +49 -0
  108. package/lib/__templates__/taro/server/tsconfig.json +24 -0
  109. package/lib/__templates__/taro/src/app.config.ts +11 -0
  110. package/lib/__templates__/taro/src/app.css +52 -0
  111. package/lib/__templates__/taro/src/app.tsx +9 -0
  112. package/lib/__templates__/taro/src/index.html +39 -0
  113. package/lib/__templates__/taro/src/network.ts +39 -0
  114. package/lib/__templates__/taro/src/pages/index/index.config.ts +3 -0
  115. package/lib/__templates__/taro/src/pages/index/index.css +1 -0
  116. package/lib/__templates__/taro/src/pages/index/index.tsx +33 -0
  117. package/lib/__templates__/taro/src/presets/dev-debug.ts +23 -0
  118. package/lib/__templates__/taro/src/presets/h5-container.tsx +15 -0
  119. package/lib/__templates__/taro/src/presets/h5-navbar.tsx +201 -0
  120. package/lib/__templates__/taro/src/presets/h5-styles.ts +142 -0
  121. package/lib/__templates__/taro/src/presets/index.tsx +18 -0
  122. package/lib/__templates__/taro/stylelint.config.mjs +4 -0
  123. package/lib/__templates__/taro/template.config.js +68 -0
  124. package/lib/__templates__/taro/tsconfig.json +29 -0
  125. package/lib/__templates__/taro/types/global.d.ts +32 -0
  126. package/lib/__templates__/templates.json +68 -0
  127. package/lib/__templates__/vite/package.json +5 -1
  128. package/lib/__templates__/vite/pnpm-lock.yaml +146 -1659
  129. package/lib/__templates__/vite/src/main.ts +17 -47
  130. package/lib/__templates__/vite/template.config.js +49 -14
  131. package/lib/__templates__/vite/vite.config.ts +1 -0
  132. package/lib/cli.js +617 -128
  133. package/package.json +2 -1
package/lib/cli.js CHANGED
@@ -4,6 +4,8 @@
4
4
  var commander = require('commander');
5
5
  var path = require('path');
6
6
  var fs = require('fs');
7
+ var node_path = require('node:path');
8
+ var node_fs = require('node:fs');
7
9
  var shelljs = require('shelljs');
8
10
  var perf_hooks = require('perf_hooks');
9
11
  var fs$1 = require('fs/promises');
@@ -481,6 +483,14 @@ const warmupTemplate = (templatePath, templateName) => {
481
483
  logger.info(`\nWarming up template: ${templateName}`);
482
484
  logger.info(` Path: ${templatePath}`);
483
485
 
486
+ // 检查是否存在 package.json
487
+ const packageJsonPath = node_path.join(templatePath, 'package.json');
488
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
489
+ if (!node_fs.existsSync(packageJsonPath)) {
490
+ logger.info(` ⊘ Skipping ${templateName} (no package.json found)`);
491
+ return;
492
+ }
493
+
484
494
  const result = shelljs.exec('pnpm install', {
485
495
  cwd: templatePath,
486
496
  silent: true,
@@ -514,13 +524,7 @@ const warmupTemplate = (templatePath, templateName) => {
514
524
  /**
515
525
  * 执行 warmup 命令的内部实现
516
526
  */
517
- const executeWarmup = async (
518
- options
519
-
520
- ,
521
-
522
- command,
523
- ) => {
527
+ const executeWarmup = async (options) => {
524
528
  const timer = new TimeTracker();
525
529
 
526
530
  try {
@@ -585,12 +589,12 @@ const executeWarmup = async (
585
589
  /**
586
590
  * 注册 warmup 命令到 program
587
591
  */
588
- const registerCommand$3 = program => {
592
+ const registerCommand$4 = program => {
589
593
  program
590
594
  .command('warmup')
591
595
  .description('Pre-install dependencies for templates to speed up init')
592
596
  .option('-t, --template <name>', 'Warmup a specific template only')
593
- .action(async (options, command) => {
597
+ .action(async options => {
594
598
  await executeWarmup(options);
595
599
  });
596
600
  };
@@ -1033,7 +1037,7 @@ const executeFix = async (options = {}) => {
1033
1037
  /**
1034
1038
  * 注册 fix 命令到 program
1035
1039
  */
1036
- const registerCommand$2 = program => {
1040
+ const registerCommand$3 = program => {
1037
1041
  program
1038
1042
  .command('fix')
1039
1043
  .description(
@@ -1052,13 +1056,13 @@ function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else
1052
1056
  /**
1053
1057
  * 日志文件名常量
1054
1058
  */
1055
- const LOG_FILE_NAME = 'dev.log';
1059
+ const LOG_FILE_NAME$1 = 'dev.log';
1056
1060
 
1057
1061
  /**
1058
1062
  * 获取日志目录
1059
1063
  * 优先使用环境变量 COZE_LOG_DIR,否则使用 ~/.coze-logs
1060
1064
  */
1061
- const getLogDir = () =>
1065
+ const getLogDir$1 = () =>
1062
1066
  process.env.COZE_LOG_DIR || path.join(os.homedir(), '.coze-logs');
1063
1067
 
1064
1068
  /**
@@ -1067,22 +1071,22 @@ const getLogDir = () =>
1067
1071
  * - 如果是相对路径,基于 getLogDir() + 相对路径
1068
1072
  * - 如果为空,使用 getLogDir() + LOG_FILE_NAME
1069
1073
  */
1070
- const resolveLogFilePath = (logFile) => {
1074
+ const resolveLogFilePath$1 = (logFile) => {
1071
1075
  if (!logFile) {
1072
- return path.join(getLogDir(), LOG_FILE_NAME);
1076
+ return path.join(getLogDir$1(), LOG_FILE_NAME$1);
1073
1077
  }
1074
1078
 
1075
1079
  if (path.isAbsolute(logFile)) {
1076
1080
  return logFile;
1077
1081
  }
1078
1082
 
1079
- return path.join(getLogDir(), logFile);
1083
+ return path.join(getLogDir$1(), logFile);
1080
1084
  };
1081
1085
 
1082
1086
  /**
1083
1087
  * 创建日志写入流
1084
1088
  */
1085
- const createLogStream = (logFilePath) => {
1089
+ const createLogStream$1 = (logFilePath) => {
1086
1090
  const logDir = path.dirname(logFilePath);
1087
1091
 
1088
1092
  // 确保日志目录存在
@@ -1105,7 +1109,7 @@ const executeRun = async (
1105
1109
  logger.info(`Running ${commandName} command...`);
1106
1110
 
1107
1111
  // 1. 对于 build 命令,先执行 fix 以确保项目配置正确
1108
- if (commandName === 'build') {
1112
+ if (['dev', 'build'].includes(commandName)) {
1109
1113
  logger.info('\n🔧 Running fix command before build...\n');
1110
1114
  try {
1111
1115
  await executeFix();
@@ -1121,8 +1125,8 @@ const executeRun = async (
1121
1125
  const commandArgs = getCommandConfig(config, commandName);
1122
1126
 
1123
1127
  // 3. 准备日志
1124
- const logFilePath = resolveLogFilePath(options.logFile);
1125
- const logStream = createLogStream(logFilePath);
1128
+ const logFilePath = resolveLogFilePath$1(options.logFile);
1129
+ const logStream = createLogStream$1(logFilePath);
1126
1130
 
1127
1131
  // 4. 执行命令
1128
1132
  const commandString = commandArgs.join(' ');
@@ -1185,7 +1189,7 @@ const executeRun = async (
1185
1189
  /**
1186
1190
  * 注册 dev/build/start 命令到 program
1187
1191
  */
1188
- const registerCommand$1 = program => {
1192
+ const registerCommand$2 = program => {
1189
1193
  // dev 命令
1190
1194
  program
1191
1195
  .command('dev')
@@ -1437,6 +1441,11 @@ const shouldIgnoreFile = (filePath) => {
1437
1441
  return directoryPatterns.some(dir => pathParts.includes(dir));
1438
1442
  };
1439
1443
 
1444
+ // ABOUTME: File system utilities for template file processing
1445
+ // ABOUTME: Provides directory scanning, file path conversion, and node_modules copying
1446
+
1447
+
1448
+ // start_aigc
1440
1449
  /**
1441
1450
  * 递归获取目录中的所有文件
1442
1451
  *
@@ -1506,7 +1515,19 @@ const convertDotfileName = (filePath) => {
1506
1515
 
1507
1516
  return filePath;
1508
1517
  };
1518
+ // end_aigc
1519
+
1520
+ // ABOUTME: File rendering utilities for template processing
1521
+ // ABOUTME: Handles file content rendering, hook execution, and file writing
1509
1522
 
1523
+
1524
+
1525
+
1526
+
1527
+
1528
+
1529
+
1530
+ // start_aigc
1510
1531
  /**
1511
1532
  * 执行文件渲染钩子
1512
1533
  *
@@ -1552,22 +1573,25 @@ const executeFileRenderHook = async (
1552
1573
  };
1553
1574
 
1554
1575
  /**
1555
- * 处理单个文件
1576
+ * 准备单个文件的渲染信息(不实际写入)
1577
+ * 用于 dry-run 阶段,收集所有将要写入的文件信息
1578
+ *
1579
+ * @param options - 准备选项
1580
+ * @returns 文件渲染信息,或 null 表示该文件被跳过
1556
1581
  */
1557
- const processSingleFile = async (options
1558
-
1582
+ const prepareFileInfo = async (options
1559
1583
 
1560
1584
 
1561
1585
 
1562
1586
 
1563
1587
  ) => {
1564
- const { file, templatePath, outputPath, context, templateConfig } = options;
1588
+ const { file, templatePath, context, templateConfig } = options;
1565
1589
 
1566
1590
  const srcPath = path.join(templatePath, file);
1567
1591
  const destFile = convertDotfileName(file);
1568
1592
 
1569
1593
  logger.verbose(
1570
- ` - Processing: ${file}${destFile !== file ? ` -> ${destFile}` : ''}`,
1594
+ ` - Preparing: ${file}${destFile !== file ? ` -> ${destFile}` : ''}`,
1571
1595
  );
1572
1596
 
1573
1597
  // 判断是否为二进制文件
@@ -1601,51 +1625,209 @@ const processSingleFile = async (options
1601
1625
  context,
1602
1626
  );
1603
1627
 
1604
- // 如果返回 null,跳过该文件
1628
+ // 如果返回 null,表示该文件被 hook 跳过
1605
1629
  if (processedFileInfo === null) {
1606
1630
  logger.verbose(' ⊘ Skipped by onFileRender hook');
1607
- return;
1631
+ return null;
1608
1632
  }
1609
1633
 
1610
- // 使用处理后的目标路径
1611
- const finalDestPath = path.join(outputPath, processedFileInfo.destPath);
1634
+ return processedFileInfo;
1635
+ };
1636
+
1637
+ /**
1638
+ * 写入渲染后的文件到目标路径
1639
+ *
1640
+ * @param options - 写入选项
1641
+ */
1642
+ const writeRenderedFile = async (options
1643
+
1644
+
1645
+
1646
+ ) => {
1647
+ const { fileInfo, srcPath, destPath } = options;
1648
+
1649
+ logger.verbose(` - Writing: ${fileInfo.destPath}`);
1612
1650
 
1613
1651
  // 确保目标目录存在
1614
- await ensureDir(path.dirname(finalDestPath));
1652
+ await ensureDir(path.dirname(destPath));
1615
1653
 
1616
1654
  // 写入文件
1617
- if (processedFileInfo.isBinary) {
1618
- // 二进制文件:如果内容没变,直接复制;否则从 base64 解码写入
1619
- if (processedFileInfo.content === content) {
1620
- await fs$1.copyFile(srcPath, finalDestPath);
1655
+ if (fileInfo.isBinary) {
1656
+ // 二进制文件:如果内容是原始 base64(未被 hook 修改),直接复制;否则从 base64 解码写入
1657
+ const buffer = await fs$1.readFile(srcPath);
1658
+ const originalContent = buffer.toString('base64');
1659
+
1660
+ if (fileInfo.content === originalContent) {
1661
+ await fs$1.copyFile(srcPath, destPath);
1621
1662
  logger.verbose(' ✓ Copied (binary)');
1622
1663
  } else {
1623
- const buffer = Buffer.from(processedFileInfo.content, 'base64');
1624
- await fs$1.writeFile(finalDestPath, buffer);
1664
+ const modifiedBuffer = Buffer.from(fileInfo.content, 'base64');
1665
+ await fs$1.writeFile(destPath, modifiedBuffer);
1625
1666
  logger.verbose(' ✓ Written (binary, modified by hook)');
1626
1667
  }
1627
1668
  } else {
1628
1669
  // 文本文件
1629
- await fs$1.writeFile(finalDestPath, processedFileInfo.content, 'utf-8');
1670
+ await fs$1.writeFile(destPath, fileInfo.content, 'utf-8');
1630
1671
  logger.verbose(' ✓ Rendered and written');
1631
1672
  }
1632
1673
  };
1674
+ // end_aigc
1675
+
1676
+ // ABOUTME: File conflict detection utilities for template processing
1677
+ // ABOUTME: Provides dry-run file collection and conflict checking
1678
+
1679
+
1680
+
1681
+
1682
+
1683
+
1684
+
1685
+ // start_aigc
1686
+ /**
1687
+ * 收集所有将要写入的文件路径(dry-run 阶段)
1688
+ *
1689
+ * @param options - 收集选项
1690
+ * @returns 将要写入的文件路径列表
1691
+ */
1692
+ const collectFilesToRender = async (options
1693
+
1694
+
1695
+
1696
+
1697
+ ) => {
1698
+ const { files, templatePath, context, templateConfig } = options;
1699
+
1700
+ logger.verbose('\nDry-run: Collecting files to render...');
1701
+
1702
+ const fileInfos = await Promise.all(
1703
+ files.map(file =>
1704
+ prepareFileInfo({
1705
+ file,
1706
+ templatePath,
1707
+ context,
1708
+ templateConfig,
1709
+ }),
1710
+ ),
1711
+ );
1712
+
1713
+ // 过滤掉被 hook 跳过的文件,收集 destPath
1714
+ const filesToWrite = fileInfos
1715
+ .filter((info) => info !== null)
1716
+ .map(info => info.destPath);
1717
+
1718
+ logger.verbose(` - ${filesToWrite.length} files will be written`);
1719
+ logger.verbose(
1720
+ ` - ${fileInfos.length - filesToWrite.length} files skipped by hooks`,
1721
+ );
1722
+
1723
+ return filesToWrite;
1724
+ };
1725
+
1726
+ /**
1727
+ * 检测文件冲突
1728
+ *
1729
+ * @param outputPath - 输出目录路径
1730
+ * @param filesToWrite - 将要写入的文件路径列表
1731
+ * @returns 冲突的文件路径列表
1732
+ */
1733
+ const detectFileConflicts = (
1734
+ outputPath,
1735
+ filesToWrite,
1736
+ ) => {
1737
+ logger.verbose('\nChecking for file conflicts...');
1738
+
1739
+ const conflicts = [];
1740
+
1741
+ for (const file of filesToWrite) {
1742
+ const fullPath = path.join(outputPath, file);
1743
+ if (fs.existsSync(fullPath)) {
1744
+ conflicts.push(file);
1745
+ logger.verbose(` ⚠ Conflict detected: ${file}`);
1746
+ }
1747
+ }
1748
+
1749
+ if (conflicts.length === 0) {
1750
+ logger.verbose(' ✓ No conflicts detected');
1751
+ } else {
1752
+ logger.verbose(` ⚠ ${conflicts.length} conflicts detected`);
1753
+ }
1754
+
1755
+ return conflicts;
1756
+ };
1757
+ // end_aigc
1758
+
1759
+ // ABOUTME: Main file processing orchestration for template rendering
1760
+ // ABOUTME: Coordinates file system, rendering, and conflict detection layers
1761
+
1762
+
1763
+
1764
+ // start_aigc
1765
+ /**
1766
+ * 处理单个文件(准备 + 写入)
1767
+ *
1768
+ * @param options - 处理选项
1769
+ */
1770
+ const processSingleFile = async (options
1771
+
1772
+
1773
+
1774
+
1775
+
1776
+ ) => {
1777
+ const { file, templatePath, outputPath, context, templateConfig } = options;
1778
+
1779
+ const srcPath = path.join(templatePath, file);
1780
+
1781
+ // 准备文件信息
1782
+ const processedFileInfo = await prepareFileInfo({
1783
+ file,
1784
+ templatePath,
1785
+ context,
1786
+ templateConfig,
1787
+ });
1788
+
1789
+ // 如果返回 null,跳过该文件
1790
+ if (processedFileInfo === null) {
1791
+ return;
1792
+ }
1793
+
1794
+ // 使用处理后的目标路径
1795
+ const finalDestPath = path.join(outputPath, processedFileInfo.destPath);
1796
+
1797
+ // 写入文件
1798
+ await writeRenderedFile({
1799
+ fileInfo: processedFileInfo,
1800
+ srcPath,
1801
+ destPath: finalDestPath,
1802
+ });
1803
+ };
1633
1804
 
1634
1805
  /**
1635
1806
  * 复制并处理模板文件到目标目录
1807
+ *
1808
+ * 流程:
1809
+ * 1. 验证模板目录
1810
+ * 2. 扫描所有模板文件
1811
+ * 3. Dry-run:收集将要写入的文件列表(考虑 hooks 影响)
1812
+ * 4. 冲突检测:检查是否有文件会被覆盖(可通过 force 跳过)
1813
+ * 5. 实际写入:渲染并写入所有文件
1814
+ * 6. 复制 node_modules(如果存在)
1815
+ *
1816
+ * @param options - 处理选项
1636
1817
  */
1637
1818
  const processTemplateFiles = async (options
1638
1819
 
1639
1820
 
1640
1821
 
1641
1822
 
1823
+
1642
1824
  ) => {
1643
- const { templatePath, outputPath, context, templateConfig } = options;
1825
+ const { templatePath, outputPath, context, templateConfig, force } = options;
1644
1826
  logger.verbose('Processing template files:');
1645
1827
  logger.verbose(` - Template path: ${templatePath}`);
1646
1828
  logger.verbose(` - Output path: ${outputPath}`);
1647
1829
 
1648
- // 验证模板目录是否存在
1830
+ // 阶段 0: 验证模板目录是否存在
1649
1831
  try {
1650
1832
  const stat = await fs$1.stat(templatePath);
1651
1833
  logger.verbose(
@@ -1661,6 +1843,7 @@ const processTemplateFiles = async (options
1661
1843
  throw error;
1662
1844
  }
1663
1845
 
1846
+ // 阶段 1: 扫描所有模板文件
1664
1847
  const files = await getAllFiles(templatePath);
1665
1848
 
1666
1849
  logger.verbose(` - Found ${files.length} files to process`);
@@ -1670,6 +1853,36 @@ const processTemplateFiles = async (options
1670
1853
  return;
1671
1854
  }
1672
1855
 
1856
+ // 阶段 2: Dry-run - 收集所有将要写入的文件
1857
+ const filesToWrite = await collectFilesToRender({
1858
+ files,
1859
+ templatePath,
1860
+ context,
1861
+ templateConfig,
1862
+ });
1863
+
1864
+ // 阶段 3: 冲突检测(force 为 true 时跳过)
1865
+ if (!force) {
1866
+ const conflicts = detectFileConflicts(outputPath, filesToWrite);
1867
+
1868
+ if (conflicts.length > 0) {
1869
+ // 有冲突,抛出详细的错误信息
1870
+ const conflictList = conflicts.map(f => ` - ${f}`).join('\n');
1871
+ throw new Error(
1872
+ `File conflicts detected in output directory: ${outputPath}\n\n` +
1873
+ `The following files already exist and would be overwritten:\n${conflictList}\n\n` +
1874
+ 'Please remove these files or use a different output directory.\n' +
1875
+ 'Or use --force to overwrite existing files.',
1876
+ );
1877
+ }
1878
+ } else {
1879
+ logger.verbose(
1880
+ ' - Force mode enabled, skipping conflict detection. Existing files will be overwritten.',
1881
+ );
1882
+ }
1883
+
1884
+ // 阶段 4: 实际写入文件
1885
+ logger.verbose('\nWriting files...');
1673
1886
  await Promise.all(
1674
1887
  files.map(file =>
1675
1888
  processSingleFile({
@@ -1684,74 +1897,9 @@ const processTemplateFiles = async (options
1684
1897
 
1685
1898
  logger.verbose('✓ All files processed successfully');
1686
1899
 
1687
- // 单独处理 node_modules 目录(如果存在)
1688
- const sourceNodeModules = path.join(templatePath, 'node_modules');
1689
- const targetNodeModules = path.join(outputPath, 'node_modules');
1690
-
1691
- if (fs.existsSync(sourceNodeModules)) {
1692
- logger.info('\nCopying node_modules from pre-warmed template...');
1693
- logger.verbose(` From: ${sourceNodeModules}`);
1694
- logger.verbose(` To: ${targetNodeModules}`);
1695
-
1696
- const result = shelljs.exec(`cp -R "${sourceNodeModules}" "${targetNodeModules}"`, {
1697
- silent: true,
1698
- });
1699
-
1700
- if (result.stdout) {
1701
- process.stdout.write(result.stdout);
1702
- }
1703
-
1704
- if (result.stderr) {
1705
- process.stderr.write(result.stderr);
1706
- }
1707
-
1708
- if (result.code === 0) {
1709
- logger.success('✓ node_modules copied successfully');
1710
- } else {
1711
- logger.warn(
1712
- `Failed to copy node_modules: ${result.stderr || 'unknown error'}`,
1713
- );
1714
- logger.info('Will need to run pnpm install manually');
1715
- }
1716
- }
1717
- };
1718
-
1719
- /**
1720
- * 检查输出目录是否为空
1721
- * 注意:.git 目录会被忽略,允许在已初始化 git 的目录中创建项目
1722
- *
1723
- * @param outputPath - 输出目录路径
1724
- * @returns 是否为空
1725
- */
1726
- const isOutputDirEmpty = async (
1727
- outputPath,
1728
- ) => {
1729
- try {
1730
- const entries = await fs$1.readdir(outputPath);
1731
- // 过滤掉 .git 目录,允许在已初始化 git 的目录中创建项目
1732
- const filteredEntries = entries.filter(entry => entry !== '.git');
1733
- return filteredEntries.length === 0;
1734
- } catch (e) {
1735
- // 目录不存在,视为空
1736
- return true;
1737
- }
1738
- };
1739
-
1740
- /**
1741
- * 验证输出目录
1742
- *
1743
- * @param outputPath - 输出目录路径
1744
- * @throws 如果目录不为空则抛出错误
1745
- */
1746
- const validateOutputDir = async (outputPath) => {
1747
- const isEmpty = await isOutputDirEmpty(outputPath);
1748
- if (!isEmpty) {
1749
- throw new Error(
1750
- `Output directory is not empty: ${outputPath}\n` +
1751
- 'Please use an empty directory or remove existing files.',
1752
- );
1753
- }
1900
+ // node_modules 将由 pnpm install 处理(利用缓存和硬链接机制)
1754
1901
  };
1902
+ // end_aigc
1755
1903
 
1756
1904
  /**
1757
1905
  * 模板引擎执行选项
@@ -1762,6 +1910,7 @@ const validateOutputDir = async (outputPath) => {
1762
1910
 
1763
1911
 
1764
1912
 
1913
+
1765
1914
  /**
1766
1915
  * 加载模板元数据和路径
1767
1916
  */
@@ -1831,22 +1980,47 @@ const executeAfterRenderHook = async (
1831
1980
  }
1832
1981
  };
1833
1982
 
1983
+ /**
1984
+ * 执行完成钩子
1985
+ */
1986
+ const executeCompleteHook = async (
1987
+ templateConfig,
1988
+ context,
1989
+ outputPath,
1990
+ ) => {
1991
+ if (templateConfig.onComplete) {
1992
+ await templateConfig.onComplete(context, outputPath);
1993
+ }
1994
+ };
1995
+
1834
1996
  /**
1835
1997
  * 准备输出目录
1836
1998
  */
1837
- const prepareOutputDirectory = async (outputPath) => {
1999
+ const prepareOutputDirectory = (outputPath) => {
1838
2000
  const absolutePath = path.resolve(process.cwd(), outputPath);
1839
- await validateOutputDir(absolutePath);
2001
+ // 不再在这里验证目录是否为空,冲突检测已移至 processTemplateFiles 中
1840
2002
  return absolutePath;
1841
2003
  };
1842
2004
 
2005
+ /**
2006
+ * 模板引擎执行结果
2007
+ */
2008
+
2009
+
2010
+
2011
+
2012
+
2013
+
2014
+
2015
+
2016
+
1843
2017
  /**
1844
2018
  * 执行完整的模板渲染流程
1845
2019
  */
1846
2020
  const execute = async (
1847
2021
  options,
1848
2022
  ) => {
1849
- const { templateName, outputPath, command } = options;
2023
+ const { templateName, outputPath, command, force } = options;
1850
2024
 
1851
2025
  // 1. 加载模板
1852
2026
  const { templatePath } = await loadTemplateMetadata(templateName);
@@ -1863,7 +2037,7 @@ const execute = async (
1863
2037
  });
1864
2038
 
1865
2039
  // 5. 准备输出目录
1866
- const absoluteOutputPath = await prepareOutputDirectory(outputPath);
2040
+ const absoluteOutputPath = prepareOutputDirectory(outputPath);
1867
2041
 
1868
2042
  // 6. 处理模板文件
1869
2043
  await processTemplateFiles({
@@ -1871,12 +2045,17 @@ const execute = async (
1871
2045
  outputPath: absoluteOutputPath,
1872
2046
  context,
1873
2047
  templateConfig,
2048
+ force,
1874
2049
  });
1875
2050
 
1876
2051
  // 7. 执行 onAfterRender 钩子
1877
2052
  await executeAfterRenderHook(templateConfig, context, absoluteOutputPath);
1878
2053
 
1879
- return absoluteOutputPath;
2054
+ return {
2055
+ outputPath: absoluteOutputPath,
2056
+ templateConfig,
2057
+ context,
2058
+ };
1880
2059
  };
1881
2060
 
1882
2061
  function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
@@ -2022,6 +2201,7 @@ const executeInit = async (
2022
2201
 
2023
2202
 
2024
2203
 
2204
+
2025
2205
  ,
2026
2206
  command,
2027
2207
  ) => {
@@ -2034,37 +2214,44 @@ const executeInit = async (
2034
2214
  skipInstall,
2035
2215
  skipGit,
2036
2216
  skipDev,
2217
+ force,
2037
2218
  } = options;
2038
2219
 
2039
2220
  logger.info(`Initializing project with template: ${templateName}`);
2040
2221
  timer.logPhase('Initialization');
2041
2222
 
2042
- // 执行模板引擎,返回绝对路径
2043
- const absoluteOutputPath = await execute({
2223
+ // 执行模板引擎,返回结果对象
2224
+ const result = await execute({
2044
2225
  templateName,
2045
2226
  outputPath,
2046
2227
  command,
2228
+ force,
2047
2229
  });
2230
+ const { outputPath: absoluteOutputPath, templateConfig, context } = result;
2048
2231
 
2049
2232
  timer.logPhase('Template engine execution');
2050
2233
  logger.success('Project created successfully!');
2051
2234
 
2052
- // 如果没有跳过安装,检查是否需要运行 pnpm install
2053
- if (!skipInstall) {
2054
- const nodeModulesPath = path.join(absoluteOutputPath, 'node_modules');
2055
- const hasNodeModules = fs.existsSync(nodeModulesPath);
2235
+ // 检查是否存在 package.json
2236
+ const packageJsonPath = path.join(absoluteOutputPath, 'package.json');
2237
+ const hasPackageJson = fs.existsSync(packageJsonPath);
2056
2238
 
2057
- if (hasNodeModules) {
2058
- logger.info(
2059
- '\n💡 Using pre-warmed node_modules, skipping pnpm install',
2060
- );
2061
- timer.logPhase('Node modules (pre-warmed)');
2062
- } else {
2239
+ // 安装依赖(始终使用 pnpm install,利用缓存机制)
2240
+ if (!skipInstall) {
2241
+ if (hasPackageJson) {
2063
2242
  runPnpmInstall(absoluteOutputPath);
2064
2243
  timer.logPhase('Dependencies installation');
2244
+ } else {
2245
+ logger.info(
2246
+ '\n💡 No package.json found, skipping dependency installation',
2247
+ );
2065
2248
  }
2066
2249
  }
2067
2250
 
2251
+ // 执行 onComplete 钩子(在 pnpm install 之后)
2252
+ await executeCompleteHook(templateConfig, context, absoluteOutputPath);
2253
+ timer.logPhase('Complete hook execution');
2254
+
2068
2255
  // 如果没有跳过 git,则初始化 git 仓库
2069
2256
  if (!skipGit) {
2070
2257
  runGitInit(absoluteOutputPath);
@@ -2079,7 +2266,7 @@ const executeInit = async (
2079
2266
  // 只有跳过 dev 时才显示 Next steps
2080
2267
  logger.info('\nNext steps:');
2081
2268
  logger.info(` cd ${outputPath}`);
2082
- if (skipInstall) {
2269
+ if (skipInstall && hasPackageJson) {
2083
2270
  logger.info(' pnpm install');
2084
2271
  }
2085
2272
  if (skipGit) {
@@ -2103,7 +2290,7 @@ const executeInit = async (
2103
2290
  /**
2104
2291
  * 注册 init 命令到 program
2105
2292
  */
2106
- const registerCommand = program => {
2293
+ const registerCommand$1 = program => {
2107
2294
  program
2108
2295
  .command('init')
2109
2296
  .description('Initialize a new project from a template')
@@ -2113,6 +2300,11 @@ const registerCommand = program => {
2113
2300
  .option('--skip-install', 'Skip automatic pnpm install', false)
2114
2301
  .option('--skip-git', 'Skip automatic git initialization', false)
2115
2302
  .option('--skip-dev', 'Skip automatic dev server start', false)
2303
+ .option(
2304
+ '--force',
2305
+ 'Force overwrite existing files without checking conflicts',
2306
+ true,
2307
+ )
2116
2308
  .allowUnknownOption() // 允许透传参数
2117
2309
  .action(async (directory, options, command) => {
2118
2310
  // 位置参数优先级高于 --output 选项
@@ -2121,15 +2313,312 @@ const registerCommand = program => {
2121
2313
  });
2122
2314
  };
2123
2315
 
2124
- var version = "0.0.1-alpha.e8683e";
2316
+ // ABOUTME: This file implements the update command for coze CLI
2317
+ // ABOUTME: It wraps pnpm update/install to update package dependencies with logging support
2318
+
2319
+
2320
+
2321
+
2322
+ /**
2323
+ * 日志文件名常量
2324
+ */
2325
+ const LOG_FILE_NAME = 'update.log';
2326
+
2327
+ /**
2328
+ * 获取日志目录
2329
+ * 优先使用环境变量 COZE_LOG_DIR,否则使用 ~/.coze-logs
2330
+ */
2331
+ const getLogDir = () =>
2332
+ process.env.COZE_LOG_DIR || path.join(os.homedir(), '.coze-logs');
2333
+
2334
+ /**
2335
+ * 解析日志文件路径
2336
+ * - 如果是绝对路径,直接使用
2337
+ * - 如果是相对路径,基于 getLogDir() + 相对路径
2338
+ * - 如果为空,使用 getLogDir() + LOG_FILE_NAME
2339
+ */
2340
+ const resolveLogFilePath = (logFile) => {
2341
+ if (!logFile) {
2342
+ return path.join(getLogDir(), LOG_FILE_NAME);
2343
+ }
2344
+
2345
+ if (path.isAbsolute(logFile)) {
2346
+ return logFile;
2347
+ }
2348
+
2349
+ return path.join(getLogDir(), logFile);
2350
+ };
2351
+
2352
+ /**
2353
+ * 创建日志写入流
2354
+ */
2355
+ const createLogStream = (logFilePath) => {
2356
+ const logDir = path.dirname(logFilePath);
2357
+
2358
+ // 确保日志目录存在
2359
+ if (!fs.existsSync(logDir)) {
2360
+ fs.mkdirSync(logDir, { recursive: true });
2361
+ }
2362
+
2363
+ // 使用 'w' 标志覆盖之前的日志
2364
+ return fs.createWriteStream(logFilePath, { flags: 'w' });
2365
+ };
2366
+
2367
+ /**
2368
+ * 格式化时间戳
2369
+ */
2370
+ const formatTimestamp = () => {
2371
+ const now = new Date();
2372
+ return now.toISOString();
2373
+ };
2374
+
2375
+ /**
2376
+ * 写入带时间戳的日志
2377
+ */
2378
+ const writeLogWithTimestamp = (stream, message) => {
2379
+ const timestamp = formatTimestamp();
2380
+ const lines = message.split('\n');
2381
+ lines.forEach(line => {
2382
+ if (line) {
2383
+ stream.write(`[${timestamp}] ${line}\n`);
2384
+ } else {
2385
+ stream.write('\n');
2386
+ }
2387
+ });
2388
+ // 确保数据写入磁盘
2389
+ stream.uncork();
2390
+ };
2391
+
2392
+ /**
2393
+ * 同时输出到控制台和日志文件
2394
+ */
2395
+ const logWithFile = (
2396
+ stream,
2397
+ level,
2398
+ message,
2399
+ ) => {
2400
+ // 输出到控制台
2401
+ switch (level) {
2402
+ case 'info':
2403
+ logger.info(message);
2404
+ break;
2405
+ case 'success':
2406
+ logger.success(message);
2407
+ break;
2408
+ case 'error':
2409
+ logger.error(message);
2410
+ break;
2411
+ default:
2412
+ logger.info(message);
2413
+ break;
2414
+ }
2415
+
2416
+ // 写入日志文件(带时间戳)
2417
+ writeLogWithTimestamp(stream, `[${level.toUpperCase()}] ${message}`);
2418
+ };
2419
+
2420
+ // start_aigc
2421
+ /**
2422
+ * 构建 pnpm add 命令
2423
+ */
2424
+ const buildPnpmCommand = (
2425
+ packageName,
2426
+ options
2427
+
2428
+
2429
+
2430
+
2431
+ ,
2432
+ ) => {
2433
+ const { global, version, registry, extraArgs } = options;
2434
+
2435
+ const parts = ['pnpm', 'add'];
2436
+
2437
+ // 添加全局标记
2438
+ if (global) {
2439
+ parts.push('-g');
2440
+ }
2441
+
2442
+ // 添加包名和版本
2443
+ if (version && version !== 'latest') {
2444
+ parts.push(`${packageName}@${version}`);
2445
+ } else {
2446
+ parts.push(`${packageName}@latest`);
2447
+ }
2448
+
2449
+ // 添加 registry
2450
+ if (registry) {
2451
+ parts.push(`--registry=${registry}`);
2452
+ }
2453
+
2454
+ // 添加额外参数
2455
+ if (extraArgs.length > 0) {
2456
+ parts.push(...extraArgs);
2457
+ }
2458
+
2459
+ return parts.join(' ');
2460
+ };
2461
+ // end_aigc
2462
+
2463
+ // start_aigc
2464
+ /**
2465
+ * 执行 update 命令的内部实现
2466
+ */
2467
+ const executeUpdate = (
2468
+ packageName,
2469
+ options
2470
+
2471
+
2472
+
2473
+
2474
+
2475
+
2476
+ ,
2477
+ ) => {
2478
+ let logStream = null;
2479
+
2480
+ try {
2481
+ const { global, cwd, version, registry, logFile, extraArgs } = options;
2482
+
2483
+ // 准备日志
2484
+ const logFilePath = resolveLogFilePath(logFile);
2485
+
2486
+ // 调试:确认日志路径
2487
+ logger.info(`Log file path resolved to: ${logFilePath}`);
2488
+
2489
+ logStream = createLogStream(logFilePath);
2490
+
2491
+ // 调试:确认流已创建
2492
+ logger.info('Log stream created successfully');
2493
+
2494
+ logWithFile(logStream, 'info', `Updating package: ${packageName}`);
2495
+
2496
+ // 构建命令
2497
+ const command = buildPnpmCommand(packageName, {
2498
+ global,
2499
+ version,
2500
+ registry,
2501
+ extraArgs,
2502
+ });
2503
+
2504
+ // 确定工作目录
2505
+ const workingDir = cwd
2506
+ ? path.isAbsolute(cwd)
2507
+ ? cwd
2508
+ : path.join(process.cwd(), cwd)
2509
+ : process.cwd();
2510
+
2511
+ logWithFile(logStream, 'info', `Executing: ${command}`);
2512
+ logWithFile(logStream, 'info', `Working directory: ${workingDir}`);
2513
+ logWithFile(logStream, 'info', `Log file: ${logFilePath}`);
2514
+
2515
+ // 记录命令开始时间
2516
+ writeLogWithTimestamp(logStream, '--- Command execution started ---');
2517
+
2518
+ // 同步执行命令
2519
+ const result = shelljs.exec(command, {
2520
+ cwd: workingDir,
2521
+ silent: true, // 使用 silent 来捕获输出
2522
+ });
2523
+
2524
+ // 将输出写入控制台和日志文件(带时间戳)
2525
+ if (result.stdout) {
2526
+ process.stdout.write(result.stdout);
2527
+ writeLogWithTimestamp(logStream, result.stdout.trim());
2528
+ }
2529
+
2530
+ if (result.stderr) {
2531
+ process.stderr.write(result.stderr);
2532
+ writeLogWithTimestamp(logStream, result.stderr.trim());
2533
+ }
2534
+
2535
+ // 记录命令结束时间
2536
+ writeLogWithTimestamp(logStream, '--- Command execution ended ---');
2537
+
2538
+ // 检查执行结果并记录到日志
2539
+ if (result.code === 0) {
2540
+ logWithFile(logStream, 'success', 'Package updated successfully');
2541
+ logWithFile(logStream, 'info', `Log file: ${logFilePath}`);
2542
+ } else {
2543
+ logWithFile(
2544
+ logStream,
2545
+ 'error',
2546
+ `Command exited with code ${result.code}`,
2547
+ );
2548
+ logWithFile(
2549
+ logStream,
2550
+ 'error',
2551
+ `Check log file for details: ${logFilePath}`,
2552
+ );
2553
+ }
2554
+
2555
+ // 关闭日志流并等待写入完成
2556
+ logStream.end(() => {
2557
+ // 流关闭后再退出进程
2558
+ if (result.code !== 0) {
2559
+ process.exit(result.code || 1);
2560
+ }
2561
+ });
2562
+ } catch (error) {
2563
+ logger.error('Failed to update package:');
2564
+ logger.error(error instanceof Error ? error.message : String(error));
2565
+
2566
+ // 写入错误到日志文件
2567
+ if (logStream) {
2568
+ writeLogWithTimestamp(
2569
+ logStream,
2570
+ `[ERROR] ${error instanceof Error ? error.message : String(error)}`,
2571
+ );
2572
+ // 等待流关闭后再退出
2573
+ logStream.end(() => {
2574
+ process.exit(1);
2575
+ });
2576
+ } else {
2577
+ process.exit(1);
2578
+ }
2579
+ }
2580
+ };
2581
+ // end_aigc
2582
+
2583
+ /**
2584
+ * 注册 update 命令到 program
2585
+ */
2586
+ const registerCommand = program => {
2587
+ program
2588
+ .command('update <package>')
2589
+ .description('Update a package dependency')
2590
+ .option('-g, --global', 'Update package globally', false)
2591
+ .option('-c, --cwd <path>', 'Working directory for the update')
2592
+ .option(
2593
+ '--to <version>',
2594
+ 'Version to update to (default: latest)',
2595
+ 'latest',
2596
+ )
2597
+ .option('--registry <url>', 'Registry URL to use for the update')
2598
+ .option('--log-file <path>', 'Log file path')
2599
+ .allowUnknownOption() // 允许透传参数给 pnpm
2600
+ .action((packageName, options, command) => {
2601
+ // 收集所有未知选项作为额外参数
2602
+ const extraArgs = command.args.slice(1);
2603
+
2604
+ executeUpdate(packageName, {
2605
+ ...options,
2606
+ version: options.to, // 将 --to 映射到 version
2607
+ extraArgs,
2608
+ });
2609
+ });
2610
+ };
2611
+
2612
+ var version = "0.0.1-alpha.e9ff73";
2125
2613
  var packageJson = {
2126
2614
  version: version};
2127
2615
 
2128
2616
  const commands = [
2129
- registerCommand,
2130
2617
  registerCommand$1,
2131
- registerCommand$3,
2132
2618
  registerCommand$2,
2619
+ registerCommand$4,
2620
+ registerCommand$3,
2621
+ registerCommand,
2133
2622
  ];
2134
2623
 
2135
2624
  const main = () => {