@coze-arch/cli 0.0.1-alpha.bcc7d9 → 0.0.1-alpha.bd5b49
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 +14 -17
- package/lib/__templates__/expo/client/app/+not-found.tsx +4 -19
- package/lib/__templates__/expo/client/app/_layout.tsx +16 -17
- package/lib/__templates__/expo/client/eslint.config.mjs +17 -1
- package/lib/__templates__/expo/client/global.css +78 -0
- package/lib/__templates__/expo/client/metro.config.js +8 -1
- package/lib/__templates__/expo/client/package.json +37 -34
- package/lib/__templates__/expo/client/screens/demo/index.tsx +6 -12
- package/lib/__templates__/expo/client/styles.css +263 -0
- package/lib/__templates__/expo/client/uniwind-types.d.ts +10 -0
- 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__/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 +80 -0
- package/lib/__templates__/taro/.cozeproj/scripts/init_env.sh +5 -0
- package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +1 -0
- package/lib/__templates__/taro/README.md +747 -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 +173 -0
- package/lib/__templates__/taro/config/prod.ts +35 -0
- package/lib/__templates__/taro/eslint.config.mjs +57 -0
- package/lib/__templates__/taro/key/private.appid.key +0 -0
- package/lib/__templates__/taro/package.json +97 -0
- package/lib/__templates__/taro/pnpm-lock.yaml +22708 -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 +41 -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.ts +14 -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/utils/h5-styles.ts +33 -0
- package/lib/__templates__/taro/src/utils/wx-debug.ts +23 -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 +32 -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/cli.js +353 -76
- package/package.json +1 -1
- package/lib/__templates__/expo/client/constants/theme.ts +0 -177
- package/lib/__templates__/expo/client/hooks/useColorScheme.tsx +0 -48
- package/lib/__templates__/expo/client/hooks/useTheme.ts +0 -33
- package/lib/__templates__/expo/client/screens/demo/styles.ts +0 -28
- package/lib/__templates__/expo/patches/expo@54.0.32.patch +0 -28
package/lib/cli.js
CHANGED
|
@@ -585,7 +585,7 @@ const executeWarmup = async (
|
|
|
585
585
|
/**
|
|
586
586
|
* 注册 warmup 命令到 program
|
|
587
587
|
*/
|
|
588
|
-
const registerCommand$
|
|
588
|
+
const registerCommand$4 = program => {
|
|
589
589
|
program
|
|
590
590
|
.command('warmup')
|
|
591
591
|
.description('Pre-install dependencies for templates to speed up init')
|
|
@@ -1033,7 +1033,7 @@ const executeFix = async (options = {}) => {
|
|
|
1033
1033
|
/**
|
|
1034
1034
|
* 注册 fix 命令到 program
|
|
1035
1035
|
*/
|
|
1036
|
-
const registerCommand$
|
|
1036
|
+
const registerCommand$3 = program => {
|
|
1037
1037
|
program
|
|
1038
1038
|
.command('fix')
|
|
1039
1039
|
.description(
|
|
@@ -1052,13 +1052,13 @@ function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else
|
|
|
1052
1052
|
/**
|
|
1053
1053
|
* 日志文件名常量
|
|
1054
1054
|
*/
|
|
1055
|
-
const LOG_FILE_NAME = 'dev.log';
|
|
1055
|
+
const LOG_FILE_NAME$1 = 'dev.log';
|
|
1056
1056
|
|
|
1057
1057
|
/**
|
|
1058
1058
|
* 获取日志目录
|
|
1059
1059
|
* 优先使用环境变量 COZE_LOG_DIR,否则使用 ~/.coze-logs
|
|
1060
1060
|
*/
|
|
1061
|
-
const getLogDir = () =>
|
|
1061
|
+
const getLogDir$1 = () =>
|
|
1062
1062
|
process.env.COZE_LOG_DIR || path.join(os.homedir(), '.coze-logs');
|
|
1063
1063
|
|
|
1064
1064
|
/**
|
|
@@ -1067,22 +1067,22 @@ const getLogDir = () =>
|
|
|
1067
1067
|
* - 如果是相对路径,基于 getLogDir() + 相对路径
|
|
1068
1068
|
* - 如果为空,使用 getLogDir() + LOG_FILE_NAME
|
|
1069
1069
|
*/
|
|
1070
|
-
const resolveLogFilePath = (logFile) => {
|
|
1070
|
+
const resolveLogFilePath$1 = (logFile) => {
|
|
1071
1071
|
if (!logFile) {
|
|
1072
|
-
return path.join(getLogDir(), LOG_FILE_NAME);
|
|
1072
|
+
return path.join(getLogDir$1(), LOG_FILE_NAME$1);
|
|
1073
1073
|
}
|
|
1074
1074
|
|
|
1075
1075
|
if (path.isAbsolute(logFile)) {
|
|
1076
1076
|
return logFile;
|
|
1077
1077
|
}
|
|
1078
1078
|
|
|
1079
|
-
return path.join(getLogDir(), logFile);
|
|
1079
|
+
return path.join(getLogDir$1(), logFile);
|
|
1080
1080
|
};
|
|
1081
1081
|
|
|
1082
1082
|
/**
|
|
1083
1083
|
* 创建日志写入流
|
|
1084
1084
|
*/
|
|
1085
|
-
const createLogStream = (logFilePath) => {
|
|
1085
|
+
const createLogStream$1 = (logFilePath) => {
|
|
1086
1086
|
const logDir = path.dirname(logFilePath);
|
|
1087
1087
|
|
|
1088
1088
|
// 确保日志目录存在
|
|
@@ -1121,8 +1121,8 @@ const executeRun = async (
|
|
|
1121
1121
|
const commandArgs = getCommandConfig(config, commandName);
|
|
1122
1122
|
|
|
1123
1123
|
// 3. 准备日志
|
|
1124
|
-
const logFilePath = resolveLogFilePath(options.logFile);
|
|
1125
|
-
const logStream = createLogStream(logFilePath);
|
|
1124
|
+
const logFilePath = resolveLogFilePath$1(options.logFile);
|
|
1125
|
+
const logStream = createLogStream$1(logFilePath);
|
|
1126
1126
|
|
|
1127
1127
|
// 4. 执行命令
|
|
1128
1128
|
const commandString = commandArgs.join(' ');
|
|
@@ -1185,7 +1185,7 @@ const executeRun = async (
|
|
|
1185
1185
|
/**
|
|
1186
1186
|
* 注册 dev/build/start 命令到 program
|
|
1187
1187
|
*/
|
|
1188
|
-
const registerCommand$
|
|
1188
|
+
const registerCommand$2 = program => {
|
|
1189
1189
|
// dev 命令
|
|
1190
1190
|
program
|
|
1191
1191
|
.command('dev')
|
|
@@ -1511,46 +1511,6 @@ const convertDotfileName = (filePath) => {
|
|
|
1511
1511
|
|
|
1512
1512
|
return filePath;
|
|
1513
1513
|
};
|
|
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
1514
|
// end_aigc
|
|
1555
1515
|
|
|
1556
1516
|
// ABOUTME: File rendering utilities for template processing
|
|
@@ -1925,11 +1885,7 @@ const processTemplateFiles = async (options
|
|
|
1925
1885
|
|
|
1926
1886
|
logger.verbose('✓ All files processed successfully');
|
|
1927
1887
|
|
|
1928
|
-
//
|
|
1929
|
-
const sourceNodeModules = path.join(templatePath, 'node_modules');
|
|
1930
|
-
const targetNodeModules = path.join(outputPath, 'node_modules');
|
|
1931
|
-
|
|
1932
|
-
copyNodeModules(sourceNodeModules, targetNodeModules);
|
|
1888
|
+
// node_modules 将由 pnpm install 处理(利用缓存和硬链接机制)
|
|
1933
1889
|
};
|
|
1934
1890
|
// end_aigc
|
|
1935
1891
|
|
|
@@ -2011,6 +1967,19 @@ const executeAfterRenderHook = async (
|
|
|
2011
1967
|
}
|
|
2012
1968
|
};
|
|
2013
1969
|
|
|
1970
|
+
/**
|
|
1971
|
+
* 执行完成钩子
|
|
1972
|
+
*/
|
|
1973
|
+
const executeCompleteHook = async (
|
|
1974
|
+
templateConfig,
|
|
1975
|
+
context,
|
|
1976
|
+
outputPath,
|
|
1977
|
+
) => {
|
|
1978
|
+
if (templateConfig.onComplete) {
|
|
1979
|
+
await templateConfig.onComplete(context, outputPath);
|
|
1980
|
+
}
|
|
1981
|
+
};
|
|
1982
|
+
|
|
2014
1983
|
/**
|
|
2015
1984
|
* 准备输出目录
|
|
2016
1985
|
*/
|
|
@@ -2020,6 +1989,18 @@ const prepareOutputDirectory = (outputPath) => {
|
|
|
2020
1989
|
return absolutePath;
|
|
2021
1990
|
};
|
|
2022
1991
|
|
|
1992
|
+
/**
|
|
1993
|
+
* 模板引擎执行结果
|
|
1994
|
+
*/
|
|
1995
|
+
|
|
1996
|
+
|
|
1997
|
+
|
|
1998
|
+
|
|
1999
|
+
|
|
2000
|
+
|
|
2001
|
+
|
|
2002
|
+
|
|
2003
|
+
|
|
2023
2004
|
/**
|
|
2024
2005
|
* 执行完整的模板渲染流程
|
|
2025
2006
|
*/
|
|
@@ -2056,7 +2037,11 @@ const execute = async (
|
|
|
2056
2037
|
// 7. 执行 onAfterRender 钩子
|
|
2057
2038
|
await executeAfterRenderHook(templateConfig, context, absoluteOutputPath);
|
|
2058
2039
|
|
|
2059
|
-
return
|
|
2040
|
+
return {
|
|
2041
|
+
outputPath: absoluteOutputPath,
|
|
2042
|
+
templateConfig,
|
|
2043
|
+
context,
|
|
2044
|
+
};
|
|
2060
2045
|
};
|
|
2061
2046
|
|
|
2062
2047
|
function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
@@ -2219,32 +2204,27 @@ const executeInit = async (
|
|
|
2219
2204
|
logger.info(`Initializing project with template: ${templateName}`);
|
|
2220
2205
|
timer.logPhase('Initialization');
|
|
2221
2206
|
|
|
2222
|
-
//
|
|
2223
|
-
const
|
|
2207
|
+
// 执行模板引擎,返回结果对象
|
|
2208
|
+
const result = await execute({
|
|
2224
2209
|
templateName,
|
|
2225
2210
|
outputPath,
|
|
2226
2211
|
command,
|
|
2227
2212
|
});
|
|
2213
|
+
const { outputPath: absoluteOutputPath, templateConfig, context } = result;
|
|
2228
2214
|
|
|
2229
2215
|
timer.logPhase('Template engine execution');
|
|
2230
2216
|
logger.success('Project created successfully!');
|
|
2231
2217
|
|
|
2232
|
-
//
|
|
2218
|
+
// 安装依赖(始终使用 pnpm install,利用缓存机制)
|
|
2233
2219
|
if (!skipInstall) {
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
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 {
|
|
2243
|
-
runPnpmInstall(absoluteOutputPath);
|
|
2244
|
-
timer.logPhase('Dependencies installation');
|
|
2245
|
-
}
|
|
2220
|
+
runPnpmInstall(absoluteOutputPath);
|
|
2221
|
+
timer.logPhase('Dependencies installation');
|
|
2246
2222
|
}
|
|
2247
2223
|
|
|
2224
|
+
// 执行 onComplete 钩子(在 pnpm install 之后)
|
|
2225
|
+
await executeCompleteHook(templateConfig, context, absoluteOutputPath);
|
|
2226
|
+
timer.logPhase('Complete hook execution');
|
|
2227
|
+
|
|
2248
2228
|
// 如果没有跳过 git,则初始化 git 仓库
|
|
2249
2229
|
if (!skipGit) {
|
|
2250
2230
|
runGitInit(absoluteOutputPath);
|
|
@@ -2283,7 +2263,7 @@ const executeInit = async (
|
|
|
2283
2263
|
/**
|
|
2284
2264
|
* 注册 init 命令到 program
|
|
2285
2265
|
*/
|
|
2286
|
-
const registerCommand = program => {
|
|
2266
|
+
const registerCommand$1 = program => {
|
|
2287
2267
|
program
|
|
2288
2268
|
.command('init')
|
|
2289
2269
|
.description('Initialize a new project from a template')
|
|
@@ -2301,15 +2281,312 @@ const registerCommand = program => {
|
|
|
2301
2281
|
});
|
|
2302
2282
|
};
|
|
2303
2283
|
|
|
2304
|
-
|
|
2284
|
+
// ABOUTME: This file implements the update command for coze CLI
|
|
2285
|
+
// ABOUTME: It wraps pnpm update/install to update package dependencies with logging support
|
|
2286
|
+
|
|
2287
|
+
|
|
2288
|
+
|
|
2289
|
+
|
|
2290
|
+
/**
|
|
2291
|
+
* 日志文件名常量
|
|
2292
|
+
*/
|
|
2293
|
+
const LOG_FILE_NAME = 'update.log';
|
|
2294
|
+
|
|
2295
|
+
/**
|
|
2296
|
+
* 获取日志目录
|
|
2297
|
+
* 优先使用环境变量 COZE_LOG_DIR,否则使用 ~/.coze-logs
|
|
2298
|
+
*/
|
|
2299
|
+
const getLogDir = () =>
|
|
2300
|
+
process.env.COZE_LOG_DIR || path.join(os.homedir(), '.coze-logs');
|
|
2301
|
+
|
|
2302
|
+
/**
|
|
2303
|
+
* 解析日志文件路径
|
|
2304
|
+
* - 如果是绝对路径,直接使用
|
|
2305
|
+
* - 如果是相对路径,基于 getLogDir() + 相对路径
|
|
2306
|
+
* - 如果为空,使用 getLogDir() + LOG_FILE_NAME
|
|
2307
|
+
*/
|
|
2308
|
+
const resolveLogFilePath = (logFile) => {
|
|
2309
|
+
if (!logFile) {
|
|
2310
|
+
return path.join(getLogDir(), LOG_FILE_NAME);
|
|
2311
|
+
}
|
|
2312
|
+
|
|
2313
|
+
if (path.isAbsolute(logFile)) {
|
|
2314
|
+
return logFile;
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2317
|
+
return path.join(getLogDir(), logFile);
|
|
2318
|
+
};
|
|
2319
|
+
|
|
2320
|
+
/**
|
|
2321
|
+
* 创建日志写入流
|
|
2322
|
+
*/
|
|
2323
|
+
const createLogStream = (logFilePath) => {
|
|
2324
|
+
const logDir = path.dirname(logFilePath);
|
|
2325
|
+
|
|
2326
|
+
// 确保日志目录存在
|
|
2327
|
+
if (!fs.existsSync(logDir)) {
|
|
2328
|
+
fs.mkdirSync(logDir, { recursive: true });
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
// 使用 'w' 标志覆盖之前的日志
|
|
2332
|
+
return fs.createWriteStream(logFilePath, { flags: 'w' });
|
|
2333
|
+
};
|
|
2334
|
+
|
|
2335
|
+
/**
|
|
2336
|
+
* 格式化时间戳
|
|
2337
|
+
*/
|
|
2338
|
+
const formatTimestamp = () => {
|
|
2339
|
+
const now = new Date();
|
|
2340
|
+
return now.toISOString();
|
|
2341
|
+
};
|
|
2342
|
+
|
|
2343
|
+
/**
|
|
2344
|
+
* 写入带时间戳的日志
|
|
2345
|
+
*/
|
|
2346
|
+
const writeLogWithTimestamp = (stream, message) => {
|
|
2347
|
+
const timestamp = formatTimestamp();
|
|
2348
|
+
const lines = message.split('\n');
|
|
2349
|
+
lines.forEach(line => {
|
|
2350
|
+
if (line) {
|
|
2351
|
+
stream.write(`[${timestamp}] ${line}\n`);
|
|
2352
|
+
} else {
|
|
2353
|
+
stream.write('\n');
|
|
2354
|
+
}
|
|
2355
|
+
});
|
|
2356
|
+
// 确保数据写入磁盘
|
|
2357
|
+
stream.uncork();
|
|
2358
|
+
};
|
|
2359
|
+
|
|
2360
|
+
/**
|
|
2361
|
+
* 同时输出到控制台和日志文件
|
|
2362
|
+
*/
|
|
2363
|
+
const logWithFile = (
|
|
2364
|
+
stream,
|
|
2365
|
+
level,
|
|
2366
|
+
message,
|
|
2367
|
+
) => {
|
|
2368
|
+
// 输出到控制台
|
|
2369
|
+
switch (level) {
|
|
2370
|
+
case 'info':
|
|
2371
|
+
logger.info(message);
|
|
2372
|
+
break;
|
|
2373
|
+
case 'success':
|
|
2374
|
+
logger.success(message);
|
|
2375
|
+
break;
|
|
2376
|
+
case 'error':
|
|
2377
|
+
logger.error(message);
|
|
2378
|
+
break;
|
|
2379
|
+
default:
|
|
2380
|
+
logger.info(message);
|
|
2381
|
+
break;
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
// 写入日志文件(带时间戳)
|
|
2385
|
+
writeLogWithTimestamp(stream, `[${level.toUpperCase()}] ${message}`);
|
|
2386
|
+
};
|
|
2387
|
+
|
|
2388
|
+
// start_aigc
|
|
2389
|
+
/**
|
|
2390
|
+
* 构建 pnpm add 命令
|
|
2391
|
+
*/
|
|
2392
|
+
const buildPnpmCommand = (
|
|
2393
|
+
packageName,
|
|
2394
|
+
options
|
|
2395
|
+
|
|
2396
|
+
|
|
2397
|
+
|
|
2398
|
+
|
|
2399
|
+
,
|
|
2400
|
+
) => {
|
|
2401
|
+
const { global, version, registry, extraArgs } = options;
|
|
2402
|
+
|
|
2403
|
+
const parts = ['pnpm', 'add'];
|
|
2404
|
+
|
|
2405
|
+
// 添加全局标记
|
|
2406
|
+
if (global) {
|
|
2407
|
+
parts.push('-g');
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
// 添加包名和版本
|
|
2411
|
+
if (version && version !== 'latest') {
|
|
2412
|
+
parts.push(`${packageName}@${version}`);
|
|
2413
|
+
} else {
|
|
2414
|
+
parts.push(`${packageName}@latest`);
|
|
2415
|
+
}
|
|
2416
|
+
|
|
2417
|
+
// 添加 registry
|
|
2418
|
+
if (registry) {
|
|
2419
|
+
parts.push(`--registry=${registry}`);
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
// 添加额外参数
|
|
2423
|
+
if (extraArgs.length > 0) {
|
|
2424
|
+
parts.push(...extraArgs);
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2427
|
+
return parts.join(' ');
|
|
2428
|
+
};
|
|
2429
|
+
// end_aigc
|
|
2430
|
+
|
|
2431
|
+
// start_aigc
|
|
2432
|
+
/**
|
|
2433
|
+
* 执行 update 命令的内部实现
|
|
2434
|
+
*/
|
|
2435
|
+
const executeUpdate = (
|
|
2436
|
+
packageName,
|
|
2437
|
+
options
|
|
2438
|
+
|
|
2439
|
+
|
|
2440
|
+
|
|
2441
|
+
|
|
2442
|
+
|
|
2443
|
+
|
|
2444
|
+
,
|
|
2445
|
+
) => {
|
|
2446
|
+
let logStream = null;
|
|
2447
|
+
|
|
2448
|
+
try {
|
|
2449
|
+
const { global, cwd, version, registry, logFile, extraArgs } = options;
|
|
2450
|
+
|
|
2451
|
+
// 准备日志
|
|
2452
|
+
const logFilePath = resolveLogFilePath(logFile);
|
|
2453
|
+
|
|
2454
|
+
// 调试:确认日志路径
|
|
2455
|
+
logger.info(`Log file path resolved to: ${logFilePath}`);
|
|
2456
|
+
|
|
2457
|
+
logStream = createLogStream(logFilePath);
|
|
2458
|
+
|
|
2459
|
+
// 调试:确认流已创建
|
|
2460
|
+
logger.info('Log stream created successfully');
|
|
2461
|
+
|
|
2462
|
+
logWithFile(logStream, 'info', `Updating package: ${packageName}`);
|
|
2463
|
+
|
|
2464
|
+
// 构建命令
|
|
2465
|
+
const command = buildPnpmCommand(packageName, {
|
|
2466
|
+
global,
|
|
2467
|
+
version,
|
|
2468
|
+
registry,
|
|
2469
|
+
extraArgs,
|
|
2470
|
+
});
|
|
2471
|
+
|
|
2472
|
+
// 确定工作目录
|
|
2473
|
+
const workingDir = cwd
|
|
2474
|
+
? path.isAbsolute(cwd)
|
|
2475
|
+
? cwd
|
|
2476
|
+
: path.join(process.cwd(), cwd)
|
|
2477
|
+
: process.cwd();
|
|
2478
|
+
|
|
2479
|
+
logWithFile(logStream, 'info', `Executing: ${command}`);
|
|
2480
|
+
logWithFile(logStream, 'info', `Working directory: ${workingDir}`);
|
|
2481
|
+
logWithFile(logStream, 'info', `Log file: ${logFilePath}`);
|
|
2482
|
+
|
|
2483
|
+
// 记录命令开始时间
|
|
2484
|
+
writeLogWithTimestamp(logStream, '--- Command execution started ---');
|
|
2485
|
+
|
|
2486
|
+
// 同步执行命令
|
|
2487
|
+
const result = shelljs.exec(command, {
|
|
2488
|
+
cwd: workingDir,
|
|
2489
|
+
silent: true, // 使用 silent 来捕获输出
|
|
2490
|
+
});
|
|
2491
|
+
|
|
2492
|
+
// 将输出写入控制台和日志文件(带时间戳)
|
|
2493
|
+
if (result.stdout) {
|
|
2494
|
+
process.stdout.write(result.stdout);
|
|
2495
|
+
writeLogWithTimestamp(logStream, result.stdout.trim());
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
if (result.stderr) {
|
|
2499
|
+
process.stderr.write(result.stderr);
|
|
2500
|
+
writeLogWithTimestamp(logStream, result.stderr.trim());
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2503
|
+
// 记录命令结束时间
|
|
2504
|
+
writeLogWithTimestamp(logStream, '--- Command execution ended ---');
|
|
2505
|
+
|
|
2506
|
+
// 检查执行结果并记录到日志
|
|
2507
|
+
if (result.code === 0) {
|
|
2508
|
+
logWithFile(logStream, 'success', 'Package updated successfully');
|
|
2509
|
+
logWithFile(logStream, 'info', `Log file: ${logFilePath}`);
|
|
2510
|
+
} else {
|
|
2511
|
+
logWithFile(
|
|
2512
|
+
logStream,
|
|
2513
|
+
'error',
|
|
2514
|
+
`Command exited with code ${result.code}`,
|
|
2515
|
+
);
|
|
2516
|
+
logWithFile(
|
|
2517
|
+
logStream,
|
|
2518
|
+
'error',
|
|
2519
|
+
`Check log file for details: ${logFilePath}`,
|
|
2520
|
+
);
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
// 关闭日志流并等待写入完成
|
|
2524
|
+
logStream.end(() => {
|
|
2525
|
+
// 流关闭后再退出进程
|
|
2526
|
+
if (result.code !== 0) {
|
|
2527
|
+
process.exit(result.code || 1);
|
|
2528
|
+
}
|
|
2529
|
+
});
|
|
2530
|
+
} catch (error) {
|
|
2531
|
+
logger.error('Failed to update package:');
|
|
2532
|
+
logger.error(error instanceof Error ? error.message : String(error));
|
|
2533
|
+
|
|
2534
|
+
// 写入错误到日志文件
|
|
2535
|
+
if (logStream) {
|
|
2536
|
+
writeLogWithTimestamp(
|
|
2537
|
+
logStream,
|
|
2538
|
+
`[ERROR] ${error instanceof Error ? error.message : String(error)}`,
|
|
2539
|
+
);
|
|
2540
|
+
// 等待流关闭后再退出
|
|
2541
|
+
logStream.end(() => {
|
|
2542
|
+
process.exit(1);
|
|
2543
|
+
});
|
|
2544
|
+
} else {
|
|
2545
|
+
process.exit(1);
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
};
|
|
2549
|
+
// end_aigc
|
|
2550
|
+
|
|
2551
|
+
/**
|
|
2552
|
+
* 注册 update 命令到 program
|
|
2553
|
+
*/
|
|
2554
|
+
const registerCommand = program => {
|
|
2555
|
+
program
|
|
2556
|
+
.command('update <package>')
|
|
2557
|
+
.description('Update a package dependency')
|
|
2558
|
+
.option('-g, --global', 'Update package globally', false)
|
|
2559
|
+
.option('-c, --cwd <path>', 'Working directory for the update')
|
|
2560
|
+
.option(
|
|
2561
|
+
'--to <version>',
|
|
2562
|
+
'Version to update to (default: latest)',
|
|
2563
|
+
'latest',
|
|
2564
|
+
)
|
|
2565
|
+
.option('--registry <url>', 'Registry URL to use for the update')
|
|
2566
|
+
.option('--log-file <path>', 'Log file path')
|
|
2567
|
+
.allowUnknownOption() // 允许透传参数给 pnpm
|
|
2568
|
+
.action((packageName, options, command) => {
|
|
2569
|
+
// 收集所有未知选项作为额外参数
|
|
2570
|
+
const extraArgs = command.args.slice(1);
|
|
2571
|
+
|
|
2572
|
+
executeUpdate(packageName, {
|
|
2573
|
+
...options,
|
|
2574
|
+
version: options.to, // 将 --to 映射到 version
|
|
2575
|
+
extraArgs,
|
|
2576
|
+
});
|
|
2577
|
+
});
|
|
2578
|
+
};
|
|
2579
|
+
|
|
2580
|
+
var version = "0.0.1-alpha.bd5b49";
|
|
2305
2581
|
var packageJson = {
|
|
2306
2582
|
version: version};
|
|
2307
2583
|
|
|
2308
2584
|
const commands = [
|
|
2309
|
-
registerCommand,
|
|
2310
2585
|
registerCommand$1,
|
|
2311
|
-
registerCommand$3,
|
|
2312
2586
|
registerCommand$2,
|
|
2587
|
+
registerCommand$4,
|
|
2588
|
+
registerCommand$3,
|
|
2589
|
+
registerCommand,
|
|
2313
2590
|
];
|
|
2314
2591
|
|
|
2315
2592
|
const main = () => {
|