@coze-arch/cli 0.0.1-alpha.ee5d83 → 0.0.1-alpha.f11735
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 +10 -10
- package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +2 -2
- package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +2 -2
- package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +45 -0
- package/lib/__templates__/expo/README.md +2 -0
- package/lib/__templates__/expo/client/app/_layout.tsx +15 -12
- package/lib/__templates__/expo/client/app/index.tsx +1 -1
- package/lib/__templates__/expo/client/app.config.ts +4 -3
- package/lib/__templates__/expo/client/components/Screen.tsx +1 -17
- package/lib/__templates__/expo/client/components/ThemedView.tsx +1 -2
- package/lib/__templates__/expo/client/constants/theme.ts +21 -698
- package/lib/__templates__/expo/client/declarations.d.ts +5 -0
- package/lib/__templates__/expo/client/eslint.config.mjs +17 -10
- package/lib/__templates__/expo/client/hooks/{useColorScheme.ts → useColorScheme.tsx} +20 -6
- package/lib/__templates__/expo/client/hooks/useTheme.ts +26 -6
- package/lib/__templates__/expo/client/screens/{home → demo}/index.tsx +1 -1
- package/lib/__templates__/expo/client/scripts/install-missing-deps.js +1 -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/reanimated/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/reanimated/rule.js +88 -0
- package/lib/__templates__/expo/server/build.js +21 -0
- package/lib/__templates__/expo/server/package.json +2 -2
- package/lib/__templates__/expo/server/src/index.ts +2 -1
- package/lib/__templates__/nextjs/.babelrc +15 -0
- package/lib/__templates__/nextjs/next.config.ts +2 -2
- package/lib/__templates__/nextjs/package.json +9 -1
- package/lib/__templates__/nextjs/pnpm-lock.yaml +2485 -1714
- package/lib/__templates__/nextjs/src/app/layout.tsx +5 -3
- package/lib/__templates__/nextjs/src/app/page.tsx +2 -2
- package/lib/__templates__/nextjs/template.config.js +5 -5
- package/lib/__templates__/vite/package.json +6 -1
- package/lib/__templates__/vite/pnpm-lock.yaml +504 -982
- package/lib/__templates__/vite/src/main.ts +1 -2
- package/lib/__templates__/vite/template.config.js +6 -4
- package/lib/cli.js +258 -14
- package/package.json +1 -1
- package/lib/__templates__/expo/client/app/home.tsx +0 -1
- /package/lib/__templates__/expo/client/screens/{home → demo}/styles.ts +0 -0
|
@@ -13,8 +13,7 @@ export function initApp(): void {
|
|
|
13
13
|
<!-- 头部:Logo 和 产品名称 -->
|
|
14
14
|
<div class="flex items-center gap-3">
|
|
15
15
|
<img
|
|
16
|
-
|
|
17
|
-
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/hkpzboz/coze_logo.png"
|
|
16
|
+
src="https://lf-coze-web-cdn.coze.cn/obj/eden-cn/lm-lgvj/ljhwZthlaukjlkulzlp/favicon.svg"
|
|
18
17
|
alt="扣子编程 Logo"
|
|
19
18
|
width="40"
|
|
20
19
|
height="40"
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
|
|
3
5
|
|
|
4
6
|
|
|
5
7
|
|
|
@@ -75,10 +77,10 @@ const config = {
|
|
|
75
77
|
console.log(`${cmd}`);
|
|
76
78
|
try {
|
|
77
79
|
const projectRoot = resolve(outputPath);
|
|
78
|
-
execSync(cmd, {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
80
|
+
// execSync(cmd, {
|
|
81
|
+
// cwd: projectRoot,
|
|
82
|
+
// stdio: 'inherit',
|
|
83
|
+
// });
|
|
82
84
|
console.log('✓ coze-coding-dev-sdk updated successfully');
|
|
83
85
|
} catch (error) {
|
|
84
86
|
console.error('✗ Failed to update coze-coding-dev-sdk:', error);
|
package/lib/cli.js
CHANGED
|
@@ -8,8 +8,8 @@ var shelljs = require('shelljs');
|
|
|
8
8
|
var perf_hooks = require('perf_hooks');
|
|
9
9
|
var fs$1 = require('fs/promises');
|
|
10
10
|
var os = require('os');
|
|
11
|
-
var toml = require('@iarna/toml');
|
|
12
11
|
var jsYaml = require('js-yaml');
|
|
12
|
+
var toml = require('@iarna/toml');
|
|
13
13
|
var child_process = require('child_process');
|
|
14
14
|
var addFormats = require('ajv-formats');
|
|
15
15
|
var Ajv = require('ajv');
|
|
@@ -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,8 +823,232 @@ 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
|
+
};
|
|
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;
|
|
870
|
+
}
|
|
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);
|
|
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);
|
|
827
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
|
+
}
|
|
950
|
+
|
|
951
|
+
return {
|
|
952
|
+
ruleName,
|
|
953
|
+
applied: false,
|
|
954
|
+
message: 'No outputFileTracingRoot config found, skipping',
|
|
955
|
+
};
|
|
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; }
|
|
828
1052
|
/**
|
|
829
1053
|
* 日志文件名常量
|
|
830
1054
|
*/
|
|
@@ -880,15 +1104,27 @@ const executeRun = async (
|
|
|
880
1104
|
try {
|
|
881
1105
|
logger.info(`Running ${commandName} command...`);
|
|
882
1106
|
|
|
883
|
-
// 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 配置
|
|
884
1120
|
const config = await loadCozeConfig();
|
|
885
1121
|
const commandArgs = getCommandConfig(config, commandName);
|
|
886
1122
|
|
|
887
|
-
//
|
|
1123
|
+
// 3. 准备日志
|
|
888
1124
|
const logFilePath = resolveLogFilePath(options.logFile);
|
|
889
1125
|
const logStream = createLogStream(logFilePath);
|
|
890
1126
|
|
|
891
|
-
//
|
|
1127
|
+
// 4. 执行命令
|
|
892
1128
|
const commandString = commandArgs.join(' ');
|
|
893
1129
|
|
|
894
1130
|
logger.info(`Executing: ${commandString}`);
|
|
@@ -1748,13 +1984,20 @@ const runGitInit = (projectPath) => {
|
|
|
1748
1984
|
/**
|
|
1749
1985
|
* 运行开发服务器(后台模式)
|
|
1750
1986
|
* 启动后台子进程运行开发服务器,父进程可以直接退出
|
|
1987
|
+
* 使用 CLI 自己的 dev 命令(定义在 run.ts)而不是直接运行 npm run dev
|
|
1751
1988
|
*/
|
|
1752
|
-
const
|
|
1989
|
+
const runDev = (projectPath) => {
|
|
1753
1990
|
logger.info('\nStarting development server in background...');
|
|
1754
|
-
|
|
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}`);
|
|
1755
1997
|
|
|
1756
1998
|
// 使用通用的后台执行函数启动开发服务器
|
|
1757
|
-
|
|
1999
|
+
// 调用 CLI 自己的 dev 命令
|
|
2000
|
+
const pid = spawnDetached(process.argv[0], [cliPath, 'dev'], {
|
|
1758
2001
|
cwd: projectPath,
|
|
1759
2002
|
verbose: false, // 不输出额外的进程信息,由 logger 统一处理
|
|
1760
2003
|
});
|
|
@@ -1830,7 +2073,7 @@ const executeInit = async (
|
|
|
1830
2073
|
|
|
1831
2074
|
// 如果没有跳过 dev,则启动开发服务器
|
|
1832
2075
|
if (!skipDev) {
|
|
1833
|
-
|
|
2076
|
+
runDev(absoluteOutputPath);
|
|
1834
2077
|
timer.logPhase('Dev server startup');
|
|
1835
2078
|
} else {
|
|
1836
2079
|
// 只有跳过 dev 时才显示 Next steps
|
|
@@ -1844,7 +2087,7 @@ const executeInit = async (
|
|
|
1844
2087
|
' git init && git add . && git commit -m "initial commit"',
|
|
1845
2088
|
);
|
|
1846
2089
|
}
|
|
1847
|
-
logger.info('
|
|
2090
|
+
logger.info(' coze dev');
|
|
1848
2091
|
}
|
|
1849
2092
|
|
|
1850
2093
|
// 输出总耗时
|
|
@@ -1878,13 +2121,14 @@ const registerCommand = program => {
|
|
|
1878
2121
|
});
|
|
1879
2122
|
};
|
|
1880
2123
|
|
|
1881
|
-
var version = "0.0.1-alpha.
|
|
2124
|
+
var version = "0.0.1-alpha.f11735";
|
|
1882
2125
|
var packageJson = {
|
|
1883
2126
|
version: version};
|
|
1884
2127
|
|
|
1885
2128
|
const commands = [
|
|
1886
2129
|
registerCommand,
|
|
1887
2130
|
registerCommand$1,
|
|
2131
|
+
registerCommand$3,
|
|
1888
2132
|
registerCommand$2,
|
|
1889
2133
|
];
|
|
1890
2134
|
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@/screens/home'
|
|
File without changes
|