@coze-arch/cli 0.0.1-alpha.d49256 → 0.0.1-alpha.d4acfb
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/server_dev_run.sh +1 -1
- package/lib/__templates__/expo/README.md +0 -1
- package/lib/__templates__/expo/client/contexts/AuthContext.tsx +5 -9
- package/lib/__templates__/expo/client/metro.config.js +3 -0
- package/lib/__templates__/expo/pnpm-lock.yaml +101 -45
- package/lib/__templates__/expo/server/package.json +9 -7
- 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/package.json +3 -1
- package/lib/__templates__/nextjs/pnpm-lock.yaml +119 -106
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +2 -2
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +4 -3
- package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +0 -15
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +117 -24
- package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -1
- package/lib/__templates__/taro/README.md +81 -17
- package/lib/__templates__/taro/config/index.ts +87 -37
- package/lib/__templates__/taro/config/prod.ts +4 -5
- package/lib/__templates__/taro/eslint.config.mjs +27 -4
- package/lib/__templates__/taro/package.json +16 -4
- package/lib/__templates__/taro/patches/@tarojs__plugin-mini-ci@4.1.9.patch +30 -0
- package/lib/__templates__/taro/pnpm-lock.yaml +785 -115
- package/lib/__templates__/taro/server/package.json +3 -1
- package/lib/__templates__/taro/server/src/main.ts +14 -2
- package/lib/__templates__/taro/src/app.css +18 -18
- package/lib/__templates__/taro/src/app.tsx +9 -0
- package/lib/__templates__/taro/src/index.html +20 -1
- 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__/templates.json +43 -0
- package/lib/__templates__/vite/package.json +5 -1
- package/lib/__templates__/vite/pnpm-lock.yaml +146 -1659
- package/lib/__templates__/vite/vite.config.ts +1 -0
- package/lib/__templates__/vite-vue/.coze +12 -0
- package/lib/__templates__/vite-vue/README.md +451 -0
- package/lib/__templates__/vite-vue/_gitignore +66 -0
- package/lib/__templates__/vite-vue/_npmrc +23 -0
- package/lib/__templates__/vite-vue/eslint.config.mjs +9 -0
- package/lib/__templates__/vite-vue/index.html +13 -0
- package/lib/__templates__/vite-vue/package.json +37 -0
- package/lib/__templates__/vite-vue/pnpm-lock.yaml +3151 -0
- package/lib/__templates__/vite-vue/postcss.config.mjs +6 -0
- package/lib/__templates__/vite-vue/scripts/build.sh +14 -0
- package/lib/__templates__/vite-vue/scripts/dev.sh +32 -0
- package/lib/__templates__/vite-vue/scripts/prepare.sh +9 -0
- package/lib/__templates__/vite-vue/scripts/start.sh +15 -0
- package/lib/__templates__/vite-vue/src/App.vue +6 -0
- package/lib/__templates__/vite-vue/src/index.css +29 -0
- package/lib/__templates__/vite-vue/src/main.ts +8 -0
- package/lib/__templates__/vite-vue/src/router/index.ts +17 -0
- package/lib/__templates__/vite-vue/src/views/Home.vue +37 -0
- package/lib/__templates__/vite-vue/src/vite-env.d.ts +8 -0
- package/lib/__templates__/vite-vue/tailwind.config.js +9 -0
- package/lib/__templates__/vite-vue/template.config.js +128 -0
- package/lib/__templates__/vite-vue/tsconfig.json +17 -0
- package/lib/__templates__/vite-vue/vite.config.ts +28 -0
- package/lib/cli.js +25 -65
- package/package.json +2 -1
- package/lib/__templates__/taro/src/app.ts +0 -14
- package/lib/__templates__/taro/src/utils/h5-styles.ts +0 -22
- package/lib/__templates__/taro/src/utils/wx-debug.ts +0 -23
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -Eeuo pipefail
|
|
3
|
+
|
|
4
|
+
COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
|
|
5
|
+
|
|
6
|
+
cd "${COZE_WORKSPACE_PATH}"
|
|
7
|
+
|
|
8
|
+
echo "Installing dependencies..."
|
|
9
|
+
pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
|
|
10
|
+
|
|
11
|
+
echo "Building the project..."
|
|
12
|
+
npx vite build
|
|
13
|
+
|
|
14
|
+
echo "Build completed successfully!"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -Eeuo pipefail
|
|
3
|
+
|
|
4
|
+
PORT=<%= port %>
|
|
5
|
+
COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
|
|
6
|
+
DEPLOY_RUN_PORT=<%= port %>
|
|
7
|
+
|
|
8
|
+
cd "${COZE_WORKSPACE_PATH}"
|
|
9
|
+
|
|
10
|
+
kill_port_if_listening() {
|
|
11
|
+
local pids
|
|
12
|
+
pids=$(ss -H -lntp 2>/dev/null | awk -v port="${DEPLOY_RUN_PORT}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
|
|
13
|
+
if [[ -z "${pids}" ]]; then
|
|
14
|
+
echo "Port ${DEPLOY_RUN_PORT} is free."
|
|
15
|
+
return
|
|
16
|
+
fi
|
|
17
|
+
echo "Port ${DEPLOY_RUN_PORT} in use by PIDs: ${pids} (SIGKILL)"
|
|
18
|
+
echo "${pids}" | xargs -I {} kill -9 {}
|
|
19
|
+
sleep 1
|
|
20
|
+
pids=$(ss -H -lntp 2>/dev/null | awk -v port="${DEPLOY_RUN_PORT}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
|
|
21
|
+
if [[ -n "${pids}" ]]; then
|
|
22
|
+
echo "Warning: port ${DEPLOY_RUN_PORT} still busy after SIGKILL, PIDs: ${pids}"
|
|
23
|
+
else
|
|
24
|
+
echo "Port ${DEPLOY_RUN_PORT} cleared."
|
|
25
|
+
fi
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
echo "Clearing port ${PORT} before start."
|
|
29
|
+
kill_port_if_listening
|
|
30
|
+
echo "Starting HTTP service on port ${PORT} for dev..."
|
|
31
|
+
|
|
32
|
+
npx vite --port $PORT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -Eeuo pipefail
|
|
3
|
+
|
|
4
|
+
COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
|
|
5
|
+
PORT=<%= port %>
|
|
6
|
+
DEPLOY_RUN_PORT="${DEPLOY_RUN_PORT:-$PORT}"
|
|
7
|
+
|
|
8
|
+
start_service() {
|
|
9
|
+
cd "${COZE_WORKSPACE_PATH}"
|
|
10
|
+
echo "Starting HTTP service on port ${DEPLOY_RUN_PORT} for deploy..."
|
|
11
|
+
npx vite preview --port $DEPLOY_RUN_PORT
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
echo "Starting HTTP service on port ${DEPLOY_RUN_PORT} for deploy..."
|
|
15
|
+
start_service
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
@tailwind base;
|
|
2
|
+
@tailwind components;
|
|
3
|
+
@tailwind utilities;
|
|
4
|
+
|
|
5
|
+
:root {
|
|
6
|
+
--background: #ffffff;
|
|
7
|
+
--foreground: #171717;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@media (prefers-color-scheme: dark) {
|
|
11
|
+
:root {
|
|
12
|
+
--background: #0a0a0a;
|
|
13
|
+
--foreground: #ededed;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
html,
|
|
18
|
+
body,
|
|
19
|
+
#app {
|
|
20
|
+
height: 100%;
|
|
21
|
+
margin: 0;
|
|
22
|
+
padding: 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
body {
|
|
26
|
+
background: var(--background);
|
|
27
|
+
color: var(--foreground);
|
|
28
|
+
font-family: Arial, Helvetica, sans-serif;
|
|
29
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createRouter, createWebHistory } from 'vue-router';
|
|
2
|
+
import type { RouteRecordRaw } from 'vue-router';
|
|
3
|
+
|
|
4
|
+
const routes: RouteRecordRaw[] = [
|
|
5
|
+
{
|
|
6
|
+
path: '/',
|
|
7
|
+
name: 'Home',
|
|
8
|
+
component: () => import('../views/Home.vue'),
|
|
9
|
+
},
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
const router = createRouter({
|
|
13
|
+
history: createWebHistory(),
|
|
14
|
+
routes,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export default router;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<script setup lang="ts"></script>
|
|
2
|
+
|
|
3
|
+
<template>
|
|
4
|
+
<div
|
|
5
|
+
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"
|
|
6
|
+
>
|
|
7
|
+
<main
|
|
8
|
+
class="flex w-full h-full max-w-3xl flex-col items-center justify-center px-16 py-32 sm:items-center"
|
|
9
|
+
>
|
|
10
|
+
<div class="flex flex-col items-center justify-between gap-4">
|
|
11
|
+
<img
|
|
12
|
+
src="https://lf-coze-web-cdn.coze.cn/obj/eden-cn/lm-lgvj/ljhwZthlaukjlkulzlp/coze-coding/icon/coze-coding.gif"
|
|
13
|
+
alt="扣子编程 Logo"
|
|
14
|
+
width="156"
|
|
15
|
+
height="130"
|
|
16
|
+
class="w-[156px] h-[130px] object-contain"
|
|
17
|
+
/>
|
|
18
|
+
<div>
|
|
19
|
+
<div
|
|
20
|
+
class="flex flex-col items-center gap-2 text-center sm:items-center sm:text-center"
|
|
21
|
+
>
|
|
22
|
+
<h1
|
|
23
|
+
class="max-w-xl text-base font-semibold leading-tight tracking-tight text-foreground dark:text-foreground"
|
|
24
|
+
>
|
|
25
|
+
应用开发中
|
|
26
|
+
</h1>
|
|
27
|
+
<p
|
|
28
|
+
class="max-w-2xl text-sm-14 leading-8 text-muted-foreground dark:text-muted-foreground"
|
|
29
|
+
>
|
|
30
|
+
请稍后,页面即将呈现
|
|
31
|
+
</p>
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
</main>
|
|
36
|
+
</div>
|
|
37
|
+
</template>
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
import { resolve, join, basename } from 'path';
|
|
4
|
+
import { appendFileSync, openSync, closeSync, mkdirSync } from 'fs';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export const paramsSchema = {
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
appName: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
minLength: 1,
|
|
20
|
+
pattern: '^[a-z0-9-]+$',
|
|
21
|
+
description:
|
|
22
|
+
'Application name (lowercase, alphanumeric and hyphens only)',
|
|
23
|
+
},
|
|
24
|
+
port: {
|
|
25
|
+
type: 'number',
|
|
26
|
+
default: 5000,
|
|
27
|
+
minimum: 1024,
|
|
28
|
+
maximum: 65535,
|
|
29
|
+
description: 'Development server port',
|
|
30
|
+
},
|
|
31
|
+
hmrPort: {
|
|
32
|
+
type: 'number',
|
|
33
|
+
default: 6000,
|
|
34
|
+
minimum: 1024,
|
|
35
|
+
maximum: 65535,
|
|
36
|
+
description: 'Development HMR server port',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
required: [],
|
|
40
|
+
additionalProperties: false,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const description = `Vite + Vue 3(Vue 项目):\`coze init \${COZE_WORKSPACE_PATH} --template vite-vue\`
|
|
44
|
+
- 适用:使用 Vue 3 框架的 SPA 应用、交互式前端、组件化仪表盘等项目
|
|
45
|
+
- 样式开发:使用 Tailwind CSS 完成所有样式开发,不支持 Less/Sass 等预处理器。`;
|
|
46
|
+
|
|
47
|
+
const config = {
|
|
48
|
+
description: description,
|
|
49
|
+
paramsSchema,
|
|
50
|
+
|
|
51
|
+
defaultParams: {
|
|
52
|
+
port: 5000,
|
|
53
|
+
hmrPort: 6000,
|
|
54
|
+
appName: 'projects',
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
onBeforeRender: async context => {
|
|
58
|
+
console.log(
|
|
59
|
+
`Creating Vue 3 + TypeScript + Vite project: ${context.appName}`,
|
|
60
|
+
);
|
|
61
|
+
return context;
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
onAfterRender: async (_context, outputPath) => {
|
|
65
|
+
console.log(`\nProject created at: ${outputPath}`);
|
|
66
|
+
console.log('\nConfiguration:');
|
|
67
|
+
console.log(' - Framework: Vue 3 + Vite');
|
|
68
|
+
console.log(' - TypeScript: enabled');
|
|
69
|
+
console.log(' - Composition API: enabled');
|
|
70
|
+
console.log(` - Port: ${_context.port}`);
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
onComplete: async (_context, outputPath) => {
|
|
74
|
+
// Skip pnpm update in test environment to avoid monorepo workspace issues
|
|
75
|
+
if (process.env.NODE_ENV === 'test') {
|
|
76
|
+
console.log('⊘ Skipping dependency update in test environment');
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const cmd = 'pnpm';
|
|
81
|
+
const args = ['update', 'coze-coding-dev-sdk@^0.7.0'];
|
|
82
|
+
console.log(
|
|
83
|
+
`\nTriggering: ${cmd} ${args.join(' ')} (running in background)`,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const projectRoot = resolve(outputPath);
|
|
88
|
+
|
|
89
|
+
// Determine log directory
|
|
90
|
+
const logDir = process.env.COZE_LOG_DIR || resolve(__dirname, '../.log');
|
|
91
|
+
mkdirSync(logDir, { recursive: true });
|
|
92
|
+
|
|
93
|
+
// Use project name in log file to avoid conflicts
|
|
94
|
+
const projectName = basename(projectRoot);
|
|
95
|
+
const logFile = join(logDir, `${projectName}-init.log`);
|
|
96
|
+
|
|
97
|
+
// Write log header
|
|
98
|
+
const timestamp = new Date().toISOString();
|
|
99
|
+
appendFileSync(
|
|
100
|
+
logFile,
|
|
101
|
+
`\n=== [${timestamp}] ${cmd} ${args.join(' ')} ===\n`,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
// Open log file for appending
|
|
105
|
+
const logFd = openSync(logFile, 'a');
|
|
106
|
+
|
|
107
|
+
// Spawn in detached mode
|
|
108
|
+
const child = spawn(cmd, args, {
|
|
109
|
+
cwd: projectRoot,
|
|
110
|
+
detached: true,
|
|
111
|
+
stdio: ['ignore', logFd, logFd],
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
child.unref();
|
|
115
|
+
closeSync(logFd);
|
|
116
|
+
|
|
117
|
+
console.log(
|
|
118
|
+
'✓ coze-coding-dev-sdk update triggered (running in background)',
|
|
119
|
+
);
|
|
120
|
+
console.log(` Log file: ${logFile}`);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.error('✗ Failed to trigger coze-coding-dev-sdk update:', error);
|
|
123
|
+
console.log(' You can manually run: pnpm update coze-coding-dev-sdk');
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export default config;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"jsx": "preserve"
|
|
15
|
+
},
|
|
16
|
+
"include": ["src"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import vue from '@vitejs/plugin-vue';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
plugins: [
|
|
6
|
+
vue({
|
|
7
|
+
include: [/\.vue$/],
|
|
8
|
+
}),
|
|
9
|
+
],
|
|
10
|
+
resolve: {
|
|
11
|
+
extensions: ['.ts', '.tsx', '.js', '.jsx', '.vue', '.json'],
|
|
12
|
+
},
|
|
13
|
+
optimizeDeps: {
|
|
14
|
+
include: ['vue'],
|
|
15
|
+
},
|
|
16
|
+
server: {
|
|
17
|
+
port: <%= port %>,
|
|
18
|
+
host: '0.0.0.0',
|
|
19
|
+
allowedHosts: true,
|
|
20
|
+
hmr: {
|
|
21
|
+
overlay: true,
|
|
22
|
+
path: '/hot/vite-hmr',
|
|
23
|
+
port: <%= hmrPort %>,
|
|
24
|
+
clientPort: 443,
|
|
25
|
+
timeout: 30000,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
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
|
|
@@ -1925,11 +1889,7 @@ const processTemplateFiles = async (options
|
|
|
1925
1889
|
|
|
1926
1890
|
logger.verbose('✓ All files processed successfully');
|
|
1927
1891
|
|
|
1928
|
-
//
|
|
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
|
|
|
@@ -2259,19 +2219,19 @@ const executeInit = async (
|
|
|
2259
2219
|
timer.logPhase('Template engine execution');
|
|
2260
2220
|
logger.success('Project created successfully!');
|
|
2261
2221
|
|
|
2262
|
-
//
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
const hasNodeModules = fs.existsSync(nodeModulesPath);
|
|
2222
|
+
// 检查是否存在 package.json
|
|
2223
|
+
const packageJsonPath = path.join(absoluteOutputPath, 'package.json');
|
|
2224
|
+
const hasPackageJson = fs.existsSync(packageJsonPath);
|
|
2266
2225
|
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
);
|
|
2271
|
-
timer.logPhase('Node modules (pre-warmed)');
|
|
2272
|
-
} else {
|
|
2226
|
+
// 安装依赖(始终使用 pnpm install,利用缓存机制)
|
|
2227
|
+
if (!skipInstall) {
|
|
2228
|
+
if (hasPackageJson) {
|
|
2273
2229
|
runPnpmInstall(absoluteOutputPath);
|
|
2274
2230
|
timer.logPhase('Dependencies installation');
|
|
2231
|
+
} else {
|
|
2232
|
+
logger.info(
|
|
2233
|
+
'\n💡 No package.json found, skipping dependency installation',
|
|
2234
|
+
);
|
|
2275
2235
|
}
|
|
2276
2236
|
}
|
|
2277
2237
|
|
|
@@ -2293,7 +2253,7 @@ const executeInit = async (
|
|
|
2293
2253
|
// 只有跳过 dev 时才显示 Next steps
|
|
2294
2254
|
logger.info('\nNext steps:');
|
|
2295
2255
|
logger.info(` cd ${outputPath}`);
|
|
2296
|
-
if (skipInstall) {
|
|
2256
|
+
if (skipInstall && hasPackageJson) {
|
|
2297
2257
|
logger.info(' pnpm install');
|
|
2298
2258
|
}
|
|
2299
2259
|
if (skipGit) {
|
|
@@ -2631,7 +2591,7 @@ const registerCommand = program => {
|
|
|
2631
2591
|
});
|
|
2632
2592
|
};
|
|
2633
2593
|
|
|
2634
|
-
var version = "0.0.1-alpha.
|
|
2594
|
+
var version = "0.0.1-alpha.d4acfb";
|
|
2635
2595
|
var packageJson = {
|
|
2636
2596
|
version: version};
|
|
2637
2597
|
|
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.d4acfb",
|
|
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,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
|
-
}
|