@coze-arch/cli 0.0.1-alpha.e8e1d7 → 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.
- package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +13 -12
- package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +9 -8
- package/lib/__templates__/expo/client/eslint.config.mjs +4 -1
- package/lib/__templates__/expo/client/metro.config.js +3 -0
- package/lib/__templates__/expo/client/package.json +35 -35
- package/lib/__templates__/expo/client/screens/demo/index.tsx +3 -3
- package/lib/__templates__/expo/eslint-plugins/react-native/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/react-native/rule.js +64 -0
- package/lib/__templates__/expo/package.json +1 -1
- package/lib/__templates__/expo/patches/{expo@54.0.32.patch → expo@54.0.33.patch} +3 -2
- package/lib/__templates__/expo/pnpm-lock.yaml +340 -1736
- package/lib/__templates__/expo/server/package.json +9 -7
- package/lib/__templates__/expo/server/src/index.ts +1 -0
- package/lib/__templates__/expo/template.config.js +56 -0
- package/lib/__templates__/native-static/.coze +11 -0
- package/lib/__templates__/native-static/index.html +33 -0
- package/lib/__templates__/native-static/styles/main.css +136 -0
- package/lib/__templates__/native-static/template.config.js +22 -0
- package/lib/__templates__/nextjs/_gitignore +3 -0
- package/lib/__templates__/nextjs/package.json +13 -1
- package/lib/__templates__/nextjs/pnpm-lock.yaml +183 -99
- package/lib/__templates__/nextjs/scripts/build.sh +4 -1
- package/lib/__templates__/nextjs/scripts/dev.sh +1 -1
- package/lib/__templates__/nextjs/scripts/start.sh +1 -1
- package/lib/__templates__/nextjs/server.ts +35 -0
- package/lib/__templates__/nextjs/src/app/page.tsx +18 -60
- package/lib/__templates__/nextjs/template.config.js +49 -14
- package/lib/__templates__/nuxt-app/.coze +12 -0
- package/lib/__templates__/nuxt-app/.nuxt/app.config.mjs +21 -0
- package/lib/__templates__/nuxt-app/.nuxt/components.d.ts +64 -0
- package/lib/__templates__/nuxt-app/.nuxt/imports.d.ts +31 -0
- package/lib/__templates__/nuxt-app/.nuxt/manifest/meta/f97812ec-f25e-427b-b45d-eab58fba39f9.json +1 -0
- package/lib/__templates__/nuxt-app/.nuxt/nuxt.d.ts +19 -0
- package/lib/__templates__/nuxt-app/.nuxt/nuxt.node.d.ts +14 -0
- package/lib/__templates__/nuxt-app/.nuxt/nuxt.shared.d.ts +6 -0
- package/lib/__templates__/nuxt-app/.nuxt/schema/nuxt.schema.d.ts +17 -0
- package/lib/__templates__/nuxt-app/.nuxt/schema/nuxt.schema.json +3 -0
- package/lib/__templates__/nuxt-app/.nuxt/tsconfig.app.json +201 -0
- package/lib/__templates__/nuxt-app/.nuxt/tsconfig.json +203 -0
- package/lib/__templates__/nuxt-app/.nuxt/tsconfig.node.json +110 -0
- package/lib/__templates__/nuxt-app/.nuxt/tsconfig.server.json +140 -0
- package/lib/__templates__/nuxt-app/.nuxt/tsconfig.shared.json +152 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/app.config.d.ts +35 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/build.d.ts +24 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/builder-env.d.ts +1 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/components.d.ts +69 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/imports.d.ts +360 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/middleware.d.ts +11 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/modules.d.ts +79 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/nitro-config.d.ts +14 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/nitro-imports.d.ts +151 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/nitro-layouts.d.ts +17 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/nitro-nuxt.d.ts +64 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/nitro-routes.d.ts +17 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/nitro.d.ts +3 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/plugins.d.ts +30 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/runtime-config.d.ts +32 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/shared-imports.d.ts +10 -0
- package/lib/__templates__/nuxt-app/.nuxt/types/vue-shim.d.ts +0 -0
- package/lib/__templates__/nuxt-app/README.md +83 -0
- package/lib/__templates__/nuxt-app/_gitignore +24 -0
- package/lib/__templates__/nuxt-app/_npmrc +23 -0
- package/lib/__templates__/nuxt-app/app/app.vue +193 -0
- package/lib/__templates__/nuxt-app/nuxt.config.ts +56 -0
- package/lib/__templates__/nuxt-app/package.json +28 -0
- package/lib/__templates__/nuxt-app/pnpm-lock.yaml +7202 -0
- package/lib/__templates__/nuxt-app/public/favicon.ico +0 -0
- package/lib/__templates__/nuxt-app/public/robots.txt +2 -0
- package/lib/__templates__/nuxt-app/scripts/build.sh +14 -0
- package/lib/__templates__/nuxt-app/scripts/dev.sh +33 -0
- package/lib/__templates__/nuxt-app/scripts/prepare.sh +14 -0
- package/lib/__templates__/nuxt-app/scripts/start.sh +15 -0
- package/lib/__templates__/nuxt-app/template.config.js +78 -0
- package/lib/__templates__/nuxt-app/tsconfig.json +18 -0
- package/lib/__templates__/taro/.coze +14 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +19 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +14 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +2 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +151 -0
- package/lib/__templates__/taro/.cozeproj/scripts/init_env.sh +5 -0
- package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -0
- package/lib/__templates__/taro/README.md +751 -0
- package/lib/__templates__/taro/_gitignore +40 -0
- package/lib/__templates__/taro/_npmrc +18 -0
- package/lib/__templates__/taro/babel.config.js +12 -0
- package/lib/__templates__/taro/config/dev.ts +9 -0
- package/lib/__templates__/taro/config/index.ts +223 -0
- package/lib/__templates__/taro/config/prod.ts +34 -0
- package/lib/__templates__/taro/eslint.config.mjs +80 -0
- package/lib/__templates__/taro/key/private.appid.key +0 -0
- package/lib/__templates__/taro/package.json +107 -0
- package/lib/__templates__/taro/patches/@tarojs__plugin-mini-ci@4.1.9.patch +30 -0
- package/lib/__templates__/taro/pnpm-lock.yaml +23100 -0
- package/lib/__templates__/taro/pnpm-workspace.yaml +2 -0
- package/lib/__templates__/taro/project.config.json +15 -0
- package/lib/__templates__/taro/server/nest-cli.json +10 -0
- package/lib/__templates__/taro/server/package.json +40 -0
- package/lib/__templates__/taro/server/src/app.controller.ts +23 -0
- package/lib/__templates__/taro/server/src/app.module.ts +10 -0
- package/lib/__templates__/taro/server/src/app.service.ts +8 -0
- package/lib/__templates__/taro/server/src/interceptors/http-status.interceptor.ts +23 -0
- package/lib/__templates__/taro/server/src/main.ts +49 -0
- package/lib/__templates__/taro/server/tsconfig.json +24 -0
- package/lib/__templates__/taro/src/app.config.ts +11 -0
- package/lib/__templates__/taro/src/app.css +52 -0
- package/lib/__templates__/taro/src/app.tsx +9 -0
- package/lib/__templates__/taro/src/index.html +39 -0
- package/lib/__templates__/taro/src/network.ts +39 -0
- package/lib/__templates__/taro/src/pages/index/index.config.ts +3 -0
- package/lib/__templates__/taro/src/pages/index/index.css +1 -0
- package/lib/__templates__/taro/src/pages/index/index.tsx +33 -0
- package/lib/__templates__/taro/src/presets/dev-debug.ts +23 -0
- package/lib/__templates__/taro/src/presets/h5-container.tsx +15 -0
- package/lib/__templates__/taro/src/presets/h5-navbar.tsx +201 -0
- package/lib/__templates__/taro/src/presets/h5-styles.ts +142 -0
- package/lib/__templates__/taro/src/presets/index.tsx +18 -0
- package/lib/__templates__/taro/stylelint.config.mjs +4 -0
- package/lib/__templates__/taro/template.config.js +68 -0
- package/lib/__templates__/taro/tsconfig.json +29 -0
- package/lib/__templates__/taro/types/global.d.ts +32 -0
- package/lib/__templates__/templates.json +68 -0
- package/lib/__templates__/vite/package.json +5 -1
- package/lib/__templates__/vite/pnpm-lock.yaml +146 -1659
- package/lib/__templates__/vite/src/main.ts +17 -47
- package/lib/__templates__/vite/template.config.js +49 -14
- package/lib/__templates__/vite/vite.config.ts +1 -0
- package/lib/cli.js +93 -81
- package/package.json +2 -1
|
@@ -7,56 +7,26 @@ export function initApp(): void {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
app.innerHTML = `
|
|
10
|
-
<div class="flex
|
|
11
|
-
|
|
12
|
-
|
|
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/
|
|
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=
|
|
19
|
-
height=
|
|
20
|
-
style="width:
|
|
16
|
+
width={156}
|
|
17
|
+
height={130}
|
|
18
|
+
style="width: 156px; height: 130px; object-fit: contain;"
|
|
21
19
|
/>
|
|
22
|
-
<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
</
|
|
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 (
|
|
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: ${
|
|
69
|
+
console.log(` - Port: ${_context.port}`);
|
|
70
|
+
},
|
|
69
71
|
|
|
70
|
-
|
|
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 =
|
|
77
|
-
|
|
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
|
-
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
|
87
|
-
|
|
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
|
};
|
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
|
|
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
|
|
@@ -1845,7 +1809,7 @@ const processSingleFile = async (options
|
|
|
1845
1809
|
* 1. 验证模板目录
|
|
1846
1810
|
* 2. 扫描所有模板文件
|
|
1847
1811
|
* 3. Dry-run:收集将要写入的文件列表(考虑 hooks 影响)
|
|
1848
|
-
* 4.
|
|
1812
|
+
* 4. 冲突检测:检查是否有文件会被覆盖(可通过 force 跳过)
|
|
1849
1813
|
* 5. 实际写入:渲染并写入所有文件
|
|
1850
1814
|
* 6. 复制 node_modules(如果存在)
|
|
1851
1815
|
*
|
|
@@ -1856,8 +1820,9 @@ const processTemplateFiles = async (options
|
|
|
1856
1820
|
|
|
1857
1821
|
|
|
1858
1822
|
|
|
1823
|
+
|
|
1859
1824
|
) => {
|
|
1860
|
-
const { templatePath, outputPath, context, templateConfig } = options;
|
|
1825
|
+
const { templatePath, outputPath, context, templateConfig, force } = options;
|
|
1861
1826
|
logger.verbose('Processing template files:');
|
|
1862
1827
|
logger.verbose(` - Template path: ${templatePath}`);
|
|
1863
1828
|
logger.verbose(` - Output path: ${outputPath}`);
|
|
@@ -1896,16 +1861,23 @@ const processTemplateFiles = async (options
|
|
|
1896
1861
|
templateConfig,
|
|
1897
1862
|
});
|
|
1898
1863
|
|
|
1899
|
-
// 阶段 3:
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
`
|
|
1908
|
-
|
|
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.',
|
|
1909
1881
|
);
|
|
1910
1882
|
}
|
|
1911
1883
|
|
|
@@ -1925,11 +1897,7 @@ const processTemplateFiles = async (options
|
|
|
1925
1897
|
|
|
1926
1898
|
logger.verbose('✓ All files processed successfully');
|
|
1927
1899
|
|
|
1928
|
-
//
|
|
1929
|
-
const sourceNodeModules = path.join(templatePath, 'node_modules');
|
|
1930
|
-
const targetNodeModules = path.join(outputPath, 'node_modules');
|
|
1931
|
-
|
|
1932
|
-
copyNodeModules(sourceNodeModules, targetNodeModules);
|
|
1900
|
+
// node_modules 将由 pnpm install 处理(利用缓存和硬链接机制)
|
|
1933
1901
|
};
|
|
1934
1902
|
// end_aigc
|
|
1935
1903
|
|
|
@@ -1942,6 +1910,7 @@ const processTemplateFiles = async (options
|
|
|
1942
1910
|
|
|
1943
1911
|
|
|
1944
1912
|
|
|
1913
|
+
|
|
1945
1914
|
/**
|
|
1946
1915
|
* 加载模板元数据和路径
|
|
1947
1916
|
*/
|
|
@@ -2011,6 +1980,19 @@ const executeAfterRenderHook = async (
|
|
|
2011
1980
|
}
|
|
2012
1981
|
};
|
|
2013
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
|
+
|
|
2014
1996
|
/**
|
|
2015
1997
|
* 准备输出目录
|
|
2016
1998
|
*/
|
|
@@ -2020,13 +2002,25 @@ const prepareOutputDirectory = (outputPath) => {
|
|
|
2020
2002
|
return absolutePath;
|
|
2021
2003
|
};
|
|
2022
2004
|
|
|
2005
|
+
/**
|
|
2006
|
+
* 模板引擎执行结果
|
|
2007
|
+
*/
|
|
2008
|
+
|
|
2009
|
+
|
|
2010
|
+
|
|
2011
|
+
|
|
2012
|
+
|
|
2013
|
+
|
|
2014
|
+
|
|
2015
|
+
|
|
2016
|
+
|
|
2023
2017
|
/**
|
|
2024
2018
|
* 执行完整的模板渲染流程
|
|
2025
2019
|
*/
|
|
2026
2020
|
const execute = async (
|
|
2027
2021
|
options,
|
|
2028
2022
|
) => {
|
|
2029
|
-
const { templateName, outputPath, command } = options;
|
|
2023
|
+
const { templateName, outputPath, command, force } = options;
|
|
2030
2024
|
|
|
2031
2025
|
// 1. 加载模板
|
|
2032
2026
|
const { templatePath } = await loadTemplateMetadata(templateName);
|
|
@@ -2051,12 +2045,17 @@ const execute = async (
|
|
|
2051
2045
|
outputPath: absoluteOutputPath,
|
|
2052
2046
|
context,
|
|
2053
2047
|
templateConfig,
|
|
2048
|
+
force,
|
|
2054
2049
|
});
|
|
2055
2050
|
|
|
2056
2051
|
// 7. 执行 onAfterRender 钩子
|
|
2057
2052
|
await executeAfterRenderHook(templateConfig, context, absoluteOutputPath);
|
|
2058
2053
|
|
|
2059
|
-
return
|
|
2054
|
+
return {
|
|
2055
|
+
outputPath: absoluteOutputPath,
|
|
2056
|
+
templateConfig,
|
|
2057
|
+
context,
|
|
2058
|
+
};
|
|
2060
2059
|
};
|
|
2061
2060
|
|
|
2062
2061
|
function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
@@ -2202,6 +2201,7 @@ const executeInit = async (
|
|
|
2202
2201
|
|
|
2203
2202
|
|
|
2204
2203
|
|
|
2204
|
+
|
|
2205
2205
|
,
|
|
2206
2206
|
command,
|
|
2207
2207
|
) => {
|
|
@@ -2214,37 +2214,44 @@ const executeInit = async (
|
|
|
2214
2214
|
skipInstall,
|
|
2215
2215
|
skipGit,
|
|
2216
2216
|
skipDev,
|
|
2217
|
+
force,
|
|
2217
2218
|
} = options;
|
|
2218
2219
|
|
|
2219
2220
|
logger.info(`Initializing project with template: ${templateName}`);
|
|
2220
2221
|
timer.logPhase('Initialization');
|
|
2221
2222
|
|
|
2222
|
-
//
|
|
2223
|
-
const
|
|
2223
|
+
// 执行模板引擎,返回结果对象
|
|
2224
|
+
const result = await execute({
|
|
2224
2225
|
templateName,
|
|
2225
2226
|
outputPath,
|
|
2226
2227
|
command,
|
|
2228
|
+
force,
|
|
2227
2229
|
});
|
|
2230
|
+
const { outputPath: absoluteOutputPath, templateConfig, context } = result;
|
|
2228
2231
|
|
|
2229
2232
|
timer.logPhase('Template engine execution');
|
|
2230
2233
|
logger.success('Project created successfully!');
|
|
2231
2234
|
|
|
2232
|
-
//
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
const hasNodeModules = fs.existsSync(nodeModulesPath);
|
|
2235
|
+
// 检查是否存在 package.json
|
|
2236
|
+
const packageJsonPath = path.join(absoluteOutputPath, 'package.json');
|
|
2237
|
+
const hasPackageJson = fs.existsSync(packageJsonPath);
|
|
2236
2238
|
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
);
|
|
2241
|
-
timer.logPhase('Node modules (pre-warmed)');
|
|
2242
|
-
} else {
|
|
2239
|
+
// 安装依赖(始终使用 pnpm install,利用缓存机制)
|
|
2240
|
+
if (!skipInstall) {
|
|
2241
|
+
if (hasPackageJson) {
|
|
2243
2242
|
runPnpmInstall(absoluteOutputPath);
|
|
2244
2243
|
timer.logPhase('Dependencies installation');
|
|
2244
|
+
} else {
|
|
2245
|
+
logger.info(
|
|
2246
|
+
'\n💡 No package.json found, skipping dependency installation',
|
|
2247
|
+
);
|
|
2245
2248
|
}
|
|
2246
2249
|
}
|
|
2247
2250
|
|
|
2251
|
+
// 执行 onComplete 钩子(在 pnpm install 之后)
|
|
2252
|
+
await executeCompleteHook(templateConfig, context, absoluteOutputPath);
|
|
2253
|
+
timer.logPhase('Complete hook execution');
|
|
2254
|
+
|
|
2248
2255
|
// 如果没有跳过 git,则初始化 git 仓库
|
|
2249
2256
|
if (!skipGit) {
|
|
2250
2257
|
runGitInit(absoluteOutputPath);
|
|
@@ -2259,7 +2266,7 @@ const executeInit = async (
|
|
|
2259
2266
|
// 只有跳过 dev 时才显示 Next steps
|
|
2260
2267
|
logger.info('\nNext steps:');
|
|
2261
2268
|
logger.info(` cd ${outputPath}`);
|
|
2262
|
-
if (skipInstall) {
|
|
2269
|
+
if (skipInstall && hasPackageJson) {
|
|
2263
2270
|
logger.info(' pnpm install');
|
|
2264
2271
|
}
|
|
2265
2272
|
if (skipGit) {
|
|
@@ -2293,6 +2300,11 @@ const registerCommand$1 = program => {
|
|
|
2293
2300
|
.option('--skip-install', 'Skip automatic pnpm install', false)
|
|
2294
2301
|
.option('--skip-git', 'Skip automatic git initialization', false)
|
|
2295
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
|
+
)
|
|
2296
2308
|
.allowUnknownOption() // 允许透传参数
|
|
2297
2309
|
.action(async (directory, options, command) => {
|
|
2298
2310
|
// 位置参数优先级高于 --output 选项
|
|
@@ -2597,7 +2609,7 @@ const registerCommand = program => {
|
|
|
2597
2609
|
});
|
|
2598
2610
|
};
|
|
2599
2611
|
|
|
2600
|
-
var version = "0.0.1-alpha.
|
|
2612
|
+
var version = "0.0.1-alpha.e9ff73";
|
|
2601
2613
|
var packageJson = {
|
|
2602
2614
|
version: version};
|
|
2603
2615
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coze-arch/cli",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.e9ff73",
|
|
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": {
|