@coze-arch/cli 0.0.1-alpha.374e8d → 0.0.1-alpha.3ed8e2

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 (150) hide show
  1. package/README.md +1 -0
  2. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +1 -1
  3. package/lib/__templates__/expo/client/components/Screen.tsx +2 -2
  4. package/lib/__templates__/expo/client/eslint.config.mjs +7 -0
  5. package/lib/__templates__/expo/client/metro.config.js +3 -0
  6. package/lib/__templates__/expo/client/package.json +35 -35
  7. package/lib/__templates__/expo/client/scripts/install-missing-deps.js +10 -10
  8. package/lib/__templates__/expo/eslint-plugins/forbid-emoji/index.js +9 -0
  9. package/lib/__templates__/expo/eslint-plugins/forbid-emoji/rule.js +112 -0
  10. package/lib/__templates__/expo/eslint-plugins/forbid-emoji/tech.md +94 -0
  11. package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/index.js +9 -0
  12. package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/rule.js +120 -0
  13. package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/tech.md +58 -0
  14. package/lib/__templates__/expo/package.json +1 -1
  15. package/lib/__templates__/expo/pnpm-lock.yaml +394 -221
  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/README.md +5 -0
  24. package/lib/__templates__/nextjs/eslint.config.mjs +5 -0
  25. package/lib/__templates__/nextjs/next.config.ts +1 -2
  26. package/lib/__templates__/nextjs/package.json +5 -6
  27. package/lib/__templates__/nextjs/pnpm-lock.yaml +1145 -109
  28. package/lib/__templates__/nextjs/scripts/build.sh +4 -1
  29. package/lib/__templates__/nextjs/scripts/dev.sh +8 -2
  30. package/lib/__templates__/nextjs/scripts/start.sh +7 -1
  31. package/lib/__templates__/nextjs/src/app/layout.tsx +1 -1
  32. package/lib/__templates__/nextjs/src/app/page.tsx +4 -3
  33. package/lib/__templates__/nextjs/src/server.ts +35 -0
  34. package/lib/__templates__/nextjs/template.config.js +49 -14
  35. package/lib/__templates__/nextjs/tsconfig.json +1 -1
  36. package/lib/__templates__/nuxt-vue/.coze +12 -0
  37. package/lib/__templates__/nuxt-vue/README.md +73 -0
  38. package/lib/__templates__/nuxt-vue/_gitignore +24 -0
  39. package/lib/__templates__/nuxt-vue/_npmrc +23 -0
  40. package/lib/__templates__/nuxt-vue/app/app.vue +6 -0
  41. package/lib/__templates__/nuxt-vue/app/pages/index.vue +23 -0
  42. package/lib/__templates__/nuxt-vue/assets/css/main.css +24 -0
  43. package/lib/__templates__/nuxt-vue/nuxt.config.ts +116 -0
  44. package/lib/__templates__/nuxt-vue/package.json +35 -0
  45. package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +8759 -0
  46. package/lib/__templates__/nuxt-vue/postcss.config.mjs +8 -0
  47. package/lib/__templates__/nuxt-vue/public/favicon.ico +0 -0
  48. package/lib/__templates__/nuxt-vue/public/robots.txt +2 -0
  49. package/lib/__templates__/nuxt-vue/scripts/build.sh +14 -0
  50. package/lib/__templates__/nuxt-vue/scripts/dev.sh +39 -0
  51. package/lib/__templates__/nuxt-vue/scripts/prepare.sh +14 -0
  52. package/lib/__templates__/nuxt-vue/scripts/start.sh +21 -0
  53. package/lib/__templates__/nuxt-vue/server/api/hello.ts +10 -0
  54. package/lib/__templates__/nuxt-vue/server/middleware/logger.ts +10 -0
  55. package/lib/__templates__/nuxt-vue/server/routes/health.ts +10 -0
  56. package/lib/__templates__/nuxt-vue/tailwind.config.js +13 -0
  57. package/lib/__templates__/nuxt-vue/template.config.js +87 -0
  58. package/lib/__templates__/nuxt-vue/tsconfig.json +18 -0
  59. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +107 -37
  60. package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -1
  61. package/lib/__templates__/taro/README.md +138 -62
  62. package/lib/__templates__/taro/config/index.ts +105 -41
  63. package/lib/__templates__/taro/config/prod.ts +4 -5
  64. package/lib/__templates__/taro/eslint.config.mjs +82 -4
  65. package/lib/__templates__/taro/package.json +23 -6
  66. package/lib/__templates__/taro/patches/@tarojs__plugin-mini-ci@4.1.9.patch +30 -0
  67. package/lib/__templates__/taro/pnpm-lock.yaml +1293 -311
  68. package/lib/__templates__/taro/server/package.json +3 -1
  69. package/lib/__templates__/taro/src/app.css +141 -37
  70. package/lib/__templates__/taro/src/app.tsx +9 -0
  71. package/lib/__templates__/taro/src/components/ui/accordion.tsx +159 -0
  72. package/lib/__templates__/taro/src/components/ui/alert-dialog.tsx +260 -0
  73. package/lib/__templates__/taro/src/components/ui/alert.tsx +60 -0
  74. package/lib/__templates__/taro/src/components/ui/aspect-ratio.tsx +36 -0
  75. package/lib/__templates__/taro/src/components/ui/avatar.tsx +84 -0
  76. package/lib/__templates__/taro/src/components/ui/badge.tsx +37 -0
  77. package/lib/__templates__/taro/src/components/ui/breadcrumb.tsx +117 -0
  78. package/lib/__templates__/taro/src/components/ui/button-group.tsx +83 -0
  79. package/lib/__templates__/taro/src/components/ui/button.tsx +67 -0
  80. package/lib/__templates__/taro/src/components/ui/calendar.tsx +394 -0
  81. package/lib/__templates__/taro/src/components/ui/card.tsx +108 -0
  82. package/lib/__templates__/taro/src/components/ui/carousel.tsx +228 -0
  83. package/lib/__templates__/taro/src/components/ui/checkbox.tsx +58 -0
  84. package/lib/__templates__/taro/src/components/ui/code-block.tsx +169 -0
  85. package/lib/__templates__/taro/src/components/ui/collapsible.tsx +71 -0
  86. package/lib/__templates__/taro/src/components/ui/command.tsx +385 -0
  87. package/lib/__templates__/taro/src/components/ui/context-menu.tsx +614 -0
  88. package/lib/__templates__/taro/src/components/ui/dialog.tsx +256 -0
  89. package/lib/__templates__/taro/src/components/ui/drawer.tsx +192 -0
  90. package/lib/__templates__/taro/src/components/ui/dropdown-menu.tsx +561 -0
  91. package/lib/__templates__/taro/src/components/ui/field.tsx +228 -0
  92. package/lib/__templates__/taro/src/components/ui/hover-card.tsx +282 -0
  93. package/lib/__templates__/taro/src/components/ui/input-group.tsx +197 -0
  94. package/lib/__templates__/taro/src/components/ui/input-otp.tsx +136 -0
  95. package/lib/__templates__/taro/src/components/ui/input.tsx +56 -0
  96. package/lib/__templates__/taro/src/components/ui/label.tsx +24 -0
  97. package/lib/__templates__/taro/src/components/ui/menubar.tsx +595 -0
  98. package/lib/__templates__/taro/src/components/ui/navigation-menu.tsx +264 -0
  99. package/lib/__templates__/taro/src/components/ui/pagination.tsx +118 -0
  100. package/lib/__templates__/taro/src/components/ui/popover.tsx +291 -0
  101. package/lib/__templates__/taro/src/components/ui/portal.tsx +19 -0
  102. package/lib/__templates__/taro/src/components/ui/progress.tsx +28 -0
  103. package/lib/__templates__/taro/src/components/ui/radio-group.tsx +64 -0
  104. package/lib/__templates__/taro/src/components/ui/resizable.tsx +346 -0
  105. package/lib/__templates__/taro/src/components/ui/scroll-area.tsx +34 -0
  106. package/lib/__templates__/taro/src/components/ui/select.tsx +438 -0
  107. package/lib/__templates__/taro/src/components/ui/separator.tsx +30 -0
  108. package/lib/__templates__/taro/src/components/ui/sheet.tsx +262 -0
  109. package/lib/__templates__/taro/src/components/ui/skeleton.tsx +17 -0
  110. package/lib/__templates__/taro/src/components/ui/slider.tsx +203 -0
  111. package/lib/__templates__/taro/src/components/ui/sonner.tsx +1 -0
  112. package/lib/__templates__/taro/src/components/ui/switch.tsx +55 -0
  113. package/lib/__templates__/taro/src/components/ui/table.tsx +142 -0
  114. package/lib/__templates__/taro/src/components/ui/tabs.tsx +114 -0
  115. package/lib/__templates__/taro/src/components/ui/textarea.tsx +54 -0
  116. package/lib/__templates__/taro/src/components/ui/toast.tsx +517 -0
  117. package/lib/__templates__/taro/src/components/ui/toggle-group.tsx +120 -0
  118. package/lib/__templates__/taro/src/components/ui/toggle.tsx +77 -0
  119. package/lib/__templates__/taro/src/components/ui/tooltip.tsx +455 -0
  120. package/lib/__templates__/taro/src/lib/hooks/use-keyboard-offset.ts +37 -0
  121. package/lib/__templates__/taro/src/lib/measure.ts +115 -0
  122. package/lib/__templates__/taro/src/lib/platform.ts +12 -0
  123. package/lib/__templates__/taro/src/lib/utils.ts +6 -0
  124. package/lib/__templates__/taro/src/presets/dev-debug.ts +23 -0
  125. package/lib/__templates__/taro/src/presets/h5-container.tsx +15 -0
  126. package/lib/__templates__/taro/src/presets/h5-navbar.tsx +238 -0
  127. package/lib/__templates__/taro/src/presets/h5-styles.ts +220 -0
  128. package/lib/__templates__/taro/src/presets/index.tsx +18 -0
  129. package/lib/__templates__/templates.json +43 -0
  130. package/lib/__templates__/vite/README.md +190 -11
  131. package/lib/__templates__/vite/_gitignore +1 -0
  132. package/lib/__templates__/vite/eslint.config.mjs +6 -1
  133. package/lib/__templates__/vite/package.json +14 -3
  134. package/lib/__templates__/vite/pnpm-lock.yaml +820 -1593
  135. package/lib/__templates__/vite/scripts/build.sh +4 -1
  136. package/lib/__templates__/vite/scripts/dev.sh +9 -2
  137. package/lib/__templates__/vite/scripts/start.sh +9 -3
  138. package/lib/__templates__/vite/server/routes/index.ts +31 -0
  139. package/lib/__templates__/vite/server/server.ts +65 -0
  140. package/lib/__templates__/vite/server/vite.ts +67 -0
  141. package/lib/__templates__/vite/src/main.ts +2 -2
  142. package/lib/__templates__/vite/template.config.js +49 -14
  143. package/lib/__templates__/vite/tsconfig.json +4 -3
  144. package/lib/__templates__/vite/vite.config.ts +5 -0
  145. package/lib/cli.js +160 -159
  146. package/package.json +7 -3
  147. package/lib/__templates__/taro/src/app.ts +0 -14
  148. package/lib/__templates__/taro/src/utils/h5-styles.ts +0 -22
  149. package/lib/__templates__/taro/src/utils/wx-debug.ts +0 -23
  150. /package/lib/__templates__/expo/patches/{expo@54.0.32.patch → expo@54.0.33.patch} +0 -0
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 {
@@ -590,7 +594,7 @@ const registerCommand$4 = 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
  };
