@coze-arch/cli 0.0.1-alpha.dffbaa → 0.0.1-alpha.e02657
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/.coze +7 -2
- package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +46 -0
- package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +229 -0
- package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +47 -0
- package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +34 -0
- package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +46 -0
- package/lib/__templates__/expo/README.md +68 -7
- package/lib/__templates__/expo/_gitignore +1 -1
- package/lib/__templates__/expo/_npmrc +2 -4
- package/lib/__templates__/expo/client/app/+not-found.tsx +15 -64
- package/lib/__templates__/expo/client/app/_layout.tsx +15 -12
- package/lib/__templates__/expo/client/app/index.tsx +1 -0
- package/lib/__templates__/expo/client/app.config.ts +76 -0
- package/lib/__templates__/expo/client/components/Screen.tsx +1 -17
- package/lib/__templates__/expo/client/components/ThemedText.tsx +33 -0
- package/lib/__templates__/expo/client/components/ThemedView.tsx +37 -0
- package/lib/__templates__/expo/client/constants/theme.ts +117 -58
- package/lib/__templates__/expo/client/declarations.d.ts +5 -0
- package/lib/__templates__/expo/{eslint.config.mjs → client/eslint.config.mjs} +33 -10
- package/lib/__templates__/expo/client/hooks/useColorScheme.tsx +48 -0
- package/lib/__templates__/expo/client/hooks/useSafeRouter.ts +152 -0
- package/lib/__templates__/expo/client/hooks/useTheme.ts +26 -6
- package/lib/__templates__/expo/client/metro.config.js +121 -0
- package/lib/__templates__/expo/client/package.json +95 -0
- package/lib/__templates__/expo/client/screens/demo/index.tsx +25 -0
- package/lib/__templates__/expo/client/screens/demo/styles.ts +28 -0
- package/lib/__templates__/expo/client/scripts/install-missing-deps.js +1 -0
- package/lib/__templates__/expo/client/tsconfig.json +24 -0
- package/lib/__templates__/expo/client/utils/index.ts +22 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/names.js +1889 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/rule.js +174 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/v5-only-names.js +388 -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/eslint-plugins/reanimated/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/reanimated/rule.js +88 -0
- package/lib/__templates__/expo/package.json +16 -103
- package/lib/__templates__/expo/patches/expo@54.0.33.patch +45 -0
- package/lib/__templates__/expo/pnpm-lock.yaml +1375 -3165
- package/lib/__templates__/expo/pnpm-workspace.yaml +3 -0
- package/lib/__templates__/expo/server/build.js +21 -0
- package/lib/__templates__/expo/server/package.json +32 -0
- package/lib/__templates__/expo/server/src/index.ts +20 -0
- package/lib/__templates__/expo/server/tsconfig.json +24 -0
- package/lib/__templates__/expo/template.config.js +57 -0
- package/lib/__templates__/expo/tsconfig.json +1 -24
- package/lib/__templates__/nextjs/.babelrc +15 -0
- package/lib/__templates__/nextjs/.coze +1 -0
- package/lib/__templates__/nextjs/_npmrc +1 -0
- package/lib/__templates__/nextjs/next.config.ts +12 -0
- package/lib/__templates__/nextjs/package.json +11 -2
- package/lib/__templates__/nextjs/pnpm-lock.yaml +2606 -1723
- package/lib/__templates__/nextjs/scripts/prepare.sh +9 -0
- package/lib/__templates__/nextjs/src/app/globals.css +109 -89
- package/lib/__templates__/nextjs/src/app/layout.tsx +5 -14
- package/lib/__templates__/nextjs/src/app/page.tsx +18 -48
- package/lib/__templates__/nextjs/src/components/ui/resizable.tsx +29 -22
- package/lib/__templates__/nextjs/src/components/ui/sidebar.tsx +228 -230
- package/lib/__templates__/nextjs/template.config.js +67 -2
- 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 +13 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +17 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +58 -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 +687 -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 +95 -0
- package/lib/__templates__/taro/pnpm-lock.yaml +22430 -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 +38 -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 +37 -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 +20 -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 +22 -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 +93 -43
- package/lib/__templates__/vite/.coze +1 -0
- package/lib/__templates__/vite/_npmrc +1 -0
- package/lib/__templates__/vite/eslint.config.mjs +9 -0
- package/lib/__templates__/vite/package.json +11 -2
- package/lib/__templates__/vite/pnpm-lock.yaml +3232 -243
- package/lib/__templates__/vite/scripts/prepare.sh +9 -0
- package/lib/__templates__/vite/src/main.ts +17 -48
- package/lib/__templates__/vite/template.config.js +67 -6
- package/lib/cli.js +1026 -134
- package/package.json +8 -3
- package/lib/__templates__/expo/.cozeproj/scripts/deploy_build.sh +0 -116
- package/lib/__templates__/expo/.cozeproj/scripts/deploy_run.sh +0 -239
- package/lib/__templates__/expo/app.json +0 -63
- package/lib/__templates__/expo/babel.config.js +0 -9
- package/lib/__templates__/expo/client/app/(tabs)/_layout.tsx +0 -43
- package/lib/__templates__/expo/client/app/(tabs)/home.tsx +0 -1
- package/lib/__templates__/expo/client/app/(tabs)/index.tsx +0 -7
- package/lib/__templates__/expo/client/hooks/useColorScheme.ts +0 -1
- package/lib/__templates__/expo/client/index.js +0 -12
- package/lib/__templates__/expo/client/screens/home/index.tsx +0 -51
- package/lib/__templates__/expo/client/screens/home/styles.ts +0 -60
- package/lib/__templates__/expo/metro.config.js +0 -53
- package/lib/__templates__/expo/src/index.ts +0 -12
- package/lib/__templates__/nextjs/.vscode/settings.json +0 -121
- package/lib/__templates__/vite/.vscode/settings.json +0 -7
- /package/lib/__templates__/expo/{eslint-formatter-simple.mjs → client/eslint-formatter-simple.mjs} +0 -0
package/lib/cli.js
CHANGED
|
@@ -7,10 +7,10 @@ var fs = require('fs');
|
|
|
7
7
|
var shelljs = require('shelljs');
|
|
8
8
|
var perf_hooks = require('perf_hooks');
|
|
9
9
|
var fs$1 = require('fs/promises');
|
|
10
|
-
var
|
|
10
|
+
var os = require('os');
|
|
11
11
|
var jsYaml = require('js-yaml');
|
|
12
|
+
var toml = require('@iarna/toml');
|
|
12
13
|
var child_process = require('child_process');
|
|
13
|
-
var os = require('os');
|
|
14
14
|
var addFormats = require('ajv-formats');
|
|
15
15
|
var Ajv = require('ajv');
|
|
16
16
|
var minimist = require('minimist');
|
|
@@ -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')
|
|
@@ -727,7 +727,7 @@ const parseConfigContent = (content) => {
|
|
|
727
727
|
return config ;
|
|
728
728
|
} catch (error) {
|
|
729
729
|
// TOML 解析失败,继续尝试其他格式
|
|
730
|
-
|
|
730
|
+
|
|
731
731
|
console.debug('TOML parse failed:', error);
|
|
732
732
|
}
|
|
733
733
|
|
|
@@ -739,7 +739,7 @@ const parseConfigContent = (content) => {
|
|
|
739
739
|
}
|
|
740
740
|
} catch (error) {
|
|
741
741
|
// YAML 解析失败,继续尝试其他格式
|
|
742
|
-
|
|
742
|
+
|
|
743
743
|
console.debug('YAML parse failed:', error);
|
|
744
744
|
}
|
|
745
745
|
|
|
@@ -823,27 +823,276 @@ const getCommandConfig = (
|
|
|
823
823
|
return commandConfig;
|
|
824
824
|
};
|
|
825
825
|
|
|
826
|
-
|
|
826
|
+
// ABOUTME: Fix rule to comment out problematic outputFileTracingRoot config in Next.js projects
|
|
827
|
+
// ABOUTME: This config can cause issues in monorepo environments and should be removed
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* 检查是否为 Next.js 项目
|
|
834
|
+
*/
|
|
835
|
+
const isNextProject = (projectFolder) => {
|
|
836
|
+
const packageJsonPath = path.join(projectFolder, 'package.json');
|
|
837
|
+
|
|
838
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
839
|
+
return false;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
try {
|
|
843
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
844
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
845
|
+
const deps = {
|
|
846
|
+
...packageJson.dependencies,
|
|
847
|
+
...packageJson.devDependencies,
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
return 'next' in deps;
|
|
851
|
+
} catch (e) {
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
};
|
|
827
855
|
|
|
828
856
|
/**
|
|
829
|
-
*
|
|
857
|
+
* 查找 Next.js 配置文件
|
|
830
858
|
*/
|
|
831
|
-
const
|
|
832
|
-
const
|
|
833
|
-
|
|
834
|
-
|
|
859
|
+
const findNextConfigFile = (projectFolder) => {
|
|
860
|
+
const possibleConfigs = [
|
|
861
|
+
'next.config.ts',
|
|
862
|
+
'next.config.js',
|
|
863
|
+
'next.config.mjs',
|
|
864
|
+
];
|
|
865
|
+
|
|
866
|
+
for (const configFile of possibleConfigs) {
|
|
867
|
+
const configPath = path.join(projectFolder, configFile);
|
|
868
|
+
if (fs.existsSync(configPath)) {
|
|
869
|
+
return configPath;
|
|
835
870
|
}
|
|
836
|
-
}
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
return null;
|
|
874
|
+
};
|
|
837
875
|
|
|
838
|
-
|
|
876
|
+
/**
|
|
877
|
+
* 注释掉 outputFileTracingRoot 配置
|
|
878
|
+
*/
|
|
879
|
+
const commentOutOutputTracingRoot = (
|
|
880
|
+
configPath,
|
|
881
|
+
) => {
|
|
882
|
+
let content = fs.readFileSync(configPath, 'utf-8');
|
|
883
|
+
let modified = false;
|
|
884
|
+
let originalLine = null;
|
|
885
|
+
|
|
886
|
+
// 匹配包含 outputFileTracingRoot 的行(尚未被注释的)
|
|
887
|
+
// 支持 path.resolve(...) 后面有空格,然后可选逗号
|
|
888
|
+
// 只匹配单行配置,不匹配跨多行的配置
|
|
889
|
+
const pattern =
|
|
890
|
+
/^(\s*)(outputFileTracingRoot:\s*path\.resolve\([^\n\r)]+\)\s*,?)\s*$/gm;
|
|
891
|
+
|
|
892
|
+
const matches = content.match(pattern);
|
|
893
|
+
|
|
894
|
+
if (matches && matches.length > 0) {
|
|
895
|
+
originalLine = matches[0].trim();
|
|
896
|
+
|
|
897
|
+
// 在匹配的行前添加 // 注释
|
|
898
|
+
content = content.replace(pattern, '$1// $2');
|
|
899
|
+
modified = true;
|
|
900
|
+
|
|
901
|
+
fs.writeFileSync(configPath, content, 'utf-8');
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
return { modified, originalLine };
|
|
905
|
+
};
|
|
906
|
+
|
|
907
|
+
// start_aigc
|
|
908
|
+
/**
|
|
909
|
+
* Fix 规则:注释掉 Next.js 项目中的 outputFileTracingRoot 配置
|
|
910
|
+
* 这个配置在 monorepo 环境中可能会导致问题
|
|
911
|
+
*/
|
|
912
|
+
const fixNextOutputTracingRoot = context => {
|
|
913
|
+
const ruleName = 'next-output-tracing-root';
|
|
914
|
+
|
|
915
|
+
// 1. 检查是否为 Next.js 项目
|
|
916
|
+
if (!isNextProject(context.projectFolder)) {
|
|
917
|
+
return {
|
|
918
|
+
ruleName,
|
|
919
|
+
applied: false,
|
|
920
|
+
message: 'Not a Next.js project, skipping',
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// 2. 查找 Next.js 配置文件
|
|
925
|
+
const configPath = findNextConfigFile(context.projectFolder);
|
|
926
|
+
|
|
927
|
+
if (!configPath) {
|
|
928
|
+
return {
|
|
929
|
+
ruleName,
|
|
930
|
+
applied: false,
|
|
931
|
+
message: 'Next.js config file not found, skipping',
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// 3. 注释掉 outputFileTracingRoot 配置
|
|
936
|
+
const { modified, originalLine } = commentOutOutputTracingRoot(configPath);
|
|
937
|
+
|
|
938
|
+
if (modified && originalLine) {
|
|
939
|
+
logger.success(
|
|
940
|
+
`Commented out outputFileTracingRoot in ${configPath.split('/').pop()}`,
|
|
941
|
+
);
|
|
942
|
+
logger.info(` Original: ${originalLine}`);
|
|
943
|
+
|
|
944
|
+
return {
|
|
945
|
+
ruleName,
|
|
946
|
+
applied: true,
|
|
947
|
+
message: `Successfully commented out: ${originalLine}`,
|
|
948
|
+
};
|
|
949
|
+
}
|
|
839
950
|
|
|
840
951
|
return {
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
},
|
|
952
|
+
ruleName,
|
|
953
|
+
applied: false,
|
|
954
|
+
message: 'No outputFileTracingRoot config found, skipping',
|
|
845
955
|
};
|
|
846
956
|
};
|
|
957
|
+
// end_aigc
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* 所有修复规则的数组
|
|
961
|
+
* 按顺序执行,新增规则直接添加到数组中
|
|
962
|
+
*/
|
|
963
|
+
const rules = [
|
|
964
|
+
// Next.js related fixes
|
|
965
|
+
fixNextOutputTracingRoot,
|
|
966
|
+
|
|
967
|
+
// Add more rules here
|
|
968
|
+
] ;
|
|
969
|
+
|
|
970
|
+
// ABOUTME: Fix command for resolving legacy issues from previous project versions
|
|
971
|
+
// ABOUTME: Applies a series of fix rules defined in the fix-rules directory
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
// start_aigc
|
|
975
|
+
/**
|
|
976
|
+
* 执行 fix 命令的内部实现
|
|
977
|
+
*/
|
|
978
|
+
const executeFix = async (options = {}) => {
|
|
979
|
+
try {
|
|
980
|
+
const cwd = process.cwd();
|
|
981
|
+
const projectFolder = options.directory
|
|
982
|
+
? path.resolve(cwd, options.directory)
|
|
983
|
+
: cwd;
|
|
984
|
+
|
|
985
|
+
logger.info(`Running fix command on: ${projectFolder}`);
|
|
986
|
+
logger.info(`Found ${rules.length} fix rule(s) to apply\n`);
|
|
987
|
+
|
|
988
|
+
const context = {
|
|
989
|
+
cwd,
|
|
990
|
+
projectFolder,
|
|
991
|
+
};
|
|
992
|
+
|
|
993
|
+
let appliedCount = 0;
|
|
994
|
+
let skippedCount = 0;
|
|
995
|
+
|
|
996
|
+
// 依次执行所有修复规则
|
|
997
|
+
for (const rule of rules) {
|
|
998
|
+
try {
|
|
999
|
+
const result = await Promise.resolve(rule(context));
|
|
1000
|
+
|
|
1001
|
+
if (result.applied) {
|
|
1002
|
+
appliedCount++;
|
|
1003
|
+
logger.success(`✓ ${result.ruleName}: ${result.message}`);
|
|
1004
|
+
} else {
|
|
1005
|
+
skippedCount++;
|
|
1006
|
+
logger.info(`○ ${result.ruleName}: ${result.message}`);
|
|
1007
|
+
}
|
|
1008
|
+
} catch (error) {
|
|
1009
|
+
logger.error(
|
|
1010
|
+
`✗ Rule execution failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
// 输出汇总信息
|
|
1016
|
+
logger.info(
|
|
1017
|
+
`\nSummary: ${appliedCount} fixed, ${skippedCount} skipped, ${rules.length} total`,
|
|
1018
|
+
);
|
|
1019
|
+
|
|
1020
|
+
if (appliedCount > 0) {
|
|
1021
|
+
logger.success('\nFixes applied successfully!');
|
|
1022
|
+
} else {
|
|
1023
|
+
logger.info('\nNo fixes needed');
|
|
1024
|
+
}
|
|
1025
|
+
} catch (error) {
|
|
1026
|
+
logger.error('Failed to run fix command:');
|
|
1027
|
+
logger.error(error instanceof Error ? error.message : String(error));
|
|
1028
|
+
process.exit(1);
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
// end_aigc
|
|
1032
|
+
|
|
1033
|
+
/**
|
|
1034
|
+
* 注册 fix 命令到 program
|
|
1035
|
+
*/
|
|
1036
|
+
const registerCommand$3 = program => {
|
|
1037
|
+
program
|
|
1038
|
+
.command('fix')
|
|
1039
|
+
.description(
|
|
1040
|
+
'Fix legacy issues from previous versions (e.g., problematic configs)',
|
|
1041
|
+
)
|
|
1042
|
+
.argument(
|
|
1043
|
+
'[directory]',
|
|
1044
|
+
'Target directory to fix (defaults to current directory)',
|
|
1045
|
+
)
|
|
1046
|
+
.action(async (directory) => {
|
|
1047
|
+
await executeFix({ directory });
|
|
1048
|
+
});
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1052
|
+
/**
|
|
1053
|
+
* 日志文件名常量
|
|
1054
|
+
*/
|
|
1055
|
+
const LOG_FILE_NAME$1 = 'dev.log';
|
|
1056
|
+
|
|
1057
|
+
/**
|
|
1058
|
+
* 获取日志目录
|
|
1059
|
+
* 优先使用环境变量 COZE_LOG_DIR,否则使用 ~/.coze-logs
|
|
1060
|
+
*/
|
|
1061
|
+
const getLogDir$1 = () =>
|
|
1062
|
+
process.env.COZE_LOG_DIR || path.join(os.homedir(), '.coze-logs');
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* 解析日志文件路径
|
|
1066
|
+
* - 如果是绝对路径,直接使用
|
|
1067
|
+
* - 如果是相对路径,基于 getLogDir() + 相对路径
|
|
1068
|
+
* - 如果为空,使用 getLogDir() + LOG_FILE_NAME
|
|
1069
|
+
*/
|
|
1070
|
+
const resolveLogFilePath$1 = (logFile) => {
|
|
1071
|
+
if (!logFile) {
|
|
1072
|
+
return path.join(getLogDir$1(), LOG_FILE_NAME$1);
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
if (path.isAbsolute(logFile)) {
|
|
1076
|
+
return logFile;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
return path.join(getLogDir$1(), logFile);
|
|
1080
|
+
};
|
|
1081
|
+
|
|
1082
|
+
/**
|
|
1083
|
+
* 创建日志写入流
|
|
1084
|
+
*/
|
|
1085
|
+
const createLogStream$1 = (logFilePath) => {
|
|
1086
|
+
const logDir = path.dirname(logFilePath);
|
|
1087
|
+
|
|
1088
|
+
// 确保日志目录存在
|
|
1089
|
+
if (!fs.existsSync(logDir)) {
|
|
1090
|
+
fs.mkdirSync(logDir, { recursive: true });
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// 使用 'w' 标志覆盖之前的日志
|
|
1094
|
+
return fs.createWriteStream(logFilePath, { flags: 'w' });
|
|
1095
|
+
};
|
|
847
1096
|
|
|
848
1097
|
/**
|
|
849
1098
|
* 执行命令的内部实现
|
|
@@ -855,21 +1104,32 @@ const executeRun = async (
|
|
|
855
1104
|
try {
|
|
856
1105
|
logger.info(`Running ${commandName} command...`);
|
|
857
1106
|
|
|
858
|
-
// 1.
|
|
1107
|
+
// 1. 对于 build 命令,先执行 fix 以确保项目配置正确
|
|
1108
|
+
if (['dev', 'build'].includes(commandName)) {
|
|
1109
|
+
logger.info('\n🔧 Running fix command before build...\n');
|
|
1110
|
+
try {
|
|
1111
|
+
await executeFix();
|
|
1112
|
+
// eslint-disable-next-line @coze-arch/no-empty-catch
|
|
1113
|
+
} catch (e) {
|
|
1114
|
+
// just ignore
|
|
1115
|
+
}
|
|
1116
|
+
logger.info('');
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// 2. 加载 .coze 配置
|
|
859
1120
|
const config = await loadCozeConfig();
|
|
860
1121
|
const commandArgs = getCommandConfig(config, commandName);
|
|
861
1122
|
|
|
862
|
-
//
|
|
863
|
-
const
|
|
864
|
-
const
|
|
865
|
-
const logStream = logManager.createWriteStream(logFile);
|
|
1123
|
+
// 3. 准备日志
|
|
1124
|
+
const logFilePath = resolveLogFilePath$1(options.logFile);
|
|
1125
|
+
const logStream = createLogStream$1(logFilePath);
|
|
866
1126
|
|
|
867
|
-
//
|
|
1127
|
+
// 4. 执行命令
|
|
868
1128
|
const commandString = commandArgs.join(' ');
|
|
869
1129
|
|
|
870
1130
|
logger.info(`Executing: ${commandString}`);
|
|
871
1131
|
logger.info(`Working directory: ${process.cwd()}`);
|
|
872
|
-
logger.info(`Log file: ${
|
|
1132
|
+
logger.info(`Log file: ${logFilePath}`);
|
|
873
1133
|
|
|
874
1134
|
const childProcess = shelljs.exec(commandString, {
|
|
875
1135
|
async: true,
|
|
@@ -898,11 +1158,11 @@ const executeRun = async (
|
|
|
898
1158
|
logger.error(
|
|
899
1159
|
`Command exited with code ${_nullishCoalesce$1(code, () => ( 'unknown'))}${signal ? ` and signal ${signal}` : ''}`,
|
|
900
1160
|
);
|
|
901
|
-
logger.error(`Check log file for details: ${
|
|
1161
|
+
logger.error(`Check log file for details: ${logFilePath}`);
|
|
902
1162
|
process.exit(code || 1);
|
|
903
1163
|
} else {
|
|
904
1164
|
logger.success('Command completed successfully');
|
|
905
|
-
logger.info(`Log file: ${
|
|
1165
|
+
logger.info(`Log file: ${logFilePath}`);
|
|
906
1166
|
}
|
|
907
1167
|
});
|
|
908
1168
|
|
|
@@ -925,7 +1185,7 @@ const executeRun = async (
|
|
|
925
1185
|
/**
|
|
926
1186
|
* 注册 dev/build/start 命令到 program
|
|
927
1187
|
*/
|
|
928
|
-
const registerCommand$
|
|
1188
|
+
const registerCommand$2 = program => {
|
|
929
1189
|
// dev 命令
|
|
930
1190
|
program
|
|
931
1191
|
.command('dev')
|
|
@@ -1177,6 +1437,11 @@ const shouldIgnoreFile = (filePath) => {
|
|
|
1177
1437
|
return directoryPatterns.some(dir => pathParts.includes(dir));
|
|
1178
1438
|
};
|
|
1179
1439
|
|
|
1440
|
+
// ABOUTME: File system utilities for template file processing
|
|
1441
|
+
// ABOUTME: Provides directory scanning, file path conversion, and node_modules copying
|
|
1442
|
+
|
|
1443
|
+
|
|
1444
|
+
// start_aigc
|
|
1180
1445
|
/**
|
|
1181
1446
|
* 递归获取目录中的所有文件
|
|
1182
1447
|
*
|
|
@@ -1248,22 +1513,356 @@ const convertDotfileName = (filePath) => {
|
|
|
1248
1513
|
};
|
|
1249
1514
|
|
|
1250
1515
|
/**
|
|
1251
|
-
*
|
|
1516
|
+
* 复制 node_modules 目录(如果存在)
|
|
1252
1517
|
*
|
|
1253
|
-
* @param
|
|
1254
|
-
* @param
|
|
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
|
+
// end_aigc
|
|
1555
|
+
|
|
1556
|
+
// ABOUTME: File rendering utilities for template processing
|
|
1557
|
+
// ABOUTME: Handles file content rendering, hook execution, and file writing
|
|
1558
|
+
|
|
1559
|
+
|
|
1560
|
+
|
|
1561
|
+
|
|
1562
|
+
|
|
1563
|
+
|
|
1564
|
+
|
|
1565
|
+
|
|
1566
|
+
// start_aigc
|
|
1567
|
+
/**
|
|
1568
|
+
* 执行文件渲染钩子
|
|
1569
|
+
*
|
|
1570
|
+
* @param templateConfig - 模板配置
|
|
1571
|
+
* @param fileInfo - 文件渲染信息
|
|
1255
1572
|
* @param context - 模板上下文
|
|
1573
|
+
* @returns 处理后的文件信息,或 null 表示跳过该文件
|
|
1256
1574
|
*/
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1259
|
-
|
|
1575
|
+
const executeFileRenderHook = async (
|
|
1576
|
+
templateConfig,
|
|
1577
|
+
fileInfo,
|
|
1260
1578
|
context,
|
|
1261
1579
|
) => {
|
|
1580
|
+
if (!templateConfig.onFileRender) {
|
|
1581
|
+
return fileInfo;
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
const result = await templateConfig.onFileRender(
|
|
1585
|
+
fileInfo,
|
|
1586
|
+
context,
|
|
1587
|
+
);
|
|
1588
|
+
|
|
1589
|
+
// false: 跳过文件
|
|
1590
|
+
if (result === false) {
|
|
1591
|
+
return null;
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
// undefined/void: 使用默认内容
|
|
1595
|
+
if (result === undefined || result === null) {
|
|
1596
|
+
return fileInfo;
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
// string: 作为 content,其他不变
|
|
1600
|
+
if (typeof result === 'string') {
|
|
1601
|
+
return {
|
|
1602
|
+
...fileInfo,
|
|
1603
|
+
content: result,
|
|
1604
|
+
};
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
// FileRenderInfo: 使用新对象的信息
|
|
1608
|
+
return result;
|
|
1609
|
+
};
|
|
1610
|
+
|
|
1611
|
+
/**
|
|
1612
|
+
* 准备单个文件的渲染信息(不实际写入)
|
|
1613
|
+
* 用于 dry-run 阶段,收集所有将要写入的文件信息
|
|
1614
|
+
*
|
|
1615
|
+
* @param options - 准备选项
|
|
1616
|
+
* @returns 文件渲染信息,或 null 表示该文件被跳过
|
|
1617
|
+
*/
|
|
1618
|
+
const prepareFileInfo = async (options
|
|
1619
|
+
|
|
1620
|
+
|
|
1621
|
+
|
|
1622
|
+
|
|
1623
|
+
) => {
|
|
1624
|
+
const { file, templatePath, context, templateConfig } = options;
|
|
1625
|
+
|
|
1626
|
+
const srcPath = path.join(templatePath, file);
|
|
1627
|
+
const destFile = convertDotfileName(file);
|
|
1628
|
+
|
|
1629
|
+
logger.verbose(
|
|
1630
|
+
` - Preparing: ${file}${destFile !== file ? ` -> ${destFile}` : ''}`,
|
|
1631
|
+
);
|
|
1632
|
+
|
|
1633
|
+
// 判断是否为二进制文件
|
|
1634
|
+
const isBinary = !shouldRenderFile(srcPath);
|
|
1635
|
+
let content;
|
|
1636
|
+
let wasRendered = false;
|
|
1637
|
+
|
|
1638
|
+
if (isBinary) {
|
|
1639
|
+
// 二进制文件,读取为 buffer 然后转为 base64
|
|
1640
|
+
const buffer = await fs$1.readFile(srcPath);
|
|
1641
|
+
content = buffer.toString('base64');
|
|
1642
|
+
} else {
|
|
1643
|
+
// 文本文件,渲染后的内容
|
|
1644
|
+
content = await renderTemplate(srcPath, context);
|
|
1645
|
+
wasRendered = true;
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
// 构造文件信息对象
|
|
1649
|
+
const fileInfo = {
|
|
1650
|
+
path: file,
|
|
1651
|
+
destPath: destFile,
|
|
1652
|
+
content,
|
|
1653
|
+
isBinary,
|
|
1654
|
+
wasRendered,
|
|
1655
|
+
};
|
|
1656
|
+
|
|
1657
|
+
// 执行文件渲染钩子
|
|
1658
|
+
const processedFileInfo = await executeFileRenderHook(
|
|
1659
|
+
templateConfig,
|
|
1660
|
+
fileInfo,
|
|
1661
|
+
context,
|
|
1662
|
+
);
|
|
1663
|
+
|
|
1664
|
+
// 如果返回 null,表示该文件被 hook 跳过
|
|
1665
|
+
if (processedFileInfo === null) {
|
|
1666
|
+
logger.verbose(' ⊘ Skipped by onFileRender hook');
|
|
1667
|
+
return null;
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
return processedFileInfo;
|
|
1671
|
+
};
|
|
1672
|
+
|
|
1673
|
+
/**
|
|
1674
|
+
* 写入渲染后的文件到目标路径
|
|
1675
|
+
*
|
|
1676
|
+
* @param options - 写入选项
|
|
1677
|
+
*/
|
|
1678
|
+
const writeRenderedFile = async (options
|
|
1679
|
+
|
|
1680
|
+
|
|
1681
|
+
|
|
1682
|
+
) => {
|
|
1683
|
+
const { fileInfo, srcPath, destPath } = options;
|
|
1684
|
+
|
|
1685
|
+
logger.verbose(` - Writing: ${fileInfo.destPath}`);
|
|
1686
|
+
|
|
1687
|
+
// 确保目标目录存在
|
|
1688
|
+
await ensureDir(path.dirname(destPath));
|
|
1689
|
+
|
|
1690
|
+
// 写入文件
|
|
1691
|
+
if (fileInfo.isBinary) {
|
|
1692
|
+
// 二进制文件:如果内容是原始 base64(未被 hook 修改),直接复制;否则从 base64 解码写入
|
|
1693
|
+
const buffer = await fs$1.readFile(srcPath);
|
|
1694
|
+
const originalContent = buffer.toString('base64');
|
|
1695
|
+
|
|
1696
|
+
if (fileInfo.content === originalContent) {
|
|
1697
|
+
await fs$1.copyFile(srcPath, destPath);
|
|
1698
|
+
logger.verbose(' ✓ Copied (binary)');
|
|
1699
|
+
} else {
|
|
1700
|
+
const modifiedBuffer = Buffer.from(fileInfo.content, 'base64');
|
|
1701
|
+
await fs$1.writeFile(destPath, modifiedBuffer);
|
|
1702
|
+
logger.verbose(' ✓ Written (binary, modified by hook)');
|
|
1703
|
+
}
|
|
1704
|
+
} else {
|
|
1705
|
+
// 文本文件
|
|
1706
|
+
await fs$1.writeFile(destPath, fileInfo.content, 'utf-8');
|
|
1707
|
+
logger.verbose(' ✓ Rendered and written');
|
|
1708
|
+
}
|
|
1709
|
+
};
|
|
1710
|
+
// end_aigc
|
|
1711
|
+
|
|
1712
|
+
// ABOUTME: File conflict detection utilities for template processing
|
|
1713
|
+
// ABOUTME: Provides dry-run file collection and conflict checking
|
|
1714
|
+
|
|
1715
|
+
|
|
1716
|
+
|
|
1717
|
+
|
|
1718
|
+
|
|
1719
|
+
|
|
1720
|
+
|
|
1721
|
+
// start_aigc
|
|
1722
|
+
/**
|
|
1723
|
+
* 收集所有将要写入的文件路径(dry-run 阶段)
|
|
1724
|
+
*
|
|
1725
|
+
* @param options - 收集选项
|
|
1726
|
+
* @returns 将要写入的文件路径列表
|
|
1727
|
+
*/
|
|
1728
|
+
const collectFilesToRender = async (options
|
|
1729
|
+
|
|
1730
|
+
|
|
1731
|
+
|
|
1732
|
+
|
|
1733
|
+
) => {
|
|
1734
|
+
const { files, templatePath, context, templateConfig } = options;
|
|
1735
|
+
|
|
1736
|
+
logger.verbose('\nDry-run: Collecting files to render...');
|
|
1737
|
+
|
|
1738
|
+
const fileInfos = await Promise.all(
|
|
1739
|
+
files.map(file =>
|
|
1740
|
+
prepareFileInfo({
|
|
1741
|
+
file,
|
|
1742
|
+
templatePath,
|
|
1743
|
+
context,
|
|
1744
|
+
templateConfig,
|
|
1745
|
+
}),
|
|
1746
|
+
),
|
|
1747
|
+
);
|
|
1748
|
+
|
|
1749
|
+
// 过滤掉被 hook 跳过的文件,收集 destPath
|
|
1750
|
+
const filesToWrite = fileInfos
|
|
1751
|
+
.filter((info) => info !== null)
|
|
1752
|
+
.map(info => info.destPath);
|
|
1753
|
+
|
|
1754
|
+
logger.verbose(` - ${filesToWrite.length} files will be written`);
|
|
1755
|
+
logger.verbose(
|
|
1756
|
+
` - ${fileInfos.length - filesToWrite.length} files skipped by hooks`,
|
|
1757
|
+
);
|
|
1758
|
+
|
|
1759
|
+
return filesToWrite;
|
|
1760
|
+
};
|
|
1761
|
+
|
|
1762
|
+
/**
|
|
1763
|
+
* 检测文件冲突
|
|
1764
|
+
*
|
|
1765
|
+
* @param outputPath - 输出目录路径
|
|
1766
|
+
* @param filesToWrite - 将要写入的文件路径列表
|
|
1767
|
+
* @returns 冲突的文件路径列表
|
|
1768
|
+
*/
|
|
1769
|
+
const detectFileConflicts = (
|
|
1770
|
+
outputPath,
|
|
1771
|
+
filesToWrite,
|
|
1772
|
+
) => {
|
|
1773
|
+
logger.verbose('\nChecking for file conflicts...');
|
|
1774
|
+
|
|
1775
|
+
const conflicts = [];
|
|
1776
|
+
|
|
1777
|
+
for (const file of filesToWrite) {
|
|
1778
|
+
const fullPath = path.join(outputPath, file);
|
|
1779
|
+
if (fs.existsSync(fullPath)) {
|
|
1780
|
+
conflicts.push(file);
|
|
1781
|
+
logger.verbose(` ⚠ Conflict detected: ${file}`);
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
if (conflicts.length === 0) {
|
|
1786
|
+
logger.verbose(' ✓ No conflicts detected');
|
|
1787
|
+
} else {
|
|
1788
|
+
logger.verbose(` ⚠ ${conflicts.length} conflicts detected`);
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
return conflicts;
|
|
1792
|
+
};
|
|
1793
|
+
// end_aigc
|
|
1794
|
+
|
|
1795
|
+
// ABOUTME: Main file processing orchestration for template rendering
|
|
1796
|
+
// ABOUTME: Coordinates file system, rendering, and conflict detection layers
|
|
1797
|
+
|
|
1798
|
+
|
|
1799
|
+
|
|
1800
|
+
// start_aigc
|
|
1801
|
+
/**
|
|
1802
|
+
* 处理单个文件(准备 + 写入)
|
|
1803
|
+
*
|
|
1804
|
+
* @param options - 处理选项
|
|
1805
|
+
*/
|
|
1806
|
+
const processSingleFile = async (options
|
|
1807
|
+
|
|
1808
|
+
|
|
1809
|
+
|
|
1810
|
+
|
|
1811
|
+
|
|
1812
|
+
) => {
|
|
1813
|
+
const { file, templatePath, outputPath, context, templateConfig } = options;
|
|
1814
|
+
|
|
1815
|
+
const srcPath = path.join(templatePath, file);
|
|
1816
|
+
|
|
1817
|
+
// 准备文件信息
|
|
1818
|
+
const processedFileInfo = await prepareFileInfo({
|
|
1819
|
+
file,
|
|
1820
|
+
templatePath,
|
|
1821
|
+
context,
|
|
1822
|
+
templateConfig,
|
|
1823
|
+
});
|
|
1824
|
+
|
|
1825
|
+
// 如果返回 null,跳过该文件
|
|
1826
|
+
if (processedFileInfo === null) {
|
|
1827
|
+
return;
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
// 使用处理后的目标路径
|
|
1831
|
+
const finalDestPath = path.join(outputPath, processedFileInfo.destPath);
|
|
1832
|
+
|
|
1833
|
+
// 写入文件
|
|
1834
|
+
await writeRenderedFile({
|
|
1835
|
+
fileInfo: processedFileInfo,
|
|
1836
|
+
srcPath,
|
|
1837
|
+
destPath: finalDestPath,
|
|
1838
|
+
});
|
|
1839
|
+
};
|
|
1840
|
+
|
|
1841
|
+
/**
|
|
1842
|
+
* 复制并处理模板文件到目标目录
|
|
1843
|
+
*
|
|
1844
|
+
* 流程:
|
|
1845
|
+
* 1. 验证模板目录
|
|
1846
|
+
* 2. 扫描所有模板文件
|
|
1847
|
+
* 3. Dry-run:收集将要写入的文件列表(考虑 hooks 影响)
|
|
1848
|
+
* 4. 冲突检测:检查是否有文件会被覆盖
|
|
1849
|
+
* 5. 实际写入:渲染并写入所有文件
|
|
1850
|
+
* 6. 复制 node_modules(如果存在)
|
|
1851
|
+
*
|
|
1852
|
+
* @param options - 处理选项
|
|
1853
|
+
*/
|
|
1854
|
+
const processTemplateFiles = async (options
|
|
1855
|
+
|
|
1856
|
+
|
|
1857
|
+
|
|
1858
|
+
|
|
1859
|
+
) => {
|
|
1860
|
+
const { templatePath, outputPath, context, templateConfig } = options;
|
|
1262
1861
|
logger.verbose('Processing template files:');
|
|
1263
1862
|
logger.verbose(` - Template path: ${templatePath}`);
|
|
1264
1863
|
logger.verbose(` - Output path: ${outputPath}`);
|
|
1265
1864
|
|
|
1266
|
-
// 验证模板目录是否存在
|
|
1865
|
+
// 阶段 0: 验证模板目录是否存在
|
|
1267
1866
|
try {
|
|
1268
1867
|
const stat = await fs$1.stat(templatePath);
|
|
1269
1868
|
logger.verbose(
|
|
@@ -1279,6 +1878,7 @@ const processTemplateFiles = async (
|
|
|
1279
1878
|
throw error;
|
|
1280
1879
|
}
|
|
1281
1880
|
|
|
1881
|
+
// 阶段 1: 扫描所有模板文件
|
|
1282
1882
|
const files = await getAllFiles(templatePath);
|
|
1283
1883
|
|
|
1284
1884
|
logger.verbose(` - Found ${files.length} files to process`);
|
|
@@ -1288,102 +1888,50 @@ const processTemplateFiles = async (
|
|
|
1288
1888
|
return;
|
|
1289
1889
|
}
|
|
1290
1890
|
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1891
|
+
// 阶段 2: Dry-run - 收集所有将要写入的文件
|
|
1892
|
+
const filesToWrite = await collectFilesToRender({
|
|
1893
|
+
files,
|
|
1894
|
+
templatePath,
|
|
1895
|
+
context,
|
|
1896
|
+
templateConfig,
|
|
1897
|
+
});
|
|
1296
1898
|
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
);
|
|
1899
|
+
// 阶段 3: 冲突检测
|
|
1900
|
+
const conflicts = detectFileConflicts(outputPath, filesToWrite);
|
|
1300
1901
|
|
|
1301
|
-
|
|
1302
|
-
|
|
1902
|
+
if (conflicts.length > 0) {
|
|
1903
|
+
// 有冲突,抛出详细的错误信息
|
|
1904
|
+
const conflictList = conflicts.map(f => ` - ${f}`).join('\n');
|
|
1905
|
+
throw new Error(
|
|
1906
|
+
`File conflicts detected in output directory: ${outputPath}\n\n` +
|
|
1907
|
+
`The following files already exist and would be overwritten:\n${conflictList}\n\n` +
|
|
1908
|
+
'Please remove these files or use a different output directory.',
|
|
1909
|
+
);
|
|
1910
|
+
}
|
|
1303
1911
|
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1912
|
+
// 阶段 4: 实际写入文件
|
|
1913
|
+
logger.verbose('\nWriting files...');
|
|
1914
|
+
await Promise.all(
|
|
1915
|
+
files.map(file =>
|
|
1916
|
+
processSingleFile({
|
|
1917
|
+
file,
|
|
1918
|
+
templatePath,
|
|
1919
|
+
outputPath,
|
|
1920
|
+
context,
|
|
1921
|
+
templateConfig,
|
|
1922
|
+
}),
|
|
1923
|
+
),
|
|
1315
1924
|
);
|
|
1316
1925
|
|
|
1317
1926
|
logger.verbose('✓ All files processed successfully');
|
|
1318
1927
|
|
|
1319
|
-
// 单独处理 node_modules 目录(如果存在)
|
|
1928
|
+
// 阶段 5: 单独处理 node_modules 目录(如果存在)
|
|
1320
1929
|
const sourceNodeModules = path.join(templatePath, 'node_modules');
|
|
1321
1930
|
const targetNodeModules = path.join(outputPath, 'node_modules');
|
|
1322
1931
|
|
|
1323
|
-
|
|
1324
|
-
logger.info('\nCopying node_modules from pre-warmed template...');
|
|
1325
|
-
logger.verbose(` From: ${sourceNodeModules}`);
|
|
1326
|
-
logger.verbose(` To: ${targetNodeModules}`);
|
|
1327
|
-
|
|
1328
|
-
const result = shelljs.exec(`cp -R "${sourceNodeModules}" "${targetNodeModules}"`, {
|
|
1329
|
-
silent: true,
|
|
1330
|
-
});
|
|
1331
|
-
|
|
1332
|
-
if (result.stdout) {
|
|
1333
|
-
process.stdout.write(result.stdout);
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
if (result.stderr) {
|
|
1337
|
-
process.stderr.write(result.stderr);
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
if (result.code === 0) {
|
|
1341
|
-
logger.success('✓ node_modules copied successfully');
|
|
1342
|
-
} else {
|
|
1343
|
-
logger.warn(
|
|
1344
|
-
`Failed to copy node_modules: ${result.stderr || 'unknown error'}`,
|
|
1345
|
-
);
|
|
1346
|
-
logger.info('Will need to run pnpm install manually');
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
};
|
|
1350
|
-
|
|
1351
|
-
/**
|
|
1352
|
-
* 检查输出目录是否为空
|
|
1353
|
-
* 注意:.git 目录会被忽略,允许在已初始化 git 的目录中创建项目
|
|
1354
|
-
*
|
|
1355
|
-
* @param outputPath - 输出目录路径
|
|
1356
|
-
* @returns 是否为空
|
|
1357
|
-
*/
|
|
1358
|
-
const isOutputDirEmpty = async (
|
|
1359
|
-
outputPath,
|
|
1360
|
-
) => {
|
|
1361
|
-
try {
|
|
1362
|
-
const entries = await fs$1.readdir(outputPath);
|
|
1363
|
-
// 过滤掉 .git 目录,允许在已初始化 git 的目录中创建项目
|
|
1364
|
-
const filteredEntries = entries.filter(entry => entry !== '.git');
|
|
1365
|
-
return filteredEntries.length === 0;
|
|
1366
|
-
} catch (e) {
|
|
1367
|
-
// 目录不存在,视为空
|
|
1368
|
-
return true;
|
|
1369
|
-
}
|
|
1370
|
-
};
|
|
1371
|
-
|
|
1372
|
-
/**
|
|
1373
|
-
* 验证输出目录
|
|
1374
|
-
*
|
|
1375
|
-
* @param outputPath - 输出目录路径
|
|
1376
|
-
* @throws 如果目录不为空则抛出错误
|
|
1377
|
-
*/
|
|
1378
|
-
const validateOutputDir = async (outputPath) => {
|
|
1379
|
-
const isEmpty = await isOutputDirEmpty(outputPath);
|
|
1380
|
-
if (!isEmpty) {
|
|
1381
|
-
throw new Error(
|
|
1382
|
-
`Output directory is not empty: ${outputPath}\n` +
|
|
1383
|
-
'Please use an empty directory or remove existing files.',
|
|
1384
|
-
);
|
|
1385
|
-
}
|
|
1932
|
+
copyNodeModules(sourceNodeModules, targetNodeModules);
|
|
1386
1933
|
};
|
|
1934
|
+
// end_aigc
|
|
1387
1935
|
|
|
1388
1936
|
/**
|
|
1389
1937
|
* 模板引擎执行选项
|
|
@@ -1463,15 +2011,40 @@ const executeAfterRenderHook = async (
|
|
|
1463
2011
|
}
|
|
1464
2012
|
};
|
|
1465
2013
|
|
|
2014
|
+
/**
|
|
2015
|
+
* 执行完成钩子
|
|
2016
|
+
*/
|
|
2017
|
+
const executeCompleteHook = async (
|
|
2018
|
+
templateConfig,
|
|
2019
|
+
context,
|
|
2020
|
+
outputPath,
|
|
2021
|
+
) => {
|
|
2022
|
+
if (templateConfig.onComplete) {
|
|
2023
|
+
await templateConfig.onComplete(context, outputPath);
|
|
2024
|
+
}
|
|
2025
|
+
};
|
|
2026
|
+
|
|
1466
2027
|
/**
|
|
1467
2028
|
* 准备输出目录
|
|
1468
2029
|
*/
|
|
1469
|
-
const prepareOutputDirectory =
|
|
2030
|
+
const prepareOutputDirectory = (outputPath) => {
|
|
1470
2031
|
const absolutePath = path.resolve(process.cwd(), outputPath);
|
|
1471
|
-
|
|
2032
|
+
// 不再在这里验证目录是否为空,冲突检测已移至 processTemplateFiles 中
|
|
1472
2033
|
return absolutePath;
|
|
1473
2034
|
};
|
|
1474
2035
|
|
|
2036
|
+
/**
|
|
2037
|
+
* 模板引擎执行结果
|
|
2038
|
+
*/
|
|
2039
|
+
|
|
2040
|
+
|
|
2041
|
+
|
|
2042
|
+
|
|
2043
|
+
|
|
2044
|
+
|
|
2045
|
+
|
|
2046
|
+
|
|
2047
|
+
|
|
1475
2048
|
/**
|
|
1476
2049
|
* 执行完整的模板渲染流程
|
|
1477
2050
|
*/
|
|
@@ -1495,15 +2068,24 @@ const execute = async (
|
|
|
1495
2068
|
});
|
|
1496
2069
|
|
|
1497
2070
|
// 5. 准备输出目录
|
|
1498
|
-
const absoluteOutputPath =
|
|
2071
|
+
const absoluteOutputPath = prepareOutputDirectory(outputPath);
|
|
1499
2072
|
|
|
1500
2073
|
// 6. 处理模板文件
|
|
1501
|
-
await processTemplateFiles(
|
|
2074
|
+
await processTemplateFiles({
|
|
2075
|
+
templatePath,
|
|
2076
|
+
outputPath: absoluteOutputPath,
|
|
2077
|
+
context,
|
|
2078
|
+
templateConfig,
|
|
2079
|
+
});
|
|
1502
2080
|
|
|
1503
2081
|
// 7. 执行 onAfterRender 钩子
|
|
1504
2082
|
await executeAfterRenderHook(templateConfig, context, absoluteOutputPath);
|
|
1505
2083
|
|
|
1506
|
-
return
|
|
2084
|
+
return {
|
|
2085
|
+
outputPath: absoluteOutputPath,
|
|
2086
|
+
templateConfig,
|
|
2087
|
+
context,
|
|
2088
|
+
};
|
|
1507
2089
|
};
|
|
1508
2090
|
|
|
1509
2091
|
function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
@@ -1611,13 +2193,20 @@ const runGitInit = (projectPath) => {
|
|
|
1611
2193
|
/**
|
|
1612
2194
|
* 运行开发服务器(后台模式)
|
|
1613
2195
|
* 启动后台子进程运行开发服务器,父进程可以直接退出
|
|
2196
|
+
* 使用 CLI 自己的 dev 命令(定义在 run.ts)而不是直接运行 npm run dev
|
|
1614
2197
|
*/
|
|
1615
|
-
const
|
|
2198
|
+
const runDev = (projectPath) => {
|
|
1616
2199
|
logger.info('\nStarting development server in background...');
|
|
1617
|
-
|
|
2200
|
+
|
|
2201
|
+
// 获取当前 CLI 的可执行文件路径
|
|
2202
|
+
// process.argv[0] 是 node,process.argv[1] 是 CLI 入口文件
|
|
2203
|
+
const cliPath = process.argv[1];
|
|
2204
|
+
|
|
2205
|
+
logger.info(`Executing: ${cliPath} dev in ${projectPath}`);
|
|
1618
2206
|
|
|
1619
2207
|
// 使用通用的后台执行函数启动开发服务器
|
|
1620
|
-
|
|
2208
|
+
// 调用 CLI 自己的 dev 命令
|
|
2209
|
+
const pid = spawnDetached(process.argv[0], [cliPath, 'dev'], {
|
|
1621
2210
|
cwd: projectPath,
|
|
1622
2211
|
verbose: false, // 不输出额外的进程信息,由 logger 统一处理
|
|
1623
2212
|
});
|
|
@@ -1659,12 +2248,13 @@ const executeInit = async (
|
|
|
1659
2248
|
logger.info(`Initializing project with template: ${templateName}`);
|
|
1660
2249
|
timer.logPhase('Initialization');
|
|
1661
2250
|
|
|
1662
|
-
//
|
|
1663
|
-
const
|
|
2251
|
+
// 执行模板引擎,返回结果对象
|
|
2252
|
+
const result = await execute({
|
|
1664
2253
|
templateName,
|
|
1665
2254
|
outputPath,
|
|
1666
2255
|
command,
|
|
1667
2256
|
});
|
|
2257
|
+
const { outputPath: absoluteOutputPath, templateConfig, context } = result;
|
|
1668
2258
|
|
|
1669
2259
|
timer.logPhase('Template engine execution');
|
|
1670
2260
|
logger.success('Project created successfully!');
|
|
@@ -1685,6 +2275,10 @@ const executeInit = async (
|
|
|
1685
2275
|
}
|
|
1686
2276
|
}
|
|
1687
2277
|
|
|
2278
|
+
// 执行 onComplete 钩子(在 pnpm install 之后)
|
|
2279
|
+
await executeCompleteHook(templateConfig, context, absoluteOutputPath);
|
|
2280
|
+
timer.logPhase('Complete hook execution');
|
|
2281
|
+
|
|
1688
2282
|
// 如果没有跳过 git,则初始化 git 仓库
|
|
1689
2283
|
if (!skipGit) {
|
|
1690
2284
|
runGitInit(absoluteOutputPath);
|
|
@@ -1693,7 +2287,7 @@ const executeInit = async (
|
|
|
1693
2287
|
|
|
1694
2288
|
// 如果没有跳过 dev,则启动开发服务器
|
|
1695
2289
|
if (!skipDev) {
|
|
1696
|
-
|
|
2290
|
+
runDev(absoluteOutputPath);
|
|
1697
2291
|
timer.logPhase('Dev server startup');
|
|
1698
2292
|
} else {
|
|
1699
2293
|
// 只有跳过 dev 时才显示 Next steps
|
|
@@ -1707,7 +2301,7 @@ const executeInit = async (
|
|
|
1707
2301
|
' git init && git add . && git commit -m "initial commit"',
|
|
1708
2302
|
);
|
|
1709
2303
|
}
|
|
1710
|
-
logger.info('
|
|
2304
|
+
logger.info(' coze dev');
|
|
1711
2305
|
}
|
|
1712
2306
|
|
|
1713
2307
|
// 输出总耗时
|
|
@@ -1723,7 +2317,7 @@ const executeInit = async (
|
|
|
1723
2317
|
/**
|
|
1724
2318
|
* 注册 init 命令到 program
|
|
1725
2319
|
*/
|
|
1726
|
-
const registerCommand = program => {
|
|
2320
|
+
const registerCommand$1 = program => {
|
|
1727
2321
|
program
|
|
1728
2322
|
.command('init')
|
|
1729
2323
|
.description('Initialize a new project from a template')
|
|
@@ -1741,14 +2335,312 @@ const registerCommand = program => {
|
|
|
1741
2335
|
});
|
|
1742
2336
|
};
|
|
1743
2337
|
|
|
1744
|
-
|
|
2338
|
+
// ABOUTME: This file implements the update command for coze CLI
|
|
2339
|
+
// ABOUTME: It wraps pnpm update/install to update package dependencies with logging support
|
|
2340
|
+
|
|
2341
|
+
|
|
2342
|
+
|
|
2343
|
+
|
|
2344
|
+
/**
|
|
2345
|
+
* 日志文件名常量
|
|
2346
|
+
*/
|
|
2347
|
+
const LOG_FILE_NAME = 'update.log';
|
|
2348
|
+
|
|
2349
|
+
/**
|
|
2350
|
+
* 获取日志目录
|
|
2351
|
+
* 优先使用环境变量 COZE_LOG_DIR,否则使用 ~/.coze-logs
|
|
2352
|
+
*/
|
|
2353
|
+
const getLogDir = () =>
|
|
2354
|
+
process.env.COZE_LOG_DIR || path.join(os.homedir(), '.coze-logs');
|
|
2355
|
+
|
|
2356
|
+
/**
|
|
2357
|
+
* 解析日志文件路径
|
|
2358
|
+
* - 如果是绝对路径,直接使用
|
|
2359
|
+
* - 如果是相对路径,基于 getLogDir() + 相对路径
|
|
2360
|
+
* - 如果为空,使用 getLogDir() + LOG_FILE_NAME
|
|
2361
|
+
*/
|
|
2362
|
+
const resolveLogFilePath = (logFile) => {
|
|
2363
|
+
if (!logFile) {
|
|
2364
|
+
return path.join(getLogDir(), LOG_FILE_NAME);
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
if (path.isAbsolute(logFile)) {
|
|
2368
|
+
return logFile;
|
|
2369
|
+
}
|
|
2370
|
+
|
|
2371
|
+
return path.join(getLogDir(), logFile);
|
|
2372
|
+
};
|
|
2373
|
+
|
|
2374
|
+
/**
|
|
2375
|
+
* 创建日志写入流
|
|
2376
|
+
*/
|
|
2377
|
+
const createLogStream = (logFilePath) => {
|
|
2378
|
+
const logDir = path.dirname(logFilePath);
|
|
2379
|
+
|
|
2380
|
+
// 确保日志目录存在
|
|
2381
|
+
if (!fs.existsSync(logDir)) {
|
|
2382
|
+
fs.mkdirSync(logDir, { recursive: true });
|
|
2383
|
+
}
|
|
2384
|
+
|
|
2385
|
+
// 使用 'w' 标志覆盖之前的日志
|
|
2386
|
+
return fs.createWriteStream(logFilePath, { flags: 'w' });
|
|
2387
|
+
};
|
|
2388
|
+
|
|
2389
|
+
/**
|
|
2390
|
+
* 格式化时间戳
|
|
2391
|
+
*/
|
|
2392
|
+
const formatTimestamp = () => {
|
|
2393
|
+
const now = new Date();
|
|
2394
|
+
return now.toISOString();
|
|
2395
|
+
};
|
|
2396
|
+
|
|
2397
|
+
/**
|
|
2398
|
+
* 写入带时间戳的日志
|
|
2399
|
+
*/
|
|
2400
|
+
const writeLogWithTimestamp = (stream, message) => {
|
|
2401
|
+
const timestamp = formatTimestamp();
|
|
2402
|
+
const lines = message.split('\n');
|
|
2403
|
+
lines.forEach(line => {
|
|
2404
|
+
if (line) {
|
|
2405
|
+
stream.write(`[${timestamp}] ${line}\n`);
|
|
2406
|
+
} else {
|
|
2407
|
+
stream.write('\n');
|
|
2408
|
+
}
|
|
2409
|
+
});
|
|
2410
|
+
// 确保数据写入磁盘
|
|
2411
|
+
stream.uncork();
|
|
2412
|
+
};
|
|
2413
|
+
|
|
2414
|
+
/**
|
|
2415
|
+
* 同时输出到控制台和日志文件
|
|
2416
|
+
*/
|
|
2417
|
+
const logWithFile = (
|
|
2418
|
+
stream,
|
|
2419
|
+
level,
|
|
2420
|
+
message,
|
|
2421
|
+
) => {
|
|
2422
|
+
// 输出到控制台
|
|
2423
|
+
switch (level) {
|
|
2424
|
+
case 'info':
|
|
2425
|
+
logger.info(message);
|
|
2426
|
+
break;
|
|
2427
|
+
case 'success':
|
|
2428
|
+
logger.success(message);
|
|
2429
|
+
break;
|
|
2430
|
+
case 'error':
|
|
2431
|
+
logger.error(message);
|
|
2432
|
+
break;
|
|
2433
|
+
default:
|
|
2434
|
+
logger.info(message);
|
|
2435
|
+
break;
|
|
2436
|
+
}
|
|
2437
|
+
|
|
2438
|
+
// 写入日志文件(带时间戳)
|
|
2439
|
+
writeLogWithTimestamp(stream, `[${level.toUpperCase()}] ${message}`);
|
|
2440
|
+
};
|
|
2441
|
+
|
|
2442
|
+
// start_aigc
|
|
2443
|
+
/**
|
|
2444
|
+
* 构建 pnpm add 命令
|
|
2445
|
+
*/
|
|
2446
|
+
const buildPnpmCommand = (
|
|
2447
|
+
packageName,
|
|
2448
|
+
options
|
|
2449
|
+
|
|
2450
|
+
|
|
2451
|
+
|
|
2452
|
+
|
|
2453
|
+
,
|
|
2454
|
+
) => {
|
|
2455
|
+
const { global, version, registry, extraArgs } = options;
|
|
2456
|
+
|
|
2457
|
+
const parts = ['pnpm', 'add'];
|
|
2458
|
+
|
|
2459
|
+
// 添加全局标记
|
|
2460
|
+
if (global) {
|
|
2461
|
+
parts.push('-g');
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2464
|
+
// 添加包名和版本
|
|
2465
|
+
if (version && version !== 'latest') {
|
|
2466
|
+
parts.push(`${packageName}@${version}`);
|
|
2467
|
+
} else {
|
|
2468
|
+
parts.push(`${packageName}@latest`);
|
|
2469
|
+
}
|
|
2470
|
+
|
|
2471
|
+
// 添加 registry
|
|
2472
|
+
if (registry) {
|
|
2473
|
+
parts.push(`--registry=${registry}`);
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
// 添加额外参数
|
|
2477
|
+
if (extraArgs.length > 0) {
|
|
2478
|
+
parts.push(...extraArgs);
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2481
|
+
return parts.join(' ');
|
|
2482
|
+
};
|
|
2483
|
+
// end_aigc
|
|
2484
|
+
|
|
2485
|
+
// start_aigc
|
|
2486
|
+
/**
|
|
2487
|
+
* 执行 update 命令的内部实现
|
|
2488
|
+
*/
|
|
2489
|
+
const executeUpdate = (
|
|
2490
|
+
packageName,
|
|
2491
|
+
options
|
|
2492
|
+
|
|
2493
|
+
|
|
2494
|
+
|
|
2495
|
+
|
|
2496
|
+
|
|
2497
|
+
|
|
2498
|
+
,
|
|
2499
|
+
) => {
|
|
2500
|
+
let logStream = null;
|
|
2501
|
+
|
|
2502
|
+
try {
|
|
2503
|
+
const { global, cwd, version, registry, logFile, extraArgs } = options;
|
|
2504
|
+
|
|
2505
|
+
// 准备日志
|
|
2506
|
+
const logFilePath = resolveLogFilePath(logFile);
|
|
2507
|
+
|
|
2508
|
+
// 调试:确认日志路径
|
|
2509
|
+
logger.info(`Log file path resolved to: ${logFilePath}`);
|
|
2510
|
+
|
|
2511
|
+
logStream = createLogStream(logFilePath);
|
|
2512
|
+
|
|
2513
|
+
// 调试:确认流已创建
|
|
2514
|
+
logger.info('Log stream created successfully');
|
|
2515
|
+
|
|
2516
|
+
logWithFile(logStream, 'info', `Updating package: ${packageName}`);
|
|
2517
|
+
|
|
2518
|
+
// 构建命令
|
|
2519
|
+
const command = buildPnpmCommand(packageName, {
|
|
2520
|
+
global,
|
|
2521
|
+
version,
|
|
2522
|
+
registry,
|
|
2523
|
+
extraArgs,
|
|
2524
|
+
});
|
|
2525
|
+
|
|
2526
|
+
// 确定工作目录
|
|
2527
|
+
const workingDir = cwd
|
|
2528
|
+
? path.isAbsolute(cwd)
|
|
2529
|
+
? cwd
|
|
2530
|
+
: path.join(process.cwd(), cwd)
|
|
2531
|
+
: process.cwd();
|
|
2532
|
+
|
|
2533
|
+
logWithFile(logStream, 'info', `Executing: ${command}`);
|
|
2534
|
+
logWithFile(logStream, 'info', `Working directory: ${workingDir}`);
|
|
2535
|
+
logWithFile(logStream, 'info', `Log file: ${logFilePath}`);
|
|
2536
|
+
|
|
2537
|
+
// 记录命令开始时间
|
|
2538
|
+
writeLogWithTimestamp(logStream, '--- Command execution started ---');
|
|
2539
|
+
|
|
2540
|
+
// 同步执行命令
|
|
2541
|
+
const result = shelljs.exec(command, {
|
|
2542
|
+
cwd: workingDir,
|
|
2543
|
+
silent: true, // 使用 silent 来捕获输出
|
|
2544
|
+
});
|
|
2545
|
+
|
|
2546
|
+
// 将输出写入控制台和日志文件(带时间戳)
|
|
2547
|
+
if (result.stdout) {
|
|
2548
|
+
process.stdout.write(result.stdout);
|
|
2549
|
+
writeLogWithTimestamp(logStream, result.stdout.trim());
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2552
|
+
if (result.stderr) {
|
|
2553
|
+
process.stderr.write(result.stderr);
|
|
2554
|
+
writeLogWithTimestamp(logStream, result.stderr.trim());
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
// 记录命令结束时间
|
|
2558
|
+
writeLogWithTimestamp(logStream, '--- Command execution ended ---');
|
|
2559
|
+
|
|
2560
|
+
// 检查执行结果并记录到日志
|
|
2561
|
+
if (result.code === 0) {
|
|
2562
|
+
logWithFile(logStream, 'success', 'Package updated successfully');
|
|
2563
|
+
logWithFile(logStream, 'info', `Log file: ${logFilePath}`);
|
|
2564
|
+
} else {
|
|
2565
|
+
logWithFile(
|
|
2566
|
+
logStream,
|
|
2567
|
+
'error',
|
|
2568
|
+
`Command exited with code ${result.code}`,
|
|
2569
|
+
);
|
|
2570
|
+
logWithFile(
|
|
2571
|
+
logStream,
|
|
2572
|
+
'error',
|
|
2573
|
+
`Check log file for details: ${logFilePath}`,
|
|
2574
|
+
);
|
|
2575
|
+
}
|
|
2576
|
+
|
|
2577
|
+
// 关闭日志流并等待写入完成
|
|
2578
|
+
logStream.end(() => {
|
|
2579
|
+
// 流关闭后再退出进程
|
|
2580
|
+
if (result.code !== 0) {
|
|
2581
|
+
process.exit(result.code || 1);
|
|
2582
|
+
}
|
|
2583
|
+
});
|
|
2584
|
+
} catch (error) {
|
|
2585
|
+
logger.error('Failed to update package:');
|
|
2586
|
+
logger.error(error instanceof Error ? error.message : String(error));
|
|
2587
|
+
|
|
2588
|
+
// 写入错误到日志文件
|
|
2589
|
+
if (logStream) {
|
|
2590
|
+
writeLogWithTimestamp(
|
|
2591
|
+
logStream,
|
|
2592
|
+
`[ERROR] ${error instanceof Error ? error.message : String(error)}`,
|
|
2593
|
+
);
|
|
2594
|
+
// 等待流关闭后再退出
|
|
2595
|
+
logStream.end(() => {
|
|
2596
|
+
process.exit(1);
|
|
2597
|
+
});
|
|
2598
|
+
} else {
|
|
2599
|
+
process.exit(1);
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
};
|
|
2603
|
+
// end_aigc
|
|
2604
|
+
|
|
2605
|
+
/**
|
|
2606
|
+
* 注册 update 命令到 program
|
|
2607
|
+
*/
|
|
2608
|
+
const registerCommand = program => {
|
|
2609
|
+
program
|
|
2610
|
+
.command('update <package>')
|
|
2611
|
+
.description('Update a package dependency')
|
|
2612
|
+
.option('-g, --global', 'Update package globally', false)
|
|
2613
|
+
.option('-c, --cwd <path>', 'Working directory for the update')
|
|
2614
|
+
.option(
|
|
2615
|
+
'--to <version>',
|
|
2616
|
+
'Version to update to (default: latest)',
|
|
2617
|
+
'latest',
|
|
2618
|
+
)
|
|
2619
|
+
.option('--registry <url>', 'Registry URL to use for the update')
|
|
2620
|
+
.option('--log-file <path>', 'Log file path')
|
|
2621
|
+
.allowUnknownOption() // 允许透传参数给 pnpm
|
|
2622
|
+
.action((packageName, options, command) => {
|
|
2623
|
+
// 收集所有未知选项作为额外参数
|
|
2624
|
+
const extraArgs = command.args.slice(1);
|
|
2625
|
+
|
|
2626
|
+
executeUpdate(packageName, {
|
|
2627
|
+
...options,
|
|
2628
|
+
version: options.to, // 将 --to 映射到 version
|
|
2629
|
+
extraArgs,
|
|
2630
|
+
});
|
|
2631
|
+
});
|
|
2632
|
+
};
|
|
2633
|
+
|
|
2634
|
+
var version = "0.0.1-alpha.e02657";
|
|
1745
2635
|
var packageJson = {
|
|
1746
2636
|
version: version};
|
|
1747
2637
|
|
|
1748
2638
|
const commands = [
|
|
1749
|
-
registerCommand,
|
|
1750
2639
|
registerCommand$1,
|
|
1751
2640
|
registerCommand$2,
|
|
2641
|
+
registerCommand$4,
|
|
2642
|
+
registerCommand$3,
|
|
2643
|
+
registerCommand,
|
|
1752
2644
|
];
|
|
1753
2645
|
|
|
1754
2646
|
const main = () => {
|