@coze-arch/cli 0.0.30-alpha.37325a → 0.0.31-alpha.08f83e
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/validate.sh +1 -1
- package/lib/__templates__/nextjs/scripts/prepare.sh +2 -2
- package/lib/__templates__/nextjs/scripts/validate.sh +1 -1
- package/lib/__templates__/nuxt-vue/scripts/prepare.sh +2 -2
- package/lib/__templates__/nuxt-vue/scripts/validate.sh +1 -1
- package/lib/__templates__/vite/scripts/prepare.sh +2 -2
- package/lib/__templates__/vite/scripts/validate.sh +1 -1
- package/lib/cli.js +601 -386
- package/package.json +5 -3
package/lib/cli.js
CHANGED
|
@@ -1628,7 +1628,7 @@ function createNodeTransport() {
|
|
|
1628
1628
|
};
|
|
1629
1629
|
}
|
|
1630
1630
|
|
|
1631
|
-
function _nullishCoalesce$
|
|
1631
|
+
function _nullishCoalesce$b(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$u(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; }/**
|
|
1632
1632
|
* Slardar CLI Reporter 主类
|
|
1633
1633
|
* 封装 @slardar/base 的初始化和上报逻辑
|
|
1634
1634
|
*/
|
|
@@ -1685,7 +1685,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1685
1685
|
release: config.release,
|
|
1686
1686
|
env: config.env,
|
|
1687
1687
|
name: config.name,
|
|
1688
|
-
useLocalConfig: _nullishCoalesce$
|
|
1688
|
+
useLocalConfig: _nullishCoalesce$b(config.useLocalConfig, () => ( false)), // 默认使用服务端配置
|
|
1689
1689
|
domain: config.domain,
|
|
1690
1690
|
// 设置本地采样率为 100%,确保事件不被过滤
|
|
1691
1691
|
sample: {
|
|
@@ -1700,7 +1700,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1700
1700
|
this.client.on('send', (ev) => {
|
|
1701
1701
|
log$6(
|
|
1702
1702
|
'send hook called for event: %s',
|
|
1703
|
-
(_optionalChain$
|
|
1703
|
+
(_optionalChain$u([ev, 'optionalAccess', _ => _.ev_type]) ) || 'unknown',
|
|
1704
1704
|
);
|
|
1705
1705
|
});
|
|
1706
1706
|
|
|
@@ -1758,7 +1758,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1758
1758
|
)
|
|
1759
1759
|
: undefined;
|
|
1760
1760
|
|
|
1761
|
-
_optionalChain$
|
|
1761
|
+
_optionalChain$u([this, 'access', _2 => _2.client, 'access', _3 => _3.sendEvent, 'optionalCall', _4 => _4({
|
|
1762
1762
|
name,
|
|
1763
1763
|
metrics: cleanMetrics ,
|
|
1764
1764
|
categories: cleanCategories ,
|
|
@@ -1829,7 +1829,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1829
1829
|
log$6('Reporting JS error:', {
|
|
1830
1830
|
name: error.name,
|
|
1831
1831
|
message: error.message.slice(0, 100),
|
|
1832
|
-
stack: _optionalChain$
|
|
1832
|
+
stack: _optionalChain$u([error, 'access', _5 => _5.stack, 'optionalAccess', _6 => _6.slice, 'call', _7 => _7(0, 200)]),
|
|
1833
1833
|
extra,
|
|
1834
1834
|
source,
|
|
1835
1835
|
});
|
|
@@ -1849,7 +1849,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1849
1849
|
if (!this.ensureInitialized()) {
|
|
1850
1850
|
return;
|
|
1851
1851
|
}
|
|
1852
|
-
_optionalChain$
|
|
1852
|
+
_optionalChain$u([this, 'access', _8 => _8.client, 'access', _9 => _9.context, 'optionalAccess', _10 => _10.set, 'call', _11 => _11(key, value)]);
|
|
1853
1853
|
}
|
|
1854
1854
|
|
|
1855
1855
|
/**
|
|
@@ -1860,7 +1860,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1860
1860
|
return;
|
|
1861
1861
|
}
|
|
1862
1862
|
log$6('Merging context:', context);
|
|
1863
|
-
_optionalChain$
|
|
1863
|
+
_optionalChain$u([this, 'access', _12 => _12.client, 'access', _13 => _13.context, 'optionalAccess', _14 => _14.merge, 'call', _15 => _15(context)]);
|
|
1864
1864
|
}
|
|
1865
1865
|
|
|
1866
1866
|
/**
|
|
@@ -1870,7 +1870,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1870
1870
|
if (!this.ensureInitialized()) {
|
|
1871
1871
|
return;
|
|
1872
1872
|
}
|
|
1873
|
-
_optionalChain$
|
|
1873
|
+
_optionalChain$u([this, 'access', _16 => _16.client, 'access', _17 => _17.context, 'optionalAccess', _18 => _18.delete, 'call', _19 => _19(key)]);
|
|
1874
1874
|
}
|
|
1875
1875
|
|
|
1876
1876
|
/**
|
|
@@ -1880,7 +1880,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1880
1880
|
if (!this.ensureInitialized()) {
|
|
1881
1881
|
return;
|
|
1882
1882
|
}
|
|
1883
|
-
_optionalChain$
|
|
1883
|
+
_optionalChain$u([this, 'access', _20 => _20.client, 'access', _21 => _21.context, 'optionalAccess', _22 => _22.clear, 'call', _23 => _23()]);
|
|
1884
1884
|
}
|
|
1885
1885
|
|
|
1886
1886
|
/**
|
|
@@ -1917,7 +1917,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1917
1917
|
return;
|
|
1918
1918
|
}
|
|
1919
1919
|
log$6('Flushing Slardar data...');
|
|
1920
|
-
_optionalChain$
|
|
1920
|
+
_optionalChain$u([this, 'access', _24 => _24.client, 'access', _25 => _25.getSender, 'optionalCall', _26 => _26(), 'optionalAccess', _27 => _27.flush, 'call', _28 => _28()]);
|
|
1921
1921
|
log$6('Waiting %dms for events to be sent...', waitMs);
|
|
1922
1922
|
await new Promise(resolve => setTimeout(resolve, waitMs));
|
|
1923
1923
|
log$6('Slardar data flushed');
|
|
@@ -1936,7 +1936,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1936
1936
|
*/
|
|
1937
1937
|
const reporter = new SlardarCLIReporter();
|
|
1938
1938
|
|
|
1939
|
-
function _optionalChain$
|
|
1939
|
+
function _optionalChain$t(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; }
|
|
1940
1940
|
|
|
1941
1941
|
|
|
1942
1942
|
|
|
@@ -1996,11 +1996,11 @@ const EventBuilder = {
|
|
|
1996
1996
|
name: CLI_EVENTS.CLI_COMMAND,
|
|
1997
1997
|
categories: {
|
|
1998
1998
|
command,
|
|
1999
|
-
args: _optionalChain$
|
|
1999
|
+
args: _optionalChain$t([options, 'optionalAccess', _ => _.args]),
|
|
2000
2000
|
status: 'running' ,
|
|
2001
|
-
..._optionalChain$
|
|
2001
|
+
..._optionalChain$t([options, 'optionalAccess', _2 => _2.categories]),
|
|
2002
2002
|
},
|
|
2003
|
-
metrics: _optionalChain$
|
|
2003
|
+
metrics: _optionalChain$t([options, 'optionalAccess', _3 => _3.metrics]),
|
|
2004
2004
|
};
|
|
2005
2005
|
},
|
|
2006
2006
|
|
|
@@ -2021,13 +2021,13 @@ const EventBuilder = {
|
|
|
2021
2021
|
name: CLI_EVENTS.CLI_COMMAND_COMPLETE,
|
|
2022
2022
|
categories: {
|
|
2023
2023
|
command,
|
|
2024
|
-
args: _optionalChain$
|
|
2024
|
+
args: _optionalChain$t([options, 'optionalAccess', _4 => _4.args]),
|
|
2025
2025
|
status: success ? ('success' ) : ('fail' ),
|
|
2026
|
-
..._optionalChain$
|
|
2026
|
+
..._optionalChain$t([options, 'optionalAccess', _5 => _5.categories]),
|
|
2027
2027
|
},
|
|
2028
2028
|
metrics: {
|
|
2029
2029
|
duration,
|
|
2030
|
-
...(_optionalChain$
|
|
2030
|
+
...(_optionalChain$t([options, 'optionalAccess', _6 => _6.errorCode]) && { errorCode: options.errorCode }),
|
|
2031
2031
|
},
|
|
2032
2032
|
};
|
|
2033
2033
|
},
|
|
@@ -2048,12 +2048,12 @@ const EventBuilder = {
|
|
|
2048
2048
|
name: CLI_EVENTS.NETWORK_REQUEST,
|
|
2049
2049
|
categories: {
|
|
2050
2050
|
url,
|
|
2051
|
-
method: _optionalChain$
|
|
2052
|
-
statusCode: _optionalChain$
|
|
2053
|
-
status: _optionalChain$
|
|
2051
|
+
method: _optionalChain$t([options, 'optionalAccess', _7 => _7.method]) || 'GET',
|
|
2052
|
+
statusCode: _optionalChain$t([options, 'optionalAccess', _8 => _8.statusCode, 'optionalAccess', _9 => _9.toString, 'call', _10 => _10()]),
|
|
2053
|
+
status: _optionalChain$t([options, 'optionalAccess', _11 => _11.success]) ? ('success' ) : ('fail' ),
|
|
2054
2054
|
},
|
|
2055
2055
|
metrics: {
|
|
2056
|
-
duration: _optionalChain$
|
|
2056
|
+
duration: _optionalChain$t([options, 'optionalAccess', _12 => _12.duration]),
|
|
2057
2057
|
},
|
|
2058
2058
|
};
|
|
2059
2059
|
},
|
|
@@ -2075,11 +2075,11 @@ const EventBuilder = {
|
|
|
2075
2075
|
categories: {
|
|
2076
2076
|
operation,
|
|
2077
2077
|
filePath,
|
|
2078
|
-
status: _optionalChain$
|
|
2078
|
+
status: _optionalChain$t([options, 'optionalAccess', _13 => _13.success]) ? ('success' ) : ('fail' ),
|
|
2079
2079
|
},
|
|
2080
2080
|
metrics: {
|
|
2081
|
-
duration: _optionalChain$
|
|
2082
|
-
fileSize: _optionalChain$
|
|
2081
|
+
duration: _optionalChain$t([options, 'optionalAccess', _14 => _14.duration]),
|
|
2082
|
+
fileSize: _optionalChain$t([options, 'optionalAccess', _15 => _15.fileSize]),
|
|
2083
2083
|
},
|
|
2084
2084
|
};
|
|
2085
2085
|
},
|
|
@@ -2107,14 +2107,15 @@ const EventBuilder = {
|
|
|
2107
2107
|
};
|
|
2108
2108
|
|
|
2109
2109
|
var name = "@coze-arch/cli";
|
|
2110
|
-
var version = "0.0.
|
|
2110
|
+
var version = "0.0.31-alpha.08f83e";
|
|
2111
2111
|
var description = "coze coding devtools cli";
|
|
2112
2112
|
var license = "MIT";
|
|
2113
2113
|
var author = "fanwenjie.fe@bytedance.com";
|
|
2114
2114
|
var maintainers = [
|
|
2115
2115
|
];
|
|
2116
2116
|
var bin = {
|
|
2117
|
-
coze: "bin/main"
|
|
2117
|
+
coze: "bin/main",
|
|
2118
|
+
"coze-dev": "bin/main"
|
|
2118
2119
|
};
|
|
2119
2120
|
var files = [
|
|
2120
2121
|
"lib",
|
|
@@ -2196,7 +2197,8 @@ var publishConfig = {
|
|
|
2196
2197
|
};
|
|
2197
2198
|
var cozePublishConfig = {
|
|
2198
2199
|
bin: {
|
|
2199
|
-
coze: "bin/main"
|
|
2200
|
+
coze: "bin/main",
|
|
2201
|
+
"coze-dev": "bin/main"
|
|
2200
2202
|
}
|
|
2201
2203
|
};
|
|
2202
2204
|
var packageJson = {
|
|
@@ -2216,7 +2218,7 @@ var packageJson = {
|
|
|
2216
2218
|
cozePublishConfig: cozePublishConfig
|
|
2217
2219
|
};
|
|
2218
2220
|
|
|
2219
|
-
function _optionalChain$
|
|
2221
|
+
function _optionalChain$s(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; }/**
|
|
2220
2222
|
* Slardar 监控初始化和上报
|
|
2221
2223
|
*/
|
|
2222
2224
|
|
|
@@ -2319,11 +2321,11 @@ const reportCommandComplete = safeRun(
|
|
|
2319
2321
|
,
|
|
2320
2322
|
) => {
|
|
2321
2323
|
const event = EventBuilder.cliCommandComplete(command, success, duration, {
|
|
2322
|
-
args: _optionalChain$
|
|
2323
|
-
errorCode: _optionalChain$
|
|
2324
|
+
args: _optionalChain$s([options, 'optionalAccess', _ => _.args]),
|
|
2325
|
+
errorCode: _optionalChain$s([options, 'optionalAccess', _2 => _2.errorCode]),
|
|
2324
2326
|
categories: {
|
|
2325
|
-
...(_optionalChain$
|
|
2326
|
-
..._optionalChain$
|
|
2327
|
+
...(_optionalChain$s([options, 'optionalAccess', _3 => _3.errorMessage]) && { errorMessage: options.errorMessage }),
|
|
2328
|
+
..._optionalChain$s([options, 'optionalAccess', _4 => _4.categories]),
|
|
2327
2329
|
},
|
|
2328
2330
|
});
|
|
2329
2331
|
reporter.sendEvent(event.name, event.metrics, event.categories);
|
|
@@ -2382,7 +2384,7 @@ const flushSlardar = safeRun('flushSlardar', async () => {
|
|
|
2382
2384
|
await reporter.flush();
|
|
2383
2385
|
});
|
|
2384
2386
|
|
|
2385
|
-
function _nullishCoalesce$
|
|
2387
|
+
function _nullishCoalesce$a(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$r(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; }var LogLevel; (function (LogLevel) {
|
|
2386
2388
|
const ERROR = 0; LogLevel[LogLevel["ERROR"] = ERROR] = "ERROR";
|
|
2387
2389
|
const WARN = 1; LogLevel[LogLevel["WARN"] = WARN] = "WARN";
|
|
2388
2390
|
const SUCCESS = 2; LogLevel[LogLevel["SUCCESS"] = SUCCESS] = "SUCCESS";
|
|
@@ -2420,7 +2422,7 @@ class Logger {
|
|
|
2420
2422
|
|
|
2421
2423
|
constructor(options = {}) {
|
|
2422
2424
|
this.level = this.parseLogLevel(options.level);
|
|
2423
|
-
this.useColor = _nullishCoalesce$
|
|
2425
|
+
this.useColor = _nullishCoalesce$a(options.useColor, () => ( this.isColorSupported()));
|
|
2424
2426
|
this.prefix = options.prefix;
|
|
2425
2427
|
}
|
|
2426
2428
|
|
|
@@ -2429,7 +2431,7 @@ class Logger {
|
|
|
2429
2431
|
return level;
|
|
2430
2432
|
}
|
|
2431
2433
|
|
|
2432
|
-
const envLevel = _optionalChain$
|
|
2434
|
+
const envLevel = _optionalChain$r([process, 'access', _ => _.env, 'access', _2 => _2.LOG_LEVEL, 'optionalAccess', _3 => _3.toLowerCase, 'call', _4 => _4()]);
|
|
2433
2435
|
if (envLevel && envLevel in LOG_LEVEL_MAP) {
|
|
2434
2436
|
return LOG_LEVEL_MAP[envLevel];
|
|
2435
2437
|
}
|
|
@@ -2441,7 +2443,7 @@ class Logger {
|
|
|
2441
2443
|
// 简单检测:Node.js 环境且支持 TTY
|
|
2442
2444
|
return (
|
|
2443
2445
|
typeof process !== 'undefined' &&
|
|
2444
|
-
_optionalChain$
|
|
2446
|
+
_optionalChain$r([process, 'access', _5 => _5.stdout, 'optionalAccess', _6 => _6.isTTY]) === true &&
|
|
2445
2447
|
process.env.NO_COLOR === undefined
|
|
2446
2448
|
);
|
|
2447
2449
|
}
|
|
@@ -2466,7 +2468,7 @@ class Logger {
|
|
|
2466
2468
|
|
|
2467
2469
|
const icon = this.colorize(options.icon, options.color);
|
|
2468
2470
|
const prefix = this.prefix ? `${icon} ${this.prefix}` : icon;
|
|
2469
|
-
console.log(prefix, options.message, ...(_nullishCoalesce$
|
|
2471
|
+
console.log(prefix, options.message, ...(_nullishCoalesce$a(options.args, () => ( []))));
|
|
2470
2472
|
}
|
|
2471
2473
|
|
|
2472
2474
|
error(message, ...args) {
|
|
@@ -2598,9 +2600,7 @@ const getTemplatesDir = () => {
|
|
|
2598
2600
|
* @returns 模板配置对象
|
|
2599
2601
|
*/
|
|
2600
2602
|
|
|
2601
|
-
const loadTemplateConfig = async (
|
|
2602
|
-
templatePath,
|
|
2603
|
-
) => {
|
|
2603
|
+
const loadTemplateConfig = async ( templatePath) => {
|
|
2604
2604
|
logger.verbose(`Loading template config from: ${templatePath}`);
|
|
2605
2605
|
|
|
2606
2606
|
const tsConfigPath = path.join(templatePath, 'template.config.ts');
|
|
@@ -2632,15 +2632,12 @@ const loadTemplateConfig = async (
|
|
|
2632
2632
|
} else if (jsExists) {
|
|
2633
2633
|
configPath = jsConfigPath;
|
|
2634
2634
|
} else {
|
|
2635
|
-
throw new Error(
|
|
2636
|
-
`Template config not found in ${templatePath}.\n` +
|
|
2637
|
-
'Expected: template.config.ts or template.config.js',
|
|
2638
|
-
);
|
|
2635
|
+
throw new Error(`Template config not found in ${templatePath}.\n` + 'Expected: template.config.ts or template.config.js');
|
|
2639
2636
|
}
|
|
2640
2637
|
|
|
2641
2638
|
logger.verbose(`Using config file: ${configPath}`);
|
|
2642
2639
|
|
|
2643
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
2640
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports -- Sucrase handles .ts files at runtime, path is validated above
|
|
2644
2641
|
const config = require(configPath);
|
|
2645
2642
|
|
|
2646
2643
|
logger.verbose('Template config loaded successfully');
|
|
@@ -2654,18 +2651,14 @@ const loadTemplateConfig = async (
|
|
|
2654
2651
|
* @param configPath - templates.json 配置文件路径
|
|
2655
2652
|
* @returns 模板列表配置
|
|
2656
2653
|
*/
|
|
2657
|
-
const loadTemplatesConfig = async (
|
|
2658
|
-
configPath,
|
|
2659
|
-
) => {
|
|
2654
|
+
const loadTemplatesConfig = async (configPath) => {
|
|
2660
2655
|
logger.verbose(`Loading templates config from: ${configPath}`);
|
|
2661
2656
|
|
|
2662
2657
|
const content = await fs$1.readFile(configPath, 'utf-8');
|
|
2663
2658
|
// eslint-disable-next-line no-restricted-syntax -- Static config file loaded at build time, safeJsonParse not needed
|
|
2664
2659
|
const config = JSON.parse(content) ;
|
|
2665
2660
|
|
|
2666
|
-
logger.verbose(
|
|
2667
|
-
`Found ${config.templates.length} templates: ${config.templates.map(t => t.name).join(', ')}`,
|
|
2668
|
-
);
|
|
2661
|
+
logger.verbose(`Found ${config.templates.length} templates: ${config.templates.map(t => t.name).join(', ')}`);
|
|
2669
2662
|
|
|
2670
2663
|
return config;
|
|
2671
2664
|
};
|
|
@@ -2677,20 +2670,13 @@ const loadTemplatesConfig = async (
|
|
|
2677
2670
|
* @param templateName - 模板名称
|
|
2678
2671
|
* @returns 模板元信息
|
|
2679
2672
|
*/
|
|
2680
|
-
const findTemplate = (
|
|
2681
|
-
templatesConfig,
|
|
2682
|
-
templateName,
|
|
2683
|
-
) => {
|
|
2673
|
+
const findTemplate = (templatesConfig, templateName) => {
|
|
2684
2674
|
const template = templatesConfig.templates.find(t => t.name === templateName);
|
|
2685
2675
|
|
|
2686
2676
|
if (!template) {
|
|
2687
|
-
const availableTemplates = templatesConfig.templates
|
|
2688
|
-
.map(t => t.name)
|
|
2689
|
-
.join(', ');
|
|
2677
|
+
const availableTemplates = templatesConfig.templates.map(t => t.name).join(', ');
|
|
2690
2678
|
throw new Error(
|
|
2691
|
-
`Template "${templateName}" not found.\n` +
|
|
2692
|
-
`Available templates: ${availableTemplates}\n` +
|
|
2693
|
-
'Use --template <name> to specify a template.',
|
|
2679
|
+
`Template "${templateName}" not found.\n` + `Available templates: ${availableTemplates}\n` + 'Use --template <name> to specify a template.',
|
|
2694
2680
|
);
|
|
2695
2681
|
}
|
|
2696
2682
|
|
|
@@ -2704,10 +2690,7 @@ const findTemplate = (
|
|
|
2704
2690
|
* @param templateMetadata - 模板元信息
|
|
2705
2691
|
* @returns 模板完整路径
|
|
2706
2692
|
*/
|
|
2707
|
-
const getTemplatePath = async (
|
|
2708
|
-
basePath,
|
|
2709
|
-
templateMetadata,
|
|
2710
|
-
) => {
|
|
2693
|
+
const getTemplatePath = async (basePath, templateMetadata) => {
|
|
2711
2694
|
logger.verbose('Resolving template path:');
|
|
2712
2695
|
logger.verbose(` - Base path: ${basePath}`);
|
|
2713
2696
|
logger.verbose(` - Template location: ${templateMetadata.location}`);
|
|
@@ -2722,9 +2705,7 @@ const getTemplatePath = async (
|
|
|
2722
2705
|
logger.verbose(' - Template directory exists: ✓');
|
|
2723
2706
|
} catch (error) {
|
|
2724
2707
|
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
|
-
);
|
|
2708
|
+
throw new Error(`Template directory not found: ${templatePath} (cause: ${error instanceof Error ? error.message : String(error)})`);
|
|
2728
2709
|
}
|
|
2729
2710
|
|
|
2730
2711
|
return templatePath;
|
|
@@ -2739,7 +2720,6 @@ const warmupTemplate = (templatePath, templateName) => {
|
|
|
2739
2720
|
|
|
2740
2721
|
// 检查是否存在 package.json
|
|
2741
2722
|
const packageJsonPath = node_path.join(templatePath, 'package.json');
|
|
2742
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
2743
2723
|
if (!node_fs.existsSync(packageJsonPath)) {
|
|
2744
2724
|
logger.info(` ⊘ Skipping ${templateName} (no package.json found)`);
|
|
2745
2725
|
return;
|
|
@@ -2791,30 +2771,22 @@ const executeWarmup = async (options) => {
|
|
|
2791
2771
|
const configPath = getTemplatesConfigPath();
|
|
2792
2772
|
const templatesConfig = await loadTemplatesConfig(configPath);
|
|
2793
2773
|
|
|
2794
|
-
logger.verbose(
|
|
2795
|
-
`Found ${templatesConfig.templates.length} templates in config`,
|
|
2796
|
-
);
|
|
2774
|
+
logger.verbose(`Found ${templatesConfig.templates.length} templates in config`);
|
|
2797
2775
|
|
|
2798
2776
|
// 过滤模板
|
|
2799
|
-
const templatesToWarmup = templateFilter
|
|
2800
|
-
? templatesConfig.templates.filter(t => t.name === templateFilter)
|
|
2801
|
-
: templatesConfig.templates;
|
|
2777
|
+
const templatesToWarmup = templateFilter ? templatesConfig.templates.filter(t => t.name === templateFilter) : templatesConfig.templates;
|
|
2802
2778
|
|
|
2803
2779
|
if (templatesToWarmup.length === 0) {
|
|
2804
2780
|
if (templateFilter) {
|
|
2805
2781
|
logger.warn(`Template "${templateFilter}" not found`);
|
|
2806
|
-
logger.info(
|
|
2807
|
-
`Available templates: ${templatesConfig.templates.map(t => t.name).join(', ')}`,
|
|
2808
|
-
);
|
|
2782
|
+
logger.info(`Available templates: ${templatesConfig.templates.map(t => t.name).join(', ')}`);
|
|
2809
2783
|
} else {
|
|
2810
2784
|
logger.warn('No templates found');
|
|
2811
2785
|
}
|
|
2812
2786
|
return;
|
|
2813
2787
|
}
|
|
2814
2788
|
|
|
2815
|
-
logger.info(
|
|
2816
|
-
`\nWill warm up ${templatesToWarmup.length} template(s): ${templatesToWarmup.map(t => t.name).join(', ')}`,
|
|
2817
|
-
);
|
|
2789
|
+
logger.info(`\nWill warm up ${templatesToWarmup.length} template(s): ${templatesToWarmup.map(t => t.name).join(', ')}`);
|
|
2818
2790
|
|
|
2819
2791
|
// 获取模板基础路径
|
|
2820
2792
|
const basePath = configPath.replace(/\/templates\.json$/, '');
|
|
@@ -2827,9 +2799,7 @@ const executeWarmup = async (options) => {
|
|
|
2827
2799
|
}
|
|
2828
2800
|
|
|
2829
2801
|
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
|
-
);
|
|
2802
|
+
logger.info('\nNext time you run `coze init`, it will be much faster as node_modules are pre-installed.');
|
|
2833
2803
|
|
|
2834
2804
|
timer.logTotal();
|
|
2835
2805
|
} catch (error) {
|
|
@@ -2843,7 +2813,7 @@ const executeWarmup = async (options) => {
|
|
|
2843
2813
|
/**
|
|
2844
2814
|
* 注册 warmup 命令到 program
|
|
2845
2815
|
*/
|
|
2846
|
-
const registerCommand$
|
|
2816
|
+
const registerCommand$7 = program => {
|
|
2847
2817
|
program
|
|
2848
2818
|
.command('warmup')
|
|
2849
2819
|
.description('Pre-install dependencies for templates to speed up init')
|
|
@@ -3255,7 +3225,7 @@ const executeUpdate = (
|
|
|
3255
3225
|
/**
|
|
3256
3226
|
* 注册 update 命令到 program
|
|
3257
3227
|
*/
|
|
3258
|
-
const registerCommand$
|
|
3228
|
+
const registerCommand$6 = program => {
|
|
3259
3229
|
program
|
|
3260
3230
|
.command('update <package>')
|
|
3261
3231
|
.description('Update a package dependency')
|
|
@@ -3281,7 +3251,7 @@ const registerCommand$5 = program => {
|
|
|
3281
3251
|
});
|
|
3282
3252
|
};
|
|
3283
3253
|
|
|
3284
|
-
function _optionalChain$
|
|
3254
|
+
function _optionalChain$q(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; }/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3285
3255
|
// Safe JSON parsing utilities with type safety and error handling
|
|
3286
3256
|
// Provides fallback values, validation, and error monitoring capabilities
|
|
3287
3257
|
|
|
@@ -3381,12 +3351,12 @@ function safeJsonParse(
|
|
|
3381
3351
|
const parsed = JSON.parse(String(input));
|
|
3382
3352
|
|
|
3383
3353
|
// Optional validation
|
|
3384
|
-
if (_optionalChain$
|
|
3354
|
+
if (_optionalChain$q([options, 'optionalAccess', _ => _.validate])) {
|
|
3385
3355
|
if (options.validate(parsed)) {
|
|
3386
3356
|
return parsed;
|
|
3387
3357
|
} else {
|
|
3388
3358
|
const validationError = new Error('JSON validation failed');
|
|
3389
|
-
_optionalChain$
|
|
3359
|
+
_optionalChain$q([options, 'access', _2 => _2.onError, 'optionalCall', _3 => _3(validationError, input)]);
|
|
3390
3360
|
|
|
3391
3361
|
if (options.throwOnValidationError) {
|
|
3392
3362
|
throw validationError;
|
|
@@ -3398,10 +3368,10 @@ function safeJsonParse(
|
|
|
3398
3368
|
return parsed;
|
|
3399
3369
|
} catch (error) {
|
|
3400
3370
|
// Re-throw validation errors when throwOnValidationError is true
|
|
3401
|
-
if (error instanceof Error && error.message === 'JSON validation failed' && _optionalChain$
|
|
3371
|
+
if (error instanceof Error && error.message === 'JSON validation failed' && _optionalChain$q([options, 'optionalAccess', _4 => _4.throwOnValidationError])) {
|
|
3402
3372
|
throw error;
|
|
3403
3373
|
}
|
|
3404
|
-
_optionalChain$
|
|
3374
|
+
_optionalChain$q([options, 'optionalAccess', _5 => _5.onError, 'optionalCall', _6 => _6(error , input)]);
|
|
3405
3375
|
return defaultValue;
|
|
3406
3376
|
}
|
|
3407
3377
|
}
|
|
@@ -3441,7 +3411,7 @@ function isNode(node) {
|
|
|
3441
3411
|
}
|
|
3442
3412
|
const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
|
|
3443
3413
|
|
|
3444
|
-
function _optionalChain$
|
|
3414
|
+
function _optionalChain$p(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; }
|
|
3445
3415
|
const BREAK = Symbol('break visit');
|
|
3446
3416
|
const SKIP = Symbol('skip children');
|
|
3447
3417
|
const REMOVE = Symbol('remove node');
|
|
@@ -3554,15 +3524,15 @@ function callVisitor(key, node, visitor, path) {
|
|
|
3554
3524
|
if (typeof visitor === 'function')
|
|
3555
3525
|
return visitor(key, node, path);
|
|
3556
3526
|
if (isMap(node))
|
|
3557
|
-
return _optionalChain$
|
|
3527
|
+
return _optionalChain$p([visitor, 'access', _ => _.Map, 'optionalCall', _2 => _2(key, node, path)]);
|
|
3558
3528
|
if (isSeq(node))
|
|
3559
|
-
return _optionalChain$
|
|
3529
|
+
return _optionalChain$p([visitor, 'access', _3 => _3.Seq, 'optionalCall', _4 => _4(key, node, path)]);
|
|
3560
3530
|
if (isPair(node))
|
|
3561
|
-
return _optionalChain$
|
|
3531
|
+
return _optionalChain$p([visitor, 'access', _5 => _5.Pair, 'optionalCall', _6 => _6(key, node, path)]);
|
|
3562
3532
|
if (isScalar(node))
|
|
3563
|
-
return _optionalChain$
|
|
3533
|
+
return _optionalChain$p([visitor, 'access', _7 => _7.Scalar, 'optionalCall', _8 => _8(key, node, path)]);
|
|
3564
3534
|
if (isAlias(node))
|
|
3565
|
-
return _optionalChain$
|
|
3535
|
+
return _optionalChain$p([visitor, 'access', _9 => _9.Alias, 'optionalCall', _10 => _10(key, node, path)]);
|
|
3566
3536
|
return undefined;
|
|
3567
3537
|
}
|
|
3568
3538
|
function replaceNode(key, path, node) {
|
|
@@ -3653,7 +3623,7 @@ function applyReviver(reviver, obj, key, val) {
|
|
|
3653
3623
|
return reviver.call(obj, key, val);
|
|
3654
3624
|
}
|
|
3655
3625
|
|
|
3656
|
-
function _optionalChain$
|
|
3626
|
+
function _optionalChain$o(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; }
|
|
3657
3627
|
/**
|
|
3658
3628
|
* Recursively convert any node or its contents to native JavaScript
|
|
3659
3629
|
*
|
|
@@ -3683,7 +3653,7 @@ function toJS(value, arg, ctx) {
|
|
|
3683
3653
|
ctx.onCreate(res);
|
|
3684
3654
|
return res;
|
|
3685
3655
|
}
|
|
3686
|
-
if (typeof value === 'bigint' && !_optionalChain$
|
|
3656
|
+
if (typeof value === 'bigint' && !_optionalChain$o([ctx, 'optionalAccess', _ => _.keep]))
|
|
3687
3657
|
return Number(value);
|
|
3688
3658
|
return value;
|
|
3689
3659
|
}
|
|
@@ -3721,7 +3691,7 @@ class NodeBase {
|
|
|
3721
3691
|
}
|
|
3722
3692
|
}
|
|
3723
3693
|
|
|
3724
|
-
function _optionalChain$
|
|
3694
|
+
function _optionalChain$n(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; }
|
|
3725
3695
|
class Alias extends NodeBase {
|
|
3726
3696
|
constructor(source) {
|
|
3727
3697
|
super(ALIAS);
|
|
@@ -3737,10 +3707,10 @@ class Alias extends NodeBase {
|
|
|
3737
3707
|
* instance of the `source` anchor before this node.
|
|
3738
3708
|
*/
|
|
3739
3709
|
resolve(doc, ctx) {
|
|
3740
|
-
if (_optionalChain$
|
|
3710
|
+
if (_optionalChain$n([ctx, 'optionalAccess', _ => _.maxAliasCount]) === 0)
|
|
3741
3711
|
throw new ReferenceError('Alias resolution is disabled');
|
|
3742
3712
|
let nodes;
|
|
3743
|
-
if (_optionalChain$
|
|
3713
|
+
if (_optionalChain$n([ctx, 'optionalAccess', _2 => _2.aliasResolveCache])) {
|
|
3744
3714
|
nodes = ctx.aliasResolveCache;
|
|
3745
3715
|
}
|
|
3746
3716
|
else {
|
|
@@ -3779,7 +3749,7 @@ class Alias extends NodeBase {
|
|
|
3779
3749
|
data = anchors.get(source);
|
|
3780
3750
|
}
|
|
3781
3751
|
/* istanbul ignore if */
|
|
3782
|
-
if (_optionalChain$
|
|
3752
|
+
if (_optionalChain$n([data, 'optionalAccess', _3 => _3.res]) === undefined) {
|
|
3783
3753
|
const msg = 'This should not happen: Alias anchor was not resolved?';
|
|
3784
3754
|
throw new ReferenceError(msg);
|
|
3785
3755
|
}
|
|
@@ -3831,7 +3801,7 @@ function getAliasCount(doc, node, anchors) {
|
|
|
3831
3801
|
return 1;
|
|
3832
3802
|
}
|
|
3833
3803
|
|
|
3834
|
-
function _optionalChain$
|
|
3804
|
+
function _optionalChain$m(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; }
|
|
3835
3805
|
const isScalarValue = (value) => !value || (typeof value !== 'function' && typeof value !== 'object');
|
|
3836
3806
|
class Scalar extends NodeBase {
|
|
3837
3807
|
constructor(value) {
|
|
@@ -3839,7 +3809,7 @@ class Scalar extends NodeBase {
|
|
|
3839
3809
|
this.value = value;
|
|
3840
3810
|
}
|
|
3841
3811
|
toJSON(arg, ctx) {
|
|
3842
|
-
return _optionalChain$
|
|
3812
|
+
return _optionalChain$m([ctx, 'optionalAccess', _ => _.keep]) ? this.value : toJS(this.value, arg, ctx);
|
|
3843
3813
|
}
|
|
3844
3814
|
toString() {
|
|
3845
3815
|
return String(this.value);
|
|
@@ -3851,17 +3821,17 @@ Scalar.PLAIN = 'PLAIN';
|
|
|
3851
3821
|
Scalar.QUOTE_DOUBLE = 'QUOTE_DOUBLE';
|
|
3852
3822
|
Scalar.QUOTE_SINGLE = 'QUOTE_SINGLE';
|
|
3853
3823
|
|
|
3854
|
-
function _nullishCoalesce$
|
|
3824
|
+
function _nullishCoalesce$9(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$l(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; }
|
|
3855
3825
|
const defaultTagPrefix = 'tag:yaml.org,2002:';
|
|
3856
3826
|
function findTagObject(value, tagName, tags) {
|
|
3857
3827
|
if (tagName) {
|
|
3858
3828
|
const match = tags.filter(t => t.tag === tagName);
|
|
3859
|
-
const tagObj = _nullishCoalesce$
|
|
3829
|
+
const tagObj = _nullishCoalesce$9(match.find(t => !t.format), () => ( match[0]));
|
|
3860
3830
|
if (!tagObj)
|
|
3861
3831
|
throw new Error(`Tag ${tagName} not found`);
|
|
3862
3832
|
return tagObj;
|
|
3863
3833
|
}
|
|
3864
|
-
return tags.find(t => _optionalChain$
|
|
3834
|
+
return tags.find(t => _optionalChain$l([t, 'access', _ => _.identify, 'optionalCall', _2 => _2(value)]) && !t.format);
|
|
3865
3835
|
}
|
|
3866
3836
|
function createNode(value, tagName, ctx) {
|
|
3867
3837
|
if (isDocument(value))
|
|
@@ -3869,7 +3839,7 @@ function createNode(value, tagName, ctx) {
|
|
|
3869
3839
|
if (isNode(value))
|
|
3870
3840
|
return value;
|
|
3871
3841
|
if (isPair(value)) {
|
|
3872
|
-
const map = _optionalChain$
|
|
3842
|
+
const map = _optionalChain$l([ctx, 'access', _3 => _3.schema, 'access', _4 => _4[MAP], 'access', _5 => _5.createNode, 'optionalCall', _6 => _6(ctx.schema, null, ctx)]);
|
|
3873
3843
|
map.items.push(value);
|
|
3874
3844
|
return map;
|
|
3875
3845
|
}
|
|
@@ -3888,7 +3858,7 @@ function createNode(value, tagName, ctx) {
|
|
|
3888
3858
|
if (aliasDuplicateObjects && value && typeof value === 'object') {
|
|
3889
3859
|
ref = sourceObjects.get(value);
|
|
3890
3860
|
if (ref) {
|
|
3891
|
-
_nullishCoalesce$
|
|
3861
|
+
_nullishCoalesce$9(ref.anchor, () => ( (ref.anchor = onAnchor(value))));
|
|
3892
3862
|
return new Alias(ref.anchor);
|
|
3893
3863
|
}
|
|
3894
3864
|
else {
|
|
@@ -3896,7 +3866,7 @@ function createNode(value, tagName, ctx) {
|
|
|
3896
3866
|
sourceObjects.set(value, ref);
|
|
3897
3867
|
}
|
|
3898
3868
|
}
|
|
3899
|
-
if (_optionalChain$
|
|
3869
|
+
if (_optionalChain$l([tagName, 'optionalAccess', _7 => _7.startsWith, 'call', _8 => _8('!!')]))
|
|
3900
3870
|
tagName = defaultTagPrefix + tagName.slice(2);
|
|
3901
3871
|
let tagObj = findTagObject(value, tagName, schema.tags);
|
|
3902
3872
|
if (!tagObj) {
|
|
@@ -3921,9 +3891,9 @@ function createNode(value, tagName, ctx) {
|
|
|
3921
3891
|
onTagObj(tagObj);
|
|
3922
3892
|
delete ctx.onTagObj;
|
|
3923
3893
|
}
|
|
3924
|
-
const node = _optionalChain$
|
|
3894
|
+
const node = _optionalChain$l([tagObj, 'optionalAccess', _9 => _9.createNode])
|
|
3925
3895
|
? tagObj.createNode(ctx.schema, value, ctx)
|
|
3926
|
-
: typeof _optionalChain$
|
|
3896
|
+
: typeof _optionalChain$l([tagObj, 'optionalAccess', _10 => _10.nodeClass, 'optionalAccess', _11 => _11.from]) === 'function'
|
|
3927
3897
|
? tagObj.nodeClass.from(ctx.schema, value, ctx)
|
|
3928
3898
|
: new Scalar(value);
|
|
3929
3899
|
if (tagName)
|
|
@@ -4241,7 +4211,7 @@ function consumeMoreIndentedLines(text, i, indent) {
|
|
|
4241
4211
|
return end;
|
|
4242
4212
|
}
|
|
4243
4213
|
|
|
4244
|
-
function _optionalChain$
|
|
4214
|
+
function _optionalChain$k(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; }
|
|
4245
4215
|
const getFoldOptions = (ctx, isBlock) => ({
|
|
4246
4216
|
indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
|
|
4247
4217
|
lineWidth: ctx.options.lineWidth,
|
|
@@ -4526,9 +4496,9 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
4526
4496
|
// booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
|
|
4527
4497
|
// and others in v1.1.
|
|
4528
4498
|
if (actualString) {
|
|
4529
|
-
const test = (tag) => tag.default && tag.tag !== 'tag:yaml.org,2002:str' && _optionalChain$
|
|
4499
|
+
const test = (tag) => tag.default && tag.tag !== 'tag:yaml.org,2002:str' && _optionalChain$k([tag, 'access', _ => _.test, 'optionalAccess', _2 => _2.test, 'call', _3 => _3(str)]);
|
|
4530
4500
|
const { compat, tags } = ctx.doc.schema;
|
|
4531
|
-
if (tags.some(test) || _optionalChain$
|
|
4501
|
+
if (tags.some(test) || _optionalChain$k([compat, 'optionalAccess', _4 => _4.some, 'call', _5 => _5(test)]))
|
|
4532
4502
|
return quotedString(value, ctx);
|
|
4533
4503
|
}
|
|
4534
4504
|
return implicitKey
|
|
@@ -4574,7 +4544,7 @@ function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
|
4574
4544
|
return res;
|
|
4575
4545
|
}
|
|
4576
4546
|
|
|
4577
|
-
function _nullishCoalesce$
|
|
4547
|
+
function _nullishCoalesce$8(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$j(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; }
|
|
4578
4548
|
function createStringifyContext(doc, options) {
|
|
4579
4549
|
const opt = Object.assign({
|
|
4580
4550
|
blockQuote: true,
|
|
@@ -4621,27 +4591,27 @@ function getTagObject(tags, item) {
|
|
|
4621
4591
|
if (item.tag) {
|
|
4622
4592
|
const match = tags.filter(t => t.tag === item.tag);
|
|
4623
4593
|
if (match.length > 0)
|
|
4624
|
-
return _nullishCoalesce$
|
|
4594
|
+
return _nullishCoalesce$8(match.find(t => t.format === item.format), () => ( match[0]));
|
|
4625
4595
|
}
|
|
4626
4596
|
let tagObj = undefined;
|
|
4627
4597
|
let obj;
|
|
4628
4598
|
if (isScalar(item)) {
|
|
4629
4599
|
obj = item.value;
|
|
4630
|
-
let match = tags.filter(t => _optionalChain$
|
|
4600
|
+
let match = tags.filter(t => _optionalChain$j([t, 'access', _ => _.identify, 'optionalCall', _2 => _2(obj)]));
|
|
4631
4601
|
if (match.length > 1) {
|
|
4632
4602
|
const testMatch = match.filter(t => t.test);
|
|
4633
4603
|
if (testMatch.length > 0)
|
|
4634
4604
|
match = testMatch;
|
|
4635
4605
|
}
|
|
4636
4606
|
tagObj =
|
|
4637
|
-
_nullishCoalesce$
|
|
4607
|
+
_nullishCoalesce$8(match.find(t => t.format === item.format), () => ( match.find(t => !t.format)));
|
|
4638
4608
|
}
|
|
4639
4609
|
else {
|
|
4640
4610
|
obj = item;
|
|
4641
4611
|
tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
|
|
4642
4612
|
}
|
|
4643
4613
|
if (!tagObj) {
|
|
4644
|
-
const name = _nullishCoalesce$
|
|
4614
|
+
const name = _nullishCoalesce$8(_optionalChain$j([obj, 'optionalAccess', _3 => _3.constructor, 'optionalAccess', _4 => _4.name]), () => ( (obj === null ? 'null' : typeof obj)));
|
|
4645
4615
|
throw new Error(`Tag not resolved for ${name} value`);
|
|
4646
4616
|
}
|
|
4647
4617
|
return tagObj;
|
|
@@ -4656,7 +4626,7 @@ function stringifyProps(node, tagObj, { anchors, doc }) {
|
|
|
4656
4626
|
anchors.add(anchor);
|
|
4657
4627
|
props.push(`&${anchor}`);
|
|
4658
4628
|
}
|
|
4659
|
-
const tag = _nullishCoalesce$
|
|
4629
|
+
const tag = _nullishCoalesce$8(node.tag, () => ( (tagObj.default ? null : tagObj.tag)));
|
|
4660
4630
|
if (tag)
|
|
4661
4631
|
props.push(doc.directives.tagString(tag));
|
|
4662
4632
|
return props.join(' ');
|
|
@@ -4667,7 +4637,7 @@ function stringify(item, ctx, onComment, onChompKeep) {
|
|
|
4667
4637
|
if (isAlias(item)) {
|
|
4668
4638
|
if (ctx.doc.directives)
|
|
4669
4639
|
return item.toString(ctx);
|
|
4670
|
-
if (_optionalChain$
|
|
4640
|
+
if (_optionalChain$j([ctx, 'access', _5 => _5.resolvedAliases, 'optionalAccess', _6 => _6.has, 'call', _7 => _7(item)])) {
|
|
4671
4641
|
throw new TypeError(`Cannot stringify circular structure without alias nodes`);
|
|
4672
4642
|
}
|
|
4673
4643
|
else {
|
|
@@ -4682,10 +4652,10 @@ function stringify(item, ctx, onComment, onChompKeep) {
|
|
|
4682
4652
|
const node = isNode(item)
|
|
4683
4653
|
? item
|
|
4684
4654
|
: ctx.doc.createNode(item, { onTagObj: o => (tagObj = o) });
|
|
4685
|
-
_nullishCoalesce$
|
|
4655
|
+
_nullishCoalesce$8(tagObj, () => ( (tagObj = getTagObject(ctx.doc.schema.tags, node))));
|
|
4686
4656
|
const props = stringifyProps(node, tagObj, ctx);
|
|
4687
4657
|
if (props.length > 0)
|
|
4688
|
-
ctx.indentAtStart = (_nullishCoalesce$
|
|
4658
|
+
ctx.indentAtStart = (_nullishCoalesce$8(ctx.indentAtStart, () => ( 0))) + props.length + 1;
|
|
4689
4659
|
const str = typeof tagObj.stringify === 'function'
|
|
4690
4660
|
? tagObj.stringify(node, ctx, onComment, onChompKeep)
|
|
4691
4661
|
: isScalar(node)
|
|
@@ -4698,7 +4668,7 @@ function stringify(item, ctx, onComment, onChompKeep) {
|
|
|
4698
4668
|
: `${props}\n${ctx.indent}${str}`;
|
|
4699
4669
|
}
|
|
4700
4670
|
|
|
4701
|
-
function _nullishCoalesce$
|
|
4671
|
+
function _nullishCoalesce$7(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
4702
4672
|
function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
|
|
4703
4673
|
const { allNullValues, doc, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx;
|
|
4704
4674
|
let keyComment = (isNode(key) && key.comment) || null;
|
|
@@ -4808,7 +4778,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
|
|
|
4808
4778
|
const vs0 = valueStr[0];
|
|
4809
4779
|
const nl0 = valueStr.indexOf('\n');
|
|
4810
4780
|
const hasNewline = nl0 !== -1;
|
|
4811
|
-
const flow = _nullishCoalesce$
|
|
4781
|
+
const flow = _nullishCoalesce$7(_nullishCoalesce$7(ctx.inFlow, () => ( value.flow)), () => ( value.items.length === 0));
|
|
4812
4782
|
if (hasNewline || !flow) {
|
|
4813
4783
|
let hasPropsLine = false;
|
|
4814
4784
|
if (hasNewline && (vs0 === '&' || vs0 === '!')) {
|
|
@@ -4849,7 +4819,7 @@ function warn(logLevel, warning) {
|
|
|
4849
4819
|
}
|
|
4850
4820
|
}
|
|
4851
4821
|
|
|
4852
|
-
function _optionalChain$
|
|
4822
|
+
function _optionalChain$i(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; }
|
|
4853
4823
|
// If the value associated with a merge key is a single mapping node, each of
|
|
4854
4824
|
// its key/value pairs is inserted into the current mapping, unless the key
|
|
4855
4825
|
// already exists in it. If the value associated with the merge key is a
|
|
@@ -4873,7 +4843,7 @@ const isMergeKey = (ctx, key) => (merge.identify(key) ||
|
|
|
4873
4843
|
(isScalar(key) &&
|
|
4874
4844
|
(!key.type || key.type === Scalar.PLAIN) &&
|
|
4875
4845
|
merge.identify(key.value))) &&
|
|
4876
|
-
_optionalChain$
|
|
4846
|
+
_optionalChain$i([ctx, 'optionalAccess', _ => _.doc, 'access', _2 => _2.schema, 'access', _3 => _3.tags, 'access', _4 => _4.some, 'call', _5 => _5(tag => tag.tag === merge.tag && tag.default)]);
|
|
4877
4847
|
function addMergeToJSMap(ctx, map, value) {
|
|
4878
4848
|
const source = resolveAliasValue(ctx, value);
|
|
4879
4849
|
if (isSeq(source))
|
|
@@ -4913,7 +4883,7 @@ function resolveAliasValue(ctx, value) {
|
|
|
4913
4883
|
return ctx && isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
|
|
4914
4884
|
}
|
|
4915
4885
|
|
|
4916
|
-
function _optionalChain$
|
|
4886
|
+
function _optionalChain$h(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; }
|
|
4917
4887
|
function addPairToJSMap(ctx, map, { key, value }) {
|
|
4918
4888
|
if (isNode(key) && key.addToJSMap)
|
|
4919
4889
|
key.addToJSMap(ctx, map, value);
|
|
@@ -4950,7 +4920,7 @@ function stringifyKey(key, jsKey, ctx) {
|
|
|
4950
4920
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
4951
4921
|
if (typeof jsKey !== 'object')
|
|
4952
4922
|
return String(jsKey);
|
|
4953
|
-
if (isNode(key) && _optionalChain$
|
|
4923
|
+
if (isNode(key) && _optionalChain$h([ctx, 'optionalAccess', _ => _.doc])) {
|
|
4954
4924
|
const strCtx = createStringifyContext(ctx.doc, {});
|
|
4955
4925
|
strCtx.anchors = new Set();
|
|
4956
4926
|
for (const node of ctx.anchors.keys())
|
|
@@ -4970,7 +4940,7 @@ function stringifyKey(key, jsKey, ctx) {
|
|
|
4970
4940
|
return JSON.stringify(jsKey);
|
|
4971
4941
|
}
|
|
4972
4942
|
|
|
4973
|
-
function _optionalChain$
|
|
4943
|
+
function _optionalChain$g(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; }
|
|
4974
4944
|
function createPair(key, value, ctx) {
|
|
4975
4945
|
const k = createNode(key, undefined, ctx);
|
|
4976
4946
|
const v = createNode(value, undefined, ctx);
|
|
@@ -4991,19 +4961,19 @@ class Pair {
|
|
|
4991
4961
|
return new Pair(key, value);
|
|
4992
4962
|
}
|
|
4993
4963
|
toJSON(_, ctx) {
|
|
4994
|
-
const pair = _optionalChain$
|
|
4964
|
+
const pair = _optionalChain$g([ctx, 'optionalAccess', _2 => _2.mapAsMap]) ? new Map() : {};
|
|
4995
4965
|
return addPairToJSMap(ctx, pair, this);
|
|
4996
4966
|
}
|
|
4997
4967
|
toString(ctx, onComment, onChompKeep) {
|
|
4998
|
-
return _optionalChain$
|
|
4968
|
+
return _optionalChain$g([ctx, 'optionalAccess', _3 => _3.doc])
|
|
4999
4969
|
? stringifyPair(this, ctx, onComment, onChompKeep)
|
|
5000
4970
|
: JSON.stringify(this);
|
|
5001
4971
|
}
|
|
5002
4972
|
}
|
|
5003
4973
|
|
|
5004
|
-
function _nullishCoalesce$
|
|
4974
|
+
function _nullishCoalesce$6(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$f(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; }
|
|
5005
4975
|
function stringifyCollection(collection, ctx, options) {
|
|
5006
|
-
const flow = _nullishCoalesce$
|
|
4976
|
+
const flow = _nullishCoalesce$6(ctx.inFlow, () => ( collection.flow));
|
|
5007
4977
|
const stringify = flow ? stringifyFlowCollection : stringifyBlockCollection;
|
|
5008
4978
|
return stringify(collection, ctx, options);
|
|
5009
4979
|
}
|
|
@@ -5095,7 +5065,7 @@ function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
|
|
|
5095
5065
|
if (iv.commentBefore)
|
|
5096
5066
|
reqNewline = true;
|
|
5097
5067
|
}
|
|
5098
|
-
else if (item.value == null && _optionalChain$
|
|
5068
|
+
else if (item.value == null && _optionalChain$f([ik, 'optionalAccess', _ => _.comment])) {
|
|
5099
5069
|
comment = ik.comment;
|
|
5100
5070
|
}
|
|
5101
5071
|
}
|
|
@@ -5150,7 +5120,7 @@ function addCommentBefore({ indent, options: { commentString } }, lines, comment
|
|
|
5150
5120
|
}
|
|
5151
5121
|
}
|
|
5152
5122
|
|
|
5153
|
-
function _nullishCoalesce$
|
|
5123
|
+
function _nullishCoalesce$5(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$e(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; }
|
|
5154
5124
|
function findPair(items, key) {
|
|
5155
5125
|
const k = isScalar(key) ? key.value : key;
|
|
5156
5126
|
for (const it of items) {
|
|
@@ -5211,12 +5181,12 @@ class YAMLMap extends Collection {
|
|
|
5211
5181
|
_pair = pair;
|
|
5212
5182
|
else if (!pair || typeof pair !== 'object' || !('key' in pair)) {
|
|
5213
5183
|
// In TypeScript, this never happens.
|
|
5214
|
-
_pair = new Pair(pair, _optionalChain$
|
|
5184
|
+
_pair = new Pair(pair, _optionalChain$e([pair, 'optionalAccess', _2 => _2.value]));
|
|
5215
5185
|
}
|
|
5216
5186
|
else
|
|
5217
5187
|
_pair = new Pair(pair.key, pair.value);
|
|
5218
5188
|
const prev = findPair(this.items, _pair.key);
|
|
5219
|
-
const sortEntries = _optionalChain$
|
|
5189
|
+
const sortEntries = _optionalChain$e([this, 'access', _3 => _3.schema, 'optionalAccess', _4 => _4.sortMapEntries]);
|
|
5220
5190
|
if (prev) {
|
|
5221
5191
|
if (!overwrite)
|
|
5222
5192
|
throw new Error(`Key ${_pair.key} already set`);
|
|
@@ -5246,8 +5216,8 @@ class YAMLMap extends Collection {
|
|
|
5246
5216
|
}
|
|
5247
5217
|
get(key, keepScalar) {
|
|
5248
5218
|
const it = findPair(this.items, key);
|
|
5249
|
-
const node = _optionalChain$
|
|
5250
|
-
return _nullishCoalesce$
|
|
5219
|
+
const node = _optionalChain$e([it, 'optionalAccess', _5 => _5.value]);
|
|
5220
|
+
return _nullishCoalesce$5((!keepScalar && isScalar(node) ? node.value : node), () => ( undefined));
|
|
5251
5221
|
}
|
|
5252
5222
|
has(key) {
|
|
5253
5223
|
return !!findPair(this.items, key);
|
|
@@ -5261,8 +5231,8 @@ class YAMLMap extends Collection {
|
|
|
5261
5231
|
* @returns Instance of Type, Map, or Object
|
|
5262
5232
|
*/
|
|
5263
5233
|
toJSON(_, ctx, Type) {
|
|
5264
|
-
const map = Type ? new Type() : _optionalChain$
|
|
5265
|
-
if (_optionalChain$
|
|
5234
|
+
const map = Type ? new Type() : _optionalChain$e([ctx, 'optionalAccess', _6 => _6.mapAsMap]) ? new Map() : {};
|
|
5235
|
+
if (_optionalChain$e([ctx, 'optionalAccess', _7 => _7.onCreate]))
|
|
5266
5236
|
ctx.onCreate(map);
|
|
5267
5237
|
for (const item of this.items)
|
|
5268
5238
|
addPairToJSMap(ctx, map, item);
|
|
@@ -5287,7 +5257,7 @@ class YAMLMap extends Collection {
|
|
|
5287
5257
|
}
|
|
5288
5258
|
}
|
|
5289
5259
|
|
|
5290
|
-
function _optionalChain$
|
|
5260
|
+
function _optionalChain$d(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; }
|
|
5291
5261
|
class YAMLSeq extends Collection {
|
|
5292
5262
|
static get tagName() {
|
|
5293
5263
|
return 'tag:yaml.org,2002:seq';
|
|
@@ -5350,7 +5320,7 @@ class YAMLSeq extends Collection {
|
|
|
5350
5320
|
}
|
|
5351
5321
|
toJSON(_, ctx) {
|
|
5352
5322
|
const seq = [];
|
|
5353
|
-
if (_optionalChain$
|
|
5323
|
+
if (_optionalChain$d([ctx, 'optionalAccess', _2 => _2.onCreate]))
|
|
5354
5324
|
ctx.onCreate(seq);
|
|
5355
5325
|
let i = 0;
|
|
5356
5326
|
for (const item of this.items)
|
|
@@ -5429,7 +5399,7 @@ function createPairs(schema, iterable, ctx) {
|
|
|
5429
5399
|
return pairs;
|
|
5430
5400
|
}
|
|
5431
5401
|
|
|
5432
|
-
function _optionalChain$
|
|
5402
|
+
function _optionalChain$c(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; }
|
|
5433
5403
|
class YAMLOMap extends YAMLSeq {
|
|
5434
5404
|
constructor() {
|
|
5435
5405
|
super();
|
|
@@ -5448,7 +5418,7 @@ class YAMLOMap extends YAMLSeq {
|
|
|
5448
5418
|
if (!ctx)
|
|
5449
5419
|
return super.toJSON(_);
|
|
5450
5420
|
const map = new Map();
|
|
5451
|
-
if (_optionalChain$
|
|
5421
|
+
if (_optionalChain$c([ctx, 'optionalAccess', _2 => _2.onCreate]))
|
|
5452
5422
|
ctx.onCreate(map);
|
|
5453
5423
|
for (const pair of this.items) {
|
|
5454
5424
|
let key, value;
|
|
@@ -5566,7 +5536,7 @@ const isDirExists = async (file) => {
|
|
|
5566
5536
|
}
|
|
5567
5537
|
};
|
|
5568
5538
|
|
|
5569
|
-
function _optionalChain$
|
|
5539
|
+
function _optionalChain$b(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; }// ABOUTME: Project type detection utility
|
|
5570
5540
|
|
|
5571
5541
|
/**
|
|
5572
5542
|
* 支持的项目类型枚举
|
|
@@ -5668,7 +5638,7 @@ const collectProjectInfo = async (
|
|
|
5668
5638
|
}
|
|
5669
5639
|
|
|
5670
5640
|
const scripts = Object.entries(
|
|
5671
|
-
(_optionalChain$
|
|
5641
|
+
(_optionalChain$b([packageJson, 'optionalAccess', _ => _.scripts]) ) || {},
|
|
5672
5642
|
).reduce((acc, [name, script]) => {
|
|
5673
5643
|
if (typeof script === 'string') {
|
|
5674
5644
|
acc[name] = script;
|
|
@@ -5822,7 +5792,7 @@ const detectProjectType = async (
|
|
|
5822
5792
|
};
|
|
5823
5793
|
};
|
|
5824
5794
|
|
|
5825
|
-
function _optionalChain$
|
|
5795
|
+
function _optionalChain$a(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; }
|
|
5826
5796
|
|
|
5827
5797
|
|
|
5828
5798
|
/**
|
|
@@ -5996,16 +5966,16 @@ const getCommandConfig = (
|
|
|
5996
5966
|
|
|
5997
5967
|
switch (commandName) {
|
|
5998
5968
|
case 'dev':
|
|
5999
|
-
commandConfig = _optionalChain$
|
|
5969
|
+
commandConfig = _optionalChain$a([config, 'access', _ => _.dev, 'optionalAccess', _2 => _2.run]);
|
|
6000
5970
|
break;
|
|
6001
5971
|
case 'build':
|
|
6002
|
-
commandConfig = _optionalChain$
|
|
5972
|
+
commandConfig = _optionalChain$a([config, 'access', _3 => _3.deploy, 'optionalAccess', _4 => _4.build]);
|
|
6003
5973
|
break;
|
|
6004
5974
|
case 'start':
|
|
6005
|
-
commandConfig = _optionalChain$
|
|
5975
|
+
commandConfig = _optionalChain$a([config, 'access', _5 => _5.deploy, 'optionalAccess', _6 => _6.run]);
|
|
6006
5976
|
break;
|
|
6007
5977
|
case 'validate':
|
|
6008
|
-
commandConfig = _optionalChain$
|
|
5978
|
+
commandConfig = _optionalChain$a([config, 'access', _7 => _7.dev, 'optionalAccess', _8 => _8.validate]);
|
|
6009
5979
|
break;
|
|
6010
5980
|
default:
|
|
6011
5981
|
throw new Error(`Unknown command: ${commandName}`);
|
|
@@ -6156,16 +6126,16 @@ const byFlag = (flag) => {
|
|
|
6156
6126
|
return predicate;
|
|
6157
6127
|
};
|
|
6158
6128
|
|
|
6159
|
-
function _optionalChain$
|
|
6129
|
+
function _optionalChain$9(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; }
|
|
6160
6130
|
|
|
6161
6131
|
|
|
6162
6132
|
|
|
6163
6133
|
|
|
6164
6134
|
|
|
6165
6135
|
|
|
6166
|
-
const PATCH_ID$
|
|
6167
|
-
const PACKAGE_JSON_FILE$
|
|
6168
|
-
const VALIDATE_SCRIPT_FILE$
|
|
6136
|
+
const PATCH_ID$7 = 'expo/validate@0.0.20';
|
|
6137
|
+
const PACKAGE_JSON_FILE$5 = 'package.json';
|
|
6138
|
+
const VALIDATE_SCRIPT_FILE$4 = '.cozeproj/scripts/validate.sh';
|
|
6169
6139
|
const EXPO_VALIDATE_FLAG = 'coding.arch.patch_expo_validate';
|
|
6170
6140
|
const TARGET_VALIDATE$3 = "pnpm run --parallel '/^(lint:client|lint:server)$/'";
|
|
6171
6141
|
const TARGET_VALIDATE_SCRIPT$3 = `#!/bin/bash
|
|
@@ -6187,7 +6157,7 @@ echo "Validate passed!"
|
|
|
6187
6157
|
* @returns
|
|
6188
6158
|
*/
|
|
6189
6159
|
const isCozeValid$3 = (cozeConfig) => {
|
|
6190
|
-
if (_optionalChain$
|
|
6160
|
+
if (_optionalChain$9([cozeConfig, 'access', _ => _.dev, 'optionalAccess', _2 => _2.validate])) {
|
|
6191
6161
|
logger.info('[patch-expo-validate] NOT APPLY: dev.validate exists');
|
|
6192
6162
|
return false;
|
|
6193
6163
|
}
|
|
@@ -6203,7 +6173,7 @@ const isCozeValid$3 = (cozeConfig) => {
|
|
|
6203
6173
|
* @returns
|
|
6204
6174
|
*/
|
|
6205
6175
|
const isPackageJsonValid$3 = async (projectFolder) => {
|
|
6206
|
-
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$
|
|
6176
|
+
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$5);
|
|
6207
6177
|
if (!(await isFileExists(packageJsonPath))) {
|
|
6208
6178
|
logger.info('[patch-expo-validate] NOT APPLY: package.json not found');
|
|
6209
6179
|
return false;
|
|
@@ -6239,7 +6209,7 @@ const isPackageJsonValid$3 = async (projectFolder) => {
|
|
|
6239
6209
|
* @returns
|
|
6240
6210
|
*/
|
|
6241
6211
|
const isScriptValid$3 = async (projectFolder) => {
|
|
6242
|
-
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE$
|
|
6212
|
+
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE$4);
|
|
6243
6213
|
if (await isFileExists(validateScriptPath)) {
|
|
6244
6214
|
logger.info('NOT APPLY: validate.sh already exists');
|
|
6245
6215
|
return false;
|
|
@@ -6253,7 +6223,7 @@ const isScriptValid$3 = async (projectFolder) => {
|
|
|
6253
6223
|
* @returns
|
|
6254
6224
|
*/
|
|
6255
6225
|
const patchPackageJson$3 = async (projectFolder) => {
|
|
6256
|
-
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$
|
|
6226
|
+
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$5);
|
|
6257
6227
|
const packageJsonContent = await fs$1.readFile(packageJsonPath, 'utf-8');
|
|
6258
6228
|
const packageJson = safeJsonParse(packageJsonContent, null);
|
|
6259
6229
|
const scripts = packageJson.scripts || {};
|
|
@@ -6273,7 +6243,7 @@ const patchPackageJson$3 = async (projectFolder) => {
|
|
|
6273
6243
|
* @returns
|
|
6274
6244
|
*/
|
|
6275
6245
|
const patchValidateScript$3 = async (projectFolder) => {
|
|
6276
|
-
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE$
|
|
6246
|
+
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE$4);
|
|
6277
6247
|
await fs$1.mkdir(path.join(projectFolder, '.cozeproj', 'scripts'), { recursive: true });
|
|
6278
6248
|
await fs$1.writeFile(validateScriptPath, TARGET_VALIDATE_SCRIPT$3, 'utf-8');
|
|
6279
6249
|
logger.info('[patch-expo-validate] validate.sh patched');
|
|
@@ -6293,18 +6263,18 @@ const patchCoze$3 = (cozeConfig) => {
|
|
|
6293
6263
|
};
|
|
6294
6264
|
|
|
6295
6265
|
const patchExpoValidate = {
|
|
6296
|
-
id: PATCH_ID$
|
|
6266
|
+
id: PATCH_ID$7,
|
|
6297
6267
|
template: 'expo',
|
|
6298
6268
|
disabled: byFlag(EXPO_VALIDATE_FLAG),
|
|
6299
6269
|
operations: [
|
|
6300
6270
|
{
|
|
6301
6271
|
kind: 'file-patch',
|
|
6302
|
-
file: PACKAGE_JSON_FILE$
|
|
6272
|
+
file: PACKAGE_JSON_FILE$5,
|
|
6303
6273
|
description: 'Add validate script for expo projects',
|
|
6304
6274
|
},
|
|
6305
6275
|
{
|
|
6306
6276
|
kind: 'create-file',
|
|
6307
|
-
file: VALIDATE_SCRIPT_FILE$
|
|
6277
|
+
file: VALIDATE_SCRIPT_FILE$4,
|
|
6308
6278
|
description: 'Add validate shell script for expo projects',
|
|
6309
6279
|
},
|
|
6310
6280
|
{
|
|
@@ -6326,22 +6296,22 @@ const patchExpoValidate = {
|
|
|
6326
6296
|
|
|
6327
6297
|
return {
|
|
6328
6298
|
applied: true,
|
|
6329
|
-
patchId: PATCH_ID$
|
|
6299
|
+
patchId: PATCH_ID$7,
|
|
6330
6300
|
message: 'expo validate patched',
|
|
6331
6301
|
};
|
|
6332
6302
|
},
|
|
6333
6303
|
};
|
|
6334
6304
|
|
|
6335
|
-
function _optionalChain$
|
|
6305
|
+
function _optionalChain$8(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; }
|
|
6336
6306
|
|
|
6337
6307
|
|
|
6338
6308
|
|
|
6339
6309
|
|
|
6340
6310
|
|
|
6341
6311
|
|
|
6342
|
-
const PATCH_ID$
|
|
6343
|
-
const PACKAGE_JSON_FILE$
|
|
6344
|
-
const VALIDATE_SCRIPT_FILE$
|
|
6312
|
+
const PATCH_ID$6 = 'nextjs/validate@0.0.20';
|
|
6313
|
+
const PACKAGE_JSON_FILE$4 = 'package.json';
|
|
6314
|
+
const VALIDATE_SCRIPT_FILE$3 = 'scripts/validate.sh';
|
|
6345
6315
|
const NEXTJS_VALIDATE_FLAG = 'coding.arch.patch_nextjs_validate';
|
|
6346
6316
|
const TARGET_LINT_BUILD$2 = 'eslint . --quiet';
|
|
6347
6317
|
const TARGET_VALIDATE$2 = "pnpm run --parallel '/^(ts-check|lint:build)$/'";
|
|
@@ -6365,7 +6335,7 @@ echo "Validate passed!"
|
|
|
6365
6335
|
* @returns
|
|
6366
6336
|
*/
|
|
6367
6337
|
const isCozeValid$2 = (cozeConfig) => {
|
|
6368
|
-
if (_optionalChain$
|
|
6338
|
+
if (_optionalChain$8([cozeConfig, 'access', _ => _.dev, 'optionalAccess', _2 => _2.validate])) {
|
|
6369
6339
|
logger.info('[patch-nextjs-validate] NOT APPLY: dev.validate exists');
|
|
6370
6340
|
return false;
|
|
6371
6341
|
}
|
|
@@ -6381,7 +6351,7 @@ const isCozeValid$2 = (cozeConfig) => {
|
|
|
6381
6351
|
* @returns
|
|
6382
6352
|
*/
|
|
6383
6353
|
const isPackageJsonValid$2 = async (projectFolder) => {
|
|
6384
|
-
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$
|
|
6354
|
+
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$4);
|
|
6385
6355
|
if (!(await isFileExists(packageJsonPath))) {
|
|
6386
6356
|
logger.info('[patch-nextjs-validate] NOT APPLY: package.json not found');
|
|
6387
6357
|
return false;
|
|
@@ -6413,7 +6383,7 @@ const isPackageJsonValid$2 = async (projectFolder) => {
|
|
|
6413
6383
|
* @returns
|
|
6414
6384
|
*/
|
|
6415
6385
|
const isScriptValid$2 = async (projectFolder) => {
|
|
6416
|
-
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE$
|
|
6386
|
+
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE$3);
|
|
6417
6387
|
if (await isFileExists(validateScriptPath)) {
|
|
6418
6388
|
logger.info(
|
|
6419
6389
|
'[patch-nextjs-validate] NOT APPLY: validate.sh already exists',
|
|
@@ -6429,7 +6399,7 @@ const isScriptValid$2 = async (projectFolder) => {
|
|
|
6429
6399
|
* @returns
|
|
6430
6400
|
*/
|
|
6431
6401
|
const patchPackageJson$2 = async (projectFolder) => {
|
|
6432
|
-
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$
|
|
6402
|
+
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$4);
|
|
6433
6403
|
const packageJsonContent = await fs$1.readFile(packageJsonPath, 'utf-8');
|
|
6434
6404
|
const packageJson = safeJsonParse(packageJsonContent, null);
|
|
6435
6405
|
const scripts = packageJson.scripts || {};
|
|
@@ -6454,7 +6424,7 @@ const patchPackageJson$2 = async (projectFolder) => {
|
|
|
6454
6424
|
* @returns
|
|
6455
6425
|
*/
|
|
6456
6426
|
const patchValidateScript$2 = async (projectFolder) => {
|
|
6457
|
-
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE$
|
|
6427
|
+
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE$3);
|
|
6458
6428
|
await fs$1.mkdir(path.join(projectFolder, 'scripts'), { recursive: true });
|
|
6459
6429
|
await fs$1.writeFile(validateScriptPath, TARGET_VALIDATE_SCRIPT$2, 'utf-8');
|
|
6460
6430
|
logger.info('[patch-nextjs-validate] validate.sh patched');
|
|
@@ -6474,18 +6444,18 @@ const patchCoze$2 = (cozeConfig) => {
|
|
|
6474
6444
|
};
|
|
6475
6445
|
|
|
6476
6446
|
const patchNextjsValidate = {
|
|
6477
|
-
id: PATCH_ID$
|
|
6447
|
+
id: PATCH_ID$6,
|
|
6478
6448
|
template: 'nextjs',
|
|
6479
6449
|
disabled: byFlag(NEXTJS_VALIDATE_FLAG),
|
|
6480
6450
|
operations: [
|
|
6481
6451
|
{
|
|
6482
6452
|
kind: 'file-patch',
|
|
6483
|
-
file: PACKAGE_JSON_FILE$
|
|
6453
|
+
file: PACKAGE_JSON_FILE$4,
|
|
6484
6454
|
description: 'Add lint:build and validate scripts for nextjs projects',
|
|
6485
6455
|
},
|
|
6486
6456
|
{
|
|
6487
6457
|
kind: 'create-file',
|
|
6488
|
-
file: VALIDATE_SCRIPT_FILE$
|
|
6458
|
+
file: VALIDATE_SCRIPT_FILE$3,
|
|
6489
6459
|
description: 'Add validate shell script for nextjs projects',
|
|
6490
6460
|
},
|
|
6491
6461
|
{
|
|
@@ -6507,22 +6477,22 @@ const patchNextjsValidate = {
|
|
|
6507
6477
|
|
|
6508
6478
|
return {
|
|
6509
6479
|
applied: true,
|
|
6510
|
-
patchId: PATCH_ID$
|
|
6480
|
+
patchId: PATCH_ID$6,
|
|
6511
6481
|
message: 'nextjs validate patched',
|
|
6512
6482
|
};
|
|
6513
6483
|
},
|
|
6514
6484
|
};
|
|
6515
6485
|
|
|
6516
|
-
function _optionalChain$
|
|
6486
|
+
function _optionalChain$7(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; }
|
|
6517
6487
|
|
|
6518
6488
|
|
|
6519
6489
|
|
|
6520
6490
|
|
|
6521
6491
|
|
|
6522
6492
|
|
|
6523
|
-
const PATCH_ID$
|
|
6524
|
-
const PACKAGE_JSON_FILE$
|
|
6525
|
-
const VALIDATE_SCRIPT_FILE$
|
|
6493
|
+
const PATCH_ID$5 = 'vite/validate@0.0.20';
|
|
6494
|
+
const PACKAGE_JSON_FILE$3 = 'package.json';
|
|
6495
|
+
const VALIDATE_SCRIPT_FILE$2 = 'scripts/validate.sh';
|
|
6526
6496
|
const VITE_VALIDATE_FLAG = 'coding.arch.patch_vite_validate';
|
|
6527
6497
|
const TARGET_LINT_BUILD$1 = 'eslint . --quiet';
|
|
6528
6498
|
const TARGET_VALIDATE$1 = "pnpm run --parallel '/^(ts-check|lint:build)$/'";
|
|
@@ -6546,7 +6516,7 @@ echo "Validate passed!"
|
|
|
6546
6516
|
* @returns
|
|
6547
6517
|
*/
|
|
6548
6518
|
const isCozeValid$1 = (cozeConfig) => {
|
|
6549
|
-
if (_optionalChain$
|
|
6519
|
+
if (_optionalChain$7([cozeConfig, 'access', _ => _.dev, 'optionalAccess', _2 => _2.validate])) {
|
|
6550
6520
|
logger.info('[patch-vite-validate] NOT APPLY: dev.validate exists');
|
|
6551
6521
|
return false;
|
|
6552
6522
|
}
|
|
@@ -6562,7 +6532,7 @@ const isCozeValid$1 = (cozeConfig) => {
|
|
|
6562
6532
|
* @returns
|
|
6563
6533
|
*/
|
|
6564
6534
|
const isPackageJsonValid$1 = async (projectFolder) => {
|
|
6565
|
-
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$
|
|
6535
|
+
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$3);
|
|
6566
6536
|
if (!(await isFileExists(packageJsonPath))) {
|
|
6567
6537
|
logger.info('[patch-vite-validate] NOT APPLY: package.json not found');
|
|
6568
6538
|
return false;
|
|
@@ -6594,7 +6564,7 @@ const isPackageJsonValid$1 = async (projectFolder) => {
|
|
|
6594
6564
|
* @returns
|
|
6595
6565
|
*/
|
|
6596
6566
|
const isScriptValid$1 = async (projectFolder) => {
|
|
6597
|
-
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE$
|
|
6567
|
+
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE$2);
|
|
6598
6568
|
if (await isFileExists(validateScriptPath)) {
|
|
6599
6569
|
logger.info('[patch-vite-validate] NOT APPLY: validate.sh already exists');
|
|
6600
6570
|
return false;
|
|
@@ -6608,7 +6578,7 @@ const isScriptValid$1 = async (projectFolder) => {
|
|
|
6608
6578
|
* @returns
|
|
6609
6579
|
*/
|
|
6610
6580
|
const patchPackageJson$1 = async (projectFolder) => {
|
|
6611
|
-
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$
|
|
6581
|
+
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$3);
|
|
6612
6582
|
const packageJsonContent = await fs$1.readFile(packageJsonPath, 'utf-8');
|
|
6613
6583
|
const packageJson = safeJsonParse(packageJsonContent, null);
|
|
6614
6584
|
const scripts = packageJson.scripts || {};
|
|
@@ -6632,7 +6602,7 @@ const patchPackageJson$1 = async (projectFolder) => {
|
|
|
6632
6602
|
* @returns
|
|
6633
6603
|
*/
|
|
6634
6604
|
const patchValidateScript$1 = async (projectFolder) => {
|
|
6635
|
-
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE$
|
|
6605
|
+
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE$2);
|
|
6636
6606
|
await fs$1.mkdir(path.join(projectFolder, 'scripts'), { recursive: true });
|
|
6637
6607
|
await fs$1.writeFile(validateScriptPath, TARGET_VALIDATE_SCRIPT$1, 'utf-8');
|
|
6638
6608
|
logger.info('[patch-vite-validate] validate.sh patched');
|
|
@@ -6652,18 +6622,18 @@ const patchCoze$1 = (cozeConfig) => {
|
|
|
6652
6622
|
};
|
|
6653
6623
|
|
|
6654
6624
|
const patchViteValidate = {
|
|
6655
|
-
id: PATCH_ID$
|
|
6625
|
+
id: PATCH_ID$5,
|
|
6656
6626
|
template: 'vite',
|
|
6657
6627
|
disabled: byFlag(VITE_VALIDATE_FLAG),
|
|
6658
6628
|
operations: [
|
|
6659
6629
|
{
|
|
6660
6630
|
kind: 'file-patch',
|
|
6661
|
-
file: PACKAGE_JSON_FILE$
|
|
6631
|
+
file: PACKAGE_JSON_FILE$3,
|
|
6662
6632
|
description: 'Add lint:build and validate scripts for vite projects',
|
|
6663
6633
|
},
|
|
6664
6634
|
{
|
|
6665
6635
|
kind: 'create-file',
|
|
6666
|
-
file: VALIDATE_SCRIPT_FILE$
|
|
6636
|
+
file: VALIDATE_SCRIPT_FILE$2,
|
|
6667
6637
|
description: 'Add validate shell script for vite projects',
|
|
6668
6638
|
},
|
|
6669
6639
|
{
|
|
@@ -6685,22 +6655,22 @@ const patchViteValidate = {
|
|
|
6685
6655
|
|
|
6686
6656
|
return {
|
|
6687
6657
|
applied: true,
|
|
6688
|
-
patchId: PATCH_ID$
|
|
6658
|
+
patchId: PATCH_ID$5,
|
|
6689
6659
|
message: 'vite validate patched',
|
|
6690
6660
|
};
|
|
6691
6661
|
},
|
|
6692
6662
|
};
|
|
6693
6663
|
|
|
6694
|
-
function _optionalChain$
|
|
6664
|
+
function _optionalChain$6(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; }
|
|
6695
6665
|
|
|
6696
6666
|
|
|
6697
6667
|
|
|
6698
6668
|
|
|
6699
6669
|
|
|
6700
6670
|
|
|
6701
|
-
const PATCH_ID$
|
|
6702
|
-
const PACKAGE_JSON_FILE$
|
|
6703
|
-
const VALIDATE_SCRIPT_FILE = '.cozeproj/scripts/validate.sh';
|
|
6671
|
+
const PATCH_ID$4 = 'taro/validate@0.0.20';
|
|
6672
|
+
const PACKAGE_JSON_FILE$2 = 'package.json';
|
|
6673
|
+
const VALIDATE_SCRIPT_FILE$1 = '.cozeproj/scripts/validate.sh';
|
|
6704
6674
|
const TARO_VALIDATE_FLAG = 'coding.arch.patch_taro_validate';
|
|
6705
6675
|
|
|
6706
6676
|
const LEGACY_LINT_BUILD =
|
|
@@ -6728,7 +6698,7 @@ echo "Validate passed!"
|
|
|
6728
6698
|
* @returns
|
|
6729
6699
|
*/
|
|
6730
6700
|
const isCozeValid = (cozeConfig) => {
|
|
6731
|
-
if (_optionalChain$
|
|
6701
|
+
if (_optionalChain$6([cozeConfig, 'access', _ => _.dev, 'optionalAccess', _2 => _2.validate])) {
|
|
6732
6702
|
logger.info('[patch-taro-validate] NOT APPLY: dev.validate exists');
|
|
6733
6703
|
return false;
|
|
6734
6704
|
}
|
|
@@ -6744,7 +6714,7 @@ const isCozeValid = (cozeConfig) => {
|
|
|
6744
6714
|
* @returns
|
|
6745
6715
|
*/
|
|
6746
6716
|
const isPackageJsonValid = async (projectFolder) => {
|
|
6747
|
-
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$
|
|
6717
|
+
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$2);
|
|
6748
6718
|
if (!(await isFileExists(packageJsonPath))) {
|
|
6749
6719
|
logger.info('[patch-taro-validate] NOT APPLY: package.json not found');
|
|
6750
6720
|
return false;
|
|
@@ -6778,7 +6748,7 @@ const isPackageJsonValid = async (projectFolder) => {
|
|
|
6778
6748
|
* @returns
|
|
6779
6749
|
*/
|
|
6780
6750
|
const isScriptValid = async (projectFolder) => {
|
|
6781
|
-
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE);
|
|
6751
|
+
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE$1);
|
|
6782
6752
|
if (await isFileExists(validateScriptPath)) {
|
|
6783
6753
|
logger.info('[patch-taro-validate] NOT APPLY: validate.sh already exists');
|
|
6784
6754
|
return false;
|
|
@@ -6792,7 +6762,7 @@ const isScriptValid = async (projectFolder) => {
|
|
|
6792
6762
|
* @returns
|
|
6793
6763
|
*/
|
|
6794
6764
|
const patchPackageJson = async (projectFolder) => {
|
|
6795
|
-
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$
|
|
6765
|
+
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$2);
|
|
6796
6766
|
const packageJsonContent = await fs$1.readFile(packageJsonPath, 'utf-8');
|
|
6797
6767
|
const packageJson = safeJsonParse(packageJsonContent, null);
|
|
6798
6768
|
const scripts = packageJson.scripts || {};
|
|
@@ -6819,7 +6789,7 @@ const patchPackageJson = async (projectFolder) => {
|
|
|
6819
6789
|
* @returns
|
|
6820
6790
|
*/
|
|
6821
6791
|
const patchValidateScript = async (projectFolder) => {
|
|
6822
|
-
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE);
|
|
6792
|
+
const validateScriptPath = path.join(projectFolder, VALIDATE_SCRIPT_FILE$1);
|
|
6823
6793
|
await fs$1.mkdir(path.join(projectFolder, '.cozeproj', 'scripts'), { recursive: true });
|
|
6824
6794
|
await fs$1.writeFile(validateScriptPath, TARGET_VALIDATE_SCRIPT, 'utf-8');
|
|
6825
6795
|
logger.info('[patch-taro-validate] validate.sh patched');
|
|
@@ -6839,19 +6809,19 @@ const patchCoze = (cozeConfig) => {
|
|
|
6839
6809
|
};
|
|
6840
6810
|
|
|
6841
6811
|
const patchTaroValidate = {
|
|
6842
|
-
id: PATCH_ID$
|
|
6812
|
+
id: PATCH_ID$4,
|
|
6843
6813
|
template: 'taro',
|
|
6844
6814
|
disabled: byFlag(TARO_VALIDATE_FLAG),
|
|
6845
6815
|
operations: [
|
|
6846
6816
|
{
|
|
6847
6817
|
kind: 'file-patch',
|
|
6848
|
-
file: PACKAGE_JSON_FILE$
|
|
6818
|
+
file: PACKAGE_JSON_FILE$2,
|
|
6849
6819
|
description:
|
|
6850
6820
|
'Update lint:build and add validate script for taro projects',
|
|
6851
6821
|
},
|
|
6852
6822
|
{
|
|
6853
6823
|
kind: 'create-file',
|
|
6854
|
-
file: VALIDATE_SCRIPT_FILE,
|
|
6824
|
+
file: VALIDATE_SCRIPT_FILE$1,
|
|
6855
6825
|
description: 'Add validate shell script for taro projects',
|
|
6856
6826
|
},
|
|
6857
6827
|
{
|
|
@@ -6871,15 +6841,15 @@ const patchTaroValidate = {
|
|
|
6871
6841
|
|
|
6872
6842
|
return {
|
|
6873
6843
|
applied: true,
|
|
6874
|
-
patchId: PATCH_ID$
|
|
6844
|
+
patchId: PATCH_ID$4,
|
|
6875
6845
|
message: 'taro validate patched',
|
|
6876
6846
|
};
|
|
6877
6847
|
},
|
|
6878
6848
|
};
|
|
6879
6849
|
|
|
6880
|
-
function _optionalChain$
|
|
6881
|
-
const PATCH_ID$
|
|
6882
|
-
const PACKAGE_JSON_FILE = 'package.json';
|
|
6850
|
+
function _optionalChain$5(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; }
|
|
6851
|
+
const PATCH_ID$3 = 'taro/update-pack-script-for-tt-build@0.0.13';
|
|
6852
|
+
const PACKAGE_JSON_FILE$1 = 'package.json';
|
|
6883
6853
|
const PACK_SCRIPT_FILE = '.cozeproj/scripts/pack.sh';
|
|
6884
6854
|
const LEGACY_PACK_SCRIPT_HASHES = new Set([
|
|
6885
6855
|
'987575c08e1c32ce7bc553e1668b3ad8faad5623343fd0d21fea34d39f25a56d',
|
|
@@ -6948,7 +6918,7 @@ const hashContent = (content) =>
|
|
|
6948
6918
|
const readPackageScripts = async (
|
|
6949
6919
|
projectFolder,
|
|
6950
6920
|
) => {
|
|
6951
|
-
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE);
|
|
6921
|
+
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE$1);
|
|
6952
6922
|
if (!(await isFileExists(packageJsonPath))) {
|
|
6953
6923
|
return null;
|
|
6954
6924
|
}
|
|
@@ -6956,12 +6926,12 @@ const readPackageScripts = async (
|
|
|
6956
6926
|
const packageJsonContent = await fs$1.readFile(packageJsonPath, 'utf-8');
|
|
6957
6927
|
const packageJson = safeJsonParse(packageJsonContent, null);
|
|
6958
6928
|
|
|
6959
|
-
return _optionalChain$
|
|
6929
|
+
return _optionalChain$5([packageJson, 'optionalAccess', _ => _.scripts]) || null;
|
|
6960
6930
|
};
|
|
6961
6931
|
|
|
6962
6932
|
const hasBuildTtScript = async (projectFolder) => {
|
|
6963
6933
|
const scripts = await readPackageScripts(projectFolder);
|
|
6964
|
-
return typeof _optionalChain$
|
|
6934
|
+
return typeof _optionalChain$5([scripts, 'optionalAccess', _2 => _2['build:tt']]) === 'string';
|
|
6965
6935
|
};
|
|
6966
6936
|
|
|
6967
6937
|
const hasLegacyPackScript = async (projectFolder) => {
|
|
@@ -6975,7 +6945,7 @@ const hasLegacyPackScript = async (projectFolder) => {
|
|
|
6975
6945
|
};
|
|
6976
6946
|
|
|
6977
6947
|
const patchTaroPackScript = {
|
|
6978
|
-
id: PATCH_ID$
|
|
6948
|
+
id: PATCH_ID$3,
|
|
6979
6949
|
template: 'taro',
|
|
6980
6950
|
disabled: byFlag('coding.arch.patch_taro_update_pack_script_for_tt_build'),
|
|
6981
6951
|
operations: [
|
|
@@ -6994,7 +6964,7 @@ const patchTaroPackScript = {
|
|
|
6994
6964
|
if (context.template !== 'taro') {
|
|
6995
6965
|
return {
|
|
6996
6966
|
applied: false,
|
|
6997
|
-
patchId: PATCH_ID$
|
|
6967
|
+
patchId: PATCH_ID$3,
|
|
6998
6968
|
message: 'Only applies to taro projects, skipping',
|
|
6999
6969
|
};
|
|
7000
6970
|
}
|
|
@@ -7002,7 +6972,7 @@ const patchTaroPackScript = {
|
|
|
7002
6972
|
if (!(await hasBuildTtScript(context.projectFolder))) {
|
|
7003
6973
|
return {
|
|
7004
6974
|
applied: false,
|
|
7005
|
-
patchId: PATCH_ID$
|
|
6975
|
+
patchId: PATCH_ID$3,
|
|
7006
6976
|
message: 'package.json does not contain build:tt, skipping',
|
|
7007
6977
|
};
|
|
7008
6978
|
}
|
|
@@ -7010,7 +6980,7 @@ const patchTaroPackScript = {
|
|
|
7010
6980
|
if (!(await hasLegacyPackScript(context.projectFolder))) {
|
|
7011
6981
|
return {
|
|
7012
6982
|
applied: false,
|
|
7013
|
-
patchId: PATCH_ID$
|
|
6983
|
+
patchId: PATCH_ID$3,
|
|
7014
6984
|
message: 'pack.sh does not match legacy template hash, skipping',
|
|
7015
6985
|
};
|
|
7016
6986
|
}
|
|
@@ -7024,13 +6994,13 @@ const patchTaroPackScript = {
|
|
|
7024
6994
|
|
|
7025
6995
|
return {
|
|
7026
6996
|
applied: true,
|
|
7027
|
-
patchId: PATCH_ID$
|
|
6997
|
+
patchId: PATCH_ID$3,
|
|
7028
6998
|
message: 'Updated legacy pack.sh to build weapp and tt targets',
|
|
7029
6999
|
};
|
|
7030
7000
|
},
|
|
7031
7001
|
};
|
|
7032
7002
|
|
|
7033
|
-
const PATCH_ID$
|
|
7003
|
+
const PATCH_ID$2 = 'taro/add-agents-md@0.0.13';
|
|
7034
7004
|
const AGENTS_FILE = 'AGENTS.md';
|
|
7035
7005
|
const getTemplateAgentsPath = () =>
|
|
7036
7006
|
path.join(getTemplatesDir(), 'taro', AGENTS_FILE);
|
|
@@ -7042,7 +7012,7 @@ const readTemplateAgentsContent = async () =>
|
|
|
7042
7012
|
fs$1.readFile(getTemplateAgentsPath(), 'utf-8');
|
|
7043
7013
|
|
|
7044
7014
|
const patchTaroAgentsMd = {
|
|
7045
|
-
id: PATCH_ID$
|
|
7015
|
+
id: PATCH_ID$2,
|
|
7046
7016
|
template: 'taro',
|
|
7047
7017
|
disabled: byFlag('coding.arch.patch_taro_add_agents_md'),
|
|
7048
7018
|
operations: [
|
|
@@ -7060,7 +7030,7 @@ const patchTaroAgentsMd = {
|
|
|
7060
7030
|
if (context.template !== 'taro') {
|
|
7061
7031
|
return {
|
|
7062
7032
|
applied: false,
|
|
7063
|
-
patchId: PATCH_ID$
|
|
7033
|
+
patchId: PATCH_ID$2,
|
|
7064
7034
|
message: 'Only applies to taro projects, skipping',
|
|
7065
7035
|
};
|
|
7066
7036
|
}
|
|
@@ -7069,7 +7039,7 @@ const patchTaroAgentsMd = {
|
|
|
7069
7039
|
if (await isFileExists(targetPath)) {
|
|
7070
7040
|
return {
|
|
7071
7041
|
applied: false,
|
|
7072
|
-
patchId: PATCH_ID$
|
|
7042
|
+
patchId: PATCH_ID$2,
|
|
7073
7043
|
message: 'AGENTS.md already exists, skipping',
|
|
7074
7044
|
};
|
|
7075
7045
|
}
|
|
@@ -7079,12 +7049,146 @@ const patchTaroAgentsMd = {
|
|
|
7079
7049
|
|
|
7080
7050
|
return {
|
|
7081
7051
|
applied: true,
|
|
7082
|
-
patchId: PATCH_ID$
|
|
7052
|
+
patchId: PATCH_ID$2,
|
|
7083
7053
|
message: 'Created AGENTS.md from taro template',
|
|
7084
7054
|
};
|
|
7085
7055
|
},
|
|
7086
7056
|
};
|
|
7087
7057
|
|
|
7058
|
+
function _optionalChain$4(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; }
|
|
7059
|
+
|
|
7060
|
+
|
|
7061
|
+
|
|
7062
|
+
|
|
7063
|
+
|
|
7064
|
+
const OLD_WEB_TEMPLATE_VALIDATE_SCRIPT = `#!/bin/bash
|
|
7065
|
+
set -Eeuo pipefail
|
|
7066
|
+
|
|
7067
|
+
COZE_WORKSPACE_PATH="\${COZE_WORKSPACE_PATH:-$(pwd)}"
|
|
7068
|
+
|
|
7069
|
+
cd "\${COZE_WORKSPACE_PATH}"
|
|
7070
|
+
|
|
7071
|
+
echo "\u{1F50D} Running validate..."
|
|
7072
|
+
pnpm validate
|
|
7073
|
+
echo "\u{2705} Validate passed!"
|
|
7074
|
+
`;
|
|
7075
|
+
|
|
7076
|
+
const OLD_WEB_PATCH_VALIDATE_SCRIPT = `#!/bin/bash
|
|
7077
|
+
set -Eeuo pipefail
|
|
7078
|
+
COZE_WORKSPACE_PATH="\${COZE_WORKSPACE_PATH:-$(pwd)}"
|
|
7079
|
+
cd "\${COZE_WORKSPACE_PATH}"
|
|
7080
|
+
echo "Running validate..."
|
|
7081
|
+
pnpm validate
|
|
7082
|
+
echo "Validate passed!"
|
|
7083
|
+
`;
|
|
7084
|
+
|
|
7085
|
+
const createValidateScript = (parallelArgs) => `#!/bin/bash
|
|
7086
|
+
set -Eeuo pipefail
|
|
7087
|
+
|
|
7088
|
+
COZE_WORKSPACE_PATH="\${COZE_WORKSPACE_PATH:-$(pwd)}"
|
|
7089
|
+
|
|
7090
|
+
cd "\${COZE_WORKSPACE_PATH}"
|
|
7091
|
+
|
|
7092
|
+
echo "Running validate..."
|
|
7093
|
+
coze-dev parallel ${parallelArgs}
|
|
7094
|
+
echo "Validate passed!"
|
|
7095
|
+
`;
|
|
7096
|
+
|
|
7097
|
+
const PACKAGE_JSON_FILE = 'package.json';
|
|
7098
|
+
const VALIDATE_SCRIPT_FILE = 'scripts/validate.sh';
|
|
7099
|
+
const PARALLEL_SCRIPT_NAMES = ['ts-check', 'lint:build', 'lint:style'] ;
|
|
7100
|
+
const REQUIRED_SCRIPT_NAMES = ['ts-check', 'lint:build'] ;
|
|
7101
|
+
|
|
7102
|
+
const isKnownOldValidateScript = (content) => [OLD_WEB_TEMPLATE_VALIDATE_SCRIPT, OLD_WEB_PATCH_VALIDATE_SCRIPT].includes(content);
|
|
7103
|
+
|
|
7104
|
+
const loadPackageJson = async (projectFolder) => {
|
|
7105
|
+
const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE);
|
|
7106
|
+
if (!(await isFileExists(packageJsonPath))) {
|
|
7107
|
+
return null;
|
|
7108
|
+
}
|
|
7109
|
+
|
|
7110
|
+
const content = await fs$1.readFile(packageJsonPath, 'utf-8');
|
|
7111
|
+
return safeJsonParse(content, null);
|
|
7112
|
+
};
|
|
7113
|
+
|
|
7114
|
+
const hasScript = (scripts, scriptName) => {
|
|
7115
|
+
if (!scripts) {
|
|
7116
|
+
return false;
|
|
7117
|
+
}
|
|
7118
|
+
return typeof _optionalChain$4([Object, 'access', _ => _.getOwnPropertyDescriptor, 'call', _2 => _2(scripts, scriptName), 'optionalAccess', _3 => _3.value]) === 'string';
|
|
7119
|
+
};
|
|
7120
|
+
|
|
7121
|
+
const getParallelArgs = async (projectFolder) => {
|
|
7122
|
+
const packageJson = await loadPackageJson(projectFolder);
|
|
7123
|
+
const scripts = _optionalChain$4([packageJson, 'optionalAccess', _4 => _4.scripts]);
|
|
7124
|
+
if (!REQUIRED_SCRIPT_NAMES.every(scriptName => hasScript(scripts, scriptName))) {
|
|
7125
|
+
return null;
|
|
7126
|
+
}
|
|
7127
|
+
|
|
7128
|
+
return PARALLEL_SCRIPT_NAMES.filter(scriptName => hasScript(scripts, scriptName)).join(' ');
|
|
7129
|
+
};
|
|
7130
|
+
|
|
7131
|
+
const applyValidateRunnerPatch = async (context, patchId) => {
|
|
7132
|
+
const validateScriptPath = path.join(context.projectFolder, VALIDATE_SCRIPT_FILE);
|
|
7133
|
+
const content = await fs$1.readFile(validateScriptPath, 'utf-8');
|
|
7134
|
+
|
|
7135
|
+
if (!isKnownOldValidateScript(content)) {
|
|
7136
|
+
return {
|
|
7137
|
+
applied: false,
|
|
7138
|
+
patchId,
|
|
7139
|
+
message: 'validate.sh content is not a known old version, skipping',
|
|
7140
|
+
};
|
|
7141
|
+
}
|
|
7142
|
+
|
|
7143
|
+
const parallelArgs = await getParallelArgs(context.projectFolder);
|
|
7144
|
+
if (!parallelArgs) {
|
|
7145
|
+
return {
|
|
7146
|
+
applied: false,
|
|
7147
|
+
patchId,
|
|
7148
|
+
message: 'package.json scripts do not contain known validate scripts, skipping',
|
|
7149
|
+
};
|
|
7150
|
+
}
|
|
7151
|
+
|
|
7152
|
+
await fs$1.writeFile(validateScriptPath, createValidateScript(parallelArgs), 'utf-8');
|
|
7153
|
+
|
|
7154
|
+
logger.info(`Patched ${VALIDATE_SCRIPT_FILE}: use coze-dev parallel`);
|
|
7155
|
+
|
|
7156
|
+
return {
|
|
7157
|
+
applied: true,
|
|
7158
|
+
patchId,
|
|
7159
|
+
message: 'Updated validate.sh',
|
|
7160
|
+
};
|
|
7161
|
+
};
|
|
7162
|
+
|
|
7163
|
+
const PATCH_ID$1 = 'nextjs/validate-runner@0.0.31';
|
|
7164
|
+
|
|
7165
|
+
const patchNextjsValidateRunner = {
|
|
7166
|
+
id: PATCH_ID$1,
|
|
7167
|
+
template: 'nextjs',
|
|
7168
|
+
disabled: byFlag('coding.arch.patch_nextjs_validate_runner'),
|
|
7169
|
+
operations: [
|
|
7170
|
+
{
|
|
7171
|
+
kind: 'file-patch',
|
|
7172
|
+
file: VALIDATE_SCRIPT_FILE,
|
|
7173
|
+
description: 'Update validate shell script to use coze-dev parallel',
|
|
7174
|
+
},
|
|
7175
|
+
],
|
|
7176
|
+
shouldApply: async context => {
|
|
7177
|
+
const validateScriptPath = path.join(context.projectFolder, VALIDATE_SCRIPT_FILE);
|
|
7178
|
+
if (!(await isFileExists(validateScriptPath))) {
|
|
7179
|
+
return false;
|
|
7180
|
+
}
|
|
7181
|
+
|
|
7182
|
+
const content = await fs$1.readFile(validateScriptPath, 'utf-8');
|
|
7183
|
+
if (!isKnownOldValidateScript(content)) {
|
|
7184
|
+
return false;
|
|
7185
|
+
}
|
|
7186
|
+
|
|
7187
|
+
return Boolean(await getParallelArgs(context.projectFolder));
|
|
7188
|
+
},
|
|
7189
|
+
apply: context => applyValidateRunnerPatch(context, PATCH_ID$1),
|
|
7190
|
+
};
|
|
7191
|
+
|
|
7088
7192
|
const SCRIPT_FILES = ['dev.sh', 'build.sh'] ;
|
|
7089
7193
|
const SUPPORTED_TEMPLATES = new Set(['nextjs', 'vite', 'nuxt-vue']);
|
|
7090
7194
|
|
|
@@ -7300,6 +7404,7 @@ const patches = [
|
|
|
7300
7404
|
patchExpoValidate,
|
|
7301
7405
|
replaceNpxWithPnpmPatchNextjs,
|
|
7302
7406
|
patchNextjsValidate,
|
|
7407
|
+
patchNextjsValidateRunner,
|
|
7303
7408
|
replaceNpxWithPnpmPatchVite,
|
|
7304
7409
|
patchViteValidate,
|
|
7305
7410
|
replaceNpxWithPnpmPatchNuxtVue,
|
|
@@ -7309,12 +7414,9 @@ const patches = [
|
|
|
7309
7414
|
patchTaroPackScript,
|
|
7310
7415
|
] ;
|
|
7311
7416
|
|
|
7312
|
-
const getTemplatePatches = (
|
|
7313
|
-
template,
|
|
7314
|
-
) =>
|
|
7315
|
-
patches.filter(patch => patch.template === template);
|
|
7417
|
+
const getTemplatePatches = (template) => patches.filter(patch => patch.template === template);
|
|
7316
7418
|
|
|
7317
|
-
function _nullishCoalesce$
|
|
7419
|
+
function _nullishCoalesce$4(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$3(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; }
|
|
7318
7420
|
const DEFAULT_LEGACY_VERSION = 'legacy';
|
|
7319
7421
|
|
|
7320
7422
|
const loadFlagsWithFallback = async () => {
|
|
@@ -7420,7 +7522,7 @@ const getNextPatchState = (
|
|
|
7420
7522
|
|
|
7421
7523
|
) => ({
|
|
7422
7524
|
template,
|
|
7423
|
-
version: _optionalChain$
|
|
7525
|
+
version: _optionalChain$3([config, 'access', _ => _.project, 'optionalAccess', _2 => _2.version]) || DEFAULT_LEGACY_VERSION,
|
|
7424
7526
|
appliedPatches: [...appliedPatches, patchId],
|
|
7425
7527
|
});
|
|
7426
7528
|
|
|
@@ -7444,15 +7546,15 @@ const executePatch = async (
|
|
|
7444
7546
|
}
|
|
7445
7547
|
|
|
7446
7548
|
const template =
|
|
7447
|
-
_optionalChain$
|
|
7549
|
+
_optionalChain$3([config, 'access', _3 => _3.project, 'optionalAccess', _4 => _4.template]) || (await detectTemplateKey(projectFolder));
|
|
7448
7550
|
|
|
7449
7551
|
if (!template) {
|
|
7450
7552
|
logger.info('Patch skipped: template not detected');
|
|
7451
7553
|
return;
|
|
7452
7554
|
}
|
|
7453
7555
|
|
|
7454
|
-
const appliedPatches = [...(_optionalChain$
|
|
7455
|
-
const projectVersion = _optionalChain$
|
|
7556
|
+
const appliedPatches = [...(_optionalChain$3([config, 'access', _5 => _5.project, 'optionalAccess', _6 => _6.appliedPatches]) || [])];
|
|
7557
|
+
const projectVersion = _optionalChain$3([config, 'access', _7 => _7.project, 'optionalAccess', _8 => _8.version]);
|
|
7456
7558
|
const flags = await loadFlagsWithFallback();
|
|
7457
7559
|
|
|
7458
7560
|
const context = {
|
|
@@ -7497,7 +7599,7 @@ const executePatch = async (
|
|
|
7497
7599
|
|
|
7498
7600
|
if (options.dryRun) {
|
|
7499
7601
|
logger.info(`Detected template: ${template}`);
|
|
7500
|
-
logger.info(`Current version: ${_nullishCoalesce$
|
|
7602
|
+
logger.info(`Current version: ${_nullishCoalesce$4(projectVersion, () => ( DEFAULT_LEGACY_VERSION))}`);
|
|
7501
7603
|
logger.info(`Applied patches: ${appliedPatches.join(', ') || '(none)'}`);
|
|
7502
7604
|
logger.info('Matched patches:');
|
|
7503
7605
|
matchedPatches.forEach(patch => {
|
|
@@ -7538,7 +7640,7 @@ const executePatch = async (
|
|
|
7538
7640
|
}
|
|
7539
7641
|
};
|
|
7540
7642
|
|
|
7541
|
-
const registerCommand$
|
|
7643
|
+
const registerCommand$5 = program => {
|
|
7542
7644
|
program
|
|
7543
7645
|
.command('patch')
|
|
7544
7646
|
.description('Apply template patches for existing projects')
|
|
@@ -7555,14 +7657,14 @@ const registerCommand$4 = program => {
|
|
|
7555
7657
|
) => {
|
|
7556
7658
|
await executePatch({
|
|
7557
7659
|
directory,
|
|
7558
|
-
dryRun: _optionalChain$
|
|
7559
|
-
showFlags: _optionalChain$
|
|
7660
|
+
dryRun: _optionalChain$3([command, 'optionalAccess', _9 => _9.dryRun]),
|
|
7661
|
+
showFlags: _optionalChain$3([command, 'optionalAccess', _10 => _10.showFlags]),
|
|
7560
7662
|
});
|
|
7561
7663
|
},
|
|
7562
7664
|
);
|
|
7563
7665
|
};
|
|
7564
7666
|
|
|
7565
|
-
function _nullishCoalesce$
|
|
7667
|
+
function _nullishCoalesce$3(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$2(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; }
|
|
7566
7668
|
const d$1 = debug('coze-init-cli:run');
|
|
7567
7669
|
|
|
7568
7670
|
/**
|
|
@@ -7595,14 +7697,11 @@ const createLogStream = (logFilePath) => {
|
|
|
7595
7697
|
const logDir = path.dirname(logFilePath);
|
|
7596
7698
|
|
|
7597
7699
|
// 确保日志目录存在
|
|
7598
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename -- resolved from config, not raw user input
|
|
7599
7700
|
if (!fs.existsSync(logDir)) {
|
|
7600
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename -- resolved from config, not raw user input
|
|
7601
7701
|
fs.mkdirSync(logDir, { recursive: true });
|
|
7602
7702
|
}
|
|
7603
7703
|
|
|
7604
7704
|
// 使用 'w' 标志覆盖之前的日志
|
|
7605
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename -- resolved from config, not raw user input
|
|
7606
7705
|
return fs.createWriteStream(logFilePath, { flags: 'w' });
|
|
7607
7706
|
};
|
|
7608
7707
|
|
|
@@ -7620,8 +7719,7 @@ const reportFailureAndExit = (
|
|
|
7620
7719
|
|
|
7621
7720
|
,
|
|
7622
7721
|
) => {
|
|
7623
|
-
const { commandName, cmdStartTime, options, categories, errorContext } =
|
|
7624
|
-
context;
|
|
7722
|
+
const { commandName, cmdStartTime, options, categories, errorContext } = context;
|
|
7625
7723
|
reportError(error, { command: commandName, ...errorContext });
|
|
7626
7724
|
reportCommandComplete(commandName, false, Date.now() - cmdStartTime, {
|
|
7627
7725
|
args: JSON.stringify(options),
|
|
@@ -7639,10 +7737,7 @@ const reportFailureAndExit = (
|
|
|
7639
7737
|
};
|
|
7640
7738
|
|
|
7641
7739
|
// 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
|
-
) => {
|
|
7740
|
+
const executeRun = async (commandName, options = {}) => {
|
|
7646
7741
|
const cmdStartTime = Date.now();
|
|
7647
7742
|
let fixDuration = 0;
|
|
7648
7743
|
let buildStartTime = 0;
|
|
@@ -7666,10 +7761,7 @@ const executeRun = async (
|
|
|
7666
7761
|
await executePatch();
|
|
7667
7762
|
} catch (patchError) {
|
|
7668
7763
|
// 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
|
-
);
|
|
7764
|
+
d$1('patch step failed (continuing): %s', patchError instanceof Error ? patchError.message : String(patchError));
|
|
7673
7765
|
}
|
|
7674
7766
|
fixDuration = Date.now() - fixStartTime;
|
|
7675
7767
|
logger.info('');
|
|
@@ -7703,12 +7795,12 @@ const executeRun = async (
|
|
|
7703
7795
|
}
|
|
7704
7796
|
|
|
7705
7797
|
// 将输出同时写入控制台和日志文件
|
|
7706
|
-
_optionalChain$
|
|
7798
|
+
_optionalChain$2([childProcess, 'access', _ => _.stdout, 'optionalAccess', _2 => _2.on, 'call', _3 => _3('data', (data) => {
|
|
7707
7799
|
process.stdout.write(data);
|
|
7708
7800
|
logStream.write(data);
|
|
7709
7801
|
})]);
|
|
7710
7802
|
|
|
7711
|
-
_optionalChain$
|
|
7803
|
+
_optionalChain$2([childProcess, 'access', _4 => _4.stderr, 'optionalAccess', _5 => _5.on, 'call', _6 => _6('data', (data) => {
|
|
7712
7804
|
process.stderr.write(data);
|
|
7713
7805
|
logStream.write(data);
|
|
7714
7806
|
})]);
|
|
@@ -7721,7 +7813,7 @@ const executeRun = async (
|
|
|
7721
7813
|
const buildDuration = Date.now() - buildStartTime;
|
|
7722
7814
|
|
|
7723
7815
|
if (code !== 0) {
|
|
7724
|
-
const errorMessage = `Command exited with code ${_nullishCoalesce$
|
|
7816
|
+
const errorMessage = `Command exited with code ${_nullishCoalesce$3(code, () => ( 'unknown'))}${signal ? ` and signal ${signal}` : ''}`;
|
|
7725
7817
|
logger.error(errorMessage);
|
|
7726
7818
|
logger.error(`Check log file for details: ${logFilePath}`);
|
|
7727
7819
|
|
|
@@ -7733,12 +7825,12 @@ const executeRun = async (
|
|
|
7733
7825
|
categories: {
|
|
7734
7826
|
fixDuration: String(fixDuration),
|
|
7735
7827
|
buildDuration: String(buildDuration),
|
|
7736
|
-
exitCode: String(_nullishCoalesce$
|
|
7828
|
+
exitCode: String(_nullishCoalesce$3(code, () => ( 'unknown'))),
|
|
7737
7829
|
projectType,
|
|
7738
7830
|
},
|
|
7739
7831
|
errorContext: {
|
|
7740
|
-
exitCode: String(_nullishCoalesce$
|
|
7741
|
-
signal: _nullishCoalesce$
|
|
7832
|
+
exitCode: String(_nullishCoalesce$3(code, () => ( 'unknown'))),
|
|
7833
|
+
signal: _nullishCoalesce$3(signal, () => ( 'none')),
|
|
7742
7834
|
logFile: logFilePath,
|
|
7743
7835
|
projectType,
|
|
7744
7836
|
},
|
|
@@ -7814,7 +7906,7 @@ const executeRun = async (
|
|
|
7814
7906
|
/**
|
|
7815
7907
|
* 注册 dev/build/start 命令到 program
|
|
7816
7908
|
*/
|
|
7817
|
-
const registerCommand$
|
|
7909
|
+
const registerCommand$4 = program => {
|
|
7818
7910
|
// dev 命令
|
|
7819
7911
|
program
|
|
7820
7912
|
.command('dev')
|
|
@@ -8642,7 +8734,7 @@ const scanRoutesOnce = async (
|
|
|
8642
8734
|
}
|
|
8643
8735
|
};
|
|
8644
8736
|
|
|
8645
|
-
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; }// Route manifest generation command
|
|
8737
|
+
function _optionalChain$1(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; }// Route manifest generation command
|
|
8646
8738
|
|
|
8647
8739
|
|
|
8648
8740
|
const log = debug('coze:routes');
|
|
@@ -8730,7 +8822,7 @@ const executeRoutes = async (
|
|
|
8730
8822
|
/**
|
|
8731
8823
|
* Register routes command to program
|
|
8732
8824
|
*/
|
|
8733
|
-
const registerCommand$
|
|
8825
|
+
const registerCommand$3 = program => {
|
|
8734
8826
|
program
|
|
8735
8827
|
.command('routes')
|
|
8736
8828
|
.description('Generate routes manifest for the current project')
|
|
@@ -8743,14 +8835,13 @@ const registerCommand$2 = program => {
|
|
|
8743
8835
|
'Output file path (defaults to ~/.coze/routes.json)',
|
|
8744
8836
|
)
|
|
8745
8837
|
.action(async (directory, options) => {
|
|
8746
|
-
await executeRoutes({ directory, output: _optionalChain([options, 'optionalAccess', _ => _.output]) });
|
|
8838
|
+
await executeRoutes({ directory, output: _optionalChain$1([options, 'optionalAccess', _ => _.output]) });
|
|
8747
8839
|
});
|
|
8748
8840
|
};
|
|
8749
8841
|
|
|
8750
|
-
function _nullishCoalesce$
|
|
8842
|
+
function _nullishCoalesce$2(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; }
|
|
8751
8843
|
|
|
8752
8844
|
|
|
8753
|
-
const d = debug('coze-init-cli:check-bins');
|
|
8754
8845
|
|
|
8755
8846
|
|
|
8756
8847
|
|
|
@@ -8758,117 +8849,127 @@ const d = debug('coze-init-cli:check-bins');
|
|
|
8758
8849
|
|
|
8759
8850
|
|
|
8760
8851
|
|
|
8761
|
-
const checkBins = async (cwd, fix) => {
|
|
8762
|
-
d('starting check, cwd=%s fix=%s', cwd, fix);
|
|
8763
8852
|
|
|
8764
|
-
const pkgJson = safeJsonParse
|
|
8765
8853
|
|
|
8766
8854
|
|
|
8767
|
-
(await fs$1.readFile(path.join(cwd, 'package.json'), 'utf8'), {});
|
|
8768
8855
|
|
|
8769
|
-
const allDeps = Object.keys({
|
|
8770
|
-
...pkgJson.dependencies,
|
|
8771
|
-
...pkgJson.devDependencies,
|
|
8772
|
-
});
|
|
8773
8856
|
|
|
8774
|
-
d('found %d total dependencies to scan', allDeps.length);
|
|
8775
8857
|
|
|
8776
|
-
const binDir = path.join(cwd, 'node_modules', '.bin');
|
|
8777
|
-
d('bin directory: %s', binDir);
|
|
8778
|
-
const missing = [];
|
|
8779
8858
|
|
|
8780
|
-
await Promise.all(
|
|
8781
|
-
allDeps.map(async depName => {
|
|
8782
|
-
let rawContent;
|
|
8783
|
-
try {
|
|
8784
|
-
rawContent = await fs$1.readFile(
|
|
8785
|
-
path.join(cwd, 'node_modules', depName, 'package.json'),
|
|
8786
|
-
'utf8',
|
|
8787
|
-
);
|
|
8788
|
-
} catch (err) {
|
|
8789
|
-
d('dep %s not found in node_modules: %s', depName, err);
|
|
8790
|
-
missing.push({ dep: depName, bin: '', reason: 'missing-package' });
|
|
8791
|
-
return;
|
|
8792
|
-
}
|
|
8793
|
-
const depPkg = safeJsonParse(
|
|
8794
|
-
rawContent,
|
|
8795
|
-
);
|
|
8796
|
-
if (!depPkg) {
|
|
8797
|
-
d('skipping %s: failed to parse package.json', depName);
|
|
8798
|
-
return;
|
|
8799
|
-
}
|
|
8800
8859
|
|
|
8801
|
-
if (!depPkg.bin) {
|
|
8802
|
-
return;
|
|
8803
|
-
}
|
|
8804
8860
|
|
|
8805
|
-
const bins =
|
|
8806
|
-
typeof depPkg.bin === 'string'
|
|
8807
|
-
? { [_nullishCoalesce$1(depName.split('/').pop(), () => ( depName))]: depPkg.bin }
|
|
8808
|
-
: depPkg.bin;
|
|
8809
8861
|
|
|
8810
|
-
d('%s declares bins: %o', depName, Object.keys(bins));
|
|
8811
8862
|
|
|
8812
|
-
|
|
8813
|
-
Object.keys(bins).map(async binName => {
|
|
8814
|
-
try {
|
|
8815
|
-
await fs$1.access(path.join(binDir, binName));
|
|
8816
|
-
d('bin present: %s', binName);
|
|
8817
|
-
} catch (err) {
|
|
8818
|
-
d('bin missing: %s (from %s): %s', binName, depName, err);
|
|
8819
|
-
missing.push({ dep: depName, bin: binName, reason: 'missing-bin' });
|
|
8820
|
-
}
|
|
8821
|
-
}),
|
|
8822
|
-
);
|
|
8823
|
-
}),
|
|
8824
|
-
);
|
|
8863
|
+
const collectOption = (value, previous = []) => [...previous, value];
|
|
8825
8864
|
|
|
8826
|
-
|
|
8865
|
+
const createScriptTask = (script, packageManager) => ({
|
|
8866
|
+
label: script,
|
|
8867
|
+
command: packageManager,
|
|
8868
|
+
args: ['run', script],
|
|
8869
|
+
});
|
|
8827
8870
|
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
8831
|
-
|
|
8832
|
-
|
|
8871
|
+
const createCommandTask = (command) => ({
|
|
8872
|
+
label: command,
|
|
8873
|
+
command,
|
|
8874
|
+
args: [],
|
|
8875
|
+
shell: true,
|
|
8876
|
+
});
|
|
8877
|
+
|
|
8878
|
+
const runTask = (task, cwd) =>
|
|
8879
|
+
new Promise(resolve => {
|
|
8880
|
+
const output = [];
|
|
8881
|
+
const child = child_process.spawn(task.command, task.args, {
|
|
8882
|
+
cwd,
|
|
8883
|
+
env: process.env,
|
|
8884
|
+
shell: task.shell,
|
|
8885
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
8886
|
+
});
|
|
8887
|
+
|
|
8888
|
+
_optionalChain([child, 'access', _ => _.stdout, 'optionalAccess', _2 => _2.on, 'call', _3 => _3('data', data => {
|
|
8889
|
+
output.push(String(data));
|
|
8890
|
+
})]);
|
|
8891
|
+
_optionalChain([child, 'access', _4 => _4.stderr, 'optionalAccess', _5 => _5.on, 'call', _6 => _6('data', data => {
|
|
8892
|
+
output.push(String(data));
|
|
8893
|
+
})]);
|
|
8894
|
+
child.on('error', error => {
|
|
8895
|
+
output.push(`${error.stack || error.message}\n`);
|
|
8896
|
+
resolve({
|
|
8897
|
+
label: task.label,
|
|
8898
|
+
code: 1,
|
|
8899
|
+
output: output.join(''),
|
|
8900
|
+
});
|
|
8901
|
+
});
|
|
8902
|
+
child.on('close', code => {
|
|
8903
|
+
resolve({
|
|
8904
|
+
label: task.label,
|
|
8905
|
+
code: _nullishCoalesce$2(code, () => ( 1)),
|
|
8906
|
+
output: output.join(''),
|
|
8907
|
+
});
|
|
8908
|
+
});
|
|
8909
|
+
});
|
|
8910
|
+
|
|
8911
|
+
const runParallelScripts = async (scripts, options = {}) => {
|
|
8912
|
+
const resolvedOptions = {
|
|
8913
|
+
cwd: options.cwd || process.cwd(),
|
|
8914
|
+
packageManager: options.packageManager || 'pnpm',
|
|
8915
|
+
commands: options.cmd || [],
|
|
8916
|
+
};
|
|
8917
|
+
const tasks = [
|
|
8918
|
+
...scripts.map(script => createScriptTask(script, resolvedOptions.packageManager)),
|
|
8919
|
+
...resolvedOptions.commands.map(command => createCommandTask(command)),
|
|
8920
|
+
];
|
|
8921
|
+
|
|
8922
|
+
if (tasks.length === 0) {
|
|
8923
|
+
process.stderr.write('No scripts or commands specified.\n');
|
|
8924
|
+
return 1;
|
|
8833
8925
|
}
|
|
8834
8926
|
|
|
8835
|
-
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
|
|
8927
|
+
process.stdout.write(`Running ${tasks.length} task(s) in parallel...\n`);
|
|
8928
|
+
tasks.forEach(task => {
|
|
8929
|
+
process.stdout.write(`[${task.label}] started\n`);
|
|
8930
|
+
});
|
|
8931
|
+
|
|
8932
|
+
const results = await Promise.all(tasks.map(task => runTask(task, resolvedOptions.cwd)));
|
|
8933
|
+
const failedResults = results.filter(result => result.code !== 0);
|
|
8934
|
+
|
|
8935
|
+
results.forEach(result => {
|
|
8936
|
+
if (result.code === 0) {
|
|
8937
|
+
process.stdout.write(`[${result.label}] passed\n`);
|
|
8839
8938
|
} else {
|
|
8840
|
-
|
|
8939
|
+
process.stdout.write(`[${result.label}] failed (exit ${result.code})\n`);
|
|
8841
8940
|
}
|
|
8842
|
-
}
|
|
8941
|
+
});
|
|
8843
8942
|
|
|
8844
|
-
if (
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
);
|
|
8848
|
-
process.exit(1);
|
|
8943
|
+
if (failedResults.length === 0) {
|
|
8944
|
+
process.stdout.write('Parallel tasks passed.\n');
|
|
8945
|
+
return 0;
|
|
8849
8946
|
}
|
|
8850
8947
|
|
|
8851
|
-
|
|
8852
|
-
|
|
8853
|
-
|
|
8854
|
-
|
|
8948
|
+
process.stdout.write('\nParallel tasks failed. Failed task logs:\n');
|
|
8949
|
+
failedResults.forEach(result => {
|
|
8950
|
+
process.stdout.write(`\n===== ${result.label} (exit ${result.code}) =====\n`);
|
|
8951
|
+
process.stdout.write(result.output || '(no output)\n');
|
|
8952
|
+
if (!result.output.endsWith('\n')) {
|
|
8953
|
+
process.stdout.write('\n');
|
|
8954
|
+
}
|
|
8955
|
+
process.stdout.write(`===== end ${result.label} =====\n`);
|
|
8956
|
+
});
|
|
8957
|
+
|
|
8958
|
+
return 1;
|
|
8855
8959
|
};
|
|
8856
8960
|
|
|
8857
|
-
const registerCommand$
|
|
8961
|
+
const registerCommand$2 = program => {
|
|
8858
8962
|
program
|
|
8859
|
-
.command('
|
|
8860
|
-
.description(
|
|
8861
|
-
|
|
8862
|
-
)
|
|
8863
|
-
.option('
|
|
8864
|
-
.option('--
|
|
8865
|
-
.action(async (options) => {
|
|
8866
|
-
|
|
8867
|
-
|
|
8868
|
-
|
|
8869
|
-
logger.warn(
|
|
8870
|
-
`check-bins: skipped due to error: ${err instanceof Error ? err.message : String(err)}`,
|
|
8871
|
-
);
|
|
8963
|
+
.command('parallel')
|
|
8964
|
+
.description('Run package scripts or shell commands in parallel and print full logs for failed tasks')
|
|
8965
|
+
.argument('[scripts...]', 'Package scripts to run with pnpm run')
|
|
8966
|
+
.option('-c, --cmd <command>', 'Shell command to run in parallel', collectOption, [])
|
|
8967
|
+
.option('--cwd <path>', 'Working directory', process.cwd())
|
|
8968
|
+
.option('--package-manager <command>', 'Package manager command', 'pnpm')
|
|
8969
|
+
.action(async (scripts, options) => {
|
|
8970
|
+
const exitCode = await runParallelScripts(scripts, options);
|
|
8971
|
+
if (exitCode !== 0) {
|
|
8972
|
+
process.exit(exitCode);
|
|
8872
8973
|
}
|
|
8873
8974
|
});
|
|
8874
8975
|
};
|
|
@@ -8972,34 +9073,26 @@ const ARGV_USER_ARGS_OFFSET = 2;
|
|
|
8972
9073
|
* @param knownOptions - 已知的选项集合(不需要透传的选项)
|
|
8973
9074
|
* @returns 参数对象
|
|
8974
9075
|
*/
|
|
8975
|
-
const parsePassThroughParams = (
|
|
8976
|
-
command,
|
|
8977
|
-
knownOptions = new Set(),
|
|
8978
|
-
) => {
|
|
9076
|
+
const parsePassThroughParams = (command, knownOptions = new Set()) => {
|
|
8979
9077
|
const parsed = minimist(process.argv.slice(ARGV_USER_ARGS_OFFSET));
|
|
8980
9078
|
|
|
8981
9079
|
// 过滤掉已知选项和位置参数(_)
|
|
8982
|
-
const filtered = Object.entries(parsed).reduce(
|
|
8983
|
-
|
|
8984
|
-
|
|
8985
|
-
|
|
8986
|
-
|
|
8987
|
-
}
|
|
9080
|
+
const filtered = Object.entries(parsed).reduce((params, [key, value]) => {
|
|
9081
|
+
// 跳过 minimist 的位置参数数组
|
|
9082
|
+
if (key === '_') {
|
|
9083
|
+
return params;
|
|
9084
|
+
}
|
|
8988
9085
|
|
|
8989
|
-
|
|
8990
|
-
|
|
8991
|
-
|
|
8992
|
-
|
|
9086
|
+
// 跳过已知选项(支持原始格式和 camelCase 格式)
|
|
9087
|
+
if (knownOptions.has(key) || knownOptions.has(changeCase.camelCase(key))) {
|
|
9088
|
+
return params;
|
|
9089
|
+
}
|
|
8993
9090
|
|
|
8994
|
-
|
|
8995
|
-
|
|
8996
|
-
// eslint-disable-next-line security/detect-object-injection -- camelKey is sanitized by camelCase
|
|
8997
|
-
params[camelKey] = value;
|
|
9091
|
+
// 将 kebab-case 转换为 camelCase
|
|
9092
|
+
const camelKey = changeCase.camelCase(key);
|
|
8998
9093
|
|
|
8999
|
-
|
|
9000
|
-
|
|
9001
|
-
{},
|
|
9002
|
-
);
|
|
9094
|
+
return { ...params, [camelKey]: value };
|
|
9095
|
+
}, {});
|
|
9003
9096
|
|
|
9004
9097
|
return filtered;
|
|
9005
9098
|
};
|
|
@@ -9756,7 +9849,7 @@ const execute = async (
|
|
|
9756
9849
|
};
|
|
9757
9850
|
};
|
|
9758
9851
|
|
|
9759
|
-
function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
9852
|
+
function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
9760
9853
|
/**
|
|
9761
9854
|
* 运行 pnpm install
|
|
9762
9855
|
*/
|
|
@@ -9946,7 +10039,7 @@ const executeTemplateEngineStep = async ctx => {
|
|
|
9946
10039
|
templateName: ctx.templateName,
|
|
9947
10040
|
outputPath: ctx.outputPath,
|
|
9948
10041
|
command: ctx.command,
|
|
9949
|
-
force: _nullishCoalesce(ctx.options.force, () => ( false)),
|
|
10042
|
+
force: _nullishCoalesce$1(ctx.options.force, () => ( false)),
|
|
9950
10043
|
});
|
|
9951
10044
|
|
|
9952
10045
|
// 保存结果到上下文
|
|
@@ -10205,7 +10298,7 @@ const executeInit = async (
|
|
|
10205
10298
|
/**
|
|
10206
10299
|
* 注册 init 命令到 program
|
|
10207
10300
|
*/
|
|
10208
|
-
const registerCommand = program => {
|
|
10301
|
+
const registerCommand$1 = program => {
|
|
10209
10302
|
program
|
|
10210
10303
|
.command('init')
|
|
10211
10304
|
.description('Initialize a new project from a template')
|
|
@@ -10223,21 +10316,148 @@ const registerCommand = program => {
|
|
|
10223
10316
|
.allowUnknownOption() // 允许透传参数
|
|
10224
10317
|
.action(async (directory, options, command) => {
|
|
10225
10318
|
// 位置参数优先级高于 --output 选项
|
|
10226
|
-
const outputPath = _nullishCoalesce(directory, () => ( options.output));
|
|
10319
|
+
const outputPath = _nullishCoalesce$1(directory, () => ( options.output));
|
|
10227
10320
|
// Always use force mode - overwrite existing files without conflict check
|
|
10228
10321
|
const force = true;
|
|
10229
10322
|
await executeInit({ ...options, output: outputPath, force }, command);
|
|
10230
10323
|
});
|
|
10231
10324
|
};
|
|
10232
10325
|
|
|
10326
|
+
function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
10327
|
+
|
|
10328
|
+
|
|
10329
|
+
const d = debug('coze-init-cli:check-bins');
|
|
10330
|
+
|
|
10331
|
+
|
|
10332
|
+
|
|
10333
|
+
|
|
10334
|
+
|
|
10335
|
+
|
|
10336
|
+
|
|
10337
|
+
const checkBins = async (cwd, fix) => {
|
|
10338
|
+
d('starting check, cwd=%s fix=%s', cwd, fix);
|
|
10339
|
+
|
|
10340
|
+
const pkgJson = safeJsonParse
|
|
10341
|
+
|
|
10342
|
+
|
|
10343
|
+
(await fs$1.readFile(path.join(cwd, 'package.json'), 'utf8'), {});
|
|
10344
|
+
|
|
10345
|
+
const allDeps = Object.keys({
|
|
10346
|
+
...pkgJson.dependencies,
|
|
10347
|
+
...pkgJson.devDependencies,
|
|
10348
|
+
});
|
|
10349
|
+
|
|
10350
|
+
d('found %d total dependencies to scan', allDeps.length);
|
|
10351
|
+
|
|
10352
|
+
const binDir = path.join(cwd, 'node_modules', '.bin');
|
|
10353
|
+
d('bin directory: %s', binDir);
|
|
10354
|
+
const missing = [];
|
|
10355
|
+
|
|
10356
|
+
await Promise.all(
|
|
10357
|
+
allDeps.map(async depName => {
|
|
10358
|
+
let rawContent;
|
|
10359
|
+
try {
|
|
10360
|
+
rawContent = await fs$1.readFile(
|
|
10361
|
+
path.join(cwd, 'node_modules', depName, 'package.json'),
|
|
10362
|
+
'utf8',
|
|
10363
|
+
);
|
|
10364
|
+
} catch (err) {
|
|
10365
|
+
d('dep %s not found in node_modules: %s', depName, err);
|
|
10366
|
+
missing.push({ dep: depName, bin: '', reason: 'missing-package' });
|
|
10367
|
+
return;
|
|
10368
|
+
}
|
|
10369
|
+
const depPkg = safeJsonParse(
|
|
10370
|
+
rawContent,
|
|
10371
|
+
);
|
|
10372
|
+
if (!depPkg) {
|
|
10373
|
+
d('skipping %s: failed to parse package.json', depName);
|
|
10374
|
+
return;
|
|
10375
|
+
}
|
|
10376
|
+
|
|
10377
|
+
if (!depPkg.bin) {
|
|
10378
|
+
return;
|
|
10379
|
+
}
|
|
10380
|
+
|
|
10381
|
+
const bins =
|
|
10382
|
+
typeof depPkg.bin === 'string'
|
|
10383
|
+
? { [_nullishCoalesce(depName.split('/').pop(), () => ( depName))]: depPkg.bin }
|
|
10384
|
+
: depPkg.bin;
|
|
10385
|
+
|
|
10386
|
+
d('%s declares bins: %o', depName, Object.keys(bins));
|
|
10387
|
+
|
|
10388
|
+
await Promise.all(
|
|
10389
|
+
Object.keys(bins).map(async binName => {
|
|
10390
|
+
try {
|
|
10391
|
+
await fs$1.access(path.join(binDir, binName));
|
|
10392
|
+
d('bin present: %s', binName);
|
|
10393
|
+
} catch (err) {
|
|
10394
|
+
d('bin missing: %s (from %s): %s', binName, depName, err);
|
|
10395
|
+
missing.push({ dep: depName, bin: binName, reason: 'missing-bin' });
|
|
10396
|
+
}
|
|
10397
|
+
}),
|
|
10398
|
+
);
|
|
10399
|
+
}),
|
|
10400
|
+
);
|
|
10401
|
+
|
|
10402
|
+
d('scan complete, missing=%d', missing.length);
|
|
10403
|
+
|
|
10404
|
+
if (missing.length === 0) {
|
|
10405
|
+
logger.success(
|
|
10406
|
+
'check-bins: all bin entries present, skipping force install.',
|
|
10407
|
+
);
|
|
10408
|
+
return;
|
|
10409
|
+
}
|
|
10410
|
+
|
|
10411
|
+
logger.warn('check-bins: missing or broken dependencies detected:');
|
|
10412
|
+
for (const { dep, bin, reason } of missing) {
|
|
10413
|
+
if (reason === 'missing-package') {
|
|
10414
|
+
logger.warn(` ${dep} -> (package not found in node_modules)`);
|
|
10415
|
+
} else {
|
|
10416
|
+
logger.warn(` ${dep} -> .bin/${bin}`);
|
|
10417
|
+
}
|
|
10418
|
+
}
|
|
10419
|
+
|
|
10420
|
+
if (!fix) {
|
|
10421
|
+
logger.error(
|
|
10422
|
+
'check-bins: missing bin entries found, run with --fix to repair.',
|
|
10423
|
+
);
|
|
10424
|
+
process.exit(1);
|
|
10425
|
+
}
|
|
10426
|
+
|
|
10427
|
+
logger.info('check-bins: running pnpm i --force to fix...');
|
|
10428
|
+
d('executing: pnpm i --force');
|
|
10429
|
+
child_process.execSync('pnpm i --force', { stdio: 'inherit', cwd });
|
|
10430
|
+
d('pnpm i --force completed');
|
|
10431
|
+
};
|
|
10432
|
+
|
|
10433
|
+
const registerCommand = program => {
|
|
10434
|
+
program
|
|
10435
|
+
.command('check-bins')
|
|
10436
|
+
.description(
|
|
10437
|
+
'Verify all bin entries from dependencies exist in node_modules/.bin, run pnpm i --force if any are missing',
|
|
10438
|
+
)
|
|
10439
|
+
.option('-c, --cwd <path>', 'Working directory to check', process.cwd())
|
|
10440
|
+
.option('--fix', 'Run pnpm i --force to repair missing bin entries', false)
|
|
10441
|
+
.action(async (options) => {
|
|
10442
|
+
try {
|
|
10443
|
+
await checkBins(options.cwd, options.fix);
|
|
10444
|
+
} catch (err) {
|
|
10445
|
+
logger.warn(
|
|
10446
|
+
`check-bins: skipped due to error: ${err instanceof Error ? err.message : String(err)}`,
|
|
10447
|
+
);
|
|
10448
|
+
}
|
|
10449
|
+
});
|
|
10450
|
+
};
|
|
10451
|
+
|
|
10233
10452
|
const commands = [
|
|
10234
|
-
registerCommand,
|
|
10235
|
-
registerCommand$3,
|
|
10236
|
-
registerCommand$6,
|
|
10453
|
+
registerCommand$1,
|
|
10237
10454
|
registerCommand$4,
|
|
10455
|
+
registerCommand$7,
|
|
10238
10456
|
registerCommand$5,
|
|
10457
|
+
registerCommand$6,
|
|
10458
|
+
registerCommand$3,
|
|
10459
|
+
registerCommand,
|
|
10239
10460
|
registerCommand$2,
|
|
10240
|
-
registerCommand$1,
|
|
10241
10461
|
];
|
|
10242
10462
|
|
|
10243
10463
|
const main = async () => {
|
|
@@ -10267,12 +10487,7 @@ const main = async () => {
|
|
|
10267
10487
|
|
|
10268
10488
|
const program = new commander.Command();
|
|
10269
10489
|
|
|
10270
|
-
program
|
|
10271
|
-
.name('coze')
|
|
10272
|
-
.description(
|
|
10273
|
-
'Coze Coding CLI - Project template engine for frontend stacks',
|
|
10274
|
-
)
|
|
10275
|
-
.version(packageJson.version);
|
|
10490
|
+
program.name('coze-dev').description('Coze Coding CLI - Project template engine for frontend stacks').version(packageJson.version);
|
|
10276
10491
|
|
|
10277
10492
|
commands.forEach(initCmd => initCmd(program));
|
|
10278
10493
|
|