@@ -1511,46 +1515,6 @@ const convertDotfileName = (filePath) => {
1511
1515
 
1512
1516
  return filePath;
1513
1517
  };
1514
-
1515
- /**
1516
- * 复制 node_modules 目录(如果存在)
1517
- *
1518
- * @param sourceNodeModules - 源 node_modules 路径
1519
- * @param targetNodeModules - 目标 node_modules 路径
1520
- */
1521
- const copyNodeModules = (
1522
- sourceNodeModules,
1523
- targetNodeModules,
1524
- ) => {
1525
- if (!fs.existsSync(sourceNodeModules)) {
1526
- return;
1527
- }
1528
-
1529
- logger.info('\nCopying node_modules from pre-warmed template...');
1530
- logger.verbose(` From: ${sourceNodeModules}`);
1531
- logger.verbose(` To: ${targetNodeModules}`);
1532
-
1533
- const result = shelljs.exec(`cp -R "${sourceNodeModules}" "${targetNodeModules}"`, {
1534
- silent: true,
1535
- });
1536
-
1537
- if (result.stdout) {
1538
- process.stdout.write(result.stdout);
1539
- }
1540
-
1541
- if (result.stderr) {
1542
- process.stderr.write(result.stderr);
1543
- }
1544
-
1545
- if (result.code === 0) {
1546
- logger.success('✓ node_modules copied successfully');
1547
- } else {
1548
- logger.warn(
1549
- `Failed to copy node_modules: ${result.stderr || 'unknown error'}`,
1550
- );
1551
- logger.info('Will need to run pnpm install manually');
1552
- }
1553
- };
1554
1518
  // end_aigc
