@coze-arch/cli 0.0.30-alpha.37325a → 0.0.30
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/cli.js +33 -83
- package/package.json +1 -1
package/lib/cli.js
CHANGED
|
@@ -2107,7 +2107,7 @@ const EventBuilder = {
|
|
|
2107
2107
|
};
|
|
2108
2108
|
|
|
2109
2109
|
var name = "@coze-arch/cli";
|
|
2110
|
-
var version = "0.0.30
|
|
2110
|
+
var version = "0.0.30";
|
|
2111
2111
|
var description = "coze coding devtools cli";
|
|
2112
2112
|
var license = "MIT";
|
|
2113
2113
|
var author = "fanwenjie.fe@bytedance.com";
|
|
@@ -2598,9 +2598,7 @@ const getTemplatesDir = () => {
|
|
|
2598
2598
|
* @returns 模板配置对象
|
|
2599
2599
|
*/
|
|
2600
2600
|
|
|
2601
|
-
const loadTemplateConfig = async (
|
|
2602
|
-
templatePath,
|
|
2603
|
-
) => {
|
|
2601
|
+
const loadTemplateConfig = async ( templatePath) => {
|
|
2604
2602
|
logger.verbose(`Loading template config from: ${templatePath}`);
|
|
2605
2603
|
|
|
2606
2604
|
const tsConfigPath = path.join(templatePath, 'template.config.ts');
|
|
@@ -2632,15 +2630,12 @@ const loadTemplateConfig = async (
|
|
|
2632
2630
|
} else if (jsExists) {
|
|
2633
2631
|
configPath = jsConfigPath;
|
|
2634
2632
|
} else {
|
|
2635
|
-
throw new Error(
|
|
2636
|
-
`Template config not found in ${templatePath}.\n` +
|
|
2637
|
-
'Expected: template.config.ts or template.config.js',
|
|
2638
|
-
);
|
|
2633
|
+
throw new Error(`Template config not found in ${templatePath}.\n` + 'Expected: template.config.ts or template.config.js');
|
|
2639
2634
|
}
|
|
2640
2635
|
|
|
2641
2636
|
logger.verbose(`Using config file: ${configPath}`);
|
|
2642
2637
|
|
|
2643
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
2638
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports -- Sucrase handles .ts files at runtime, path is validated above
|
|
2644
2639
|
const config = require(configPath);
|
|
2645
2640
|
|
|
2646
2641
|
logger.verbose('Template config loaded successfully');
|
|
@@ -2654,18 +2649,14 @@ const loadTemplateConfig = async (
|
|
|
2654
2649
|
* @param configPath - templates.json 配置文件路径
|
|
2655
2650
|
* @returns 模板列表配置
|
|
2656
2651
|
*/
|
|
2657
|
-
const loadTemplatesConfig = async (
|
|
2658
|
-
configPath,
|
|
2659
|
-
) => {
|
|
2652
|
+
const loadTemplatesConfig = async (configPath) => {
|
|
2660
2653
|
logger.verbose(`Loading templates config from: ${configPath}`);
|
|
2661
2654
|
|
|
2662
2655
|
const content = await fs$1.readFile(configPath, 'utf-8');
|
|
2663
2656
|
// eslint-disable-next-line no-restricted-syntax -- Static config file loaded at build time, safeJsonParse not needed
|
|
2664
2657
|
const config = JSON.parse(content) ;
|
|
2665
2658
|
|
|
2666
|
-
logger.verbose(
|
|
2667
|
-
`Found ${config.templates.length} templates: ${config.templates.map(t => t.name).join(', ')}`,
|
|
2668
|
-
);
|
|
2659
|
+
logger.verbose(`Found ${config.templates.length} templates: ${config.templates.map(t => t.name).join(', ')}`);
|
|
2669
2660
|
|
|
2670
2661
|
return config;
|
|
2671
2662
|
};
|
|
@@ -2677,20 +2668,13 @@ const loadTemplatesConfig = async (
|
|
|
2677
2668
|
* @param templateName - 模板名称
|
|
2678
2669
|
* @returns 模板元信息
|
|
2679
2670
|
*/
|
|
2680
|
-
const findTemplate = (
|
|
2681
|
-
templatesConfig,
|
|
2682
|
-
templateName,
|
|
2683
|
-
) => {
|
|
2671
|
+
const findTemplate = (templatesConfig, templateName) => {
|
|
2684
2672
|
const template = templatesConfig.templates.find(t => t.name === templateName);
|
|
2685
2673
|
|
|
2686
2674
|
if (!template) {
|
|
2687
|
-
const availableTemplates = templatesConfig.templates
|
|
2688
|
-
.map(t => t.name)
|
|
2689
|
-
.join(', ');
|
|
2675
|
+
const availableTemplates = templatesConfig.templates.map(t => t.name).join(', ');
|
|
2690
2676
|
throw new Error(
|
|
2691
|
-
`Template "${templateName}" not found.\n` +
|
|
2692
|
-
`Available templates: ${availableTemplates}\n` +
|
|
2693
|
-
'Use --template <name> to specify a template.',
|
|
2677
|
+
`Template "${templateName}" not found.\n` + `Available templates: ${availableTemplates}\n` + 'Use --template <name> to specify a template.',
|
|
2694
2678
|
);
|
|
2695
2679
|
}
|
|
2696
2680
|
|
|
@@ -2704,10 +2688,7 @@ const findTemplate = (
|
|
|
2704
2688
|
* @param templateMetadata - 模板元信息
|
|
2705
2689
|
* @returns 模板完整路径
|
|
2706
2690
|
*/
|
|
2707
|
-
const getTemplatePath = async (
|
|
2708
|
-
basePath,
|
|
2709
|
-
templateMetadata,
|
|
2710
|
-
) => {
|
|
2691
|
+
const getTemplatePath = async (basePath, templateMetadata) => {
|
|
2711
2692
|
logger.verbose('Resolving template path:');
|
|
2712
2693
|
logger.verbose(` - Base path: ${basePath}`);
|
|
2713
2694
|
logger.verbose(` - Template location: ${templateMetadata.location}`);
|
|
@@ -2722,9 +2703,7 @@ const getTemplatePath = async (
|
|
|
2722
2703
|
logger.verbose(' - Template directory exists: ✓');
|
|
2723
2704
|
} catch (error) {
|
|
2724
2705
|
logger.error(' - Template directory does not exist: ✗');
|
|
2725
|
-
throw new Error(
|
|
2726
|
-
`Template directory not found: ${templatePath} (cause: ${error instanceof Error ? error.message : String(error)})`,
|
|
2727
|
-
);
|
|
2706
|
+
throw new Error(`Template directory not found: ${templatePath} (cause: ${error instanceof Error ? error.message : String(error)})`);
|
|
2728
2707
|
}
|
|
2729
2708
|
|
|
2730
2709
|
return templatePath;
|
|
@@ -2739,7 +2718,6 @@ const warmupTemplate = (templatePath, templateName) => {
|
|
|
2739
2718
|
|
|
2740
2719
|
// 检查是否存在 package.json
|
|
2741
2720
|
const packageJsonPath = node_path.join(templatePath, 'package.json');
|
|
2742
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
2743
2721
|
if (!node_fs.existsSync(packageJsonPath)) {
|
|
2744
2722
|
logger.info(` ⊘ Skipping ${templateName} (no package.json found)`);
|
|
2745
2723
|
return;
|
|
@@ -2791,30 +2769,22 @@ const executeWarmup = async (options) => {
|
|
|
2791
2769
|
const configPath = getTemplatesConfigPath();
|
|
2792
2770
|
const templatesConfig = await loadTemplatesConfig(configPath);
|
|
2793
2771
|
|
|
2794
|
-
logger.verbose(
|
|
2795
|
-
`Found ${templatesConfig.templates.length} templates in config`,
|
|
2796
|
-
);
|
|
2772
|
+
logger.verbose(`Found ${templatesConfig.templates.length} templates in config`);
|
|
2797
2773
|
|
|
2798
2774
|
// 过滤模板
|
|
2799
|
-
const templatesToWarmup = templateFilter
|
|
2800
|
-
? templatesConfig.templates.filter(t => t.name === templateFilter)
|
|
2801
|
-
: templatesConfig.templates;
|
|
2775
|
+
const templatesToWarmup = templateFilter ? templatesConfig.templates.filter(t => t.name === templateFilter) : templatesConfig.templates;
|
|
2802
2776
|
|
|
2803
2777
|
if (templatesToWarmup.length === 0) {
|
|
2804
2778
|
if (templateFilter) {
|
|
2805
2779
|
logger.warn(`Template "${templateFilter}" not found`);
|
|
2806
|
-
logger.info(
|
|
2807
|
-
`Available templates: ${templatesConfig.templates.map(t => t.name).join(', ')}`,
|
|
2808
|
-
);
|
|
2780
|
+
logger.info(`Available templates: ${templatesConfig.templates.map(t => t.name).join(', ')}`);
|
|
2809
2781
|
} else {
|
|
2810
2782
|
logger.warn('No templates found');
|
|
2811
2783
|
}
|
|
2812
2784
|
return;
|
|
2813
2785
|
}
|
|
2814
2786
|
|
|
2815
|
-
logger.info(
|
|
2816
|
-
`\nWill warm up ${templatesToWarmup.length} template(s): ${templatesToWarmup.map(t => t.name).join(', ')}`,
|
|
2817
|
-
);
|
|
2787
|
+
logger.info(`\nWill warm up ${templatesToWarmup.length} template(s): ${templatesToWarmup.map(t => t.name).join(', ')}`);
|
|
2818
2788
|
|
|
2819
2789
|
// 获取模板基础路径
|
|
2820
2790
|
const basePath = configPath.replace(/\/templates\.json$/, '');
|
|
@@ -2827,9 +2797,7 @@ const executeWarmup = async (options) => {
|
|
|
2827
2797
|
}
|
|
2828
2798
|
|
|
2829
2799
|
logger.success('\n✅ All templates warmed up successfully!');
|
|
2830
|
-
logger.info(
|
|
2831
|
-
'\nNext time you run `coze init`, it will be much faster as node_modules are pre-installed.',
|
|
2832
|
-
);
|
|
2800
|
+
logger.info('\nNext time you run `coze init`, it will be much faster as node_modules are pre-installed.');
|
|
2833
2801
|
|
|
2834
2802
|
timer.logTotal();
|
|
2835
2803
|
} catch (error) {
|
|
@@ -7595,14 +7563,11 @@ const createLogStream = (logFilePath) => {
|
|
|
7595
7563
|
const logDir = path.dirname(logFilePath);
|
|
7596
7564
|
|
|
7597
7565
|
// 确保日志目录存在
|
|
7598
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename -- resolved from config, not raw user input
|
|
7599
7566
|
if (!fs.existsSync(logDir)) {
|
|
7600
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename -- resolved from config, not raw user input
|
|
7601
7567
|
fs.mkdirSync(logDir, { recursive: true });
|
|
7602
7568
|
}
|
|
7603
7569
|
|
|
7604
7570
|
// 使用 'w' 标志覆盖之前的日志
|
|
7605
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename -- resolved from config, not raw user input
|
|
7606
7571
|
return fs.createWriteStream(logFilePath, { flags: 'w' });
|
|
7607
7572
|
};
|
|
7608
7573
|
|
|
@@ -7620,8 +7585,7 @@ const reportFailureAndExit = (
|
|
|
7620
7585
|
|
|
7621
7586
|
,
|
|
7622
7587
|
) => {
|
|
7623
|
-
const { commandName, cmdStartTime, options, categories, errorContext } =
|
|
7624
|
-
context;
|
|
7588
|
+
const { commandName, cmdStartTime, options, categories, errorContext } = context;
|
|
7625
7589
|
reportError(error, { command: commandName, ...errorContext });
|
|
7626
7590
|
reportCommandComplete(commandName, false, Date.now() - cmdStartTime, {
|
|
7627
7591
|
args: JSON.stringify(options),
|
|
@@ -7639,10 +7603,7 @@ const reportFailureAndExit = (
|
|
|
7639
7603
|
};
|
|
7640
7604
|
|
|
7641
7605
|
// eslint-disable-next-line @coze-arch/max-line-per-function, max-lines-per-function -- orchestrates fix+build+reporting
|
|
7642
|
-
const executeRun = async (
|
|
7643
|
-
commandName,
|
|
7644
|
-
options = {},
|
|
7645
|
-
) => {
|
|
7606
|
+
const executeRun = async (commandName, options = {}) => {
|
|
7646
7607
|
const cmdStartTime = Date.now();
|
|
7647
7608
|
let fixDuration = 0;
|
|
7648
7609
|
let buildStartTime = 0;
|
|
@@ -7666,10 +7627,7 @@ const executeRun = async (
|
|
|
7666
7627
|
await executePatch();
|
|
7667
7628
|
} catch (patchError) {
|
|
7668
7629
|
// patch errors are intentionally non-fatal: trace and proceed with the main command
|
|
7669
|
-
d$1(
|
|
7670
|
-
'patch step failed (continuing): %s',
|
|
7671
|
-
patchError instanceof Error ? patchError.message : String(patchError),
|
|
7672
|
-
);
|
|
7630
|
+
d$1('patch step failed (continuing): %s', patchError instanceof Error ? patchError.message : String(patchError));
|
|
7673
7631
|
}
|
|
7674
7632
|
fixDuration = Date.now() - fixStartTime;
|
|
7675
7633
|
logger.info('');
|
|
@@ -8972,34 +8930,26 @@ const ARGV_USER_ARGS_OFFSET = 2;
|
|
|
8972
8930
|
* @param knownOptions - 已知的选项集合(不需要透传的选项)
|
|
8973
8931
|
* @returns 参数对象
|
|
8974
8932
|
*/
|
|
8975
|
-
const parsePassThroughParams = (
|
|
8976
|
-
command,
|
|
8977
|
-
knownOptions = new Set(),
|
|
8978
|
-
) => {
|
|
8933
|
+
const parsePassThroughParams = (command, knownOptions = new Set()) => {
|
|
8979
8934
|
const parsed = minimist(process.argv.slice(ARGV_USER_ARGS_OFFSET));
|
|
8980
8935
|
|
|
8981
8936
|
// 过滤掉已知选项和位置参数(_)
|
|
8982
|
-
const filtered = Object.entries(parsed).reduce(
|
|
8983
|
-
|
|
8984
|
-
|
|
8985
|
-
|
|
8986
|
-
|
|
8987
|
-
}
|
|
8937
|
+
const filtered = Object.entries(parsed).reduce((params, [key, value]) => {
|
|
8938
|
+
// 跳过 minimist 的位置参数数组
|
|
8939
|
+
if (key === '_') {
|
|
8940
|
+
return params;
|
|
8941
|
+
}
|
|
8988
8942
|
|
|
8989
|
-
|
|
8990
|
-
|
|
8991
|
-
|
|
8992
|
-
|
|
8943
|
+
// 跳过已知选项(支持原始格式和 camelCase 格式)
|
|
8944
|
+
if (knownOptions.has(key) || knownOptions.has(changeCase.camelCase(key))) {
|
|
8945
|
+
return params;
|
|
8946
|
+
}
|
|
8993
8947
|
|
|
8994
|
-
|
|
8995
|
-
|
|
8996
|
-
// eslint-disable-next-line security/detect-object-injection -- camelKey is sanitized by camelCase
|
|
8997
|
-
params[camelKey] = value;
|
|
8948
|
+
// 将 kebab-case 转换为 camelCase
|
|
8949
|
+
const camelKey = changeCase.camelCase(key);
|
|
8998
8950
|
|
|
8999
|
-
|
|
9000
|
-
|
|
9001
|
-
{},
|
|
9002
|
-
);
|
|
8951
|
+
return { ...params, [camelKey]: value };
|
|
8952
|
+
}, {});
|
|
9003
8953
|
|
|
9004
8954
|
return filtered;
|
|
9005
8955
|
};
|