@coze-arch/cli 0.0.1-alpha.d85d9d → 0.0.1-alpha.db1c06

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 (53) hide show
  1. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +13 -12
  2. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +9 -8
  3. package/lib/__templates__/expo/client/metro.config.js +3 -0
  4. package/lib/__templates__/expo/client/package.json +35 -35
  5. package/lib/__templates__/expo/client/screens/demo/index.tsx +3 -3
  6. package/lib/__templates__/expo/package.json +1 -1
  7. package/lib/__templates__/expo/patches/{expo@54.0.32.patch → expo@54.0.33.patch} +3 -2
  8. package/lib/__templates__/expo/pnpm-lock.yaml +340 -1736
  9. package/lib/__templates__/expo/server/package.json +9 -7
  10. package/lib/__templates__/expo/server/src/index.ts +1 -0
  11. package/lib/__templates__/expo/template.config.js +56 -0
  12. package/lib/__templates__/native-static/.coze +11 -0
  13. package/lib/__templates__/native-static/index.html +33 -0
  14. package/lib/__templates__/native-static/styles/main.css +136 -0
  15. package/lib/__templates__/native-static/template.config.js +22 -0
  16. package/lib/__templates__/nextjs/package.json +3 -1
  17. package/lib/__templates__/nextjs/pnpm-lock.yaml +119 -106
  18. package/lib/__templates__/nextjs/src/app/page.tsx +18 -60
  19. package/lib/__templates__/nextjs/template.config.js +49 -14
  20. package/lib/__templates__/taro/.coze +1 -1
  21. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +5 -6
  22. package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +6 -8
  23. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +0 -15
  24. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +117 -24
  25. package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -1
  26. package/lib/__templates__/taro/README.md +81 -17
  27. package/lib/__templates__/taro/_gitignore +40 -0
  28. package/lib/__templates__/taro/_npmrc +18 -0
  29. package/lib/__templates__/taro/config/index.ts +4 -3
  30. package/lib/__templates__/taro/eslint.config.mjs +79 -0
  31. package/lib/__templates__/taro/package.json +32 -33
  32. package/lib/__templates__/taro/pnpm-lock.yaml +742 -677
  33. package/lib/__templates__/taro/server/package.json +10 -7
  34. package/lib/__templates__/taro/server/src/main.ts +14 -2
  35. package/lib/__templates__/taro/src/app.css +18 -18
  36. package/lib/__templates__/taro/src/app.tsx +9 -0
  37. package/lib/__templates__/taro/src/index.html +20 -1
  38. package/lib/__templates__/taro/src/pages/index/index.tsx +14 -11
  39. package/lib/__templates__/taro/src/presets/h5-navbar.tsx +171 -0
  40. package/lib/__templates__/taro/src/{utils → presets}/h5-styles.ts +15 -4
  41. package/lib/__templates__/taro/src/presets/index.tsx +18 -0
  42. package/lib/__templates__/taro/src/presets/wx-debug.ts +23 -0
  43. package/lib/__templates__/templates.json +11 -0
  44. package/lib/__templates__/vite/package.json +5 -1
  45. package/lib/__templates__/vite/pnpm-lock.yaml +146 -1659
  46. package/lib/__templates__/vite/src/main.ts +17 -47
  47. package/lib/__templates__/vite/template.config.js +49 -14
  48. package/lib/__templates__/vite/vite.config.ts +1 -0
  49. package/lib/cli.js +62 -68
  50. package/package.json +2 -1
  51. package/lib/__templates__/taro/.eslintrc +0 -40
  52. package/lib/__templates__/taro/commitlint.config.mjs +0 -1
  53. package/lib/__templates__/taro/src/app.ts +0 -28
@@ -7,56 +7,26 @@ export function initApp(): void {
7
7
  }
8
8
 
