@coze-arch/cli 0.0.1-alpha.351659 → 0.0.1-alpha.400852
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 +220 -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 +45 -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/_layout.tsx +14 -14
- 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/ThemedText.tsx +33 -0
- package/lib/__templates__/expo/client/components/ThemedView.tsx +38 -0
- package/lib/__templates__/expo/client/constants/theme.ts +786 -50
- package/lib/__templates__/expo/client/declarations.d.ts +5 -0
- package/lib/__templates__/expo/{eslint.config.mjs → client/eslint.config.mjs} +13 -10
- package/lib/__templates__/expo/client/hooks/useColorScheme.ts +34 -1
- 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 +93 -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 +2486 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/rule.js +155 -0
- package/lib/__templates__/expo/package.json +13 -103
- package/lib/__templates__/expo/pnpm-lock.yaml +451 -867
- 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 +19 -0
- package/lib/__templates__/expo/server/tsconfig.json +24 -0
- package/lib/__templates__/expo/template.config.js +1 -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 +2486 -1707
- package/lib/__templates__/nextjs/scripts/dev.sh +7 -26
- 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 +35 -23
- 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 +30 -0
- package/lib/__templates__/templates.json +61 -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/dev.sh +7 -26
- package/lib/__templates__/vite/scripts/prepare.sh +9 -0
- package/lib/__templates__/vite/src/main.ts +1 -2
- package/lib/__templates__/vite/template.config.js +30 -4
- package/lib/__templates__/vite/vite.config.ts +3 -3
- package/lib/cli.js +443 -62
- 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/app/+not-found.tsx +0 -79
- 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$3 = 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
|
+
|
|
827
831
|
|
|
828
832
|
/**
|
|
829
|
-
*
|
|
833
|
+
* 检查是否为 Next.js 项目
|
|
830
834
|
*/
|
|
831
|
-
const
|
|
832
|
-
const
|
|
833
|
-
|
|
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
|
+
};
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* 查找 Next.js 配置文件
|
|
858
|
+
*/
|
|
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
|
+
};
|
|
875
|
+
|
|
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);
|
|
837
926
|
|
|
838
|
-
|
|
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$2 = 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 = 'dev.log';
|
|
1056
|
+
|
|
1057
|
+
/**
|
|
1058
|
+
* 获取日志目录
|
|
1059
|
+
* 优先使用环境变量 COZE_LOG_DIR,否则使用 ~/.coze-logs
|
|
1060
|
+
*/
|
|
1061
|
+
const getLogDir = () =>
|
|
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 = (logFile) => {
|
|
1071
|
+
if (!logFile) {
|
|
1072
|
+
return path.join(getLogDir(), LOG_FILE_NAME);
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
if (path.isAbsolute(logFile)) {
|
|
1076
|
+
return logFile;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
return path.join(getLogDir(), logFile);
|
|
1080
|
+
};
|
|
1081
|
+
|
|
1082
|
+
/**
|
|
1083
|
+
* 创建日志写入流
|
|
1084
|
+
*/
|
|
1085
|
+
const createLogStream = (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 (commandName === 'build') {
|
|
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(options.logFile);
|
|
1125
|
+
const logStream = createLogStream(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
|
|
|
@@ -1248,17 +1508,139 @@ const convertDotfileName = (filePath) => {
|
|
|
1248
1508
|
};
|
|
1249
1509
|
|
|
1250
1510
|
/**
|
|
1251
|
-
*
|
|
1511
|
+
* 执行文件渲染钩子
|
|
1252
1512
|
*
|
|
1253
|
-
* @param
|
|
1254
|
-
* @param
|
|
1513
|
+
* @param templateConfig - 模板配置
|
|
1514
|
+
* @param fileInfo - 文件渲染信息
|
|
1255
1515
|
* @param context - 模板上下文
|
|
1516
|
+
* @returns 处理后的文件信息,或 null 表示跳过该文件
|
|
1256
1517
|
*/
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1259
|
-
|
|
1518
|
+
const executeFileRenderHook = async (
|
|
1519
|
+
templateConfig,
|
|
1520
|
+
fileInfo,
|
|
1260
1521
|
context,
|
|
1261
1522
|
) => {
|
|
1523
|
+
if (!templateConfig.onFileRender) {
|
|
1524
|
+
return fileInfo;
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
const result = await templateConfig.onFileRender(
|
|
1528
|
+
fileInfo,
|
|
1529
|
+
context,
|
|
1530
|
+
);
|
|
1531
|
+
|
|
1532
|
+
// false: 跳过文件
|
|
1533
|
+
if (result === false) {
|
|
1534
|
+
return null;
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
// undefined/void: 使用默认内容
|
|
1538
|
+
if (result === undefined || result === null) {
|
|
1539
|
+
return fileInfo;
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
// string: 作为 content,其他不变
|
|
1543
|
+
if (typeof result === 'string') {
|
|
1544
|
+
return {
|
|
1545
|
+
...fileInfo,
|
|
1546
|
+
content: result,
|
|
1547
|
+
};
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
// FileRenderInfo: 使用新对象的信息
|
|
1551
|
+
return result;
|
|
1552
|
+
};
|
|
1553
|
+
|
|
1554
|
+
/**
|
|
1555
|
+
* 处理单个文件
|
|
1556
|
+
*/
|
|
1557
|
+
const processSingleFile = async (options
|
|
1558
|
+
|
|
1559
|
+
|
|
1560
|
+
|
|
1561
|
+
|
|
1562
|
+
|
|
1563
|
+
) => {
|
|
1564
|
+
const { file, templatePath, outputPath, context, templateConfig } = options;
|
|
1565
|
+
|
|
1566
|
+
const srcPath = path.join(templatePath, file);
|
|
1567
|
+
const destFile = convertDotfileName(file);
|
|
1568
|
+
|
|
1569
|
+
logger.verbose(
|
|
1570
|
+
` - Processing: ${file}${destFile !== file ? ` -> ${destFile}` : ''}`,
|
|
1571
|
+
);
|
|
1572
|
+
|
|
1573
|
+
// 判断是否为二进制文件
|
|
1574
|
+
const isBinary = !shouldRenderFile(srcPath);
|
|
1575
|
+
let content;
|
|
1576
|
+
let wasRendered = false;
|
|
1577
|
+
|
|
1578
|
+
if (isBinary) {
|
|
1579
|
+
// 二进制文件,读取为 buffer 然后转为 base64
|
|
1580
|
+
const buffer = await fs$1.readFile(srcPath);
|
|
1581
|
+
content = buffer.toString('base64');
|
|
1582
|
+
} else {
|
|
1583
|
+
// 文本文件,渲染后的内容
|
|
1584
|
+
content = await renderTemplate(srcPath, context);
|
|
1585
|
+
wasRendered = true;
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
// 构造文件信息对象
|
|
1589
|
+
const fileInfo = {
|
|
1590
|
+
path: file,
|
|
1591
|
+
destPath: destFile,
|
|
1592
|
+
content,
|
|
1593
|
+
isBinary,
|
|
1594
|
+
wasRendered,
|
|
1595
|
+
};
|
|
1596
|
+
|
|
1597
|
+
// 执行文件渲染钩子
|
|
1598
|
+
const processedFileInfo = await executeFileRenderHook(
|
|
1599
|
+
templateConfig,
|
|
1600
|
+
fileInfo,
|
|
1601
|
+
context,
|
|
1602
|
+
);
|
|
1603
|
+
|
|
1604
|
+
// 如果返回 null,跳过该文件
|
|
1605
|
+
if (processedFileInfo === null) {
|
|
1606
|
+
logger.verbose(' ⊘ Skipped by onFileRender hook');
|
|
1607
|
+
return;
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
// 使用处理后的目标路径
|
|
1611
|
+
const finalDestPath = path.join(outputPath, processedFileInfo.destPath);
|
|
1612
|
+
|
|
1613
|
+
// 确保目标目录存在
|
|
1614
|
+
await ensureDir(path.dirname(finalDestPath));
|
|
1615
|
+
|
|
1616
|
+
// 写入文件
|
|
1617
|
+
if (processedFileInfo.isBinary) {
|
|
1618
|
+
// 二进制文件:如果内容没变,直接复制;否则从 base64 解码写入
|
|
1619
|
+
if (processedFileInfo.content === content) {
|
|
1620
|
+
await fs$1.copyFile(srcPath, finalDestPath);
|
|
1621
|
+
logger.verbose(' ✓ Copied (binary)');
|
|
1622
|
+
} else {
|
|
1623
|
+
const buffer = Buffer.from(processedFileInfo.content, 'base64');
|
|
1624
|
+
await fs$1.writeFile(finalDestPath, buffer);
|
|
1625
|
+
logger.verbose(' ✓ Written (binary, modified by hook)');
|
|
1626
|
+
}
|
|
1627
|
+
} else {
|
|
1628
|
+
// 文本文件
|
|
1629
|
+
await fs$1.writeFile(finalDestPath, processedFileInfo.content, 'utf-8');
|
|
1630
|
+
logger.verbose(' ✓ Rendered and written');
|
|
1631
|
+
}
|
|
1632
|
+
};
|
|
1633
|
+
|
|
1634
|
+
/**
|
|
1635
|
+
* 复制并处理模板文件到目标目录
|
|
1636
|
+
*/
|
|
1637
|
+
const processTemplateFiles = async (options
|
|
1638
|
+
|
|
1639
|
+
|
|
1640
|
+
|
|
1641
|
+
|
|
1642
|
+
) => {
|
|
1643
|
+
const { templatePath, outputPath, context, templateConfig } = options;
|
|
1262
1644
|
logger.verbose('Processing template files:');
|
|
1263
1645
|
logger.verbose(` - Template path: ${templatePath}`);
|
|
1264
1646
|
logger.verbose(` - Output path: ${outputPath}`);
|
|
@@ -1289,29 +1671,15 @@ const processTemplateFiles = async (
|
|
|
1289
1671
|
}
|
|
1290
1672
|
|
|
1291
1673
|
await Promise.all(
|
|
1292
|
-
files.map(
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
)
|
|
1300
|
-
|
|
1301
|
-
// 确保目标目录存在
|
|
1302
|
-
await ensureDir(path.dirname(destPath));
|
|
1303
|
-
|
|
1304
|
-
if (shouldRenderFile(srcPath)) {
|
|
1305
|
-
// 渲染文本文件
|
|
1306
|
-
const rendered = await renderTemplate(srcPath, context);
|
|
1307
|
-
await fs$1.writeFile(destPath, rendered, 'utf-8');
|
|
1308
|
-
logger.verbose(' ✓ Rendered and written');
|
|
1309
|
-
} else {
|
|
1310
|
-
// 直接复制二进制文件
|
|
1311
|
-
await fs$1.copyFile(srcPath, destPath);
|
|
1312
|
-
logger.verbose(' ✓ Copied');
|
|
1313
|
-
}
|
|
1314
|
-
}),
|
|
1674
|
+
files.map(file =>
|
|
1675
|
+
processSingleFile({
|
|
1676
|
+
file,
|
|
1677
|
+
templatePath,
|
|
1678
|
+
outputPath,
|
|
1679
|
+
context,
|
|
1680
|
+
templateConfig,
|
|
1681
|
+
}),
|
|
1682
|
+
),
|
|
1315
1683
|
);
|
|
1316
1684
|
|
|
1317
1685
|
logger.verbose('✓ All files processed successfully');
|
|
@@ -1498,7 +1866,12 @@ const execute = async (
|
|
|
1498
1866
|
const absoluteOutputPath = await prepareOutputDirectory(outputPath);
|
|
1499
1867
|
|
|
1500
1868
|
// 6. 处理模板文件
|
|
1501
|
-
await processTemplateFiles(
|
|
1869
|
+
await processTemplateFiles({
|
|
1870
|
+
templatePath,
|
|
1871
|
+
outputPath: absoluteOutputPath,
|
|
1872
|
+
context,
|
|
1873
|
+
templateConfig,
|
|
1874
|
+
});
|
|
1502
1875
|
|
|
1503
1876
|
// 7. 执行 onAfterRender 钩子
|
|
1504
1877
|
await executeAfterRenderHook(templateConfig, context, absoluteOutputPath);
|
|
@@ -1611,13 +1984,20 @@ const runGitInit = (projectPath) => {
|
|
|
1611
1984
|
/**
|
|
1612
1985
|
* 运行开发服务器(后台模式)
|
|
1613
1986
|
* 启动后台子进程运行开发服务器,父进程可以直接退出
|
|
1987
|
+
* 使用 CLI 自己的 dev 命令(定义在 run.ts)而不是直接运行 npm run dev
|
|
1614
1988
|
*/
|
|
1615
|
-
const
|
|
1989
|
+
const runDev = (projectPath) => {
|
|
1616
1990
|
logger.info('\nStarting development server in background...');
|
|
1617
|
-
|
|
1991
|
+
|
|
1992
|
+
// 获取当前 CLI 的可执行文件路径
|
|
1993
|
+
// process.argv[0] 是 node,process.argv[1] 是 CLI 入口文件
|
|
1994
|
+
const cliPath = process.argv[1];
|
|
1995
|
+
|
|
1996
|
+
logger.info(`Executing: ${cliPath} dev in ${projectPath}`);
|
|
1618
1997
|
|
|
1619
1998
|
// 使用通用的后台执行函数启动开发服务器
|
|
1620
|
-
|
|
1999
|
+
// 调用 CLI 自己的 dev 命令
|
|
2000
|
+
const pid = spawnDetached(process.argv[0], [cliPath, 'dev'], {
|
|
1621
2001
|
cwd: projectPath,
|
|
1622
2002
|
verbose: false, // 不输出额外的进程信息,由 logger 统一处理
|
|
1623
2003
|
});
|
|
@@ -1693,7 +2073,7 @@ const executeInit = async (
|
|
|
1693
2073
|
|
|
1694
2074
|
// 如果没有跳过 dev,则启动开发服务器
|
|
1695
2075
|
if (!skipDev) {
|
|
1696
|
-
|
|
2076
|
+
runDev(absoluteOutputPath);
|
|
1697
2077
|
timer.logPhase('Dev server startup');
|
|
1698
2078
|
} else {
|
|
1699
2079
|
// 只有跳过 dev 时才显示 Next steps
|
|
@@ -1707,7 +2087,7 @@ const executeInit = async (
|
|
|
1707
2087
|
' git init && git add . && git commit -m "initial commit"',
|
|
1708
2088
|
);
|
|
1709
2089
|
}
|
|
1710
|
-
logger.info('
|
|
2090
|
+
logger.info(' coze dev');
|
|
1711
2091
|
}
|
|
1712
2092
|
|
|
1713
2093
|
// 输出总耗时
|
|
@@ -1741,13 +2121,14 @@ const registerCommand = program => {
|
|
|
1741
2121
|
});
|
|
1742
2122
|
};
|
|
1743
2123
|
|
|
1744
|
-
var version = "0.0.1-alpha.
|
|
2124
|
+
var version = "0.0.1-alpha.400852";
|
|
1745
2125
|
var packageJson = {
|
|
1746
2126
|
version: version};
|
|
1747
2127
|
|
|
1748
2128
|
const commands = [
|
|
1749
2129
|
registerCommand,
|
|
1750
2130
|
registerCommand$1,
|
|
2131
|
+
registerCommand$3,
|
|
1751
2132
|
registerCommand$2,
|
|
1752
2133
|
];
|
|
1753
2134
|
|
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.400852",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "coze coding devtools cli",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,12 +19,13 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"prebuild": "tsx scripts/prebuild.ts",
|
|
21
21
|
"build": "tsx scripts/build.ts",
|
|
22
|
+
"create": "tsx scripts/create-template.ts",
|
|
22
23
|
"lint": "eslint ./ --cache",
|
|
23
24
|
"postpublish": "bash scripts/sync-npmmirror.sh",
|
|
24
25
|
"test": "vitest --run --passWithNoTests",
|
|
25
26
|
"test:all": "bash scripts/test-coverage.sh",
|
|
26
27
|
"test:cov": "vitest --run --passWithNoTests --coverage",
|
|
27
|
-
"test:e2e": "bash scripts/e2e.sh",
|
|
28
|
+
"test:e2e": "NODE_ENV=test bash scripts/e2e.sh",
|
|
28
29
|
"test:perf": "vitest bench --run --config vitest.perf.config.ts",
|
|
29
30
|
"test:perf:compare": "bash scripts/compare-perf.sh",
|
|
30
31
|
"test:perf:save": "bash scripts/run-perf-with-output.sh"
|
|
@@ -48,21 +49,25 @@
|
|
|
48
49
|
"@coze-arch/ts-config": "workspace:*",
|
|
49
50
|
"@coze-arch/vitest-config": "workspace:*",
|
|
50
51
|
"@coze-coding/lambda": "workspace:*",
|
|
52
|
+
"@inquirer/prompts": "^3.2.0",
|
|
51
53
|
"@types/ejs": "^3.1.5",
|
|
52
54
|
"@types/iarna__toml": "^2.0.5",
|
|
53
55
|
"@types/js-yaml": "^4.0.9",
|
|
56
|
+
"@types/minimatch": "^5.1.2",
|
|
54
57
|
"@types/minimist": "^1.2.5",
|
|
55
58
|
"@types/node": "^24",
|
|
56
59
|
"@types/shelljs": "^0.10.0",
|
|
57
60
|
"@vitest/coverage-v8": "~4.0.16",
|
|
58
61
|
"json-schema-to-typescript": "^15.0.3",
|
|
62
|
+
"minimatch": "^10.0.1",
|
|
59
63
|
"rollup": "^4.41.1",
|
|
60
64
|
"sucrase": "^3.35.0",
|
|
61
65
|
"tsx": "^4.20.6",
|
|
62
66
|
"vitest": "~4.0.16"
|
|
63
67
|
},
|
|
64
68
|
"publishConfig": {
|
|
65
|
-
"access": "public"
|
|
69
|
+
"access": "public",
|
|
70
|
+
"registry": "https://registry.npmjs.org"
|
|
66
71
|
},
|
|
67
72
|
"cozePublishConfig": {
|
|
68
73
|
"bin": {
|