1555
1519
 
1556
1520
  // ABOUTME: File rendering utilities for template processing
@@ -1758,38 +1722,6 @@ const collectFilesToRender = async (options
1758
1722
 
1759
1723
  return filesToWrite;
1760
1724
  };
1761
-
1762
- /**
1763
- * 检测文件冲突
1764
- *
1765
- * @param outputPath - 输出目录路径
1766
- * @param filesToWrite - 将要写入的文件路径列表
1767
- * @returns 冲突的文件路径列表
1768
- */
1769
- const detectFileConflicts = (
1770
- outputPath,
1771
- filesToWrite,
1772
- ) => {
1773
- logger.verbose('\nChecking for file conflicts...');
1774
-
1775
- const conflicts = [];
1776
-
1777
- for (const file of filesToWrite) {
1778
- const fullPath = path.join(outputPath, file);
1779
- if (fs.existsSync(fullPath)) {
1780
- conflicts.push(file);
1781
- logger.verbose(` ⚠ Conflict detected: ${file}`);
1782
- }
1783
- }
1784
-
1785
- if (conflicts.length === 0) {
1786
- logger.verbose(' ✓ No conflicts detected');
1787
- } else {
1788
- logger.verbose(` ⚠ ${conflicts.length} conflicts detected`);
1789
- }
1790
-
1791
- return conflicts;
1792
- };
1793
1725
  // end_aigc
