@dialecte/cli 0.4.0 → 0.5.0
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/README.md +384 -58
- package/dist/cli.js +27224 -17775
- package/dist/ignorers.js +11 -0
- package/dist/lookups.d.ts +143 -8
- package/dist/lookups.js +385 -138
- package/package.json +47 -2
package/dist/lookups.js
CHANGED
|
@@ -140,11 +140,11 @@ import {
|
|
|
140
140
|
unlinkSync,
|
|
141
141
|
writeFileSync
|
|
142
142
|
} from "fs";
|
|
143
|
-
import { dirname as dirname2, join as join2, parse, relative, resolve } from "path";
|
|
143
|
+
import { dirname as dirname2, join as join2, parse, relative as relative2, resolve } from "path";
|
|
144
144
|
|
|
145
145
|
// src/lib/file-system.ts
|
|
146
146
|
import { lstatSync, realpathSync, statSync } from "fs";
|
|
147
|
-
import { basename, dirname, join } from "path";
|
|
147
|
+
import { basename, dirname, isAbsolute, join, relative, sep } from "path";
|
|
148
148
|
|
|
149
149
|
// src/lib/skills/skill-file.ts
|
|
150
150
|
function readFrontmatter(markdown) {
|
|
@@ -337,6 +337,40 @@ function isApiJson(value) {
|
|
|
337
337
|
return typeof value === "object" && value !== null && "package" in value && typeof value.package === "string" && "methods" in value && Array.isArray(value.methods);
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
+
// src/lib/print/print.ts
|
|
341
|
+
import { writeSync } from "fs";
|
|
342
|
+
|
|
343
|
+
// src/lib/print/print.constants.ts
|
|
344
|
+
var DISPLAY_ESCAPED_RANGES = [
|
|
345
|
+
[0, 31],
|
|
346
|
+
[127, 159],
|
|
347
|
+
[1564, 1564],
|
|
348
|
+
[8206, 8207],
|
|
349
|
+
[8232, 8233],
|
|
350
|
+
[8234, 8238],
|
|
351
|
+
[8294, 8297]
|
|
352
|
+
];
|
|
353
|
+
var ESCAPE_RADIX = 16;
|
|
354
|
+
var LINE_FEED = "\n";
|
|
355
|
+
|
|
356
|
+
// src/lib/print/print.ts
|
|
357
|
+
function escapeControlCharacters(params) {
|
|
358
|
+
return Array.from(params.text, function escapeOf(character) {
|
|
359
|
+
const code = character.codePointAt(0) ?? 0;
|
|
360
|
+
const escaped = DISPLAY_ESCAPED_RANGES.some(([first, last]) => code >= first && code <= last);
|
|
361
|
+
return escaped ? `\\u{${code.toString(ESCAPE_RADIX)}}` : character;
|
|
362
|
+
}).join("");
|
|
363
|
+
}
|
|
364
|
+
function textOf(lines) {
|
|
365
|
+
return lines.map((line) => escapeControlCharacters({ text: line })).join(LINE_FEED);
|
|
366
|
+
}
|
|
367
|
+
function jsonOf(value, indent) {
|
|
368
|
+
return JSON.stringify(value, null, indent);
|
|
369
|
+
}
|
|
370
|
+
function endedOf(text) {
|
|
371
|
+
return `${text}${LINE_FEED}`;
|
|
372
|
+
}
|
|
373
|
+
|
|
340
374
|
// src/lib/api/short-summary.ts
|
|
341
375
|
function shortSummary(summary) {
|
|
342
376
|
const sentence = summary.match(/^.*?[.!?](?=\s|$)/)?.[0] ?? summary;
|
|
@@ -346,31 +380,47 @@ function shortSummary(summary) {
|
|
|
346
380
|
// src/lib/api/render-api.ts
|
|
347
381
|
function renderFound(params) {
|
|
348
382
|
if (params.json)
|
|
349
|
-
return
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
383
|
+
return endedOf(
|
|
384
|
+
jsonOf(
|
|
385
|
+
{
|
|
386
|
+
need: params.need,
|
|
387
|
+
methods: params.found.map((found) => ({
|
|
388
|
+
path: found.method.path,
|
|
389
|
+
root: found.method.root,
|
|
390
|
+
package: found.packageName,
|
|
391
|
+
hits: found.hits,
|
|
392
|
+
intent: found.matchingIntent,
|
|
393
|
+
summary: found.method.summary
|
|
394
|
+
}))
|
|
395
|
+
},
|
|
396
|
+
" "
|
|
397
|
+
)
|
|
398
|
+
);
|
|
399
|
+
return endedTextOf(
|
|
400
|
+
params.found.map(
|
|
401
|
+
(found) => `${found.method.path} ${found.method.root} ${found.matchingIntent ?? shortSummary(found.method.summary ?? "-")} ${found.packageName}`
|
|
402
|
+
)
|
|
403
|
+
);
|
|
364
404
|
}
|
|
365
405
|
function renderShown(params) {
|
|
366
406
|
if (params.json)
|
|
367
|
-
return
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
407
|
+
return endedOf(
|
|
408
|
+
jsonOf(
|
|
409
|
+
{
|
|
410
|
+
methods: params.methods.map(({ method, packageName: packageName2 }) => ({
|
|
411
|
+
package: packageName2,
|
|
412
|
+
...method
|
|
413
|
+
}))
|
|
414
|
+
},
|
|
415
|
+
" "
|
|
416
|
+
)
|
|
417
|
+
);
|
|
418
|
+
return endedTextOf(
|
|
419
|
+
params.methods.flatMap((packaged, index) => [
|
|
420
|
+
...index === 0 ? [] : [""],
|
|
421
|
+
...renderMethod(packaged)
|
|
422
|
+
])
|
|
423
|
+
);
|
|
374
424
|
}
|
|
375
425
|
function renderMethod({ method, packageName: packageName2 }) {
|
|
376
426
|
const lines = [`${method.path} (${packageName2})`, method.signature];
|
|
@@ -379,22 +429,39 @@ function renderMethod({ method, packageName: packageName2 }) {
|
|
|
379
429
|
if (method.otherRoutes.length) lines.push(`also: ${method.otherRoutes.join(", ")}`);
|
|
380
430
|
if (method.declaredAt) lines.push(`source (repository): ${method.declaredAt}`);
|
|
381
431
|
if (method.example) lines.push(`example: ${method.example}`);
|
|
382
|
-
return
|
|
383
|
-
`;
|
|
432
|
+
return lines;
|
|
384
433
|
}
|
|
385
|
-
function
|
|
386
|
-
return
|
|
387
|
-
`;
|
|
434
|
+
function endedTextOf(lines) {
|
|
435
|
+
return textOf(lines.length === 0 ? [] : [...lines, ""]);
|
|
388
436
|
}
|
|
389
437
|
|
|
390
438
|
// src/lib/config.ts
|
|
391
439
|
import { readFileSync as readFileSync3, existsSync as existsSync3, readdirSync as readdirSync3, statSync as statSync3 } from "fs";
|
|
392
440
|
import { join as join4 } from "path";
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
441
|
+
|
|
442
|
+
// src/lib/config.constants.ts
|
|
443
|
+
var CORE_PACKAGE = "@dialecte/core";
|
|
444
|
+
var CORE_TEST_DIALECT = {
|
|
445
|
+
version: "core",
|
|
446
|
+
binding: {
|
|
447
|
+
kind: "core",
|
|
448
|
+
coreAlias: "Core",
|
|
449
|
+
coreImport: "@/index",
|
|
450
|
+
configType: "TestDialecteConfig",
|
|
451
|
+
configImport: "@/test/config"
|
|
452
|
+
},
|
|
453
|
+
constantsDir: "./src/test/generated",
|
|
454
|
+
outDir: "./benchmarks/types/generated"
|
|
396
455
|
};
|
|
397
|
-
|
|
456
|
+
|
|
457
|
+
// src/lib/config.ts
|
|
458
|
+
function getArg(argv, name) {
|
|
459
|
+
const index = argv.indexOf(`--${name}`);
|
|
460
|
+
return index >= 0 ? argv[index + 1] : void 0;
|
|
461
|
+
}
|
|
462
|
+
function hasFlag(argv, name) {
|
|
463
|
+
return argv.includes(`--${name}`);
|
|
464
|
+
}
|
|
398
465
|
function positionalArguments(params) {
|
|
399
466
|
const words = [];
|
|
400
467
|
for (let index = 0; index < params.argv.length; index++) {
|
|
@@ -404,13 +471,19 @@ function positionalArguments(params) {
|
|
|
404
471
|
}
|
|
405
472
|
return words;
|
|
406
473
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
474
|
+
function tsconfigOf(argv, cwd = process.cwd()) {
|
|
475
|
+
return getArg(argv, "tsconfig") ?? pkgConfig(cwd).tsconfig ?? "tsconfig.build.json";
|
|
476
|
+
}
|
|
477
|
+
function readPkg(cwd) {
|
|
478
|
+
const packageJson = join4(cwd, "package.json");
|
|
479
|
+
return existsSync3(packageJson) ? JSON.parse(readFileSync3(packageJson, "utf8")) : {};
|
|
480
|
+
}
|
|
481
|
+
function pkgConfig(cwd) {
|
|
482
|
+
return readPkg(cwd).dialecte ?? {};
|
|
483
|
+
}
|
|
484
|
+
function capitalize(word) {
|
|
485
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
486
|
+
}
|
|
414
487
|
function discoverNamespace(cwd) {
|
|
415
488
|
return capitalize(
|
|
416
489
|
String(readPkg(cwd).name ?? "dialecte").split("/").pop() ?? "dialecte"
|
|
@@ -423,19 +496,6 @@ function discoverVersions(cwd) {
|
|
|
423
496
|
(v) => existsSync3(join4(src, v, "definition", "constants.generated.ts")) && existsSync3(join4(src, v, "definition", "definition.generated.ts"))
|
|
424
497
|
).sort();
|
|
425
498
|
}
|
|
426
|
-
var CORE_PACKAGE = "@dialecte/core";
|
|
427
|
-
var CORE_TEST_DIALECT = {
|
|
428
|
-
version: "core",
|
|
429
|
-
binding: {
|
|
430
|
-
kind: "core",
|
|
431
|
-
coreAlias: "Core",
|
|
432
|
-
coreImport: "@/index",
|
|
433
|
-
configType: "TestDialecteConfig",
|
|
434
|
-
configImport: "@/test/config"
|
|
435
|
-
},
|
|
436
|
-
constantsDir: "./src/test/generated",
|
|
437
|
-
outDir: "./benchmarks/types/generated"
|
|
438
|
-
};
|
|
439
499
|
function resolveTargets(argv, cwd = process.cwd()) {
|
|
440
500
|
if (readPkg(cwd).name === CORE_PACKAGE)
|
|
441
501
|
return [
|
|
@@ -469,8 +529,10 @@ import { existsSync as existsSync4 } from "fs";
|
|
|
469
529
|
import { join as join5 } from "path";
|
|
470
530
|
function missingPackage(params) {
|
|
471
531
|
return existsSync4(join5(params.cwd, "package.json")) ? void 0 : {
|
|
472
|
-
output:
|
|
473
|
-
`,
|
|
532
|
+
output: textOf([
|
|
533
|
+
`no package.json in ${params.cwd}: run dialecte in your package's folder`,
|
|
534
|
+
""
|
|
535
|
+
]),
|
|
474
536
|
exitCode: 2
|
|
475
537
|
};
|
|
476
538
|
}
|
|
@@ -489,8 +551,7 @@ function runApi(params) {
|
|
|
489
551
|
const words = positionalArguments({ argv: rest, valueOptions: API_VALUE_OPTIONS });
|
|
490
552
|
const limit = Number(getArg([...rest], "limit") ?? DEFAULT_FIND_LIMIT);
|
|
491
553
|
if (!isSubcommand(subcommand) || words.length === 0 || !Number.isInteger(limit) || limit < 1)
|
|
492
|
-
return { output:
|
|
493
|
-
`, exitCode: 2 };
|
|
554
|
+
return { output: textOf([API_USAGE, ""]), exitCode: 2 };
|
|
494
555
|
const packageName2 = getArg([...rest], "package");
|
|
495
556
|
const indexes = readApiIndexes({ cwd: params.cwd }).filter(
|
|
496
557
|
(index) => packageName2 === void 0 || index.package === packageName2
|
|
@@ -505,8 +566,10 @@ function find(params) {
|
|
|
505
566
|
const found = findMethods(params);
|
|
506
567
|
if (found.length === 0 && !params.json)
|
|
507
568
|
return {
|
|
508
|
-
output:
|
|
509
|
-
`,
|
|
569
|
+
output: textOf([
|
|
570
|
+
`no method found for "${params.need}" in ${packagesText(params.indexes)}: try other words, or \`npx @dialecte/cli members <expression>\` for the live types`,
|
|
571
|
+
""
|
|
572
|
+
]),
|
|
510
573
|
exitCode: 1
|
|
511
574
|
};
|
|
512
575
|
return {
|
|
@@ -518,8 +581,10 @@ function show(params) {
|
|
|
518
581
|
const methods = findByPath(params);
|
|
519
582
|
if (methods.length === 0 && !params.json)
|
|
520
583
|
return {
|
|
521
|
-
output:
|
|
522
|
-
`,
|
|
584
|
+
output: textOf([
|
|
585
|
+
`no method "${params.path}" in ${packagesText(params.indexes)}: \`npx @dialecte/cli api find "<what you need>"\` lists the routes`,
|
|
586
|
+
""
|
|
587
|
+
]),
|
|
523
588
|
exitCode: 1
|
|
524
589
|
};
|
|
525
590
|
return { output: renderShown({ methods, json: params.json }), exitCode: methods.length ? 0 : 1 };
|
|
@@ -531,24 +596,22 @@ function packagesText(indexes) {
|
|
|
531
596
|
// src/lib/doctor/answer-doctor.ts
|
|
532
597
|
function answerDoctor(params) {
|
|
533
598
|
const exitCode = params.lines.some((line) => line.status !== "ok") ? 1 : 0;
|
|
534
|
-
if (params.json)
|
|
535
|
-
|
|
536
|
-
`, exitCode };
|
|
537
|
-
return { output: params.lines.map(renderLine).join(""), exitCode };
|
|
599
|
+
if (params.json) return { output: endedOf(jsonOf({ lines: params.lines }, " ")), exitCode };
|
|
600
|
+
return { output: endedTextOf2(params.lines.map(renderLine)), exitCode };
|
|
538
601
|
}
|
|
539
602
|
function answerDoctorBrief(lines) {
|
|
540
603
|
return {
|
|
541
|
-
output: lines.filter((line) => line.status !== "ok").map(renderLine)
|
|
604
|
+
output: endedTextOf2(lines.filter((line) => line.status !== "ok").map(renderLine)),
|
|
542
605
|
exitCode: 0
|
|
543
606
|
};
|
|
544
607
|
}
|
|
608
|
+
function endedTextOf2(lines) {
|
|
609
|
+
return textOf(lines.length === 0 ? [] : [...lines, ""]);
|
|
610
|
+
}
|
|
545
611
|
function renderLine(line) {
|
|
546
|
-
if (line.status === "ok") return `\u2705 ${line.subject} ${line.detail}
|
|
547
|
-
`;
|
|
612
|
+
if (line.status === "ok") return `\u2705 ${line.subject} ${line.detail}`;
|
|
548
613
|
const fix = line.fix ? ` - fix: ${line.fix}` : "";
|
|
549
|
-
return line.status === "error" ? `\u274C ${line.subject} ${line.detail}${fix}
|
|
550
|
-
` : `\u26A0\uFE0F ${line.subject} ${line.detail}${fix}
|
|
551
|
-
`;
|
|
614
|
+
return line.status === "error" ? `\u274C ${line.subject} ${line.detail}${fix}` : `\u26A0\uFE0F ${line.subject} ${line.detail}${fix}`;
|
|
552
615
|
}
|
|
553
616
|
|
|
554
617
|
// src/lib/doctor/diagnose.ts
|
|
@@ -1120,7 +1183,7 @@ function runBrief(context) {
|
|
|
1120
1183
|
diagnose({ ...context, cliVersion: resolveVersion(context.cliVersion), brief: true })
|
|
1121
1184
|
);
|
|
1122
1185
|
} catch {
|
|
1123
|
-
return { output:
|
|
1186
|
+
return { output: textOf([]), exitCode: 0 };
|
|
1124
1187
|
}
|
|
1125
1188
|
}
|
|
1126
1189
|
function resolveVersion(cliVersion) {
|
|
@@ -1198,13 +1261,11 @@ function answerMembers(params) {
|
|
|
1198
1261
|
const members = listMembers(params);
|
|
1199
1262
|
if (params.json)
|
|
1200
1263
|
return {
|
|
1201
|
-
output:
|
|
1202
|
-
`,
|
|
1264
|
+
output: endedOf(jsonOf({ expression, members }, " ")),
|
|
1203
1265
|
exitCode: members.length ? 0 : 1
|
|
1204
1266
|
};
|
|
1205
1267
|
if (members.length)
|
|
1206
|
-
return { output:
|
|
1207
|
-
`, exitCode: 0 };
|
|
1268
|
+
return { output: textOf([expression, ...members.map(memberLine), ""]), exitCode: 0 };
|
|
1208
1269
|
const parent = expression.slice(0, Math.max(0, expression.lastIndexOf(".")));
|
|
1209
1270
|
const neighbours = parent ? listMembers({ entries: params.entries, expression: parent }).map((member) => member.name) : [];
|
|
1210
1271
|
const closest = closestNames({
|
|
@@ -1213,8 +1274,7 @@ function answerMembers(params) {
|
|
|
1213
1274
|
limit: MEMBER_SUGGESTION_LIMIT
|
|
1214
1275
|
});
|
|
1215
1276
|
const hint = parent ? ` - under ${parent}: ${(closest.length ? closest : neighbours).join(", ") || "nothing"}` : "";
|
|
1216
|
-
return { output: `nothing at ${expression}${hint}
|
|
1217
|
-
`, exitCode: 1 };
|
|
1277
|
+
return { output: textOf([`nothing at ${expression}${hint}`, ""]), exitCode: 1 };
|
|
1218
1278
|
}
|
|
1219
1279
|
function memberLine(member) {
|
|
1220
1280
|
if (member.kind === "group")
|
|
@@ -1274,6 +1334,7 @@ async function loadDialectes(params) {
|
|
|
1274
1334
|
return result;
|
|
1275
1335
|
}
|
|
1276
1336
|
async function loadDialecte(params) {
|
|
1337
|
+
const standard = readStandard(params.manifest);
|
|
1277
1338
|
let config;
|
|
1278
1339
|
for (const file of entryFiles(params)) {
|
|
1279
1340
|
const exported = await import(pathToFileURL(file).href);
|
|
@@ -1287,7 +1348,17 @@ async function loadDialecte(params) {
|
|
|
1287
1348
|
throw new Error(
|
|
1288
1349
|
`its core (${readersFile}) lacks ${CORE_READER_NAMES.filter((name) => typeof readers[name] !== "function").join(", ")}: update @dialecte/core`
|
|
1289
1350
|
);
|
|
1290
|
-
return { packageName: params.packageName, config, readers };
|
|
1351
|
+
return { packageName: params.packageName, config, readers, standard };
|
|
1352
|
+
}
|
|
1353
|
+
function readStandard(manifest) {
|
|
1354
|
+
const field = manifest.dialecte;
|
|
1355
|
+
if (typeof field !== "object" || field === null || !("standard" in field)) return void 0;
|
|
1356
|
+
const { standard } = field;
|
|
1357
|
+
if (typeof standard !== "string" || standard.trim() === "")
|
|
1358
|
+
throw new Error(
|
|
1359
|
+
`dialecte.standard must be a non-empty string, found ${JSON.stringify(standard) ?? String(standard)}`
|
|
1360
|
+
);
|
|
1361
|
+
return standard;
|
|
1291
1362
|
}
|
|
1292
1363
|
function readManifest(folder) {
|
|
1293
1364
|
const path = join12(folder, "package.json");
|
|
@@ -1323,7 +1394,7 @@ function isCoreReaders(module) {
|
|
|
1323
1394
|
// src/lib/api/installed-bindings.constants.ts
|
|
1324
1395
|
var VERSION_SUBPATH_PATTERN = /^\.\/[^/*]+$/;
|
|
1325
1396
|
var TEST_ENTRY = "test";
|
|
1326
|
-
var NO_DIALECTE_INSTALLED = "no dialecte installed here (a dependency built on @dialecte/core exporting ./<version> with ./<version>/test): pass --namespace <Name> --entry <module
|
|
1397
|
+
var NO_DIALECTE_INSTALLED = "no dialecte installed here (a dependency built on @dialecte/core exporting ./<version> with ./<version>/test): pass --namespace <Name> --entry <module>";
|
|
1327
1398
|
|
|
1328
1399
|
// src/lib/api/installed-bindings.ts
|
|
1329
1400
|
function findInstalledBindings(params) {
|
|
@@ -1348,7 +1419,8 @@ function versionsOf(manifest) {
|
|
|
1348
1419
|
return subpaths.filter((subpath) => VERSION_SUBPATH_PATTERN.test(subpath)).filter((subpath) => subpaths.includes(`${subpath}/${TEST_ENTRY}`)).map((subpath) => subpath.slice(2));
|
|
1349
1420
|
}
|
|
1350
1421
|
function chooseInstalledBinding(params) {
|
|
1351
|
-
if (params.bindings.length === 0)
|
|
1422
|
+
if (params.bindings.length === 0)
|
|
1423
|
+
return { kind: "output", message: textOf([NO_DIALECTE_INSTALLED, ""]) };
|
|
1352
1424
|
const matching = params.bindings.filter(
|
|
1353
1425
|
(binding) => (params.packageName === void 0 || binding.packageName === params.packageName) && (params.version === void 0 || binding.version === params.version)
|
|
1354
1426
|
);
|
|
@@ -1360,24 +1432,29 @@ function chooseInstalledBinding(params) {
|
|
|
1360
1432
|
].join(" ");
|
|
1361
1433
|
return {
|
|
1362
1434
|
kind: "output",
|
|
1363
|
-
message:
|
|
1364
|
-
${
|
|
1435
|
+
message: textOf([
|
|
1436
|
+
`no installed dialecte matches ${named}; installed:`,
|
|
1437
|
+
...listLines(params.bindings),
|
|
1438
|
+
""
|
|
1439
|
+
])
|
|
1365
1440
|
};
|
|
1366
1441
|
}
|
|
1367
1442
|
return {
|
|
1368
1443
|
kind: "output",
|
|
1369
|
-
message:
|
|
1370
|
-
|
|
1444
|
+
message: textOf([
|
|
1445
|
+
"several dialectes are installed: pass --package <name> [--version <v>]",
|
|
1446
|
+
...listLines(matching),
|
|
1447
|
+
""
|
|
1448
|
+
])
|
|
1371
1449
|
};
|
|
1372
1450
|
}
|
|
1373
1451
|
function listLines(bindings) {
|
|
1374
|
-
return bindings.map((binding) => ` ${binding.packageName} --version ${binding.version}
|
|
1375
|
-
`).join("");
|
|
1452
|
+
return bindings.map((binding) => ` ${binding.packageName} --version ${binding.version}`);
|
|
1376
1453
|
}
|
|
1377
1454
|
|
|
1378
1455
|
// src/lib/discover.ts
|
|
1379
1456
|
import { mkdirSync as mkdirSync2, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
1380
|
-
import { dirname as dirname5, join as join13, relative as
|
|
1457
|
+
import { dirname as dirname5, join as join13, relative as relative3 } from "path";
|
|
1381
1458
|
|
|
1382
1459
|
// src/lib/discover.constants.ts
|
|
1383
1460
|
import ts from "typescript";
|
|
@@ -1639,12 +1716,12 @@ function declaresFunction(declaration) {
|
|
|
1639
1716
|
function declarationKey(params) {
|
|
1640
1717
|
const declaration = params.symbol?.declarations?.[0];
|
|
1641
1718
|
if (!declaration) return void 0;
|
|
1642
|
-
return `${
|
|
1719
|
+
return `${relative3(params.root, declaration.getSourceFile().fileName)}:${declaration.getStart()}`;
|
|
1643
1720
|
}
|
|
1644
1721
|
function isDeclaredInPackage(params) {
|
|
1645
1722
|
const fileName = params.symbol?.declarations?.[0]?.getSourceFile().fileName;
|
|
1646
1723
|
if (!fileName) return false;
|
|
1647
|
-
const path =
|
|
1724
|
+
const path = relative3(params.root, fileName);
|
|
1648
1725
|
return !path.startsWith("..") && !path.split(/[\\/]/).includes("node_modules");
|
|
1649
1726
|
}
|
|
1650
1727
|
function declarationOf(symbol) {
|
|
@@ -1722,8 +1799,7 @@ function readMemberEntries(params) {
|
|
|
1722
1799
|
const [expression] = positionalArguments({ argv, valueOptions: MEMBERS_VALUE_OPTIONS });
|
|
1723
1800
|
const usage = {
|
|
1724
1801
|
kind: "output",
|
|
1725
|
-
output: { output:
|
|
1726
|
-
`, exitCode: 2 }
|
|
1802
|
+
output: { output: textOf([MEMBERS_USAGE, ""]), exitCode: 2 }
|
|
1727
1803
|
};
|
|
1728
1804
|
if (!expression) return usage;
|
|
1729
1805
|
const binding = readBinding({ argv, cwd });
|
|
@@ -1754,31 +1830,35 @@ function answerModels(params) {
|
|
|
1754
1830
|
const knownIds = VENDOR_IDS;
|
|
1755
1831
|
if (params.vendor === void 0)
|
|
1756
1832
|
return {
|
|
1757
|
-
output:
|
|
1758
|
-
|
|
1833
|
+
output: textOf([
|
|
1834
|
+
`dialecte models: no vendor known for this project. Run \`dialecte skills sync --vendor <${knownIds.join("|")}>\`, or pass \`--vendor <id>\`.`,
|
|
1835
|
+
""
|
|
1836
|
+
]),
|
|
1759
1837
|
exitCode: 2
|
|
1760
1838
|
};
|
|
1761
1839
|
if (!isVendorId(params.vendor))
|
|
1762
1840
|
return {
|
|
1763
|
-
output:
|
|
1764
|
-
`,
|
|
1841
|
+
output: textOf([
|
|
1842
|
+
`dialecte models: unknown vendor "${params.vendor}" (known: ${knownIds.join(", ")})`,
|
|
1843
|
+
""
|
|
1844
|
+
]),
|
|
1765
1845
|
exitCode: 1
|
|
1766
1846
|
};
|
|
1767
1847
|
const models = MODEL_TIERS.vendors[params.vendor];
|
|
1768
1848
|
if (params.json)
|
|
1769
1849
|
return {
|
|
1770
|
-
output:
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1850
|
+
output: endedOf(
|
|
1851
|
+
jsonOf(
|
|
1852
|
+
{
|
|
1853
|
+
vendor: params.vendor,
|
|
1854
|
+
checkedAt: MODEL_TIERS.checkedAt,
|
|
1855
|
+
tiers: models.tiers,
|
|
1856
|
+
...models.note === void 0 ? {} : { note: models.note },
|
|
1857
|
+
definitions: TIER_DEFINITIONS
|
|
1858
|
+
},
|
|
1859
|
+
" "
|
|
1860
|
+
)
|
|
1861
|
+
),
|
|
1782
1862
|
exitCode: 0
|
|
1783
1863
|
};
|
|
1784
1864
|
const width = Math.max(...TIER_NAMES.map((tier) => tier.length)) + 2;
|
|
@@ -1789,8 +1869,7 @@ function answerModels(params) {
|
|
|
1789
1869
|
"",
|
|
1790
1870
|
...TIER_NAMES.map((tier) => `${tier.padEnd(width)}${TIER_DEFINITIONS[tier]}`)
|
|
1791
1871
|
];
|
|
1792
|
-
return { output:
|
|
1793
|
-
`, exitCode: 0 };
|
|
1872
|
+
return { output: textOf([...lines, ""]), exitCode: 0 };
|
|
1794
1873
|
}
|
|
1795
1874
|
function renderModel(tierModel) {
|
|
1796
1875
|
return tierModel.effort === void 0 ? tierModel.model : `${tierModel.model} (${tierModel.effort})`;
|
|
@@ -1799,22 +1878,102 @@ function renderModel(tierModel) {
|
|
|
1799
1878
|
// src/commands/models.ts
|
|
1800
1879
|
function runModels(params) {
|
|
1801
1880
|
const missing = missingPackage({ cwd: params.cwd });
|
|
1802
|
-
if (missing) return { ...missing, warnings:
|
|
1881
|
+
if (missing) return { ...missing, warnings: textOf([]) };
|
|
1803
1882
|
const argv = [...params.argv];
|
|
1804
1883
|
const remembered = readRememberedVendor(params.cwd);
|
|
1805
1884
|
const answer = answerModels({
|
|
1806
1885
|
vendor: getArg(argv, "vendor") ?? remembered.vendor,
|
|
1807
1886
|
json: hasFlag(argv, "json")
|
|
1808
1887
|
});
|
|
1809
|
-
|
|
1810
|
-
|
|
1888
|
+
const warnings = remembered.warnings.map((warning) => `\u26A0\uFE0F ${warning}`);
|
|
1889
|
+
return { ...answer, warnings: textOf(warnings.length === 0 ? [] : [...warnings, ""]) };
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
// src/lib/schema/resolve-declaration.ts
|
|
1893
|
+
function resolveDeclaration(params) {
|
|
1894
|
+
const tagLevel = params.definition[params.tagName];
|
|
1895
|
+
if (tagLevel === void 0) return void 0;
|
|
1896
|
+
const declarations = tagLevel.declarations;
|
|
1897
|
+
if (declarations === void 0) return { declarations: 1, resolved: true, id: void 0 };
|
|
1898
|
+
const id = singleHeldId({
|
|
1899
|
+
definition: params.definition,
|
|
1900
|
+
tagName: params.tagName,
|
|
1901
|
+
parent: params.parent
|
|
1902
|
+
});
|
|
1903
|
+
const known = id !== void 0 && declarations[id] !== void 0;
|
|
1904
|
+
return {
|
|
1905
|
+
declarations: Object.keys(declarations).length,
|
|
1906
|
+
resolved: known,
|
|
1907
|
+
id: known ? id : void 0
|
|
1908
|
+
};
|
|
1909
|
+
}
|
|
1910
|
+
function heldDeclarationIds(params) {
|
|
1911
|
+
const held = heldByNamespace(params);
|
|
1912
|
+
return held === void 0 ? [] : [...new Set(Object.values(held).flat())];
|
|
1913
|
+
}
|
|
1914
|
+
function declarationParents(params) {
|
|
1915
|
+
const { definition, tagName, id } = params;
|
|
1916
|
+
return (definition[tagName]?.parents ?? []).filter(function holdsDeclaration(parent) {
|
|
1917
|
+
return heldDeclarationIds({ definition, tagName, parent }).includes(id);
|
|
1918
|
+
});
|
|
1919
|
+
}
|
|
1920
|
+
function singleHeldId(params) {
|
|
1921
|
+
const held = heldByNamespace(params);
|
|
1922
|
+
if (held === void 0) return void 0;
|
|
1923
|
+
const namespaces = Object.keys(held);
|
|
1924
|
+
if (namespaces.length !== 1) return void 0;
|
|
1925
|
+
const ids = held[namespaces[0]];
|
|
1926
|
+
return ids?.length === 1 ? ids[0] : void 0;
|
|
1927
|
+
}
|
|
1928
|
+
function heldByNamespace(params) {
|
|
1929
|
+
if (params.parent === void 0) return void 0;
|
|
1930
|
+
return params.definition[params.parent]?.children.details[params.tagName]?.declarations;
|
|
1811
1931
|
}
|
|
1812
1932
|
|
|
1813
1933
|
// src/lib/schema/describe-element.ts
|
|
1814
1934
|
function describeElement(params) {
|
|
1935
|
+
const { dialecte, tagName, parent } = params;
|
|
1936
|
+
const { definition, elements } = dialecte.config;
|
|
1937
|
+
const tagLevel = definition[tagName];
|
|
1938
|
+
if (!elements.includes(tagName) || tagLevel === void 0) return void 0;
|
|
1939
|
+
if (parent !== void 0 && !tagLevel.parents.includes(parent)) return void 0;
|
|
1940
|
+
const resolution = resolveDeclaration({ definition, tagName, parent });
|
|
1941
|
+
if (resolution === void 0) return void 0;
|
|
1942
|
+
if (resolution.id !== void 0)
|
|
1943
|
+
return describeDeclaration({ dialecte, tagName, id: resolution.id });
|
|
1944
|
+
return describeDefinition({
|
|
1945
|
+
dialecte,
|
|
1946
|
+
tagName,
|
|
1947
|
+
declaration: void 0,
|
|
1948
|
+
declarations: resolution.declarations,
|
|
1949
|
+
resolved: resolution.resolved
|
|
1950
|
+
});
|
|
1951
|
+
}
|
|
1952
|
+
function describeDeclaration(params) {
|
|
1953
|
+
const { dialecte, tagName, id } = params;
|
|
1954
|
+
const declarations = dialecte.config.definition[tagName]?.declarations;
|
|
1955
|
+
if (declarations?.[id] === void 0) return void 0;
|
|
1956
|
+
return describeDefinition({
|
|
1957
|
+
dialecte: { ...dialecte, config: declarationView({ config: dialecte.config, tagName, id }) },
|
|
1958
|
+
tagName,
|
|
1959
|
+
declaration: id,
|
|
1960
|
+
declarations: Object.keys(declarations).length,
|
|
1961
|
+
resolved: true
|
|
1962
|
+
});
|
|
1963
|
+
}
|
|
1964
|
+
function declarationView(params) {
|
|
1965
|
+
const { config, tagName, id } = params;
|
|
1966
|
+
const tagLevel = config.definition[tagName];
|
|
1967
|
+
const declaration = tagLevel.declarations?.[id];
|
|
1968
|
+
if (declaration === void 0) return config;
|
|
1969
|
+
const parents = declarationParents({ definition: config.definition, tagName, id });
|
|
1970
|
+
const element = { ...declaration, tag: tagLevel.tag, parents };
|
|
1971
|
+
return { ...config, definition: { ...config.definition, [tagName]: element } };
|
|
1972
|
+
}
|
|
1973
|
+
function describeDefinition(params) {
|
|
1815
1974
|
const { config, readers, packageName: packageName2 } = params.dialecte;
|
|
1816
1975
|
const record = { tagName: params.tagName, parent: null, attributes: [] };
|
|
1817
|
-
const definition =
|
|
1976
|
+
const definition = readers.resolveDefinition({ dialecteConfig: config, record });
|
|
1818
1977
|
if (definition === void 0) return void 0;
|
|
1819
1978
|
const occurrences = readers.childOccurrences({ definition });
|
|
1820
1979
|
const children = readers.orderByConfigSequence({
|
|
@@ -1845,7 +2004,12 @@ function describeElement(params) {
|
|
|
1845
2004
|
};
|
|
1846
2005
|
}),
|
|
1847
2006
|
text: definition.textContent ? typeName(definition.textContent.type) ?? "string" : void 0,
|
|
1848
|
-
xsiTypes: readers.admittedXsiTypes({ dialecteConfig: config, record })
|
|
2007
|
+
xsiTypes: readers.admittedXsiTypes({ dialecteConfig: config, record }),
|
|
2008
|
+
type: definition.type,
|
|
2009
|
+
documentation: definition.documentation,
|
|
2010
|
+
declaration: params.declaration,
|
|
2011
|
+
declarations: params.declarations,
|
|
2012
|
+
resolved: params.resolved
|
|
1849
2013
|
};
|
|
1850
2014
|
}
|
|
1851
2015
|
function typeName(datatype) {
|
|
@@ -1854,24 +2018,104 @@ function typeName(datatype) {
|
|
|
1854
2018
|
return "list" in datatype ? "list" : "union";
|
|
1855
2019
|
}
|
|
1856
2020
|
|
|
2021
|
+
// src/lib/schema/describe-declarations.ts
|
|
2022
|
+
function describeDeclarations(params) {
|
|
2023
|
+
const { dialecte, tagName, ids } = params;
|
|
2024
|
+
const { definition, elements } = dialecte.config;
|
|
2025
|
+
const declarations = elements.includes(tagName) ? definition[tagName]?.declarations : void 0;
|
|
2026
|
+
const kept = Object.entries(declarations ?? {}).filter(
|
|
2027
|
+
([id]) => ids === void 0 || ids.includes(id)
|
|
2028
|
+
);
|
|
2029
|
+
return kept.flatMap(function describeWay([id, declaration]) {
|
|
2030
|
+
const element = describeDeclaration({ dialecte, tagName, id });
|
|
2031
|
+
if (element === void 0) return [];
|
|
2032
|
+
return [
|
|
2033
|
+
{
|
|
2034
|
+
id,
|
|
2035
|
+
parents: declarationParents({ definition, tagName, id }),
|
|
2036
|
+
global: declaration.global === true,
|
|
2037
|
+
element
|
|
2038
|
+
}
|
|
2039
|
+
];
|
|
2040
|
+
});
|
|
2041
|
+
}
|
|
2042
|
+
|
|
1857
2043
|
// src/lib/schema/answer-schema.ts
|
|
1858
2044
|
function answerSchema(params) {
|
|
1859
|
-
const { loaded, tagName } = params;
|
|
1860
|
-
const
|
|
1861
|
-
(dialecte) =>
|
|
2045
|
+
const { loaded, tagName, under } = params;
|
|
2046
|
+
const answers = loaded.dialectes.flatMap(
|
|
2047
|
+
(dialecte) => answerOf({ dialecte, tagName, under }) ?? []
|
|
1862
2048
|
);
|
|
1863
2049
|
if (params.json)
|
|
1864
2050
|
return {
|
|
1865
|
-
output:
|
|
1866
|
-
|
|
1867
|
-
|
|
2051
|
+
output: endedOf(
|
|
2052
|
+
jsonOf({ elements: answers.map(jsonElementOf), skipped: loaded.skipped }, " ")
|
|
2053
|
+
),
|
|
2054
|
+
exitCode: answers.length ? 0 : 1
|
|
2055
|
+
};
|
|
2056
|
+
if (answers.length)
|
|
2057
|
+
return {
|
|
2058
|
+
output: textOf([
|
|
2059
|
+
...answers.flatMap((answer, index) => [
|
|
2060
|
+
...index === 0 ? [] : [""],
|
|
2061
|
+
...renderAnswer(answer)
|
|
2062
|
+
]),
|
|
2063
|
+
""
|
|
2064
|
+
]),
|
|
2065
|
+
exitCode: 0
|
|
1868
2066
|
};
|
|
1869
|
-
|
|
2067
|
+
return { output: textOf([...missingLines({ loaded, tagName, under }), ""]), exitCode: 1 };
|
|
2068
|
+
}
|
|
2069
|
+
function answerOf(params) {
|
|
2070
|
+
const { dialecte, tagName, under } = params;
|
|
2071
|
+
const element = describeElement({ dialecte, tagName, parent: under });
|
|
2072
|
+
if (element === void 0) return void 0;
|
|
2073
|
+
const ways = element.resolved ? [] : describeDeclarations({ dialecte, tagName, ids: openIds({ dialecte, tagName, under }) });
|
|
2074
|
+
return { element, ways, under };
|
|
2075
|
+
}
|
|
2076
|
+
function openIds(params) {
|
|
2077
|
+
const { dialecte, tagName, under } = params;
|
|
2078
|
+
if (under === void 0) return void 0;
|
|
2079
|
+
const held = heldDeclarationIds({
|
|
2080
|
+
definition: dialecte.config.definition,
|
|
2081
|
+
tagName,
|
|
2082
|
+
parent: under
|
|
2083
|
+
});
|
|
2084
|
+
return held.length ? held : void 0;
|
|
2085
|
+
}
|
|
2086
|
+
function jsonElementOf(answer) {
|
|
2087
|
+
return answer.element.resolved ? answer.element : { ...answer.element, ways: answer.ways };
|
|
2088
|
+
}
|
|
2089
|
+
function renderAnswer(answer) {
|
|
2090
|
+
const { element, under } = answer;
|
|
2091
|
+
if (element.resolved && (element.declaration === void 0 || under === void 0))
|
|
2092
|
+
return renderElement(element);
|
|
2093
|
+
if (element.resolved)
|
|
2094
|
+
return [
|
|
2095
|
+
`${element.tag} under ${under}: declaration ${element.declaration}, one of ${element.declarations} ways`,
|
|
2096
|
+
...renderElement(element)
|
|
2097
|
+
];
|
|
2098
|
+
const heading = under === void 0 ? `${element.tag} is declared ${element.declarations} ways - pick one with --under <Parent>` : `${element.tag} under ${under}: declarations ${listOf(answer.ways.map((way) => way.id))} of ${element.declarations}, the parent does not decide`;
|
|
2099
|
+
return [
|
|
2100
|
+
heading,
|
|
2101
|
+
...answer.ways.flatMap((way, index) => [...index === 0 ? [] : [""], ...renderWay(way)])
|
|
2102
|
+
];
|
|
2103
|
+
}
|
|
2104
|
+
function renderWay(way) {
|
|
2105
|
+
return [`declaration ${way.id}${way.global ? " global" : ""}`, ...renderElement(way.element)];
|
|
2106
|
+
}
|
|
2107
|
+
function listOf(words) {
|
|
2108
|
+
if (words.length < 2) return words.join("");
|
|
2109
|
+
return `${words.slice(0, -1).join(", ")} and ${words[words.length - 1]}`;
|
|
2110
|
+
}
|
|
2111
|
+
function missingLines(params) {
|
|
2112
|
+
const { loaded, tagName, under } = params;
|
|
1870
2113
|
const skipped = loaded.skipped.length ? ` (skipped ${loaded.skipped.map((entry) => `${entry.packageName}: ${entry.reason}`).join("; ")})` : "";
|
|
1871
|
-
if (loaded.dialectes.length === 0)
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
2114
|
+
if (loaded.dialectes.length === 0) return [`no installed dialecte holds "${tagName}"${skipped}`];
|
|
2115
|
+
const lines = loaded.dialectes.map(function missingLine(dialecte) {
|
|
2116
|
+
const tagLevel = dialecte.config.elements.includes(tagName) ? dialecte.config.definition[tagName] : void 0;
|
|
2117
|
+
if (tagLevel !== void 0 && under !== void 0)
|
|
2118
|
+
return `no ${tagName} under ${under} - its parents: ${tagLevel.parents.join(", ") || "none (the root)"}`;
|
|
1875
2119
|
const closest = closestNames({
|
|
1876
2120
|
name: tagName,
|
|
1877
2121
|
candidates: dialecte.config.elements,
|
|
@@ -1879,14 +2123,14 @@ function answerSchema(params) {
|
|
|
1879
2123
|
});
|
|
1880
2124
|
return `no element "${tagName}" in ${dialecte.packageName}${closest.length ? ` - closest: ${closest.join(", ")}` : ""}`;
|
|
1881
2125
|
});
|
|
1882
|
-
|
|
1883
|
-
|
|
2126
|
+
const lastIndex = lines.length - 1;
|
|
2127
|
+
return lines.map((line, index) => index === lastIndex ? `${line}${skipped}` : line);
|
|
1884
2128
|
}
|
|
1885
2129
|
function renderElement(element) {
|
|
1886
|
-
const lines = [
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
2130
|
+
const lines = [`${element.tag} ${element.packageName} {${element.namespace}}`];
|
|
2131
|
+
if (element.documentation !== void 0) lines.push(`documentation: ${element.documentation}`);
|
|
2132
|
+
if (element.type !== void 0) lines.push(`type: ${element.type}`);
|
|
2133
|
+
lines.push(`parents: ${element.parents.join(", ") || "none (the root)"}`);
|
|
1890
2134
|
if (element.children.length || element.anyChild) lines.push("children, in order:");
|
|
1891
2135
|
else lines.push("children: none");
|
|
1892
2136
|
for (const child of element.children)
|
|
@@ -1896,8 +2140,7 @@ function renderElement(element) {
|
|
|
1896
2140
|
for (const attribute of element.attributes) lines.push(` ${renderAttribute(attribute)}`);
|
|
1897
2141
|
lines.push(`text: ${element.text ?? "none"}`);
|
|
1898
2142
|
if (element.xsiTypes.length) lines.push(`xsi:type: ${element.xsiTypes.join(", ")}`);
|
|
1899
|
-
return
|
|
1900
|
-
`;
|
|
2143
|
+
return lines;
|
|
1901
2144
|
}
|
|
1902
2145
|
function renderAttribute(attribute) {
|
|
1903
2146
|
const parts = [
|
|
@@ -1915,21 +2158,24 @@ function renderAttribute(attribute) {
|
|
|
1915
2158
|
}
|
|
1916
2159
|
|
|
1917
2160
|
// src/commands/schema.constants.ts
|
|
1918
|
-
var SCHEMA_VALUE_OPTIONS = ["package"];
|
|
1919
|
-
var SCHEMA_USAGE = "usage: dialecte schema <Tag> [--package <name>] [--json]";
|
|
2161
|
+
var SCHEMA_VALUE_OPTIONS = ["package", "under"];
|
|
2162
|
+
var SCHEMA_USAGE = "usage: dialecte schema <Tag> [--under <Parent>] [--package <name>] [--json]";
|
|
1920
2163
|
|
|
1921
2164
|
// src/commands/schema.ts
|
|
1922
2165
|
async function readSchemaDialectes(params) {
|
|
1923
2166
|
const missing = missingPackage({ cwd: params.cwd });
|
|
1924
2167
|
if (missing) return { kind: "output", output: missing };
|
|
1925
2168
|
const [tagName] = positionalArguments({ argv: params.argv, valueOptions: SCHEMA_VALUE_OPTIONS });
|
|
1926
|
-
|
|
1927
|
-
|
|
2169
|
+
const under = getArg(params.argv, "under");
|
|
2170
|
+
const underWithoutValue = hasFlag(params.argv, "under") && (under === void 0 || under === "" || under.startsWith("--"));
|
|
2171
|
+
if (!tagName || underWithoutValue)
|
|
2172
|
+
return { kind: "output", output: { output: textOf([SCHEMA_USAGE, ""]), exitCode: 2 } };
|
|
1928
2173
|
const packageName2 = getArg(params.argv, "package");
|
|
1929
2174
|
const loaded = await loadDialectes({ cwd: params.cwd });
|
|
1930
2175
|
return {
|
|
1931
2176
|
kind: "dialectes",
|
|
1932
2177
|
tagName,
|
|
2178
|
+
under,
|
|
1933
2179
|
packageName: packageName2,
|
|
1934
2180
|
installed: loaded.dialectes.map((dialecte) => dialecte.packageName),
|
|
1935
2181
|
loaded: {
|
|
@@ -1943,6 +2189,7 @@ async function readSchemaDialectes(params) {
|
|
|
1943
2189
|
export {
|
|
1944
2190
|
answerMembers,
|
|
1945
2191
|
answerSchema,
|
|
2192
|
+
describeElement,
|
|
1946
2193
|
packagesText,
|
|
1947
2194
|
readApiIndexes,
|
|
1948
2195
|
readCliVersion,
|