9
9
  app.innerHTML = `
10
- <div class="flex min-h-screen items-center justify-center bg-white text-black transition-colors duration-300 dark:bg-black dark:text-white">
11
- <!-- 主容器 -->
12
- <main class="flex min-h-screen w-full max-w-3xl flex-col items-center justify-between px-16 py-32 sm:items-start">
13
- <!-- 头部:Logo 和 产品名称 -->
14
- <div class="flex items-center gap-3">
10
+ <div class="flex h-full items-center justify-center bg-background text-foreground transition-colors duration-300 dark:bg-background dark:text-foreground overflow-hidden min-h-screen">
11
+ <main class="flex w-full h-full max-w-3xl flex-col items-center justify-center px-16 py-32 sm:items-center">
12
+ <div class="flex flex-col items-center justify-between gap-4">
15
13
  <img
16
- src="https://lf-coze-web-cdn.coze.cn/obj/eden-cn/lm-lgvj/ljhwZthlaukjlkulzlp/favicon.svg"
14
+ src="https://lf-coze-web-cdn.coze.cn/obj/eden-cn/lm-lgvj/ljhwZthlaukjlkulzlp/coze-coding/icon/coze-coding.gif"
17
15
  alt="扣子编程 Logo"
18
- width="40"
19
- height="40"
20
- style="width: 40px; height: 40px; object-fit: contain;"
16
+ width={156}
17
+ height={130}
18
+ style="width: 156px; height: 130px; object-fit: contain;"
21
19
  />
22
- <span class="text-xl font-bold tracking-tight text-black dark:text-zinc-50">
23
- 扣子编程
24
- </span>
25
- </div>
26
-
27
- <!-- 中间内容区:主标题和副标题 -->
28
- <div class="flex flex-col items-center gap-6 text-center sm:items-start sm:text-left">
29
- <h1 class="max-w-xl text-4xl font-semibold leading-tight tracking-tight text-black dark:text-zinc-50">
30
- 扣子编程,你的 AI 开发伙伴已就位
31
- </h1>
32
- <p class="max-w-2xl text-lg leading-8 text-zinc-600 dark:text-zinc-400">
33
- 当前是空白入口文件,项目正在开发中,请稍候...
34
- <br />
35
- 开发完成后界面将自动更新。如未自动更新成功,可以手动点击右上角刷新或重启按钮查看效果。
36
- </p>
37
- </div>
38
-
39
- <!-- 底部按钮区 -->
40
- <div class="flex w-full flex-col gap-4 text-base font-medium sm:w-auto sm:flex-row">
41
- <!-- 按钮 1:前往首页 -->
42
- <a
43
- class="flex h-12 w-full min-w-[160px] items-center justify-center gap-2 rounded-full bg-black px-8 text-white transition-colors hover:bg-zinc-800 dark:bg-white dark:text-black dark:hover:bg-zinc-200 md:w-auto"
44
- href="https://code.coze.cn/"
45
- target="_blank"
46
- rel="noopener noreferrer"
47
- >
48
- 前往首页
49
- </a>
50
-
51
- <!-- 按钮 2:查看文档 -->
52
- <a
53
- class="flex h-12 w-full min-w-[160px] items-center justify-center rounded-full border border-solid border-black/[.08] px-8 transition-colors hover:border-transparent hover:bg-black/[.04] dark:border-white/[.145] dark:hover:bg-[#1a1a1a] md:w-auto"
54
- href="https://docs.coze.cn/"
55
- target="_blank"
56
- rel="noopener noreferrer"
57
- >
58
- 查看文档
59
- </a>
20
+ <div>
21
+ <div class="flex flex-col items-center gap-2 text-center sm:items-center sm:text-center">
22
+ <h1 class="max-w-xl text-base font-semibold leading-tight tracking-tight text-foreground dark:text-foreground">
23
+ 应用开发中
24
+ </h1>
25
+ <p class="max-w-2xl text-sm-14 leading-8 text-muted-foreground dark:text-muted-foreground">
26
+ 请稍后,页面即将呈现
27
+ </p>
28
+ </div>
29
+ </div>
60
30
  </div>
61
31
  </main>
62
32
  </div>
@@ -1,6 +1,7 @@
1
1
 
2
-
3
- import { resolve } from 'path';
2
+ import { spawn } from 'child_process';
3
+ import { resolve, join, basename } from 'path';
4
+ import { appendFileSync, openSync, closeSync, mkdirSync } from 'fs';
4
5
 
5
6
 
6
7
 
@@ -59,32 +60,66 @@ const config = {
59
60
  return context;
60
61
  },
61
62
 
62
- onAfterRender: async (context, outputPath) => {
63
+ onAfterRender: async (_context, outputPath) => {
63
64
  console.log(`\nProject created at: ${outputPath}`);
64
65
  console.log('\nConfiguration:');
65
66
  console.log(' - Framework: vite');
66
67
  console.log(' - TypeScript: enabled');
67
68
  console.log(' - App Router: enabled');
68
- console.log(` - Port: ${context.port}`);
69
+ console.log(` - Port: ${_context.port}`);
70
+ },
69
71
 
70
- // Skip pnpm add in test environment to avoid monorepo workspace issues
72
+ onComplete: async (_context, outputPath) => {
73
+ // Skip pnpm update in test environment to avoid monorepo workspace issues
71
74
  if (process.env.NODE_ENV === 'test') {
72
75
  console.log('⊘ Skipping dependency update in test environment');
73
76
  return;
74
77
  }
75
78
 
76
- const cmd = `pnpm add coze-coding-dev-sdk@"^0.7.0"`;
77
- console.log(`${cmd}`);
79
+ const cmd = 'pnpm';
80
+ const args = ['update', 'coze-coding-dev-sdk@^0.7.0'];
81
+ console.log(
82
+ `\nTriggering: ${cmd} ${args.join(' ')} (running in background)`,
83
+ );
84
+
78
85
  try {
79
86
  const projectRoot = resolve(outputPath);
80
- // execSync(cmd, {
81
- // cwd: projectRoot,
82
- // stdio: 'inherit',
83
- // });
84
- console.log('✓ coze-coding-dev-sdk updated successfully');
87
+
88
+ // Determine log directory
89
+ const logDir = process.env.COZE_LOG_DIR || resolve(__dirname, '../.log');
90
+ mkdirSync(logDir, { recursive: true });
91
+
92
+ // Use project name in log file to avoid conflicts
93
+ const projectName = basename(projectRoot);
94
+ const logFile = join(logDir, `${projectName}-init.log`);
95
+
96
+ // Write log header
97
+ const timestamp = new Date().toISOString();
98
+ appendFileSync(
99
+ logFile,
100
+ `\n=== [${timestamp}] ${cmd} ${args.join(' ')} ===\n`,
101
+ );
102
+
103
+ // Open log file for appending
104
+ const logFd = openSync(logFile, 'a');
105
+
106
+ // Spawn in detached mode
107
+ const child = spawn(cmd, args, {
108
+ cwd: projectRoot,
109
+ detached: true,
110
+ stdio: ['ignore', logFd, logFd],
111
+ });
112
+
113
+ child.unref();
114
+ closeSync(logFd);
115
+
116
+ console.log(
117
+ '✓ coze-coding-dev-sdk update triggered (running in background)',
118
+ );
119
+ console.log(` Log file: ${logFile}`);
85
120
  } catch (error) {
86
- console.error('✗ Failed to update coze-coding-dev-sdk:', error);
87
- throw error;
121
+ console.error('✗ Failed to trigger coze-coding-dev-sdk update:', error);
122
+ console.log(' You can manually run: pnpm update coze-coding-dev-sdk');
88
123
  }
89
124
  },
90
125
  };
@@ -4,6 +4,7 @@ export default defineConfig({
4
4
  server: {
5
5
  port: <%= port %>,
6
6
  host: '0.0.0.0',
7
+ allowedHosts: true,
7
8
  hmr: {
8
9
  overlay: true,
9
10
  path: '/hot/vite-hmr',
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
@@ -1925,11 +1889,7 @@ const processTemplateFiles = async (options
1925
1889
 
1926
1890
  logger.verbose('✓ All files processed successfully');
1927
1891
 
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);
1892
+ // node_modules 将由 pnpm install 处理(利用缓存和硬链接机制)
1933
1893
  };
1934
1894
  // end_aigc
1935
1895
 
@@ -2011,6 +1971,19 @@ const executeAfterRenderHook = async (
2011
1971
  }
2012
1972
  };
2013
1973
 
1974
+ /**
1975
+ * 执行完成钩子
1976
+ */
1977
+ const executeCompleteHook = async (
1978
+ templateConfig,
1979
+ context,
1980
+ outputPath,
1981
+ ) => {
1982
+ if (templateConfig.onComplete) {
1983
+ await templateConfig.onComplete(context, outputPath);
1984
+ }
1985
+ };
1986
+
2014
1987
  /**
2015
1988
  * 准备输出目录
2016
1989
  */
@@ -2020,6 +1993,18 @@ const prepareOutputDirectory = (outputPath) => {
2020
1993
  return absolutePath;
2021
1994
  };
2022
1995
 
1996
+ /**
1997
+ * 模板引擎执行结果
1998
+ */
1999
+
2000
+
2001
+
2002
+
2003
+
2004
+
2005
+
2006
+
2007
+
2023
2008
  /**
2024
2009
  * 执行完整的模板渲染流程
2025
2010
  */
@@ -2056,7 +2041,11 @@ const execute = async (
2056
2041
  // 7. 执行 onAfterRender 钩子
2057
2042
  await executeAfterRenderHook(templateConfig, context, absoluteOutputPath);
2058
2043
 
2059
- return absoluteOutputPath;
2044
+ return {
2045
+ outputPath: absoluteOutputPath,
2046
+ templateConfig,
2047
+ context,
2048
+ };
2060
2049
  };
2061
2050
 
2062
2051
  function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
@@ -2219,32 +2208,37 @@ const executeInit = async (
2219
2208
  logger.info(`Initializing project with template: ${templateName}`);
2220
2209
  timer.logPhase('Initialization');
2221
2210
 
2222
- // 执行模板引擎,返回绝对路径
2223
- const absoluteOutputPath = await execute({
2211
+ // 执行模板引擎,返回结果对象
2212
+ const result = await execute({
2224
2213
  templateName,
2225
2214
  outputPath,
2226
2215
  command,
2227
2216
  });
2217
+ const { outputPath: absoluteOutputPath, templateConfig, context } = result;
2228
2218
 
2229
2219
  timer.logPhase('Template engine execution');
2230
2220
  logger.success('Project created successfully!');
2231
2221
 
2232
- // 如果没有跳过安装,检查是否需要运行 pnpm install
2233
- if (!skipInstall) {
2234
- const nodeModulesPath = path.join(absoluteOutputPath, 'node_modules');
2235
- const hasNodeModules = fs.existsSync(nodeModulesPath);
2222
+ // 检查是否存在 package.json
2223
+ const packageJsonPath = path.join(absoluteOutputPath, 'package.json');
2224
+ const hasPackageJson = fs.existsSync(packageJsonPath);
2236
2225
 
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 {
2226
+ // 安装依赖(始终使用 pnpm install,利用缓存机制)
2227
+ if (!skipInstall) {
2228
+ if (hasPackageJson) {
2243
2229
  runPnpmInstall(absoluteOutputPath);
2244
2230
  timer.logPhase('Dependencies installation');
2231
+ } else {
2232
+ logger.info(
2233
+ '\n💡 No package.json found, skipping dependency installation',
2234
+ );
2245
2235
  }
2246
2236
  }
2247
2237
 
2238
+ // 执行 onComplete 钩子(在 pnpm install 之后)
2239
+ await executeCompleteHook(templateConfig, context, absoluteOutputPath);
2240
+ timer.logPhase('Complete hook execution');
2241
+
2248
2242
  // 如果没有跳过 git,则初始化 git 仓库
2249
2243
  if (!skipGit) {
2250
2244
  runGitInit(absoluteOutputPath);
@@ -2259,7 +2253,7 @@ const executeInit = async (
2259
2253
  // 只有跳过 dev 时才显示 Next steps
2260
2254
  logger.info('\nNext steps:');
2261
2255
  logger.info(` cd ${outputPath}`);
2262
- if (skipInstall) {
2256
+ if (skipInstall && hasPackageJson) {
2263
2257
  logger.info(' pnpm install');
2264
2258
  }
2265
2259
  if (skipGit) {
@@ -2597,7 +2591,7 @@ const registerCommand = program => {
2597
2591
  });
2598
2592
  };
2599
2593
 
2600
- var version = "0.0.1-alpha.d85d9d";
2594
+ var version = "0.0.1-alpha.db1c06";
2601
2595
  var packageJson = {
2602
2596
  version: version};
2603
2597
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze-arch/cli",
3
- "version": "0.0.1-alpha.d85d9d",
3
+ "version": "0.0.1-alpha.db1c06",
4
4
  "private": false,
5
5
  "description": "coze coding devtools cli",
6
6
  "license": "MIT",
@@ -63,6 +63,7 @@
63
63
  "rollup": "^4.41.1",
64
64
  "sucrase": "^3.35.0",
65
65
  "tsx": "^4.20.6",
66
+ "vite-tsconfig-paths": "^4.2.1",
66
67
  "vitest": "~4.0.16"
67
68
  },
68
69
  "publishConfig": {
@@ -1,40 +0,0 @@
1
- {
2
- "extends": ["taro/react"],
3
- "rules": {
4
- "react/jsx-uses-react": "off",
5
- "react/react-in-jsx-scope": "off"
6
- },
7
- "overrides": [
8
- {
9
- "files": ["src/**/*.{js,jsx,ts,tsx}"],
10
- "excludedFiles": ["src/network.ts"],
11
- "rules": {
12
- "no-restricted-syntax": [
13
- "error",
14
- {
15
- "selector": "MemberExpression[object.name='process'][property.name='env']",
16
- "message": "请勿在 src 目录下直接使用 process.env\n如需获取 URL 请求前缀,请使用已经注入全局的 PROJECT_DOMAIN()"
17
- }
18
- ],
19
- "no-restricted-properties": [
20
- "error",
21
- {
22
- "object": "Taro",
23
- "property": "request",
24
- "message": "请使用 Network.request 替代 Taro.request"
25
- },
26
- {
27
- "object": "Taro",
28
- "property": "uploadFile",
29
- "message": "请使用 Network.uploadFile 替代 Taro.uploadFile"
30
- },
31
- {
32
- "object": "Taro",
33
- "property": "downloadFile",
34
- "message": "请使用 Network.downloadFile 替代 Taro.downloadFile"
35
- }
36
- ]
37
- }
38
- }
39
- ]
40
- }
@@ -1 +0,0 @@
1
- export default { extends: ["@commitlint/config-conventional"] };
@@ -1,28 +0,0 @@
1
- import { PropsWithChildren } from 'react'
2
- import Taro, { useLaunch } from '@tarojs/taro'
3
- import { injectH5Styles } from '@/utils/h5-styles'
4
- import '@/app.css'
5
-
6
- export default ({ children }: PropsWithChildren<any>) => {
7
- useLaunch(() => {
8
- // 仅在微信小程序环境执行
9
- if (process.env.TARO_ENV === '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
-
24
- injectH5Styles()
25
- })
26
-
27
- return children
28
- }