1794
1726
 
1795
1727
  // ABOUTME: Main file processing orchestration for template rendering
@@ -1845,7 +1777,7 @@ const processSingleFile = async (options
1845
1777
  * 1. 验证模板目录
1846
1778
  * 2. 扫描所有模板文件
1847
1779
  * 3. Dry-run:收集将要写入的文件列表(考虑 hooks 影响)
1848
- * 4. 冲突检测:检查是否有文件会被覆盖
1780
+ * 4. 冲突检测:检查是否有文件会被覆盖(可通过 force 跳过)
1849
1781
  * 5. 实际写入:渲染并写入所有文件
1850
1782
  * 6. 复制 node_modules(如果存在)
1851
1783
  *
@@ -1856,8 +1788,9 @@ const processTemplateFiles = async (options
1856
1788
 
1857
1789
 
1858
1790
 
1791
+
1859
1792
  ) => {
1860
- const { templatePath, outputPath, context, templateConfig } = options;
1793
+ const { templatePath, outputPath, context, templateConfig} = options;
1861
1794
  logger.verbose('Processing template files:');
1862
1795
  logger.verbose(` - Template path: ${templatePath}`);
1863
1796
  logger.verbose(` - Output path: ${outputPath}`);
@@ -1889,23 +1822,17 @@ const processTemplateFiles = async (options
1889
1822
  }
1890
1823
 
1891
1824
  // 阶段 2: Dry-run - 收集所有将要写入的文件
1892
- const filesToWrite = await collectFilesToRender({
1825
+ await collectFilesToRender({
1893
1826
  files,
1894
1827
  templatePath,
1895
1828
  context,
1896
1829
  templateConfig,
1897
1830
  });
1898
1831
 
1899
- // 阶段 3: 冲突检测
1900
- const conflicts = detectFileConflicts(outputPath, filesToWrite);
1901
-
1902
- if (conflicts.length > 0) {
1903
- // 有冲突,抛出详细的错误信息
1904
- const conflictList = conflicts.map(f => ` - ${f}`).join('\n');
1905
- throw new Error(
1906
- `File conflicts detected in output directory: ${outputPath}\n\n` +
1907
- `The following files already exist and would be overwritten:\n${conflictList}\n\n` +
1908
- 'Please remove these files or use a different output directory.',
1832
+ // 阶段 3: 冲突检测(force 为 true 时跳过)
1833
+ {
1834
+ logger.verbose(
1835
+ ' - Force mode enabled, skipping conflict detection. Existing files will be overwritten.',
1909
1836
  );
1910
1837
  }
1911
1838
 
@@ -1925,11 +1852,7 @@ const processTemplateFiles = async (options
1925
1852
 
1926
1853
  logger.verbose('✓ All files processed successfully');
1927
1854
 
1928
- // 阶段 5: 单独处理 node_modules 目录(如果存在)
1929
- const sourceNodeModules = path.join(templatePath, 'node_modules');
1930
- const targetNodeModules = path.join(outputPath, 'node_modules');
1931
-
1932
- copyNodeModules(sourceNodeModules, targetNodeModules);
1855
+ // node_modules 将由 pnpm install 处理(利用缓存和硬链接机制)
1933
1856
  };
1934
1857
  // end_aigc
1935
1858
 
@@ -1942,6 +1865,7 @@ const processTemplateFiles = async (options
1942
1865
 
1943
1866
 
1944
1867
 
1868
+
1945
1869
  /**
1946
1870
  * 加载模板元数据和路径
1947
1871
  */
@@ -2011,6 +1935,19 @@ const executeAfterRenderHook = async (
2011
1935
  }
2012
1936
  };
2013
1937
 
1938
+ /**
1939
+ * 执行完成钩子
1940
+ */
1941
+ const executeCompleteHook = async (
1942
+ templateConfig,
1943
+ context,
1944
+ outputPath,
1945
+ ) => {
1946
+ if (templateConfig.onComplete) {
1947
+ await templateConfig.onComplete(context, outputPath);
1948
+ }
1949
+ };
1950
+
2014
1951
  /**
2015
1952
  * 准备输出目录
2016
1953
  */
@@ -2020,13 +1957,25 @@ const prepareOutputDirectory = (outputPath) => {
2020
1957
  return absolutePath;
2021
1958
  };
2022
1959
 
1960
+ /**
1961
+ * 模板引擎执行结果
1962
+ */
1963
+
1964
+
1965
+
1966
+
1967
+
1968
+
1969
+
1970
+
1971
+
2023
1972
  /**
2024
1973
  * 执行完整的模板渲染流程
2025
1974
  */
2026
1975
  const execute = async (
2027
1976
  options,
2028
1977
  ) => {
2029
- const { templateName, outputPath, command } = options;
1978
+ const { templateName, outputPath, command} = options;
2030
1979
 
2031
1980
  // 1. 加载模板
2032
1981
  const { templatePath } = await loadTemplateMetadata(templateName);
@@ -2050,13 +1999,16 @@ const execute = async (
2050
1999
  templatePath,
2051
2000
  outputPath: absoluteOutputPath,
2052
2001
  context,
2053
- templateConfig,
2054
- });
2002
+ templateConfig});
2055
2003
 
2056
2004
  // 7. 执行 onAfterRender 钩子
2057
2005
  await executeAfterRenderHook(templateConfig, context, absoluteOutputPath);
2058
2006
 
2059
- return absoluteOutputPath;
2007
+ return {
2008
+ outputPath: absoluteOutputPath,
2009
+ templateConfig,
2010
+ context,
2011
+ };
2060
2012
  };
2061
2013
 
2062
2014
  function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
@@ -2098,7 +2050,40 @@ const runPnpmInstall = (projectPath) => {
2098
2050
  };
2099
2051
 
2100
2052
  /**
2101
- * 初始化 git 仓库并创建初始提交
2053
+ * 运行 git 命令的辅助函数
2054
+ */
2055
+ const runGitCommand = (command, projectPath) => {
2056
+ logger.info(`Executing: ${command}`);
2057
+
2058
+ const result = shelljs.exec(command, {
2059
+ cwd: projectPath,
2060
+ silent: true,
2061
+ });
2062
+
2063
+ // 输出命令的结果
2064
+ if (result.stdout) {
2065
+ process.stdout.write(result.stdout);
2066
+ }
2067
+
2068
+ if (result.stderr) {
2069
+ process.stderr.write(result.stderr);
2070
+ }
2071
+
2072
+ if (result.code !== 0) {
2073
+ const errorMessage = [
2074
+ `${command} failed with exit code ${result.code}`,
2075
+ result.stderr ? `\nStderr:\n${result.stderr}` : '',
2076
+ result.stdout ? `\nStdout:\n${result.stdout}` : '',
2077
+ ]
2078
+ .filter(Boolean)
2079
+ .join('');
2080
+
2081
+ throw new Error(errorMessage);
2082
+ }
2083
+ };
2084
+
2085
+ /**
2086
+ * 初始化 git 仓库
2102
2087
  * 如果目录中已存在 .git,则跳过初始化
2103
2088
  */
2104
2089
  const runGitInit = (projectPath) => {
@@ -2111,46 +2096,9 @@ const runGitInit = (projectPath) => {
2111
2096
  return;
2112
2097
  }
2113
2098
 
2114
- const runGitCommand = (command) => {
2115
- logger.info(`Executing: ${command}`);
2116
-
2117
- const result = shelljs.exec(command, {
2118
- cwd: projectPath,
2119
- silent: true,
2120
- });
2121
-
2122
- // 输出命令的结果
2123
- if (result.stdout) {
2124
- process.stdout.write(result.stdout);
2125
- }
2126
-
2127
- if (result.stderr) {
2128
- process.stderr.write(result.stderr);
2129
- }
2130
-
2131
- if (result.code !== 0) {
2132
- const errorMessage = [
2133
- `${command} failed with exit code ${result.code}`,
2134
- result.stderr ? `\nStderr:\n${result.stderr}` : '',
2135
- result.stdout ? `\nStdout:\n${result.stdout}` : '',
2136
- ]
2137
- .filter(Boolean)
2138
- .join('');
2139
-
2140
- throw new Error(errorMessage);
2141
- }
2142
- };
2143
-
2144
2099
  try {
2145
2100
  logger.info('\nInitializing git repository...');
2146
- runGitCommand('git init');
2147
-
2148
- logger.info('Adding files to git...');
2149
- runGitCommand('git add .');
2150
-
2151
- logger.info('Creating initial commit...');
2152
- runGitCommand('git commit -m "chore: initial commit"');
2153
-
2101
+ runGitCommand('git init', projectPath);
2154
2102
  logger.success('Git repository initialized successfully!');
2155
2103
  } catch (error) {
2156
2104
  // Git 初始化失败不应该导致整个流程失败
@@ -2161,6 +2109,35 @@ const runGitInit = (projectPath) => {
2161
2109
  }
2162
2110
  };
2163
2111
 
2112
+ /**
2113
+ * 提交初始化生成的所有文件
2114
+ */
2115
+ const commitChanges = (projectPath) => {
2116
+ // 检查是否存在 .git 目录
2117
+ const gitDir = path.join(projectPath, '.git');
2118
+ if (!fs.existsSync(gitDir)) {
2119
+ logger.warn(
2120
+ '\n⚠️ Git repository does not exist, skipping commit. Run git init first.',
2121
+ );
2122
+ return;
2123
+ }
2124
+
2125
+ try {
2126
+ logger.info('\nCommitting initialized files...');
2127
+ runGitCommand('git add --all', projectPath);
2128
+ runGitCommand('git commit -m "chore: init env"', projectPath);
2129
+ logger.success('Changes committed successfully!');
2130
+ } catch (error) {
2131
+ // Commit 失败不应该导致整个流程失败
2132
+ logger.warn(
2133
+ `Git commit failed: ${error instanceof Error ? error.message : String(error)}`,
2134
+ );
2135
+ logger.info(
2136
+ 'You can manually commit later with: git add --all && git commit -m "chore: init env"',
2137
+ );
2138
+ }
2139
+ };
2140
+
2164
2141
  /**
2165
2142
  * 运行开发服务器(后台模式)
2166
2143
  * 启动后台子进程运行开发服务器,父进程可以直接退出
@@ -2202,6 +2179,8 @@ const executeInit = async (
2202
2179
 
2203
2180
 
2204
2181
 
2182
+
2183
+
2205
2184
  ,
2206
2185
  command,
2207
2186
  ) => {
@@ -2213,44 +2192,58 @@ const executeInit = async (
2213
2192
  output: outputPath,
2214
2193
  skipInstall,
2215
2194
  skipGit,
2195
+ skipCommit,
2216
2196
  skipDev,
2197
+ force,
2217
2198
  } = options;
2218
2199
 
2219
2200
  logger.info(`Initializing project with template: ${templateName}`);
2220
2201
  timer.logPhase('Initialization');
2221
2202
 
2222
- // 执行模板引擎,返回绝对路径
2223
- const absoluteOutputPath = await execute({
2203
+ // 执行模板引擎,返回结果对象
2204
+ const result = await execute({
2224
2205
  templateName,
2225
2206
  outputPath,
2226
2207
  command,
2208
+ force,
2227
2209
  });
2210
+ const { outputPath: absoluteOutputPath, templateConfig, context } = result;
2228
2211
 
2229
2212
  timer.logPhase('Template engine execution');
2230
2213
  logger.success('Project created successfully!');
2231
2214
 
2232
- // 如果没有跳过安装,检查是否需要运行 pnpm install
2233
- if (!skipInstall) {
2234
- const nodeModulesPath = path.join(absoluteOutputPath, 'node_modules');
2235
- const hasNodeModules = fs.existsSync(nodeModulesPath);
2215
+ // 检查是否存在 package.json
2216
+ const packageJsonPath = path.join(absoluteOutputPath, 'package.json');
2217
+ const hasPackageJson = fs.existsSync(packageJsonPath);
2236
2218
 
2237
- if (hasNodeModules) {
2238
- logger.info(
2239
- '\n💡 Using pre-warmed node_modules, skipping pnpm install',
2240
- );
2241
- timer.logPhase('Node modules (pre-warmed)');
2242
- } else {
2219
+ // 安装依赖(始终使用 pnpm install,利用缓存机制)
2220
+ if (!skipInstall) {
2221
+ if (hasPackageJson) {
2243
2222
  runPnpmInstall(absoluteOutputPath);
2244
2223
  timer.logPhase('Dependencies installation');
2224
+ } else {
2225
+ logger.info(
2226
+ '\n💡 No package.json found, skipping dependency installation',
2227
+ );
2245
2228
  }
2246
2229
  }
2247
2230
 
2231
+ // 执行 onComplete 钩子(在 pnpm install 之后)
2232
+ await executeCompleteHook(templateConfig, context, absoluteOutputPath);
2233
+ timer.logPhase('Complete hook execution');
2234
+
2248
2235
  // 如果没有跳过 git,则初始化 git 仓库
2249
2236
  if (!skipGit) {
2250
2237
  runGitInit(absoluteOutputPath);
2251
2238
  timer.logPhase('Git initialization');
2252
2239
  }
2253
2240
 
2241
+ // 如果没有跳过 commit,则提交初始化生成的文件
2242
+ if (!skipCommit) {
2243
+ commitChanges(absoluteOutputPath);
2244
+ timer.logPhase('Git commit');
2245
+ }
2246
+
2254
2247
  // 如果没有跳过 dev,则启动开发服务器
2255
2248
  if (!skipDev) {
2256
2249
  runDev(absoluteOutputPath);
@@ -2259,13 +2252,14 @@ const executeInit = async (
2259
2252
  // 只有跳过 dev 时才显示 Next steps
2260
2253
  logger.info('\nNext steps:');
2261
2254
  logger.info(` cd ${outputPath}`);
2262
- if (skipInstall) {
2255
+ if (skipInstall && hasPackageJson) {
2263
2256
  logger.info(' pnpm install');
2264
2257
  }
2265
2258
  if (skipGit) {
2266
- logger.info(
2267
- ' git init && git add . && git commit -m "initial commit"',
2268
- );
2259
+ logger.info(' git init');
2260
+ }
2261
+ if (skipCommit) {
2262
+ logger.info(' git add --all && git commit -m "chore: init env"');
2269
2263
  }
2270
2264
  logger.info(' coze dev');
2271
2265
  }
@@ -2292,12 +2286,19 @@ const registerCommand$1 = program => {
2292
2286
  .option('-o, --output <path>', 'Output directory', process.cwd())
2293
2287
  .option('--skip-install', 'Skip automatic pnpm install', false)
2294
2288
  .option('--skip-git', 'Skip automatic git initialization', false)
2289
+ .option(
2290
+ '--skip-commit',
2291
+ 'Skip automatic git commit after initialization',
2292
+ false,
2293
+ )
2295
2294
  .option('--skip-dev', 'Skip automatic dev server start', false)
2296
2295
  .allowUnknownOption() // 允许透传参数
2297
2296
  .action(async (directory, options, command) => {
2298
2297
  // 位置参数优先级高于 --output 选项
2299
2298
  const outputPath = _nullishCoalesce(directory, () => ( options.output));
2300
- await executeInit({ ...options, output: outputPath }, command);
2299
+ // Always use force mode - overwrite existing files without conflict check
2300
+ const force = true;
2301
+ await executeInit({ ...options, output: outputPath, force }, command);
2301
2302
  });
2302
2303
  };
2303
2304
 
@@ -2597,7 +2598,7 @@ const registerCommand = program => {
2597
2598
  });
2598
2599
  };
2599
2600
 
2600
- var version = "0.0.1-alpha.374e8d";
2601
+ var version = "0.0.1-alpha.3ed8e2";
2601
2602
  var packageJson = {
2602
2603
  version: version};
2603
2604
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze-arch/cli",
3
- "version": "0.0.1-alpha.374e8d",
3
+ "version": "0.0.1-alpha.3ed8e2",
4
4
  "private": false,
5
5
  "description": "coze coding devtools cli",
6
6
  "license": "MIT",
@@ -50,6 +50,7 @@
50
50
  "@coze-arch/vitest-config": "workspace:*",
51
51
  "@coze-coding/lambda": "workspace:*",
52
52
  "@inquirer/prompts": "^3.2.0",
53
+ "@playwright/test": "~1.55.0",
53
54
  "@types/ejs": "^3.1.5",
54
55
  "@types/iarna__toml": "^2.0.5",
55
56
  "@types/js-yaml": "^4.0.9",
@@ -57,13 +58,16 @@
57
58
  "@types/minimist": "^1.2.5",
58
59
  "@types/node": "^24",
59
60
  "@types/shelljs": "^0.10.0",
60
- "@vitest/coverage-v8": "~4.0.16",
61
+ "@vitest/coverage-v8": "~4.0.18",
61
62
  "json-schema-to-typescript": "^15.0.3",
62
63
  "minimatch": "^10.0.1",
64
+ "playwright": "~1.55.0",
63
65
  "rollup": "^4.41.1",
64
66
  "sucrase": "^3.35.0",
67
+ "tree-kill": "^1.2.2",
65
68
  "tsx": "^4.20.6",
66
- "vitest": "~4.0.16"
69
+ "vite-tsconfig-paths": "^4.2.1",
70
+ "vitest": "~4.0.18"
67
71
  },
68
72
  "publishConfig": {
69
73
  "access": "public",
@@ -1,14 +0,0 @@
1
- import { PropsWithChildren } from 'react';
2
- import { useLaunch } from '@tarojs/taro';
3
- import { injectH5Styles } from '@/utils/h5-styles';
4
- import { enableWxDebugIfNeeded } from '@/utils/wx-debug';
5
- import '@/app.css';
6
-
7
- export default ({ children }: PropsWithChildren<any>) => {
8
- useLaunch(() => {
9
- enableWxDebugIfNeeded();
10
- injectH5Styles();
11
- });
12
-
13
- return children;
14
- };
@@ -1,22 +0,0 @@
1
- /**
2
- * H5 端特殊样式注入
3
- * 如无必要,请勿修改本文件
4
- */
5
- export function injectH5Styles() {
6
- if (TARO_ENV !== 'h5') return
7
-
8
- const style = document.createElement('style')
9
- style.innerHTML = `
10
- /* H5 端隐藏 TabBar 空图标(只隐藏没有 src 的图标) */
11
- .weui-tabbar__icon:not([src]),
12
- .weui-tabbar__icon[src=''] {
13
- display: none !important;
14
- }
15
-
16
- .weui-tabbar__item:has(.weui-tabbar__icon:not([src])) .weui-tabbar__label,
17
- .weui-tabbar__item:has(.weui-tabbar__icon[src='']) .weui-tabbar__label {
18
- margin-top: 0 !important;
19
- }
20
- `
21
- document.head.appendChild(style)
22
- }
@@ -1,23 +0,0 @@
1
- import Taro from '@tarojs/taro'
2
-
3
- /**
4
- * 微信小程序调试工具
5
- * 在开发版/体验版自动开启调试模式
6
- */
7
- export function enableWxDebugIfNeeded() {
8
- // 仅在微信小程序环境执行
9
- if (Taro.getEnv() === Taro.ENV_TYPE.WEAPP) {
10
- try {
11
- const accountInfo = Taro.getAccountInfoSync()
12
- const envVersion = accountInfo.miniProgram.envVersion
13
- console.log('[Debug] envVersion:', envVersion)
14
-
15
- // 开发版/体验版自动开启调试
16
- if (envVersion !== 'release') {
17
- Taro.setEnableDebug({ enableDebug: true })
18
- }
19
- } catch (error) {
20
- console.error('[Debug] 开启调试模式失败:', error)
21
- }
22
- }
23
- }