@coze-arch/cli 0.0.1-alpha.bcc7d9 → 0.0.1-alpha.bd55ba
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 +15 -14
- package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +9 -8
- package/lib/__templates__/expo/README.md +2 -2
- package/lib/__templates__/expo/client/eslint.config.mjs +17 -1
- package/lib/__templates__/expo/client/metro.config.js +3 -0
- package/lib/__templates__/expo/client/package.json +36 -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.33.patch +45 -0
- package/lib/__templates__/expo/pnpm-lock.yaml +338 -1735
- 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/package.json +3 -1
- package/lib/__templates__/nextjs/pnpm-lock.yaml +1051 -934
- package/lib/__templates__/nextjs/src/app/page.tsx +18 -60
- package/lib/__templates__/nextjs/template.config.js +49 -14
- 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 +75 -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/__templates__/vite-vue/.coze +12 -0
- package/lib/__templates__/vite-vue/README.md +342 -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 +3132 -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 +38 -0
- package/lib/__templates__/vite-vue/src/index.css +29 -0
- package/lib/__templates__/vite-vue/src/main.ts +6 -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 +127 -0
- package/lib/__templates__/vite-vue/tsconfig.json +17 -0
- package/lib/__templates__/vite-vue/vite.config.ts +28 -0
- package/lib/cli.js +373 -82
- package/package.json +2 -1
- package/lib/__templates__/expo/patches/expo@54.0.32.patch +0 -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 {
|
|
@@ -585,12 +589,12 @@ const executeWarmup = async (
|
|
|
585
589
|
/**
|
|
586
590
|
* 注册 warmup 命令到 program
|
|
587
591
|
*/
|
|
588
|
-
const registerCommand$
|
|
592
|
+
const registerCommand$4 = program => {
|
|
589
593
|
program
|
|
590
594
|
.command('warmup')
|
|
591
595
|
.description('Pre-install dependencies for templates to speed up init')
|
|
592
596
|
.option('-t, --template <name>', 'Warmup a specific template only')
|
|
593
|
-
.action(async
|
|
597
|
+
.action(async options => {
|
|
594
598
|
await executeWarmup(options);
|
|
595
599
|
});
|
|
596
600
|
};
|
|
@@ -1033,7 +1037,7 @@ const executeFix = async (options = {}) => {
|
|
|
1033
1037
|
/**
|
|
1034
1038
|
* 注册 fix 命令到 program
|
|
1035
1039
|
*/
|
|
1036
|
-
const registerCommand$
|
|
1040
|
+
const registerCommand$3 = program => {
|
|
1037
1041
|
program
|
|
1038
1042
|
.command('fix')
|
|
1039
1043
|
.description(
|
|
@@ -1052,13 +1056,13 @@ function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else
|
|
|
1052
1056
|
/**
|
|
1053
1057
|
* 日志文件名常量
|
|
1054
1058
|
*/
|
|
1055
|
-
const LOG_FILE_NAME = 'dev.log';
|
|
1059
|
+
const LOG_FILE_NAME$1 = 'dev.log';
|
|
1056
1060
|
|
|
1057
1061
|
/**
|
|
1058
1062
|
* 获取日志目录
|
|
1059
1063
|
* 优先使用环境变量 COZE_LOG_DIR,否则使用 ~/.coze-logs
|
|
1060
1064
|
*/
|
|
1061
|
-
const getLogDir = () =>
|
|
1065
|
+
const getLogDir$1 = () =>
|
|
1062
1066
|
process.env.COZE_LOG_DIR || path.join(os.homedir(), '.coze-logs');
|
|
1063
1067
|
|
|
1064
1068
|
/**
|
|
@@ -1067,22 +1071,22 @@ const getLogDir = () =>
|
|
|
1067
1071
|
* - 如果是相对路径,基于 getLogDir() + 相对路径
|
|
1068
1072
|
* - 如果为空,使用 getLogDir() + LOG_FILE_NAME
|
|
1069
1073
|
*/
|
|
1070
|
-
const resolveLogFilePath = (logFile) => {
|
|
1074
|
+
const resolveLogFilePath$1 = (logFile) => {
|
|
1071
1075
|
if (!logFile) {
|
|
1072
|
-
return path.join(getLogDir(), LOG_FILE_NAME);
|
|
1076
|
+
return path.join(getLogDir$1(), LOG_FILE_NAME$1);
|
|
1073
1077
|
}
|
|
1074
1078
|
|
|
1075
1079
|
if (path.isAbsolute(logFile)) {
|
|
1076
1080
|
return logFile;
|
|
1077
1081
|
}
|
|
1078
1082
|
|
|
1079
|
-
return path.join(getLogDir(), logFile);
|
|
1083
|
+
return path.join(getLogDir$1(), logFile);
|
|
1080
1084
|
};
|
|
1081
1085
|
|
|
1082
1086
|
/**
|
|
1083
1087
|
* 创建日志写入流
|
|
1084
1088
|
*/
|
|
1085
|
-
const createLogStream = (logFilePath) => {
|
|
1089
|
+
const createLogStream$1 = (logFilePath) => {
|
|
1086
1090
|
const logDir = path.dirname(logFilePath);
|
|
1087
1091
|
|
|
1088
1092
|
// 确保日志目录存在
|
|
@@ -1121,8 +1125,8 @@ const executeRun = async (
|
|
|
1121
1125
|
const commandArgs = getCommandConfig(config, commandName);
|
|
1122
1126
|
|
|
1123
1127
|
// 3. 准备日志
|
|
1124
|
-
const logFilePath = resolveLogFilePath(options.logFile);
|
|
1125
|
-
const logStream = createLogStream(logFilePath);
|
|
1128
|
+
const logFilePath = resolveLogFilePath$1(options.logFile);
|
|
1129
|
+
const logStream = createLogStream$1(logFilePath);
|
|
1126
1130
|
|
|
1127
1131
|
// 4. 执行命令
|
|
1128
1132
|
const commandString = commandArgs.join(' ');
|
|
@@ -1185,7 +1189,7 @@ const executeRun = async (
|
|
|
1185
1189
|
/**
|
|
1186
1190
|
* 注册 dev/build/start 命令到 program
|
|
1187
1191
|
*/
|
|
1188
|
-
const registerCommand$
|
|
1192
|
+
const registerCommand$2 = program => {
|
|
1189
1193
|
// dev 命令
|
|
1190
1194
|
program
|
|
1191
1195
|
.command('dev')
|
|
@@ -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
|
|
|
@@ -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
|
|
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
|
|
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
|
-
//
|
|
2233
|
-
|
|
2234
|
-
|
|
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
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
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) {
|
|
@@ -2283,7 +2277,7 @@ const executeInit = async (
|
|
|
2283
2277
|
/**
|
|
2284
2278
|
* 注册 init 命令到 program
|
|
2285
2279
|
*/
|
|
2286
|
-
const registerCommand = program => {
|
|
2280
|
+
const registerCommand$1 = program => {
|
|
2287
2281
|
program
|
|
2288
2282
|
.command('init')
|
|
2289
2283
|
.description('Initialize a new project from a template')
|
|
@@ -2301,15 +2295,312 @@ const registerCommand = program => {
|
|
|
2301
2295
|
});
|
|
2302
2296
|
};
|
|
2303
2297
|
|
|
2304
|
-
|
|
2298
|
+
// ABOUTME: This file implements the update command for coze CLI
|
|
2299
|
+
// ABOUTME: It wraps pnpm update/install to update package dependencies with logging support
|
|
2300
|
+
|
|
2301
|
+
|
|
2302
|
+
|
|
2303
|
+
|
|
2304
|
+
/**
|
|
2305
|
+
* 日志文件名常量
|
|
2306
|
+
*/
|
|
2307
|
+
const LOG_FILE_NAME = 'update.log';
|
|
2308
|
+
|
|
2309
|
+
/**
|
|
2310
|
+
* 获取日志目录
|
|
2311
|
+
* 优先使用环境变量 COZE_LOG_DIR,否则使用 ~/.coze-logs
|
|
2312
|
+
*/
|
|
2313
|
+
const getLogDir = () =>
|
|
2314
|
+
process.env.COZE_LOG_DIR || path.join(os.homedir(), '.coze-logs');
|
|
2315
|
+
|
|
2316
|
+
/**
|
|
2317
|
+
* 解析日志文件路径
|
|
2318
|
+
* - 如果是绝对路径,直接使用
|
|
2319
|
+
* - 如果是相对路径,基于 getLogDir() + 相对路径
|
|
2320
|
+
* - 如果为空,使用 getLogDir() + LOG_FILE_NAME
|
|
2321
|
+
*/
|
|
2322
|
+
const resolveLogFilePath = (logFile) => {
|
|
2323
|
+
if (!logFile) {
|
|
2324
|
+
return path.join(getLogDir(), LOG_FILE_NAME);
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
if (path.isAbsolute(logFile)) {
|
|
2328
|
+
return logFile;
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
return path.join(getLogDir(), logFile);
|
|
2332
|
+
};
|
|
2333
|
+
|
|
2334
|
+
/**
|
|
2335
|
+
* 创建日志写入流
|
|
2336
|
+
*/
|
|
2337
|
+
const createLogStream = (logFilePath) => {
|
|
2338
|
+
const logDir = path.dirname(logFilePath);
|
|
2339
|
+
|
|
2340
|
+
// 确保日志目录存在
|
|
2341
|
+
if (!fs.existsSync(logDir)) {
|
|
2342
|
+
fs.mkdirSync(logDir, { recursive: true });
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
// 使用 'w' 标志覆盖之前的日志
|
|
2346
|
+
return fs.createWriteStream(logFilePath, { flags: 'w' });
|
|
2347
|
+
};
|
|
2348
|
+
|
|
2349
|
+
/**
|
|
2350
|
+
* 格式化时间戳
|
|
2351
|
+
*/
|
|
2352
|
+
const formatTimestamp = () => {
|
|
2353
|
+
const now = new Date();
|
|
2354
|
+
return now.toISOString();
|
|
2355
|
+
};
|
|
2356
|
+
|
|
2357
|
+
/**
|
|
2358
|
+
* 写入带时间戳的日志
|
|
2359
|
+
*/
|
|
2360
|
+
const writeLogWithTimestamp = (stream, message) => {
|
|
2361
|
+
const timestamp = formatTimestamp();
|
|
2362
|
+
const lines = message.split('\n');
|
|
2363
|
+
lines.forEach(line => {
|
|
2364
|
+
if (line) {
|
|
2365
|
+
stream.write(`[${timestamp}] ${line}\n`);
|
|
2366
|
+
} else {
|
|
2367
|
+
stream.write('\n');
|
|
2368
|
+
}
|
|
2369
|
+
});
|
|
2370
|
+
// 确保数据写入磁盘
|
|
2371
|
+
stream.uncork();
|
|
2372
|
+
};
|
|
2373
|
+
|
|
2374
|
+
/**
|
|
2375
|
+
* 同时输出到控制台和日志文件
|
|
2376
|
+
*/
|
|
2377
|
+
const logWithFile = (
|
|
2378
|
+
stream,
|
|
2379
|
+
level,
|
|
2380
|
+
message,
|
|
2381
|
+
) => {
|
|
2382
|
+
// 输出到控制台
|
|
2383
|
+
switch (level) {
|
|
2384
|
+
case 'info':
|
|
2385
|
+
logger.info(message);
|
|
2386
|
+
break;
|
|
2387
|
+
case 'success':
|
|
2388
|
+
logger.success(message);
|
|
2389
|
+
break;
|
|
2390
|
+
case 'error':
|
|
2391
|
+
logger.error(message);
|
|
2392
|
+
break;
|
|
2393
|
+
default:
|
|
2394
|
+
logger.info(message);
|
|
2395
|
+
break;
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
// 写入日志文件(带时间戳)
|
|
2399
|
+
writeLogWithTimestamp(stream, `[${level.toUpperCase()}] ${message}`);
|
|
2400
|
+
};
|
|
2401
|
+
|
|
2402
|
+
// start_aigc
|
|
2403
|
+
/**
|
|
2404
|
+
* 构建 pnpm add 命令
|
|
2405
|
+
*/
|
|
2406
|
+
const buildPnpmCommand = (
|
|
2407
|
+
packageName,
|
|
2408
|
+
options
|
|
2409
|
+
|
|
2410
|
+
|
|
2411
|
+
|
|
2412
|
+
|
|
2413
|
+
,
|
|
2414
|
+
) => {
|
|
2415
|
+
const { global, version, registry, extraArgs } = options;
|
|
2416
|
+
|
|
2417
|
+
const parts = ['pnpm', 'add'];
|
|
2418
|
+
|
|
2419
|
+
// 添加全局标记
|
|
2420
|
+
if (global) {
|
|
2421
|
+
parts.push('-g');
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
// 添加包名和版本
|
|
2425
|
+
if (version && version !== 'latest') {
|
|
2426
|
+
parts.push(`${packageName}@${version}`);
|
|
2427
|
+
} else {
|
|
2428
|
+
parts.push(`${packageName}@latest`);
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2431
|
+
// 添加 registry
|
|
2432
|
+
if (registry) {
|
|
2433
|
+
parts.push(`--registry=${registry}`);
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
// 添加额外参数
|
|
2437
|
+
if (extraArgs.length > 0) {
|
|
2438
|
+
parts.push(...extraArgs);
|
|
2439
|
+
}
|
|
2440
|
+
|
|
2441
|
+
return parts.join(' ');
|
|
2442
|
+
};
|
|
2443
|
+
// end_aigc
|
|
2444
|
+
|
|
2445
|
+
// start_aigc
|
|
2446
|
+
/**
|
|
2447
|
+
* 执行 update 命令的内部实现
|
|
2448
|
+
*/
|
|
2449
|
+
const executeUpdate = (
|
|
2450
|
+
packageName,
|
|
2451
|
+
options
|
|
2452
|
+
|
|
2453
|
+
|
|
2454
|
+
|
|
2455
|
+
|
|
2456
|
+
|
|
2457
|
+
|
|
2458
|
+
,
|
|
2459
|
+
) => {
|
|
2460
|
+
let logStream = null;
|
|
2461
|
+
|
|
2462
|
+
try {
|
|
2463
|
+
const { global, cwd, version, registry, logFile, extraArgs } = options;
|
|
2464
|
+
|
|
2465
|
+
// 准备日志
|
|
2466
|
+
const logFilePath = resolveLogFilePath(logFile);
|
|
2467
|
+
|
|
2468
|
+
// 调试:确认日志路径
|
|
2469
|
+
logger.info(`Log file path resolved to: ${logFilePath}`);
|
|
2470
|
+
|
|
2471
|
+
logStream = createLogStream(logFilePath);
|
|
2472
|
+
|
|
2473
|
+
// 调试:确认流已创建
|
|
2474
|
+
logger.info('Log stream created successfully');
|
|
2475
|
+
|
|
2476
|
+
logWithFile(logStream, 'info', `Updating package: ${packageName}`);
|
|
2477
|
+
|
|
2478
|
+
// 构建命令
|
|
2479
|
+
const command = buildPnpmCommand(packageName, {
|
|
2480
|
+
global,
|
|
2481
|
+
version,
|
|
2482
|
+
registry,
|
|
2483
|
+
extraArgs,
|
|
2484
|
+
});
|
|
2485
|
+
|
|
2486
|
+
// 确定工作目录
|
|
2487
|
+
const workingDir = cwd
|
|
2488
|
+
? path.isAbsolute(cwd)
|
|
2489
|
+
? cwd
|
|
2490
|
+
: path.join(process.cwd(), cwd)
|
|
2491
|
+
: process.cwd();
|
|
2492
|
+
|
|
2493
|
+
logWithFile(logStream, 'info', `Executing: ${command}`);
|
|
2494
|
+
logWithFile(logStream, 'info', `Working directory: ${workingDir}`);
|
|
2495
|
+
logWithFile(logStream, 'info', `Log file: ${logFilePath}`);
|
|
2496
|
+
|
|
2497
|
+
// 记录命令开始时间
|
|
2498
|
+
writeLogWithTimestamp(logStream, '--- Command execution started ---');
|
|
2499
|
+
|
|
2500
|
+
// 同步执行命令
|
|
2501
|
+
const result = shelljs.exec(command, {
|
|
2502
|
+
cwd: workingDir,
|
|
2503
|
+
silent: true, // 使用 silent 来捕获输出
|
|
2504
|
+
});
|
|
2505
|
+
|
|
2506
|
+
// 将输出写入控制台和日志文件(带时间戳)
|
|
2507
|
+
if (result.stdout) {
|
|
2508
|
+
process.stdout.write(result.stdout);
|
|
2509
|
+
writeLogWithTimestamp(logStream, result.stdout.trim());
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
if (result.stderr) {
|
|
2513
|
+
process.stderr.write(result.stderr);
|
|
2514
|
+
writeLogWithTimestamp(logStream, result.stderr.trim());
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2517
|
+
// 记录命令结束时间
|
|
2518
|
+
writeLogWithTimestamp(logStream, '--- Command execution ended ---');
|
|
2519
|
+
|
|
2520
|
+
// 检查执行结果并记录到日志
|
|
2521
|
+
if (result.code === 0) {
|
|
2522
|
+
logWithFile(logStream, 'success', 'Package updated successfully');
|
|
2523
|
+
logWithFile(logStream, 'info', `Log file: ${logFilePath}`);
|
|
2524
|
+
} else {
|
|
2525
|
+
logWithFile(
|
|
2526
|
+
logStream,
|
|
2527
|
+
'error',
|
|
2528
|
+
`Command exited with code ${result.code}`,
|
|
2529
|
+
);
|
|
2530
|
+
logWithFile(
|
|
2531
|
+
logStream,
|
|
2532
|
+
'error',
|
|
2533
|
+
`Check log file for details: ${logFilePath}`,
|
|
2534
|
+
);
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2537
|
+
// 关闭日志流并等待写入完成
|
|
2538
|
+
logStream.end(() => {
|
|
2539
|
+
// 流关闭后再退出进程
|
|
2540
|
+
if (result.code !== 0) {
|
|
2541
|
+
process.exit(result.code || 1);
|
|
2542
|
+
}
|
|
2543
|
+
});
|
|
2544
|
+
} catch (error) {
|
|
2545
|
+
logger.error('Failed to update package:');
|
|
2546
|
+
logger.error(error instanceof Error ? error.message : String(error));
|
|
2547
|
+
|
|
2548
|
+
// 写入错误到日志文件
|
|
2549
|
+
if (logStream) {
|
|
2550
|
+
writeLogWithTimestamp(
|
|
2551
|
+
logStream,
|
|
2552
|
+
`[ERROR] ${error instanceof Error ? error.message : String(error)}`,
|
|
2553
|
+
);
|
|
2554
|
+
// 等待流关闭后再退出
|
|
2555
|
+
logStream.end(() => {
|
|
2556
|
+
process.exit(1);
|
|
2557
|
+
});
|
|
2558
|
+
} else {
|
|
2559
|
+
process.exit(1);
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
};
|
|
2563
|
+
// end_aigc
|
|
2564
|
+
|
|
2565
|
+
/**
|
|
2566
|
+
* 注册 update 命令到 program
|
|
2567
|
+
*/
|
|
2568
|
+
const registerCommand = program => {
|
|
2569
|
+
program
|
|
2570
|
+
.command('update <package>')
|
|
2571
|
+
.description('Update a package dependency')
|
|
2572
|
+
.option('-g, --global', 'Update package globally', false)
|
|
2573
|
+
.option('-c, --cwd <path>', 'Working directory for the update')
|
|
2574
|
+
.option(
|
|
2575
|
+
'--to <version>',
|
|
2576
|
+
'Version to update to (default: latest)',
|
|
2577
|
+
'latest',
|
|
2578
|
+
)
|
|
2579
|
+
.option('--registry <url>', 'Registry URL to use for the update')
|
|
2580
|
+
.option('--log-file <path>', 'Log file path')
|
|
2581
|
+
.allowUnknownOption() // 允许透传参数给 pnpm
|
|
2582
|
+
.action((packageName, options, command) => {
|
|
2583
|
+
// 收集所有未知选项作为额外参数
|
|
2584
|
+
const extraArgs = command.args.slice(1);
|
|
2585
|
+
|
|
2586
|
+
executeUpdate(packageName, {
|
|
2587
|
+
...options,
|
|
2588
|
+
version: options.to, // 将 --to 映射到 version
|
|
2589
|
+
extraArgs,
|
|
2590
|
+
});
|
|
2591
|
+
});
|
|
2592
|
+
};
|
|
2593
|
+
|
|
2594
|
+
var version = "0.0.1-alpha.bd55ba";
|
|
2305
2595
|
var packageJson = {
|
|
2306
2596
|
version: version};
|
|
2307
2597
|
|
|
2308
2598
|
const commands = [
|
|
2309
|
-
registerCommand,
|
|
2310
2599
|
registerCommand$1,
|
|
2311
|
-
registerCommand$3,
|
|
2312
2600
|
registerCommand$2,
|
|
2601
|
+
registerCommand$4,
|
|
2602
|
+
registerCommand$3,
|
|
2603
|
+
registerCommand,
|
|
2313
2604
|
];
|
|
2314
2605
|
|
|
2315
2606
|
const main = () => {
|
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.bd55ba",
|
|
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,28 +0,0 @@
|
|
|
1
|
-
diff --git a/src/async-require/hmr.ts b/src/async-require/hmr.ts
|
|
2
|
-
index 33ce50ee2950c40d2b0553b148710f1e24e44f3d..ed853b38809866ea8d1b78e5a71342f02dd735ef 100644
|
|
3
|
-
--- a/src/async-require/hmr.ts
|
|
4
|
-
+++ b/src/async-require/hmr.ts
|
|
5
|
-
@@ -216,6 +216,23 @@ const HMRClient: HMRClientNativeInterface = {
|
|
6
|
-
|
|
7
|
-
client.on('update-done', () => {
|
|
8
|
-
hideLoading();
|
|
9
|
-
+
|
|
10
|
-
+ if (process.env.EXPO_PUBLIC_COZE_PROJECT_ID && typeof window !== 'undefined' && window.location) {
|
|
11
|
-
+ if((window as any).__updateTimeoutId) {
|
|
12
|
-
+ clearTimeout((window as any).__updateTimeoutId);
|
|
13
|
-
+ }
|
|
14
|
-
+
|
|
15
|
-
+ const updateDoneTime = Date.now();
|
|
16
|
-
+ (window as any).__updateDoneTime = updateDoneTime;
|
|
17
|
-
+
|
|
18
|
-
+ (window as any).__updateTimeoutId = setTimeout(() => {
|
|
19
|
-
+ const lastUpdateTime = (window as any).__updateDoneTime;
|
|
20
|
-
+ if (lastUpdateTime === updateDoneTime) {
|
|
21
|
-
+ console.warn('[HMR] Update timeout, force reload');
|
|
22
|
-
+ window.location.reload();
|
|
23
|
-
+ }
|
|
24
|
-
+ }, 35_000);
|
|
25
|
-
+ }
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
client.on('error', (data: { type: string; message: string }) => {
|