ylcwf 0.6.0 → 0.6.1
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/CHANGELOG.md +34 -24
- package/README.md +14 -3
- package/dist/index.js +629 -458
- package/package.json +1 -1
- package/ui-dist/assets/{index-Q5HhNqSF.js → index-D4qqW48f.js} +2 -2
- package/ui-dist/index.html +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from "node:events";
|
|
2
2
|
import node_child_process, { execFile, execFileSync, spawn } from "node:child_process";
|
|
3
|
-
import node_path, { basename, dirname as external_node_path_dirname, extname, isAbsolute, join as external_node_path_join, relative as external_node_path_relative, resolve as external_node_path_resolve, sep } from "node:path";
|
|
3
|
+
import node_path, { basename, dirname as external_node_path_dirname, extname, isAbsolute as external_node_path_isAbsolute, join as external_node_path_join, relative as external_node_path_relative, resolve as external_node_path_resolve, sep } from "node:path";
|
|
4
4
|
import node_fs, { appendFileSync, chmodSync, closeSync, copyFileSync, existsSync as external_node_fs_existsSync, mkdirSync, openSync, readFileSync, readdirSync as external_node_fs_readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
5
5
|
import node_process, { stdin as external_node_process_stdin, stdout as external_node_process_stdout } from "node:process";
|
|
6
6
|
import { stripVTControlCharacters as external_node_util_stripVTControlCharacters, styleText as external_node_util_styleText } from "node:util";
|
|
@@ -9234,9 +9234,9 @@ const CONFIG_DIR = external_node_path_join(homedir(), '.ylcwf');
|
|
|
9234
9234
|
const DEFAULT_CONFIG_PATH = external_node_path_join(CONFIG_DIR, 'config.yaml');
|
|
9235
9235
|
function paths_resolveConfigPath(explicit) {
|
|
9236
9236
|
const fromFlag = explicit?.trim();
|
|
9237
|
-
if (void 0 !== fromFlag && fromFlag.length > 0) return
|
|
9237
|
+
if (void 0 !== fromFlag && fromFlag.length > 0) return external_node_path_isAbsolute(fromFlag) ? fromFlag : external_node_path_resolve(process.cwd(), fromFlag);
|
|
9238
9238
|
const fromEnv = process.env['YLCWF_CONFIG']?.trim();
|
|
9239
|
-
if (void 0 !== fromEnv && fromEnv.length > 0) return
|
|
9239
|
+
if (void 0 !== fromEnv && fromEnv.length > 0) return external_node_path_isAbsolute(fromEnv) ? fromEnv : external_node_path_resolve(process.cwd(), fromEnv);
|
|
9240
9240
|
return DEFAULT_CONFIG_PATH;
|
|
9241
9241
|
}
|
|
9242
9242
|
function serveTokenPath() {
|
|
@@ -9248,184 +9248,97 @@ function historyPath() {
|
|
|
9248
9248
|
function backupsDir(configPath) {
|
|
9249
9249
|
return external_node_path_join(external_node_path_dirname(configPath), 'backups');
|
|
9250
9250
|
}
|
|
9251
|
-
const
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
return YEAR_PATTERN.test(name);
|
|
9258
|
-
}
|
|
9259
|
-
function isIterationYear(value) {
|
|
9260
|
-
return Number.isInteger(value) && YEAR_PATTERN.test(String(value));
|
|
9261
|
-
}
|
|
9262
|
-
function iterationsRootPath(docsRoot, iterationsRoot) {
|
|
9263
|
-
const base = 0 === iterationsRoot.trim().length ? DEFAULT_ITERATIONS_ROOT : iterationsRoot.trim();
|
|
9264
|
-
return external_node_path_join(docsRoot, base);
|
|
9265
|
-
}
|
|
9266
|
-
function yearDirPath(docsRoot, iterationsRoot, year) {
|
|
9267
|
-
return external_node_path_join(iterationsRootPath(docsRoot, iterationsRoot), String(year));
|
|
9268
|
-
}
|
|
9269
|
-
function iterationRelPath(year, name) {
|
|
9270
|
-
return `${year}/${name}`;
|
|
9271
|
-
}
|
|
9272
|
-
function listIterationYears(docsRoot, iterationsRoot) {
|
|
9273
|
-
const root = iterationsRootPath(docsRoot, iterationsRoot);
|
|
9274
|
-
if (!external_node_fs_existsSync(root)) return [];
|
|
9275
|
-
try {
|
|
9276
|
-
return external_node_fs_readdirSync(root, {
|
|
9277
|
-
withFileTypes: true
|
|
9278
|
-
}).filter((entry)=>entry.isDirectory() && isYearDirectory(entry.name)).map((entry)=>Number.parseInt(entry.name, 10)).sort((left, right)=>left - right);
|
|
9279
|
-
} catch {
|
|
9280
|
-
return [];
|
|
9281
|
-
}
|
|
9282
|
-
}
|
|
9283
|
-
function listIterationDirs(docsRoot, iterationsRoot) {
|
|
9284
|
-
const result = [];
|
|
9285
|
-
for (const year of listIterationYears(docsRoot, iterationsRoot)){
|
|
9286
|
-
const yearDir = yearDirPath(docsRoot, iterationsRoot, year);
|
|
9287
|
-
let entries;
|
|
9288
|
-
try {
|
|
9289
|
-
entries = external_node_fs_readdirSync(yearDir, {
|
|
9290
|
-
withFileTypes: true
|
|
9291
|
-
}).filter((entry)=>entry.isDirectory() && !entry.name.startsWith('.')).map((entry)=>entry.name);
|
|
9292
|
-
} catch {
|
|
9293
|
-
continue;
|
|
9294
|
-
}
|
|
9295
|
-
for (const name of entries.sort())result.push({
|
|
9296
|
-
name,
|
|
9297
|
-
year,
|
|
9298
|
-
dir: external_node_path_join(yearDir, name),
|
|
9299
|
-
relPath: iterationRelPath(year, name)
|
|
9300
|
-
});
|
|
9301
|
-
}
|
|
9302
|
-
return result;
|
|
9303
|
-
}
|
|
9304
|
-
function parseIterationRef(input) {
|
|
9305
|
-
const text = input.trim().replace(/^\.\//, '');
|
|
9306
|
-
const match = /^(\d{4})[/\\](.+)$/.exec(text);
|
|
9307
|
-
if (null === match) return {
|
|
9308
|
-
year: null,
|
|
9309
|
-
name: text
|
|
9310
|
-
};
|
|
9311
|
-
const year = Number.parseInt(match[1] ?? '', 10);
|
|
9312
|
-
const name = (match[2] ?? '').trim();
|
|
9313
|
-
return Number.isInteger(year) ? {
|
|
9314
|
-
year,
|
|
9315
|
-
name
|
|
9251
|
+
const TERMINAL_CATALOG_FILE = 'execution_terminals.json';
|
|
9252
|
+
function terminals_error(code, message, where) {
|
|
9253
|
+
return void 0 === where ? {
|
|
9254
|
+
level: 'error',
|
|
9255
|
+
code,
|
|
9256
|
+
message
|
|
9316
9257
|
} : {
|
|
9317
|
-
|
|
9318
|
-
|
|
9258
|
+
level: 'error',
|
|
9259
|
+
code,
|
|
9260
|
+
message,
|
|
9261
|
+
where
|
|
9319
9262
|
};
|
|
9320
9263
|
}
|
|
9321
|
-
function
|
|
9322
|
-
|
|
9323
|
-
return new errors_CliError(`迭代名在多个年份下重复:${name}(${listed})。请用「年份/迭代名」显式指定,例如 -i ${pool[0]?.relPath ?? ''}`, errors_EXIT.USAGE);
|
|
9324
|
-
}
|
|
9325
|
-
function resolveIterationDir(docsRoot, iterationsRoot, input) {
|
|
9326
|
-
const { year, name } = parseIterationRef(input);
|
|
9327
|
-
if (0 === name.length) throw new errors_CliError('必须指定迭代目录', errors_EXIT.USAGE);
|
|
9328
|
-
const all = listIterationDirs(docsRoot, iterationsRoot);
|
|
9329
|
-
const scoped = null === year ? all : all.filter((item)=>item.year === year);
|
|
9330
|
-
const exact = scoped.filter((item)=>item.name === name);
|
|
9331
|
-
if (1 === exact.length && void 0 !== exact[0]) return exact[0];
|
|
9332
|
-
if (exact.length > 1) throw ambiguous(name, exact);
|
|
9333
|
-
const folded = scoped.filter((item)=>item.name.toLowerCase() === name.toLowerCase());
|
|
9334
|
-
if (1 === folded.length && void 0 !== folded[0]) return folded[0];
|
|
9335
|
-
if (folded.length > 1) throw ambiguous(name, folded);
|
|
9336
|
-
const where = null === year ? '' : `(${year} 年)`;
|
|
9337
|
-
const years = listIterationYears(docsRoot, iterationsRoot);
|
|
9338
|
-
const hint = 0 === years.length ? `\n该文档仓库尚未建立迭代目录:${iterationsRootPath(docsRoot, iterationsRoot)}` : `\n已有年份:${years.join('、')}`;
|
|
9339
|
-
throw new errors_CliError(`迭代目录不存在${where}:${name}${hint}`, errors_EXIT.NOT_FOUND);
|
|
9264
|
+
function terminals_isRecord(value) {
|
|
9265
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
9340
9266
|
}
|
|
9341
|
-
function
|
|
9342
|
-
const
|
|
9343
|
-
if (
|
|
9344
|
-
|
|
9345
|
-
|
|
9346
|
-
|
|
9347
|
-
|
|
9348
|
-
|
|
9267
|
+
function checkTerminalCatalog(raw) {
|
|
9268
|
+
const issues = [];
|
|
9269
|
+
if (!terminals_isRecord(raw)) return {
|
|
9270
|
+
catalog: null,
|
|
9271
|
+
issues: [
|
|
9272
|
+
terminals_error('TERMINAL_CATALOG_TYPE', `${TERMINAL_CATALOG_FILE} 必须是对象`)
|
|
9273
|
+
]
|
|
9274
|
+
};
|
|
9275
|
+
const list = raw['terminals'];
|
|
9276
|
+
if (!Array.isArray(list)) return {
|
|
9277
|
+
catalog: null,
|
|
9278
|
+
issues: [
|
|
9279
|
+
terminals_error('TERMINAL_CATALOG_INVALID', 'terminals 必须是数组', 'terminals')
|
|
9280
|
+
]
|
|
9281
|
+
};
|
|
9282
|
+
const entries = [];
|
|
9283
|
+
const seen = new Set();
|
|
9284
|
+
list.forEach((item, index)=>{
|
|
9285
|
+
const where = `terminals[${index}]`;
|
|
9286
|
+
const name = terminals_isRecord(item) ? item['name'] : item;
|
|
9287
|
+
if ('string' != typeof name || 0 === name.trim().length) return void issues.push(terminals_error('TERMINAL_CATALOG_NAME_INVALID', `${where}.name 不能为空`, `${where}.name`));
|
|
9288
|
+
const trimmed = name.trim();
|
|
9289
|
+
if (seen.has(trimmed)) return void issues.push(terminals_error('TERMINAL_CATALOG_DUPLICATED', `执行终端「${trimmed}」重复声明`, `${where}.name`));
|
|
9290
|
+
seen.add(trimmed);
|
|
9291
|
+
const descRaw = terminals_isRecord(item) ? item['desc'] : void 0;
|
|
9292
|
+
entries.push({
|
|
9293
|
+
name: trimmed,
|
|
9294
|
+
desc: 'string' == typeof descRaw && descRaw.trim().length > 0 ? descRaw.trim() : null
|
|
9295
|
+
});
|
|
9349
9296
|
});
|
|
9297
|
+
if (issues.some((issue)=>'error' === issue.level)) return {
|
|
9298
|
+
catalog: null,
|
|
9299
|
+
issues
|
|
9300
|
+
};
|
|
9350
9301
|
return {
|
|
9351
|
-
|
|
9352
|
-
|
|
9353
|
-
|
|
9354
|
-
|
|
9302
|
+
catalog: {
|
|
9303
|
+
terminals: entries
|
|
9304
|
+
},
|
|
9305
|
+
issues
|
|
9355
9306
|
};
|
|
9356
9307
|
}
|
|
9357
|
-
function
|
|
9308
|
+
function loadTerminalCatalog(docsRoot) {
|
|
9309
|
+
const path = external_node_path_join(docsRoot, TERMINAL_CATALOG_FILE);
|
|
9310
|
+
let text;
|
|
9358
9311
|
try {
|
|
9359
|
-
|
|
9360
|
-
} catch
|
|
9361
|
-
|
|
9362
|
-
|
|
9363
|
-
|
|
9364
|
-
|
|
9365
|
-
|
|
9312
|
+
text = readFileSync(path, 'utf8');
|
|
9313
|
+
} catch {
|
|
9314
|
+
return {
|
|
9315
|
+
path,
|
|
9316
|
+
catalog: null,
|
|
9317
|
+
issues: []
|
|
9318
|
+
};
|
|
9366
9319
|
}
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
9372
|
-
|
|
9373
|
-
|
|
9374
|
-
|
|
9375
|
-
|
|
9376
|
-
|
|
9377
|
-
|
|
9378
|
-
|
|
9379
|
-
iteration: target,
|
|
9380
|
-
created: false
|
|
9381
|
-
};
|
|
9382
|
-
const existing = listIterationDirs(docsRoot, iterationsRoot).filter((item)=>item.name.toLowerCase() === trimmed.toLowerCase());
|
|
9383
|
-
if (null === prefixYear && existing.length > 0) {
|
|
9384
|
-
const listed = existing.map((item)=>item.relPath).join('、');
|
|
9385
|
-
throw new errors_CliError(`迭代名已存在于其他年份:${trimmed}(${listed})\n如需在新年份下再建一个同名迭代,请显式写年份:ylcwf iteration create ${year}/${trimmed}`, errors_EXIT.USAGE);
|
|
9320
|
+
let raw;
|
|
9321
|
+
try {
|
|
9322
|
+
raw = JSON.parse(text);
|
|
9323
|
+
} catch (caught) {
|
|
9324
|
+
const detail = caught instanceof Error ? caught.message : String(caught);
|
|
9325
|
+
return {
|
|
9326
|
+
path,
|
|
9327
|
+
catalog: null,
|
|
9328
|
+
issues: [
|
|
9329
|
+
terminals_error('TERMINAL_CATALOG_JSON', `${TERMINAL_CATALOG_FILE} 不是合法 JSON:${detail}`)
|
|
9330
|
+
]
|
|
9331
|
+
};
|
|
9386
9332
|
}
|
|
9387
|
-
mkdirSync(target.dir, {
|
|
9388
|
-
recursive: true
|
|
9389
|
-
});
|
|
9390
9333
|
return {
|
|
9391
|
-
|
|
9392
|
-
|
|
9334
|
+
path,
|
|
9335
|
+
...checkTerminalCatalog(raw)
|
|
9393
9336
|
};
|
|
9394
9337
|
}
|
|
9395
|
-
function
|
|
9396
|
-
const
|
|
9397
|
-
if (
|
|
9398
|
-
|
|
9399
|
-
const segments = text.split(/[/\\]+/).filter((segment)=>segment.length > 0);
|
|
9400
|
-
if (0 === segments.length) return '迭代根目录不能为空';
|
|
9401
|
-
if (segments.some((segment)=>'..' === segment || '.' === segment)) return '迭代根目录不能包含「..」或「.」';
|
|
9402
|
-
return null;
|
|
9403
|
-
}
|
|
9404
|
-
const DASH_PATTERN = /[\u2010-\u2015\u2212\uFE58\uFE63\uFF0D_-]+/g;
|
|
9405
|
-
function normalizeName(input) {
|
|
9406
|
-
return input.normalize('NFKC').replace(/\s+/g, '').replace(DASH_PATTERN, '-').replace(/^-+/, '').replace(/-+$/, '').toLowerCase();
|
|
9407
|
-
}
|
|
9408
|
-
function normalize_editDistance(a, b) {
|
|
9409
|
-
if (a === b) return 0;
|
|
9410
|
-
if (0 === a.length) return b.length;
|
|
9411
|
-
if (0 === b.length) return a.length;
|
|
9412
|
-
let previous = Array.from({
|
|
9413
|
-
length: b.length + 1
|
|
9414
|
-
}, (_, index)=>index);
|
|
9415
|
-
for(let i = 1; i <= a.length; i += 1){
|
|
9416
|
-
const current = [
|
|
9417
|
-
i
|
|
9418
|
-
];
|
|
9419
|
-
for(let j = 1; j <= b.length; j += 1){
|
|
9420
|
-
const cost = a.charAt(i - 1) === b.charAt(j - 1) ? 0 : 1;
|
|
9421
|
-
const deletion = (previous[j] ?? 0) + 1;
|
|
9422
|
-
const insertion = (current[j - 1] ?? 0) + 1;
|
|
9423
|
-
const substitution = (previous[j - 1] ?? 0) + cost;
|
|
9424
|
-
current[j] = Math.min(deletion, insertion, substitution);
|
|
9425
|
-
}
|
|
9426
|
-
previous = current;
|
|
9427
|
-
}
|
|
9428
|
-
return previous[b.length] ?? 0;
|
|
9338
|
+
function catalogNames(docsRoot) {
|
|
9339
|
+
const loaded = loadTerminalCatalog(docsRoot);
|
|
9340
|
+
if (null === loaded.catalog) return [];
|
|
9341
|
+
return loaded.catalog.terminals.map((entry)=>entry.name);
|
|
9429
9342
|
}
|
|
9430
9343
|
function utils_isRecord(value) {
|
|
9431
9344
|
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
@@ -9457,6 +9370,51 @@ function isAbsolutePath(value) {
|
|
|
9457
9370
|
if (/^[\\/]{2}[^\\/]/.test(input)) return true;
|
|
9458
9371
|
return input.startsWith('/');
|
|
9459
9372
|
}
|
|
9373
|
+
function parseDotPath(input) {
|
|
9374
|
+
const parts = input.split('.').map((part)=>part.trim());
|
|
9375
|
+
if (0 === parts.length || parts.some((part)=>0 === part.length)) throw new errors_CliError(`路径不合法:${input}(应形如 docs.role)`, errors_EXIT.USAGE);
|
|
9376
|
+
return parts;
|
|
9377
|
+
}
|
|
9378
|
+
function getIn(root, path) {
|
|
9379
|
+
let current = root;
|
|
9380
|
+
for (const key of path){
|
|
9381
|
+
if (!utils_isRecord(current)) return;
|
|
9382
|
+
if (!Object.hasOwn(current, key)) return;
|
|
9383
|
+
current = current[key];
|
|
9384
|
+
}
|
|
9385
|
+
return current;
|
|
9386
|
+
}
|
|
9387
|
+
function renderScalar(value) {
|
|
9388
|
+
if ('string' == typeof value) return value;
|
|
9389
|
+
if (null === value) return 'null';
|
|
9390
|
+
return JSON.stringify(value);
|
|
9391
|
+
}
|
|
9392
|
+
const DASH_PATTERN = /[\u2010-\u2015\u2212\uFE58\uFE63\uFF0D_-]+/g;
|
|
9393
|
+
function normalizeName(input) {
|
|
9394
|
+
return input.normalize('NFKC').replace(/\s+/g, '').replace(DASH_PATTERN, '-').replace(/^-+/, '').replace(/-+$/, '').toLowerCase();
|
|
9395
|
+
}
|
|
9396
|
+
function normalize_editDistance(a, b) {
|
|
9397
|
+
if (a === b) return 0;
|
|
9398
|
+
if (0 === a.length) return b.length;
|
|
9399
|
+
if (0 === b.length) return a.length;
|
|
9400
|
+
let previous = Array.from({
|
|
9401
|
+
length: b.length + 1
|
|
9402
|
+
}, (_, index)=>index);
|
|
9403
|
+
for(let i = 1; i <= a.length; i += 1){
|
|
9404
|
+
const current = [
|
|
9405
|
+
i
|
|
9406
|
+
];
|
|
9407
|
+
for(let j = 1; j <= b.length; j += 1){
|
|
9408
|
+
const cost = a.charAt(i - 1) === b.charAt(j - 1) ? 0 : 1;
|
|
9409
|
+
const deletion = (previous[j] ?? 0) + 1;
|
|
9410
|
+
const insertion = (current[j - 1] ?? 0) + 1;
|
|
9411
|
+
const substitution = (previous[j - 1] ?? 0) + cost;
|
|
9412
|
+
current[j] = Math.min(deletion, insertion, substitution);
|
|
9413
|
+
}
|
|
9414
|
+
previous = current;
|
|
9415
|
+
}
|
|
9416
|
+
return previous[b.length] ?? 0;
|
|
9417
|
+
}
|
|
9460
9418
|
const ROLES = [
|
|
9461
9419
|
'frontend',
|
|
9462
9420
|
'backend',
|
|
@@ -9477,7 +9435,6 @@ const PROFILE_KEYS = new Set([
|
|
|
9477
9435
|
]);
|
|
9478
9436
|
const DOCS_KEYS = new Set([
|
|
9479
9437
|
'root',
|
|
9480
|
-
'iterationsRoot',
|
|
9481
9438
|
'git',
|
|
9482
9439
|
'validator'
|
|
9483
9440
|
]);
|
|
@@ -9528,7 +9485,8 @@ function warning(code, message, where) {
|
|
|
9528
9485
|
};
|
|
9529
9486
|
}
|
|
9530
9487
|
const REMOVED_DOCS_KEYS = new Set([
|
|
9531
|
-
'iterationWriteYear'
|
|
9488
|
+
'iterationWriteYear',
|
|
9489
|
+
'iterationsRoot'
|
|
9532
9490
|
]);
|
|
9533
9491
|
const REMOVED_TERMINAL_KEYS = new Set([
|
|
9534
9492
|
'aliases'
|
|
@@ -9624,33 +9582,16 @@ function parseDocs(rawInput, options, issues) {
|
|
|
9624
9582
|
if (null === parsed) return null;
|
|
9625
9583
|
root = parsed;
|
|
9626
9584
|
}
|
|
9627
|
-
const iterationsRoot = parseIterationsRoot(raw['iterationsRoot'], issues);
|
|
9628
|
-
if (null === iterationsRoot) return null;
|
|
9629
9585
|
const git = parseGitPolicy(raw['git'], issues);
|
|
9630
9586
|
if (null === git) return null;
|
|
9631
9587
|
const validator = parseValidatorPolicy(raw['validator'], issues);
|
|
9632
9588
|
if (null === validator) return null;
|
|
9633
9589
|
return {
|
|
9634
9590
|
root,
|
|
9635
|
-
iterationsRoot,
|
|
9636
9591
|
git,
|
|
9637
9592
|
validator
|
|
9638
9593
|
};
|
|
9639
9594
|
}
|
|
9640
|
-
function parseIterationsRoot(raw, issues) {
|
|
9641
|
-
if (null == raw) return DEFAULT_ITERATIONS_ROOT;
|
|
9642
|
-
if ('string' != typeof raw) {
|
|
9643
|
-
issues.push(schema_error('ITERATIONS_ROOT_INVALID', 'docs.iterationsRoot 必须是字符串', 'docs.iterationsRoot'));
|
|
9644
|
-
return null;
|
|
9645
|
-
}
|
|
9646
|
-
const problem = validateIterationsRoot(raw);
|
|
9647
|
-
if (null !== problem) {
|
|
9648
|
-
issues.push(schema_error('ITERATIONS_ROOT_INVALID', problem, 'docs.iterationsRoot'));
|
|
9649
|
-
return null;
|
|
9650
|
-
}
|
|
9651
|
-
const text = raw.trim();
|
|
9652
|
-
return 0 === text.length ? DEFAULT_ITERATIONS_ROOT : text;
|
|
9653
|
-
}
|
|
9654
9595
|
function parseValidatorPolicy(raw, issues) {
|
|
9655
9596
|
if (null == raw) return {
|
|
9656
9597
|
...DEFAULT_VALIDATOR_POLICY
|
|
@@ -9761,15 +9702,21 @@ function parseRepos(raw, where, issues) {
|
|
|
9761
9702
|
}
|
|
9762
9703
|
return valid ? repos : null;
|
|
9763
9704
|
}
|
|
9764
|
-
function parseTerminals(raw, issues) {
|
|
9705
|
+
function parseTerminals(raw, issues, catalog = []) {
|
|
9765
9706
|
if (!utils_isRecord(raw)) {
|
|
9766
9707
|
issues.push(schema_error('TERMINALS_TYPE', 'terminals 必须是对象', 'terminals'));
|
|
9767
9708
|
return null;
|
|
9768
9709
|
}
|
|
9769
9710
|
const terminals = {};
|
|
9770
9711
|
let valid = true;
|
|
9712
|
+
const allowed = 0 === catalog.length ? null : catalog.map((name)=>normalizeName(name));
|
|
9771
9713
|
for (const [name, value] of Object.entries(raw)){
|
|
9772
9714
|
const where = `terminals.${name}`;
|
|
9715
|
+
if (null !== allowed && !allowed.includes(normalizeName(name))) {
|
|
9716
|
+
issues.push(schema_error('TERMINAL_NOT_IN_CATALOG', `执行终端「${name}」不在文档仓库 execution_terminals.json 中;可选:${catalog.join('、')}`, where));
|
|
9717
|
+
valid = false;
|
|
9718
|
+
continue;
|
|
9719
|
+
}
|
|
9773
9720
|
if (name.includes('.')) {
|
|
9774
9721
|
issues.push(schema_error('TERMINAL_KEY_DOT', `执行终端名不能包含「.」:${name}`, where));
|
|
9775
9722
|
valid = false;
|
|
@@ -9862,7 +9809,7 @@ function checkConfig(raw, options = {}) {
|
|
|
9862
9809
|
issues.push(...unknownKeys(normalized, TOP_LEVEL_KEYS, 'root'));
|
|
9863
9810
|
const profile = parseProfile(normalized['profile'], options, issues);
|
|
9864
9811
|
const docs = parseDocs(normalized['docs'], options, issues);
|
|
9865
|
-
const terminals = parseTerminals(normalized['terminals'] ?? {}, issues);
|
|
9812
|
+
const terminals = parseTerminals(normalized['terminals'] ?? {}, issues, options.terminalCatalog);
|
|
9866
9813
|
if (null === profile || null === docs || null === terminals) return {
|
|
9867
9814
|
config: null,
|
|
9868
9815
|
issues
|
|
@@ -9984,9 +9931,6 @@ profile:
|
|
|
9984
9931
|
|
|
9985
9932
|
docs:
|
|
9986
9933
|
root: ''
|
|
9987
|
-
# 团队约定:迭代根目录(相对 root),其下按年份分组 iterations/2026/<迭代>/
|
|
9988
|
-
# 通常不需要改;确需调整时用 ylcwf set docs.iterationsRoot <新值>
|
|
9989
|
-
iterationsRoot: iterations
|
|
9990
9934
|
git:
|
|
9991
9935
|
cli: { commit: true, push: false }
|
|
9992
9936
|
ui: { commit: true, push: false }
|
|
@@ -9996,6 +9940,17 @@ terminals: {}
|
|
|
9996
9940
|
function createEmptyDocument() {
|
|
9997
9941
|
return (0, dist_0.Tp)(TEMPLATE);
|
|
9998
9942
|
}
|
|
9943
|
+
function checkConfigWithCatalog(raw, options = {}) {
|
|
9944
|
+
const docsRoot = getIn(raw, [
|
|
9945
|
+
'docs',
|
|
9946
|
+
'root'
|
|
9947
|
+
]);
|
|
9948
|
+
const catalog = 'string' == typeof docsRoot && docsRoot.trim().length > 0 ? catalogNames(docsRoot.trim()) : [];
|
|
9949
|
+
return checkConfig(raw, {
|
|
9950
|
+
...options,
|
|
9951
|
+
terminalCatalog: options.terminalCatalog ?? catalog
|
|
9952
|
+
});
|
|
9953
|
+
}
|
|
9999
9954
|
function config_loadConfig(explicit) {
|
|
10000
9955
|
const path = paths_resolveConfigPath(explicit);
|
|
10001
9956
|
if (!external_node_fs_existsSync(path)) return {
|
|
@@ -10013,7 +9968,7 @@ function config_loadConfig(explicit) {
|
|
|
10013
9968
|
throw new errors_CliError(`配置文件 YAML 语法错误:${path}\n${detail}`, errors_EXIT.INVALID);
|
|
10014
9969
|
}
|
|
10015
9970
|
const raw = doc.toJS();
|
|
10016
|
-
const checked =
|
|
9971
|
+
const checked = checkConfigWithCatalog(raw, {
|
|
10017
9972
|
allowIncomplete: true
|
|
10018
9973
|
});
|
|
10019
9974
|
return {
|
|
@@ -10049,7 +10004,7 @@ function obtainDocument(explicit) {
|
|
|
10049
10004
|
}
|
|
10050
10005
|
function assertWritable(doc, path) {
|
|
10051
10006
|
const raw = doc.toJS();
|
|
10052
|
-
const checked =
|
|
10007
|
+
const checked = checkConfigWithCatalog(raw, {
|
|
10053
10008
|
allowIncomplete: true
|
|
10054
10009
|
});
|
|
10055
10010
|
if (null === checked.config || checked.issues.some((issue)=>'error' === issue.level)) throw new errors_CliError(`配置校验失败,已取消写入:${path}\n${formatIssues(checked.issues)}`, errors_EXIT.INVALID);
|
|
@@ -10073,13 +10028,23 @@ function saveDocument(doc, target) {
|
|
|
10073
10028
|
mkdirSync(external_node_path_dirname(target), {
|
|
10074
10029
|
recursive: true
|
|
10075
10030
|
});
|
|
10076
|
-
|
|
10077
|
-
|
|
10078
|
-
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
|
|
10082
|
-
|
|
10031
|
+
for (const path of [
|
|
10032
|
+
[
|
|
10033
|
+
'schemaVersion'
|
|
10034
|
+
],
|
|
10035
|
+
[
|
|
10036
|
+
'docs',
|
|
10037
|
+
'iterationWriteYear'
|
|
10038
|
+
],
|
|
10039
|
+
[
|
|
10040
|
+
'docs',
|
|
10041
|
+
'iterationsRoot'
|
|
10042
|
+
],
|
|
10043
|
+
[
|
|
10044
|
+
'docs',
|
|
10045
|
+
'remote'
|
|
10046
|
+
]
|
|
10047
|
+
])if (doc.hasIn(path)) doc.deleteIn(path);
|
|
10083
10048
|
toBlockStyle(doc.contents);
|
|
10084
10049
|
const text = doc.toString({
|
|
10085
10050
|
lineWidth: 0
|
|
@@ -10108,25 +10073,6 @@ function backup(target) {
|
|
|
10108
10073
|
const stale = files.slice(0, Math.max(0, files.length - MAX_BACKUPS));
|
|
10109
10074
|
for (const name of stale)unlinkSync(`${dir}/${name}`);
|
|
10110
10075
|
}
|
|
10111
|
-
function parseDotPath(input) {
|
|
10112
|
-
const parts = input.split('.').map((part)=>part.trim());
|
|
10113
|
-
if (0 === parts.length || parts.some((part)=>0 === part.length)) throw new errors_CliError(`路径不合法:${input}(应形如 docs.role)`, errors_EXIT.USAGE);
|
|
10114
|
-
return parts;
|
|
10115
|
-
}
|
|
10116
|
-
function getIn(root, path) {
|
|
10117
|
-
let current = root;
|
|
10118
|
-
for (const key of path){
|
|
10119
|
-
if (!utils_isRecord(current)) return;
|
|
10120
|
-
if (!Object.hasOwn(current, key)) return;
|
|
10121
|
-
current = current[key];
|
|
10122
|
-
}
|
|
10123
|
-
return current;
|
|
10124
|
-
}
|
|
10125
|
-
function renderScalar(value) {
|
|
10126
|
-
if ('string' == typeof value) return value;
|
|
10127
|
-
if (null === value) return 'null';
|
|
10128
|
-
return JSON.stringify(value);
|
|
10129
|
-
}
|
|
10130
10076
|
function bail() {
|
|
10131
10077
|
cancel('已取消');
|
|
10132
10078
|
process.exit(errors_EXIT.OK);
|
|
@@ -10152,7 +10098,7 @@ async function askConfirm(message, initialValue) {
|
|
|
10152
10098
|
function validateExistingDir(value) {
|
|
10153
10099
|
const trimmed = (value ?? '').trim();
|
|
10154
10100
|
if (0 === trimmed.length) return '不能为空';
|
|
10155
|
-
if (!
|
|
10101
|
+
if (!external_node_path_isAbsolute(trimmed)) return '必须是绝对路径';
|
|
10156
10102
|
if (!external_node_fs_existsSync(trimmed)) return '路径不存在';
|
|
10157
10103
|
if (!statSync(trimmed).isDirectory()) return '不是目录';
|
|
10158
10104
|
}
|
|
@@ -10318,7 +10264,7 @@ function showConfig(explicit, format) {
|
|
|
10318
10264
|
printLine('运行 `ylcwf init` 完成首次配置,或 `ylcwf set <path> <value>` 精确修改。');
|
|
10319
10265
|
return;
|
|
10320
10266
|
}
|
|
10321
|
-
const checked =
|
|
10267
|
+
const checked = checkConfigWithCatalog(loaded.raw, {
|
|
10322
10268
|
checkFs: true
|
|
10323
10269
|
});
|
|
10324
10270
|
if ('json' === format) return void printJson({
|
|
@@ -10457,13 +10403,13 @@ function assertSettable(path) {
|
|
|
10457
10403
|
if (4 === path.length && 'docs' === first && 'git' === second && ('cli' === third || 'ui' === third) && ('commit' === fourth || 'push' === fourth)) return;
|
|
10458
10404
|
if (2 === path.length && 'profile' === first && ('developer' === second || 'role' === second)) return;
|
|
10459
10405
|
if (4 === path.length && 'terminals' === first && void 0 !== second && 'repos' === third && void 0 !== fourth && SIDE_SET.has(fourth)) return;
|
|
10460
|
-
throw new errors_CliError(`不支持通过 set 修改该路径:${path.join('.')}\n允许:docs.root / docs.
|
|
10406
|
+
throw new errors_CliError(`不支持通过 set 修改该路径:${path.join('.')}\n允许:docs.root / docs.git.<cli|ui>.<commit|push> / profile.developer / profile.role / terminals.<执行终端>.repos.frontend|backend\n执行终端的新增与删除请用:ylcwf terminal add | rm`, errors_EXIT.USAGE);
|
|
10461
10407
|
}
|
|
10462
10408
|
function coerceValue(path, raw) {
|
|
10463
10409
|
const key = path[path.length - 1];
|
|
10464
10410
|
const trimmed = raw.trim();
|
|
10465
10411
|
if ('root' === key) {
|
|
10466
|
-
if (!
|
|
10412
|
+
if (!external_node_path_isAbsolute(trimmed)) throw new errors_CliError(`文档仓库必须是绝对路径:${raw}`, errors_EXIT.USAGE);
|
|
10467
10413
|
return trimmed;
|
|
10468
10414
|
}
|
|
10469
10415
|
if ('remote' === key) {
|
|
@@ -10481,7 +10427,7 @@ function coerceValue(path, raw) {
|
|
|
10481
10427
|
}
|
|
10482
10428
|
if ('frontend' === key || 'backend' === key) {
|
|
10483
10429
|
const parts = parsePathList(trimmed);
|
|
10484
|
-
for (const part of parts)if (!
|
|
10430
|
+
for (const part of parts)if (!external_node_path_isAbsolute(part)) throw new errors_CliError(`仓库路径必须是绝对路径:${part}`, errors_EXIT.USAGE);
|
|
10485
10431
|
return parts;
|
|
10486
10432
|
}
|
|
10487
10433
|
return raw;
|
|
@@ -10621,7 +10567,7 @@ function terminal_collect(value, previous) {
|
|
|
10621
10567
|
function assertAbsolute(value, field) {
|
|
10622
10568
|
const trimmed = value.trim();
|
|
10623
10569
|
if (0 === trimmed.length) throw new errors_CliError(`${field} 不能为空`, errors_EXIT.USAGE);
|
|
10624
|
-
if (!
|
|
10570
|
+
if (!external_node_path_isAbsolute(trimmed)) throw new errors_CliError(`${field} 必须是绝对路径:${value}`, errors_EXIT.USAGE);
|
|
10625
10571
|
return trimmed;
|
|
10626
10572
|
}
|
|
10627
10573
|
function parseSide(value) {
|
|
@@ -10668,11 +10614,21 @@ function runTerminalList(options) {
|
|
|
10668
10614
|
}
|
|
10669
10615
|
}
|
|
10670
10616
|
}
|
|
10617
|
+
function assertInCatalog(name, configPath) {
|
|
10618
|
+
const loaded = config_loadConfig(configPath);
|
|
10619
|
+
const docsRoot = loaded.config?.docs.root ?? '';
|
|
10620
|
+
if (0 === docsRoot.length) return;
|
|
10621
|
+
const names = catalogNames(docsRoot);
|
|
10622
|
+
if (0 === names.length) return;
|
|
10623
|
+
if (names.includes(name)) return;
|
|
10624
|
+
throw new errors_CliError(`执行终端「${name}」不在文档仓库 execution_terminals.json 中\n可选:${names.join('、')}\n新增执行终端请先修改文档仓库的 execution_terminals.json`, errors_EXIT.USAGE);
|
|
10625
|
+
}
|
|
10671
10626
|
function runTerminalAdd(key, options) {
|
|
10672
10627
|
const trimmedKey = key.trim();
|
|
10673
10628
|
if (0 === trimmedKey.length) throw new errors_CliError('执行终端名不能为空', errors_EXIT.USAGE);
|
|
10674
10629
|
if (trimmedKey.includes('.')) throw new errors_CliError('执行终端名不能包含「.」(与配置路径语法冲突)', errors_EXIT.USAGE);
|
|
10675
10630
|
const { path: configPath, doc } = obtainDocument(options.config);
|
|
10631
|
+
assertInCatalog(trimmedKey, configPath);
|
|
10676
10632
|
if (void 0 !== getIn(doc.toJS(), [
|
|
10677
10633
|
'terminals',
|
|
10678
10634
|
trimmedKey
|
|
@@ -10874,16 +10830,160 @@ function aggregateViaPython(docsRoot, lists) {
|
|
|
10874
10830
|
progress: value.progress
|
|
10875
10831
|
});
|
|
10876
10832
|
}
|
|
10877
|
-
return result;
|
|
10878
|
-
} catch {
|
|
10879
|
-
continue;
|
|
10833
|
+
return result;
|
|
10834
|
+
} catch {
|
|
10835
|
+
continue;
|
|
10836
|
+
}
|
|
10837
|
+
return null;
|
|
10838
|
+
}
|
|
10839
|
+
const DEFAULT_ITERATIONS_ROOT = 'iterations';
|
|
10840
|
+
const YEAR_PATTERN = /^\d{4}$/;
|
|
10841
|
+
function currentIterationYear() {
|
|
10842
|
+
return new Date().getFullYear();
|
|
10843
|
+
}
|
|
10844
|
+
function isYearDirectory(name) {
|
|
10845
|
+
return YEAR_PATTERN.test(name);
|
|
10846
|
+
}
|
|
10847
|
+
function isIterationYear(value) {
|
|
10848
|
+
return Number.isInteger(value) && YEAR_PATTERN.test(String(value));
|
|
10849
|
+
}
|
|
10850
|
+
function iterationsRootPath(docsRoot, iterationsRoot) {
|
|
10851
|
+
const base = 0 === iterationsRoot.trim().length ? DEFAULT_ITERATIONS_ROOT : iterationsRoot.trim();
|
|
10852
|
+
return external_node_path_join(docsRoot, base);
|
|
10853
|
+
}
|
|
10854
|
+
function yearDirPath(docsRoot, iterationsRoot, year) {
|
|
10855
|
+
return external_node_path_join(iterationsRootPath(docsRoot, iterationsRoot), String(year));
|
|
10856
|
+
}
|
|
10857
|
+
function iterationRelPath(year, name) {
|
|
10858
|
+
return `${year}/${name}`;
|
|
10859
|
+
}
|
|
10860
|
+
function listIterationYears(docsRoot, iterationsRoot) {
|
|
10861
|
+
const root = iterationsRootPath(docsRoot, iterationsRoot);
|
|
10862
|
+
if (!external_node_fs_existsSync(root)) return [];
|
|
10863
|
+
try {
|
|
10864
|
+
return external_node_fs_readdirSync(root, {
|
|
10865
|
+
withFileTypes: true
|
|
10866
|
+
}).filter((entry)=>entry.isDirectory() && isYearDirectory(entry.name)).map((entry)=>Number.parseInt(entry.name, 10)).sort((left, right)=>left - right);
|
|
10867
|
+
} catch {
|
|
10868
|
+
return [];
|
|
10869
|
+
}
|
|
10870
|
+
}
|
|
10871
|
+
function listIterationDirs(docsRoot, iterationsRoot) {
|
|
10872
|
+
const result = [];
|
|
10873
|
+
for (const year of listIterationYears(docsRoot, iterationsRoot)){
|
|
10874
|
+
const yearDir = yearDirPath(docsRoot, iterationsRoot, year);
|
|
10875
|
+
let entries;
|
|
10876
|
+
try {
|
|
10877
|
+
entries = external_node_fs_readdirSync(yearDir, {
|
|
10878
|
+
withFileTypes: true
|
|
10879
|
+
}).filter((entry)=>entry.isDirectory() && !entry.name.startsWith('.')).map((entry)=>entry.name);
|
|
10880
|
+
} catch {
|
|
10881
|
+
continue;
|
|
10882
|
+
}
|
|
10883
|
+
for (const name of entries.sort())result.push({
|
|
10884
|
+
name,
|
|
10885
|
+
year,
|
|
10886
|
+
dir: external_node_path_join(yearDir, name),
|
|
10887
|
+
relPath: iterationRelPath(year, name)
|
|
10888
|
+
});
|
|
10889
|
+
}
|
|
10890
|
+
return result;
|
|
10891
|
+
}
|
|
10892
|
+
function parseIterationRef(input) {
|
|
10893
|
+
const text = input.trim().replace(/^\.\//, '');
|
|
10894
|
+
const match = /^(\d{4})[/\\](.+)$/.exec(text);
|
|
10895
|
+
if (null === match) return {
|
|
10896
|
+
year: null,
|
|
10897
|
+
name: text
|
|
10898
|
+
};
|
|
10899
|
+
const year = Number.parseInt(match[1] ?? '', 10);
|
|
10900
|
+
const name = (match[2] ?? '').trim();
|
|
10901
|
+
return Number.isInteger(year) ? {
|
|
10902
|
+
year,
|
|
10903
|
+
name
|
|
10904
|
+
} : {
|
|
10905
|
+
year: null,
|
|
10906
|
+
name: text
|
|
10907
|
+
};
|
|
10908
|
+
}
|
|
10909
|
+
function ambiguous(name, pool) {
|
|
10910
|
+
const listed = pool.map((item)=>item.relPath).sort().join('、');
|
|
10911
|
+
return new errors_CliError(`迭代名在多个年份下重复:${name}(${listed})。请用「年份/迭代名」显式指定,例如 -i ${pool[0]?.relPath ?? ''}`, errors_EXIT.USAGE);
|
|
10912
|
+
}
|
|
10913
|
+
function resolveIterationDir(docsRoot, iterationsRoot, input) {
|
|
10914
|
+
const { year, name } = parseIterationRef(input);
|
|
10915
|
+
if (0 === name.length) throw new errors_CliError('必须指定迭代目录', errors_EXIT.USAGE);
|
|
10916
|
+
const all = listIterationDirs(docsRoot, iterationsRoot);
|
|
10917
|
+
const scoped = null === year ? all : all.filter((item)=>item.year === year);
|
|
10918
|
+
const exact = scoped.filter((item)=>item.name === name);
|
|
10919
|
+
if (1 === exact.length && void 0 !== exact[0]) return exact[0];
|
|
10920
|
+
if (exact.length > 1) throw ambiguous(name, exact);
|
|
10921
|
+
const folded = scoped.filter((item)=>item.name.toLowerCase() === name.toLowerCase());
|
|
10922
|
+
if (1 === folded.length && void 0 !== folded[0]) return folded[0];
|
|
10923
|
+
if (folded.length > 1) throw ambiguous(name, folded);
|
|
10924
|
+
const where = null === year ? '' : `(${year} 年)`;
|
|
10925
|
+
const years = listIterationYears(docsRoot, iterationsRoot);
|
|
10926
|
+
const hint = 0 === years.length ? `\n该文档仓库尚未建立迭代目录:${iterationsRootPath(docsRoot, iterationsRoot)}` : `\n已有年份:${years.join('、')}`;
|
|
10927
|
+
throw new errors_CliError(`迭代目录不存在${where}:${name}${hint}`, errors_EXIT.NOT_FOUND);
|
|
10928
|
+
}
|
|
10929
|
+
function newIterationDir(docsRoot, iterationsRoot, writeYear, name, options = {}) {
|
|
10930
|
+
const trimmed = name.trim();
|
|
10931
|
+
if (0 === trimmed.length) throw new errors_CliError('迭代目录名不能为空', errors_EXIT.USAGE);
|
|
10932
|
+
if (trimmed.includes('/') || trimmed.includes('\\') || trimmed.includes('..')) throw new errors_CliError(`迭代目录名不能包含路径分隔符:${name}`, errors_EXIT.USAGE);
|
|
10933
|
+
if (!isIterationYear(writeYear)) throw new errors_CliError(`写入年份必须是 4 位数字:${writeYear}`, errors_EXIT.USAGE);
|
|
10934
|
+
const dir = external_node_path_join(yearDirPath(docsRoot, iterationsRoot, writeYear), trimmed);
|
|
10935
|
+
if (false !== options.create) mkdirSync(dir, {
|
|
10936
|
+
recursive: true
|
|
10937
|
+
});
|
|
10938
|
+
return {
|
|
10939
|
+
name: trimmed,
|
|
10940
|
+
year: writeYear,
|
|
10941
|
+
dir,
|
|
10942
|
+
relPath: iterationRelPath(writeYear, trimmed)
|
|
10943
|
+
};
|
|
10944
|
+
}
|
|
10945
|
+
function requireIterationDir(docsRoot, iterationsRoot, input) {
|
|
10946
|
+
try {
|
|
10947
|
+
return resolveIterationDir(docsRoot, iterationsRoot, input);
|
|
10948
|
+
} catch (error) {
|
|
10949
|
+
if (error instanceof errors_CliError && error.exitCode === errors_EXIT.NOT_FOUND) {
|
|
10950
|
+
const { name } = parseIterationRef(input);
|
|
10951
|
+
throw new errors_CliError(`${error.message}\n新建迭代目录:ylcwf iteration create <年份>/${name}`, errors_EXIT.NOT_FOUND);
|
|
10952
|
+
}
|
|
10953
|
+
throw error;
|
|
10880
10954
|
}
|
|
10881
|
-
|
|
10955
|
+
}
|
|
10956
|
+
function createIterationDir(docsRoot, iterationsRoot, input, options = {}) {
|
|
10957
|
+
const { year: prefixYear, name } = parseIterationRef(input);
|
|
10958
|
+
const trimmed = name.trim();
|
|
10959
|
+
if (0 === trimmed.length) throw new errors_CliError('迭代目录名不能为空', errors_EXIT.USAGE);
|
|
10960
|
+
if (trimmed.includes('/') || trimmed.includes('\\') || trimmed.includes('..')) throw new errors_CliError(`迭代目录名不能包含路径分隔符:${name}`, errors_EXIT.USAGE);
|
|
10961
|
+
const year = prefixYear ?? options.year ?? currentIterationYear();
|
|
10962
|
+
if (!isIterationYear(year)) throw new errors_CliError(`年份必须是 4 位数字:${String(year)}`, errors_EXIT.USAGE);
|
|
10963
|
+
const target = newIterationDir(docsRoot, iterationsRoot, year, trimmed, {
|
|
10964
|
+
create: false
|
|
10965
|
+
});
|
|
10966
|
+
if (external_node_fs_existsSync(target.dir)) return {
|
|
10967
|
+
iteration: target,
|
|
10968
|
+
created: false
|
|
10969
|
+
};
|
|
10970
|
+
const existing = listIterationDirs(docsRoot, iterationsRoot).filter((item)=>item.name.toLowerCase() === trimmed.toLowerCase());
|
|
10971
|
+
if (null === prefixYear && existing.length > 0) {
|
|
10972
|
+
const listed = existing.map((item)=>item.relPath).join('、');
|
|
10973
|
+
throw new errors_CliError(`迭代名已存在于其他年份:${trimmed}(${listed})\n如需在新年份下再建一个同名迭代,请显式写年份:ylcwf iteration create ${year}/${trimmed}`, errors_EXIT.USAGE);
|
|
10974
|
+
}
|
|
10975
|
+
mkdirSync(target.dir, {
|
|
10976
|
+
recursive: true
|
|
10977
|
+
});
|
|
10978
|
+
return {
|
|
10979
|
+
iteration: target,
|
|
10980
|
+
created: true
|
|
10981
|
+
};
|
|
10882
10982
|
}
|
|
10883
10983
|
function layoutOf(config) {
|
|
10884
10984
|
return {
|
|
10885
10985
|
root: config?.docs.root ?? '',
|
|
10886
|
-
iterationsRoot:
|
|
10986
|
+
iterationsRoot: DEFAULT_ITERATIONS_ROOT
|
|
10887
10987
|
};
|
|
10888
10988
|
}
|
|
10889
10989
|
function normalizeIterationKey(value) {
|
|
@@ -12872,7 +12972,7 @@ function commitInDocsRepo(docsRoot, file, message, push) {
|
|
|
12872
12972
|
realFile = realpathSync(item);
|
|
12873
12973
|
} catch {}
|
|
12874
12974
|
const relativePath = external_node_path_relative(realRoot, realFile);
|
|
12875
|
-
if (relativePath.startsWith('..') ||
|
|
12975
|
+
if (relativePath.startsWith('..') || external_node_path_isAbsolute(relativePath)) return {
|
|
12876
12976
|
committed: false,
|
|
12877
12977
|
pushed: false,
|
|
12878
12978
|
message: '目标文件不在文档仓库内,已跳过提交'
|
|
@@ -15115,9 +15215,9 @@ async function fetchManifest(url) {
|
|
|
15115
15215
|
const payload = await response.json();
|
|
15116
15216
|
if ('string' != typeof payload.version || 0 === payload.version.length) return null;
|
|
15117
15217
|
return {
|
|
15118
|
-
current: "0.6.
|
|
15218
|
+
current: "0.6.1",
|
|
15119
15219
|
latest: payload.version,
|
|
15120
|
-
hasUpdate: isNewer(payload.version, "0.6.
|
|
15220
|
+
hasUpdate: isNewer(payload.version, "0.6.1"),
|
|
15121
15221
|
downloadUrl: 'string' == typeof payload.downloadUrl ? payload.downloadUrl : null,
|
|
15122
15222
|
source: 'manifest',
|
|
15123
15223
|
checkedAt: new Date().toISOString(),
|
|
@@ -15129,7 +15229,7 @@ async function fetchManifest(url) {
|
|
|
15129
15229
|
}
|
|
15130
15230
|
async function fetchNpm() {
|
|
15131
15231
|
const base = {
|
|
15132
|
-
current: "0.6.
|
|
15232
|
+
current: "0.6.1",
|
|
15133
15233
|
latest: null,
|
|
15134
15234
|
hasUpdate: false,
|
|
15135
15235
|
downloadUrl: null,
|
|
@@ -15156,7 +15256,7 @@ async function fetchNpm() {
|
|
|
15156
15256
|
return {
|
|
15157
15257
|
...base,
|
|
15158
15258
|
latest,
|
|
15159
|
-
hasUpdate: isNewer(latest, "0.6.
|
|
15259
|
+
hasUpdate: isNewer(latest, "0.6.1"),
|
|
15160
15260
|
downloadUrl: null
|
|
15161
15261
|
};
|
|
15162
15262
|
} catch (error) {
|
|
@@ -15247,7 +15347,7 @@ async function runUpgrade(options) {
|
|
|
15247
15347
|
const kind = detectInstallKind();
|
|
15248
15348
|
const result = await checkUpdate(true);
|
|
15249
15349
|
const target = options.to?.trim() ?? result.latest;
|
|
15250
|
-
printLine("当前版本:0.6.
|
|
15350
|
+
printLine("当前版本:0.6.1");
|
|
15251
15351
|
if (null !== result.error) printLine(`版本查询失败:${result.error}`);
|
|
15252
15352
|
else if (null !== result.latest) printLine(`最新版本:${result.latest}(来源:${result.source})`);
|
|
15253
15353
|
if (null === target) throw new errors_CliError('无法确定目标版本,请稍后重试或用 --to 指定', errors_EXIT.NOT_FOUND);
|
|
@@ -15380,32 +15480,233 @@ function runResolve(name, options) {
|
|
|
15380
15480
|
if ('json' === format) return void printJson({
|
|
15381
15481
|
input: name,
|
|
15382
15482
|
matched: true,
|
|
15383
|
-
matchedBy: result.matchedBy,
|
|
15384
|
-
terminal,
|
|
15385
|
-
repos
|
|
15386
|
-
});
|
|
15387
|
-
printLine(`执行终端:${terminal}(匹配方式:${result.matchedBy ?? 'exact'})`);
|
|
15388
|
-
for (const item of SIDES){
|
|
15389
|
-
const list = repos[item];
|
|
15390
|
-
if (0 === list.length) {
|
|
15391
|
-
printLine(` ${item} (未配置)`);
|
|
15392
|
-
continue;
|
|
15393
|
-
}
|
|
15394
|
-
list.forEach((repo, index)=>{
|
|
15395
|
-
const prefix = 1 === list.length ? ` ${item} ` : ` ${item} ${index + 1}) `;
|
|
15396
|
-
printLine(`${prefix}${repo.path} ${repo.exists ? '✓' : '✗'}`);
|
|
15397
|
-
});
|
|
15398
|
-
}
|
|
15483
|
+
matchedBy: result.matchedBy,
|
|
15484
|
+
terminal,
|
|
15485
|
+
repos
|
|
15486
|
+
});
|
|
15487
|
+
printLine(`执行终端:${terminal}(匹配方式:${result.matchedBy ?? 'exact'})`);
|
|
15488
|
+
for (const item of SIDES){
|
|
15489
|
+
const list = repos[item];
|
|
15490
|
+
if (0 === list.length) {
|
|
15491
|
+
printLine(` ${item} (未配置)`);
|
|
15492
|
+
continue;
|
|
15493
|
+
}
|
|
15494
|
+
list.forEach((repo, index)=>{
|
|
15495
|
+
const prefix = 1 === list.length ? ` ${item} ` : ` ${item} ${index + 1}) `;
|
|
15496
|
+
printLine(`${prefix}${repo.path} ${repo.exists ? '✓' : '✗'}`);
|
|
15497
|
+
});
|
|
15498
|
+
}
|
|
15499
|
+
}
|
|
15500
|
+
function registerResolve(program) {
|
|
15501
|
+
program.command('resolve <name>').description('把执行终端名(支持中文)解析为本地仓库路径').option('-c, --config <path>', '指定配置文件路径').option('--side <side>', '限定端口:frontend | backend').option('--field <field>', '输出字段:path | exists | terminal | repos', 'repos').option('--pick <repo>', '该端存在多个仓库时显式指定:序号(1 起)、完整路径或目录名').option('--all', '输出该端全部仓库').option('--format <format>', '输出格式:human | json', 'human').action((name, options)=>{
|
|
15502
|
+
runResolve(name, options);
|
|
15503
|
+
});
|
|
15504
|
+
}
|
|
15505
|
+
const YAPI_PLATFORM_FILE = 'yapi_platform.json';
|
|
15506
|
+
function yapi_error(code, message, where) {
|
|
15507
|
+
return void 0 === where ? {
|
|
15508
|
+
level: 'error',
|
|
15509
|
+
code,
|
|
15510
|
+
message
|
|
15511
|
+
} : {
|
|
15512
|
+
level: 'error',
|
|
15513
|
+
code,
|
|
15514
|
+
message,
|
|
15515
|
+
where
|
|
15516
|
+
};
|
|
15517
|
+
}
|
|
15518
|
+
function yapi_warning(code, message, where) {
|
|
15519
|
+
return void 0 === where ? {
|
|
15520
|
+
level: 'warning',
|
|
15521
|
+
code,
|
|
15522
|
+
message
|
|
15523
|
+
} : {
|
|
15524
|
+
level: 'warning',
|
|
15525
|
+
code,
|
|
15526
|
+
message,
|
|
15527
|
+
where
|
|
15528
|
+
};
|
|
15529
|
+
}
|
|
15530
|
+
function yapi_isRecord(value) {
|
|
15531
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
15532
|
+
}
|
|
15533
|
+
function yapi_isPositiveInteger(value) {
|
|
15534
|
+
return 'number' == typeof value && Number.isInteger(value) && value > 0;
|
|
15535
|
+
}
|
|
15536
|
+
function checkYapiCatalog(raw) {
|
|
15537
|
+
const issues = [];
|
|
15538
|
+
if (!yapi_isRecord(raw)) return {
|
|
15539
|
+
catalog: null,
|
|
15540
|
+
issues: [
|
|
15541
|
+
yapi_error('YAPI_TYPE', 'yapi_platform.json 必须是对象')
|
|
15542
|
+
]
|
|
15543
|
+
};
|
|
15544
|
+
const groups = [];
|
|
15545
|
+
const groupsRaw = raw['groups'];
|
|
15546
|
+
if (Array.isArray(groupsRaw)) groupsRaw.forEach((item, index)=>{
|
|
15547
|
+
const where = `groups[${index}]`;
|
|
15548
|
+
if (!yapi_isRecord(item)) return void issues.push(yapi_error('YAPI_GROUP_INVALID', `${where} 必须是对象`, where));
|
|
15549
|
+
const groupId = item['groupId'];
|
|
15550
|
+
const name = item['name'];
|
|
15551
|
+
if (!yapi_isPositiveInteger(groupId)) return void issues.push(yapi_error('YAPI_GROUP_ID_INVALID', `${where}.groupId 必须是正整数`, `${where}.groupId`));
|
|
15552
|
+
if ('string' != typeof name || 0 === name.trim().length) return void issues.push(yapi_error('YAPI_GROUP_NAME_INVALID', `${where}.name 不能为空`, `${where}.name`));
|
|
15553
|
+
groups.push({
|
|
15554
|
+
groupId,
|
|
15555
|
+
name: name.trim()
|
|
15556
|
+
});
|
|
15557
|
+
});
|
|
15558
|
+
else issues.push(yapi_error('YAPI_GROUPS_INVALID', 'groups 必须是数组', 'groups'));
|
|
15559
|
+
const knownGroupIds = new Set(groups.map((group)=>group.groupId));
|
|
15560
|
+
const platforms = [];
|
|
15561
|
+
const seenTerminals = new Map();
|
|
15562
|
+
const platformsRaw = raw['platforms'];
|
|
15563
|
+
if (Array.isArray(platformsRaw)) platformsRaw.forEach((item, index)=>{
|
|
15564
|
+
const where = `platforms[${index}]`;
|
|
15565
|
+
if (!yapi_isRecord(item)) return void issues.push(yapi_error('YAPI_PLATFORM_INVALID', `${where} 必须是对象`, where));
|
|
15566
|
+
const terminal = item['terminal'];
|
|
15567
|
+
const groupId = item['groupId'];
|
|
15568
|
+
const projectIds = item['projectIds'];
|
|
15569
|
+
const platformRaw = item['platform'];
|
|
15570
|
+
if ('string' != typeof terminal || 0 === terminal.trim().length) return void issues.push(yapi_error('YAPI_TERMINAL_REQUIRED', `${where}.terminal 不能为空`, `${where}.terminal`));
|
|
15571
|
+
if (!yapi_isPositiveInteger(groupId)) return void issues.push(yapi_error('YAPI_GROUP_ID_INVALID', `${where}.groupId 必须是正整数`, `${where}.groupId`));
|
|
15572
|
+
if (!knownGroupIds.has(groupId)) issues.push(yapi_error('YAPI_GROUP_UNKNOWN', `${where}.groupId ${groupId} 未在 groups 中声明`, `${where}.groupId`));
|
|
15573
|
+
if (!Array.isArray(projectIds) || 0 === projectIds.length) return void issues.push(yapi_error('YAPI_PROJECT_IDS_INVALID', `${where}.projectIds 必须是非空数组`, `${where}.projectIds`));
|
|
15574
|
+
const invalidProject = projectIds.find((id)=>!yapi_isPositiveInteger(id));
|
|
15575
|
+
if (void 0 !== invalidProject) return void issues.push(yapi_error('YAPI_PROJECT_IDS_INVALID', `${where}.projectIds 只能包含正整数:${String(invalidProject)}`, `${where}.projectIds`));
|
|
15576
|
+
const key = normalizeName(terminal);
|
|
15577
|
+
const duplicate = seenTerminals.get(key);
|
|
15578
|
+
if (void 0 !== duplicate) issues.push(yapi_error('YAPI_TERMINAL_DUPLICATED', `执行终端「${terminal.trim()}」重复声明(另见「${duplicate}」),按归一化比较重复`, `${where}.terminal`));
|
|
15579
|
+
else seenTerminals.set(key, terminal.trim());
|
|
15580
|
+
platforms.push({
|
|
15581
|
+
platform: 'string' == typeof platformRaw && platformRaw.trim().length > 0 ? platformRaw.trim() : null,
|
|
15582
|
+
terminal: terminal.trim(),
|
|
15583
|
+
groupId,
|
|
15584
|
+
projectIds: [
|
|
15585
|
+
...projectIds
|
|
15586
|
+
].sort((left, right)=>left - right)
|
|
15587
|
+
});
|
|
15588
|
+
});
|
|
15589
|
+
else issues.push(yapi_error('YAPI_PLATFORMS_INVALID', 'platforms 必须是数组', 'platforms'));
|
|
15590
|
+
if (issues.some((issue)=>'error' === issue.level)) return {
|
|
15591
|
+
catalog: null,
|
|
15592
|
+
issues
|
|
15593
|
+
};
|
|
15594
|
+
return {
|
|
15595
|
+
catalog: {
|
|
15596
|
+
groups,
|
|
15597
|
+
platforms
|
|
15598
|
+
},
|
|
15599
|
+
issues
|
|
15600
|
+
};
|
|
15601
|
+
}
|
|
15602
|
+
function loadYapiCatalog(docsRoot) {
|
|
15603
|
+
const path = external_node_path_join(docsRoot, YAPI_PLATFORM_FILE);
|
|
15604
|
+
let text;
|
|
15605
|
+
try {
|
|
15606
|
+
text = readFileSync(path, 'utf8');
|
|
15607
|
+
} catch {
|
|
15608
|
+
return {
|
|
15609
|
+
path,
|
|
15610
|
+
catalog: null,
|
|
15611
|
+
issues: []
|
|
15612
|
+
};
|
|
15613
|
+
}
|
|
15614
|
+
let raw;
|
|
15615
|
+
try {
|
|
15616
|
+
raw = JSON.parse(text);
|
|
15617
|
+
} catch (caught) {
|
|
15618
|
+
const detail = caught instanceof Error ? caught.message : String(caught);
|
|
15619
|
+
return {
|
|
15620
|
+
path,
|
|
15621
|
+
catalog: null,
|
|
15622
|
+
issues: [
|
|
15623
|
+
yapi_error('YAPI_JSON_INVALID', `${YAPI_PLATFORM_FILE} 不是合法 JSON:${detail}`)
|
|
15624
|
+
]
|
|
15625
|
+
};
|
|
15626
|
+
}
|
|
15627
|
+
return {
|
|
15628
|
+
path,
|
|
15629
|
+
...checkYapiCatalog(raw)
|
|
15630
|
+
};
|
|
15631
|
+
}
|
|
15632
|
+
function terminalNameByRepo(terminals, input) {
|
|
15633
|
+
const target = normalizeName(input);
|
|
15634
|
+
const hits = [];
|
|
15635
|
+
for (const [name, terminal] of Object.entries(terminals)){
|
|
15636
|
+
const repos = [
|
|
15637
|
+
...terminal.repos.frontend,
|
|
15638
|
+
...terminal.repos.backend
|
|
15639
|
+
];
|
|
15640
|
+
if (repos.some((repo)=>normalizeName(basename(repo)) === target)) hits.push(name);
|
|
15641
|
+
}
|
|
15642
|
+
return 1 === hits.length ? hits[0] ?? null : null;
|
|
15643
|
+
}
|
|
15644
|
+
function resolveConfigTerminal(terminals, input) {
|
|
15645
|
+
const target = normalizeName(input);
|
|
15646
|
+
for (const name of Object.keys(terminals))if (normalizeName(name) === target) return {
|
|
15647
|
+
terminalName: name,
|
|
15648
|
+
matchedBy: 'terminal'
|
|
15649
|
+
};
|
|
15650
|
+
const byRepo = terminalNameByRepo(terminals, input);
|
|
15651
|
+
if (null !== byRepo) return {
|
|
15652
|
+
terminalName: byRepo,
|
|
15653
|
+
matchedBy: 'repo'
|
|
15654
|
+
};
|
|
15655
|
+
return {
|
|
15656
|
+
terminalName: null,
|
|
15657
|
+
matchedBy: null
|
|
15658
|
+
};
|
|
15659
|
+
}
|
|
15660
|
+
function describePlatform(item) {
|
|
15661
|
+
return null === item.platform ? item.terminal : `${item.terminal}(${item.platform})`;
|
|
15662
|
+
}
|
|
15663
|
+
function matchYapiPlatform(options) {
|
|
15664
|
+
const { catalog, terminals, input } = options;
|
|
15665
|
+
const trimmed = input.trim();
|
|
15666
|
+
const empty = {
|
|
15667
|
+
matched: false,
|
|
15668
|
+
terminalName: null,
|
|
15669
|
+
matchedBy: null,
|
|
15670
|
+
platform: null,
|
|
15671
|
+
group: null,
|
|
15672
|
+
candidates: catalog.platforms.map(describePlatform)
|
|
15673
|
+
};
|
|
15674
|
+
if (0 === trimmed.length) return empty;
|
|
15675
|
+
const resolved = resolveConfigTerminal(terminals, trimmed);
|
|
15676
|
+
const target = normalizeName(resolved.terminalName ?? trimmed);
|
|
15677
|
+
const byTerminal = catalog.platforms.filter((item)=>normalizeName(item.terminal) === target);
|
|
15678
|
+
if (1 === byTerminal.length && void 0 !== byTerminal[0]) return buildMatch(byTerminal[0], resolved.terminalName, resolved.matchedBy ?? 'terminal', catalog);
|
|
15679
|
+
if (byTerminal.length > 1) return {
|
|
15680
|
+
...empty,
|
|
15681
|
+
terminalName: resolved.terminalName,
|
|
15682
|
+
candidates: byTerminal.map(describePlatform)
|
|
15683
|
+
};
|
|
15684
|
+
return {
|
|
15685
|
+
...empty,
|
|
15686
|
+
terminalName: resolved.terminalName
|
|
15687
|
+
};
|
|
15688
|
+
}
|
|
15689
|
+
function buildMatch(item, terminalName, matchedBy, catalog) {
|
|
15690
|
+
return {
|
|
15691
|
+
matched: true,
|
|
15692
|
+
terminalName,
|
|
15693
|
+
matchedBy,
|
|
15694
|
+
platform: item,
|
|
15695
|
+
group: catalog.groups.find((group)=>group.groupId === item.groupId) ?? null,
|
|
15696
|
+
candidates: []
|
|
15697
|
+
};
|
|
15399
15698
|
}
|
|
15400
|
-
function
|
|
15401
|
-
|
|
15402
|
-
|
|
15403
|
-
|
|
15699
|
+
function checkYapiAgainstTerminalCatalog(catalog, terminalNames) {
|
|
15700
|
+
if (0 === terminalNames.length) return [];
|
|
15701
|
+
const allowed = terminalNames.map((name)=>normalizeName(name));
|
|
15702
|
+
const issues = [];
|
|
15703
|
+
for (const item of catalog.platforms)if (!allowed.includes(normalizeName(item.terminal))) issues.push(yapi_warning('YAPI_TERMINAL_NOT_IN_CATALOG', `${YAPI_PLATFORM_FILE} 中的执行终端「${item.terminal}」不在 execution_terminals.json 里;可选:${terminalNames.join('、')}(以清单为准,请改 yapi 文件)`, `platforms.${item.terminal}`));
|
|
15704
|
+
return issues;
|
|
15404
15705
|
}
|
|
15405
15706
|
function checkDocsSides(config) {
|
|
15406
15707
|
const messages = [];
|
|
15407
15708
|
const root = config.docs.root;
|
|
15408
|
-
const iterationsRoot =
|
|
15709
|
+
const iterationsRoot = DEFAULT_ITERATIONS_ROOT;
|
|
15409
15710
|
let iterations;
|
|
15410
15711
|
try {
|
|
15411
15712
|
iterations = listIterationDirs(root, iterationsRoot);
|
|
@@ -15437,17 +15738,43 @@ function checkDocsSides(config) {
|
|
|
15437
15738
|
} catch {}
|
|
15438
15739
|
return messages;
|
|
15439
15740
|
}
|
|
15741
|
+
function doctor_checkTerminalCatalog(config) {
|
|
15742
|
+
const root = config.docs.root;
|
|
15743
|
+
if (0 === root.trim().length) return [];
|
|
15744
|
+
const loaded = loadTerminalCatalog(root);
|
|
15745
|
+
const issues = loaded.issues.map((issue)=>({
|
|
15746
|
+
level: issue.level,
|
|
15747
|
+
message: issue.message
|
|
15748
|
+
}));
|
|
15749
|
+
const names = loaded.catalog?.terminals.map((entry)=>entry.name) ?? [];
|
|
15750
|
+
if (null === loaded.catalog && 0 === loaded.issues.length) {
|
|
15751
|
+
issues.push({
|
|
15752
|
+
level: 'warning',
|
|
15753
|
+
message: `文档仓库缺少 ${TERMINAL_CATALOG_FILE}:本次不限制执行终端名。需要统一命名为合法值请补该文件`
|
|
15754
|
+
});
|
|
15755
|
+
return issues;
|
|
15756
|
+
}
|
|
15757
|
+
const yapi = loadYapiCatalog(root);
|
|
15758
|
+
if (null !== yapi.catalog) issues.push(...checkYapiAgainstTerminalCatalog(yapi.catalog, names).map((issue)=>({
|
|
15759
|
+
level: issue.level,
|
|
15760
|
+
message: issue.message
|
|
15761
|
+
})));
|
|
15762
|
+
return issues;
|
|
15763
|
+
}
|
|
15440
15764
|
function runDoctor(options) {
|
|
15441
15765
|
const format = parseFormat(options.format);
|
|
15442
15766
|
const loaded = config_loadConfig(options.config);
|
|
15443
15767
|
if (!loaded.exists) throw new errors_CliError(`配置未初始化:${loaded.path}\n请先运行:ylcwf init`, errors_EXIT.NOT_FOUND);
|
|
15444
|
-
const checked =
|
|
15768
|
+
const checked = checkConfigWithCatalog(loaded.raw, {
|
|
15445
15769
|
checkFs: true
|
|
15446
15770
|
});
|
|
15447
15771
|
const errors = countIssues(checked.issues).errors;
|
|
15448
15772
|
const ok = !hasError(checked.issues);
|
|
15449
15773
|
const sideIssues = [];
|
|
15450
|
-
if (true === options.docs && null !== checked.config && ok)
|
|
15774
|
+
if (true === options.docs && null !== checked.config && ok) {
|
|
15775
|
+
sideIssues.push(...doctor_checkTerminalCatalog(checked.config));
|
|
15776
|
+
sideIssues.push(...checkDocsSides(checked.config));
|
|
15777
|
+
}
|
|
15451
15778
|
const sideErrors = sideIssues.filter((item)=>'error' === item.level).length;
|
|
15452
15779
|
const allOk = ok && 0 === sideErrors;
|
|
15453
15780
|
if ('json' === format) printJson({
|
|
@@ -15518,10 +15845,13 @@ function syncDocument(doc, next) {
|
|
|
15518
15845
|
'docs',
|
|
15519
15846
|
'root'
|
|
15520
15847
|
], next.docs.root);
|
|
15521
|
-
doc.
|
|
15848
|
+
if (doc.hasIn([
|
|
15522
15849
|
'docs',
|
|
15523
15850
|
'iterationsRoot'
|
|
15524
|
-
]
|
|
15851
|
+
])) doc.deleteIn([
|
|
15852
|
+
'docs',
|
|
15853
|
+
'iterationsRoot'
|
|
15854
|
+
]);
|
|
15525
15855
|
for (const side of [
|
|
15526
15856
|
'cli',
|
|
15527
15857
|
'ui'
|
|
@@ -15551,7 +15881,11 @@ function syncDocument(doc, next) {
|
|
|
15551
15881
|
key
|
|
15552
15882
|
]);
|
|
15553
15883
|
for (const [key, terminal] of Object.entries(next.terminals)){
|
|
15554
|
-
doc.
|
|
15884
|
+
if (doc.hasIn([
|
|
15885
|
+
'terminals',
|
|
15886
|
+
key,
|
|
15887
|
+
'aliases'
|
|
15888
|
+
])) doc.deleteIn([
|
|
15555
15889
|
'terminals',
|
|
15556
15890
|
key,
|
|
15557
15891
|
'aliases'
|
|
@@ -15629,7 +15963,7 @@ function repoView(path) {
|
|
|
15629
15963
|
function readState(explicitPath) {
|
|
15630
15964
|
const configPath = paths_resolveConfigPath(explicitPath);
|
|
15631
15965
|
const loaded = config_loadConfig(explicitPath);
|
|
15632
|
-
const checked = loaded.exists ?
|
|
15966
|
+
const checked = loaded.exists ? checkConfigWithCatalog(loaded.raw, {
|
|
15633
15967
|
checkFs: true
|
|
15634
15968
|
}) : {
|
|
15635
15969
|
config: null,
|
|
@@ -15642,14 +15976,14 @@ function readState(explicitPath) {
|
|
|
15642
15976
|
issues: checked.issues,
|
|
15643
15977
|
backups: listBackups(explicitPath),
|
|
15644
15978
|
meta: {
|
|
15645
|
-
version: "0.6.
|
|
15979
|
+
version: "0.6.1",
|
|
15646
15980
|
features: SERVER_FEATURES
|
|
15647
15981
|
}
|
|
15648
15982
|
};
|
|
15649
15983
|
}
|
|
15650
15984
|
function saveConfig(raw, explicitPath) {
|
|
15651
15985
|
const configPath = paths_resolveConfigPath(explicitPath);
|
|
15652
|
-
const structural =
|
|
15986
|
+
const structural = checkConfigWithCatalog(raw, {
|
|
15653
15987
|
allowIncomplete: false,
|
|
15654
15988
|
checkFs: false
|
|
15655
15989
|
});
|
|
@@ -15724,13 +16058,13 @@ function resetConfig(explicitPath) {
|
|
|
15724
16058
|
configPath
|
|
15725
16059
|
};
|
|
15726
16060
|
}
|
|
15727
|
-
function inspectPath(target
|
|
16061
|
+
function inspectPath(target) {
|
|
15728
16062
|
const view = repoView(target);
|
|
15729
16063
|
const hasDocsSkill = view.exists && external_node_fs_existsSync(external_node_path_join(target, 'skills', 'iteration-task-docs', 'SKILL.md'));
|
|
15730
16064
|
return {
|
|
15731
16065
|
...view,
|
|
15732
16066
|
hasDocsSkill,
|
|
15733
|
-
iterationYears: view.exists ? listIterationYears(target,
|
|
16067
|
+
iterationYears: view.exists ? listIterationYears(target, DEFAULT_ITERATIONS_ROOT) : []
|
|
15734
16068
|
};
|
|
15735
16069
|
}
|
|
15736
16070
|
function inspectOnboarding(configPath) {
|
|
@@ -15779,7 +16113,7 @@ function inspectOnboarding(configPath) {
|
|
|
15779
16113
|
};
|
|
15780
16114
|
}
|
|
15781
16115
|
function completeOnboarding(draftRaw, configPath) {
|
|
15782
|
-
const structural =
|
|
16116
|
+
const structural = checkConfigWithCatalog(draftRaw, {
|
|
15783
16117
|
allowIncomplete: true,
|
|
15784
16118
|
checkFs: false
|
|
15785
16119
|
});
|
|
@@ -15794,7 +16128,7 @@ function completeOnboarding(draftRaw, configPath) {
|
|
|
15794
16128
|
return inspectOnboarding(configPath);
|
|
15795
16129
|
}
|
|
15796
16130
|
function assertDirectory(target) {
|
|
15797
|
-
const absolute =
|
|
16131
|
+
const absolute = external_node_path_isAbsolute(target) ? external_node_path_resolve(target) : external_node_path_resolve(homedir(), target);
|
|
15798
16132
|
if (!external_node_fs_existsSync(absolute)) throw new errors_CliError(`目录不存在:${absolute}`, errors_EXIT.NOT_FOUND);
|
|
15799
16133
|
if (!statSync(absolute).isDirectory()) throw new errors_CliError(`不是目录:${absolute}`, errors_EXIT.USAGE);
|
|
15800
16134
|
return absolute;
|
|
@@ -16125,13 +16459,32 @@ const OPERATIONS = [
|
|
|
16125
16459
|
},
|
|
16126
16460
|
ipc: 'ylcwf:inspect',
|
|
16127
16461
|
ipcParams: [
|
|
16128
|
-
'path'
|
|
16129
|
-
'iterationsRoot'
|
|
16462
|
+
'path'
|
|
16130
16463
|
],
|
|
16131
|
-
run: (input)=>
|
|
16132
|
-
|
|
16133
|
-
|
|
16134
|
-
|
|
16464
|
+
run: (input)=>inspectPath(input.text('path'))
|
|
16465
|
+
},
|
|
16466
|
+
{
|
|
16467
|
+
name: 'terminal-catalog',
|
|
16468
|
+
http: {
|
|
16469
|
+
method: 'GET',
|
|
16470
|
+
path: '/api/terminal-catalog'
|
|
16471
|
+
},
|
|
16472
|
+
ipc: 'ylcwf:terminalCatalog',
|
|
16473
|
+
ipcParams: [],
|
|
16474
|
+
run: (_input, context)=>{
|
|
16475
|
+
const loaded = config_loadConfig(context.configPath);
|
|
16476
|
+
const layout = layoutOf(loaded.config);
|
|
16477
|
+
if (0 === layout.root.length) return {
|
|
16478
|
+
path: null,
|
|
16479
|
+
terminals: [],
|
|
16480
|
+
issues: []
|
|
16481
|
+
};
|
|
16482
|
+
const loadedCatalog = loadTerminalCatalog(layout.root);
|
|
16483
|
+
return {
|
|
16484
|
+
path: loadedCatalog.path,
|
|
16485
|
+
terminals: loadedCatalog.catalog?.terminals ?? [],
|
|
16486
|
+
issues: loadedCatalog.issues
|
|
16487
|
+
};
|
|
16135
16488
|
}
|
|
16136
16489
|
},
|
|
16137
16490
|
{
|
|
@@ -16703,188 +17056,6 @@ function registerServe(program) {
|
|
|
16703
17056
|
await runServe(options);
|
|
16704
17057
|
});
|
|
16705
17058
|
}
|
|
16706
|
-
const YAPI_PLATFORM_FILE = 'yapi_platform.json';
|
|
16707
|
-
function yapi_error(code, message, where) {
|
|
16708
|
-
return void 0 === where ? {
|
|
16709
|
-
level: 'error',
|
|
16710
|
-
code,
|
|
16711
|
-
message
|
|
16712
|
-
} : {
|
|
16713
|
-
level: 'error',
|
|
16714
|
-
code,
|
|
16715
|
-
message,
|
|
16716
|
-
where
|
|
16717
|
-
};
|
|
16718
|
-
}
|
|
16719
|
-
function yapi_isRecord(value) {
|
|
16720
|
-
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
16721
|
-
}
|
|
16722
|
-
function yapi_isPositiveInteger(value) {
|
|
16723
|
-
return 'number' == typeof value && Number.isInteger(value) && value > 0;
|
|
16724
|
-
}
|
|
16725
|
-
function checkYapiCatalog(raw) {
|
|
16726
|
-
const issues = [];
|
|
16727
|
-
if (!yapi_isRecord(raw)) return {
|
|
16728
|
-
catalog: null,
|
|
16729
|
-
issues: [
|
|
16730
|
-
yapi_error('YAPI_TYPE', 'yapi_platform.json 必须是对象')
|
|
16731
|
-
]
|
|
16732
|
-
};
|
|
16733
|
-
const groups = [];
|
|
16734
|
-
const groupsRaw = raw['groups'];
|
|
16735
|
-
if (Array.isArray(groupsRaw)) groupsRaw.forEach((item, index)=>{
|
|
16736
|
-
const where = `groups[${index}]`;
|
|
16737
|
-
if (!yapi_isRecord(item)) return void issues.push(yapi_error('YAPI_GROUP_INVALID', `${where} 必须是对象`, where));
|
|
16738
|
-
const groupId = item['groupId'];
|
|
16739
|
-
const name = item['name'];
|
|
16740
|
-
if (!yapi_isPositiveInteger(groupId)) return void issues.push(yapi_error('YAPI_GROUP_ID_INVALID', `${where}.groupId 必须是正整数`, `${where}.groupId`));
|
|
16741
|
-
if ('string' != typeof name || 0 === name.trim().length) return void issues.push(yapi_error('YAPI_GROUP_NAME_INVALID', `${where}.name 不能为空`, `${where}.name`));
|
|
16742
|
-
groups.push({
|
|
16743
|
-
groupId,
|
|
16744
|
-
name: name.trim()
|
|
16745
|
-
});
|
|
16746
|
-
});
|
|
16747
|
-
else issues.push(yapi_error('YAPI_GROUPS_INVALID', 'groups 必须是数组', 'groups'));
|
|
16748
|
-
const knownGroupIds = new Set(groups.map((group)=>group.groupId));
|
|
16749
|
-
const platforms = [];
|
|
16750
|
-
const seenTerminals = new Map();
|
|
16751
|
-
const platformsRaw = raw['platforms'];
|
|
16752
|
-
if (Array.isArray(platformsRaw)) platformsRaw.forEach((item, index)=>{
|
|
16753
|
-
const where = `platforms[${index}]`;
|
|
16754
|
-
if (!yapi_isRecord(item)) return void issues.push(yapi_error('YAPI_PLATFORM_INVALID', `${where} 必须是对象`, where));
|
|
16755
|
-
const terminal = item['terminal'];
|
|
16756
|
-
const groupId = item['groupId'];
|
|
16757
|
-
const projectIds = item['projectIds'];
|
|
16758
|
-
const platformRaw = item['platform'];
|
|
16759
|
-
if ('string' != typeof terminal || 0 === terminal.trim().length) return void issues.push(yapi_error('YAPI_TERMINAL_REQUIRED', `${where}.terminal 不能为空`, `${where}.terminal`));
|
|
16760
|
-
if (!yapi_isPositiveInteger(groupId)) return void issues.push(yapi_error('YAPI_GROUP_ID_INVALID', `${where}.groupId 必须是正整数`, `${where}.groupId`));
|
|
16761
|
-
if (!knownGroupIds.has(groupId)) issues.push(yapi_error('YAPI_GROUP_UNKNOWN', `${where}.groupId ${groupId} 未在 groups 中声明`, `${where}.groupId`));
|
|
16762
|
-
if (!Array.isArray(projectIds) || 0 === projectIds.length) return void issues.push(yapi_error('YAPI_PROJECT_IDS_INVALID', `${where}.projectIds 必须是非空数组`, `${where}.projectIds`));
|
|
16763
|
-
const invalidProject = projectIds.find((id)=>!yapi_isPositiveInteger(id));
|
|
16764
|
-
if (void 0 !== invalidProject) return void issues.push(yapi_error('YAPI_PROJECT_IDS_INVALID', `${where}.projectIds 只能包含正整数:${String(invalidProject)}`, `${where}.projectIds`));
|
|
16765
|
-
const key = normalizeName(terminal);
|
|
16766
|
-
const duplicate = seenTerminals.get(key);
|
|
16767
|
-
if (void 0 !== duplicate) issues.push(yapi_error('YAPI_TERMINAL_DUPLICATED', `执行终端「${terminal.trim()}」重复声明(另见「${duplicate}」),按归一化比较重复`, `${where}.terminal`));
|
|
16768
|
-
else seenTerminals.set(key, terminal.trim());
|
|
16769
|
-
platforms.push({
|
|
16770
|
-
platform: 'string' == typeof platformRaw && platformRaw.trim().length > 0 ? platformRaw.trim() : null,
|
|
16771
|
-
terminal: terminal.trim(),
|
|
16772
|
-
groupId,
|
|
16773
|
-
projectIds: [
|
|
16774
|
-
...projectIds
|
|
16775
|
-
].sort((left, right)=>left - right)
|
|
16776
|
-
});
|
|
16777
|
-
});
|
|
16778
|
-
else issues.push(yapi_error('YAPI_PLATFORMS_INVALID', 'platforms 必须是数组', 'platforms'));
|
|
16779
|
-
if (issues.some((issue)=>'error' === issue.level)) return {
|
|
16780
|
-
catalog: null,
|
|
16781
|
-
issues
|
|
16782
|
-
};
|
|
16783
|
-
return {
|
|
16784
|
-
catalog: {
|
|
16785
|
-
groups,
|
|
16786
|
-
platforms
|
|
16787
|
-
},
|
|
16788
|
-
issues
|
|
16789
|
-
};
|
|
16790
|
-
}
|
|
16791
|
-
function loadYapiCatalog(docsRoot) {
|
|
16792
|
-
const path = external_node_path_join(docsRoot, YAPI_PLATFORM_FILE);
|
|
16793
|
-
let text;
|
|
16794
|
-
try {
|
|
16795
|
-
text = readFileSync(path, 'utf8');
|
|
16796
|
-
} catch {
|
|
16797
|
-
return {
|
|
16798
|
-
path,
|
|
16799
|
-
catalog: null,
|
|
16800
|
-
issues: []
|
|
16801
|
-
};
|
|
16802
|
-
}
|
|
16803
|
-
let raw;
|
|
16804
|
-
try {
|
|
16805
|
-
raw = JSON.parse(text);
|
|
16806
|
-
} catch (caught) {
|
|
16807
|
-
const detail = caught instanceof Error ? caught.message : String(caught);
|
|
16808
|
-
return {
|
|
16809
|
-
path,
|
|
16810
|
-
catalog: null,
|
|
16811
|
-
issues: [
|
|
16812
|
-
yapi_error('YAPI_JSON_INVALID', `${YAPI_PLATFORM_FILE} 不是合法 JSON:${detail}`)
|
|
16813
|
-
]
|
|
16814
|
-
};
|
|
16815
|
-
}
|
|
16816
|
-
return {
|
|
16817
|
-
path,
|
|
16818
|
-
...checkYapiCatalog(raw)
|
|
16819
|
-
};
|
|
16820
|
-
}
|
|
16821
|
-
function terminalNameByRepo(terminals, input) {
|
|
16822
|
-
const target = normalizeName(input);
|
|
16823
|
-
const hits = [];
|
|
16824
|
-
for (const [name, terminal] of Object.entries(terminals)){
|
|
16825
|
-
const repos = [
|
|
16826
|
-
...terminal.repos.frontend,
|
|
16827
|
-
...terminal.repos.backend
|
|
16828
|
-
];
|
|
16829
|
-
if (repos.some((repo)=>normalizeName(basename(repo)) === target)) hits.push(name);
|
|
16830
|
-
}
|
|
16831
|
-
return 1 === hits.length ? hits[0] ?? null : null;
|
|
16832
|
-
}
|
|
16833
|
-
function resolveConfigTerminal(terminals, input) {
|
|
16834
|
-
const target = normalizeName(input);
|
|
16835
|
-
for (const name of Object.keys(terminals))if (normalizeName(name) === target) return {
|
|
16836
|
-
terminalName: name,
|
|
16837
|
-
matchedBy: 'terminal'
|
|
16838
|
-
};
|
|
16839
|
-
const byRepo = terminalNameByRepo(terminals, input);
|
|
16840
|
-
if (null !== byRepo) return {
|
|
16841
|
-
terminalName: byRepo,
|
|
16842
|
-
matchedBy: 'repo'
|
|
16843
|
-
};
|
|
16844
|
-
return {
|
|
16845
|
-
terminalName: null,
|
|
16846
|
-
matchedBy: null
|
|
16847
|
-
};
|
|
16848
|
-
}
|
|
16849
|
-
function describePlatform(item) {
|
|
16850
|
-
return null === item.platform ? item.terminal : `${item.terminal}(${item.platform})`;
|
|
16851
|
-
}
|
|
16852
|
-
function matchYapiPlatform(options) {
|
|
16853
|
-
const { catalog, terminals, input } = options;
|
|
16854
|
-
const trimmed = input.trim();
|
|
16855
|
-
const empty = {
|
|
16856
|
-
matched: false,
|
|
16857
|
-
terminalName: null,
|
|
16858
|
-
matchedBy: null,
|
|
16859
|
-
platform: null,
|
|
16860
|
-
group: null,
|
|
16861
|
-
candidates: catalog.platforms.map(describePlatform)
|
|
16862
|
-
};
|
|
16863
|
-
if (0 === trimmed.length) return empty;
|
|
16864
|
-
const resolved = resolveConfigTerminal(terminals, trimmed);
|
|
16865
|
-
const target = normalizeName(resolved.terminalName ?? trimmed);
|
|
16866
|
-
const byTerminal = catalog.platforms.filter((item)=>normalizeName(item.terminal) === target);
|
|
16867
|
-
if (1 === byTerminal.length && void 0 !== byTerminal[0]) return buildMatch(byTerminal[0], resolved.terminalName, resolved.matchedBy ?? 'terminal', catalog);
|
|
16868
|
-
if (byTerminal.length > 1) return {
|
|
16869
|
-
...empty,
|
|
16870
|
-
terminalName: resolved.terminalName,
|
|
16871
|
-
candidates: byTerminal.map(describePlatform)
|
|
16872
|
-
};
|
|
16873
|
-
return {
|
|
16874
|
-
...empty,
|
|
16875
|
-
terminalName: resolved.terminalName
|
|
16876
|
-
};
|
|
16877
|
-
}
|
|
16878
|
-
function buildMatch(item, terminalName, matchedBy, catalog) {
|
|
16879
|
-
return {
|
|
16880
|
-
matched: true,
|
|
16881
|
-
terminalName,
|
|
16882
|
-
matchedBy,
|
|
16883
|
-
platform: item,
|
|
16884
|
-
group: catalog.groups.find((group)=>group.groupId === item.groupId) ?? null,
|
|
16885
|
-
candidates: []
|
|
16886
|
-
};
|
|
16887
|
-
}
|
|
16888
17059
|
function requireCatalog(docsRoot) {
|
|
16889
17060
|
const loaded = loadYapiCatalog(docsRoot);
|
|
16890
17061
|
if (null !== loaded.catalog) return loaded.catalog;
|
|
@@ -17034,7 +17205,7 @@ function registerReset(program) {
|
|
|
17034
17205
|
}
|
|
17035
17206
|
function buildProgram() {
|
|
17036
17207
|
const program = new command_Command();
|
|
17037
|
-
program.name('ylcwf').description('YLC 研发工作流配置:文档仓库、开发者标识、默认角色与执行终端仓库映射').version("0.6.
|
|
17208
|
+
program.name('ylcwf').description('YLC 研发工作流配置:文档仓库、开发者标识、默认角色与执行终端仓库映射').version("0.6.1", '-v, --version', '显示版本号').showHelpAfterError();
|
|
17038
17209
|
registerInit(program);
|
|
17039
17210
|
registerShow(program);
|
|
17040
17211
|
registerGet(program);
|