@voxgig/sdkgen 4.44.3 → 4.46.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/bin/voxgig-sdkgen +1 -1
- package/dist/action/check.js +15 -0
- package/dist/action/check.js.map +1 -1
- package/dist/action/copies.js +1 -0
- package/dist/action/copies.js.map +1 -1
- package/dist/action/doctor.d.ts +21 -2
- package/dist/action/doctor.js +166 -9
- package/dist/action/doctor.js.map +1 -1
- package/dist/action/package.js +9 -0
- package/dist/action/package.js.map +1 -1
- package/dist/action/remove.js +2 -1
- package/dist/action/remove.js.map +1 -1
- package/dist/action/target.d.ts +2 -1
- package/dist/action/target.js +50 -11
- package/dist/action/target.js.map +1 -1
- package/dist/cmp/AgentGuide.js +19 -8
- package/dist/cmp/AgentGuide.js.map +1 -1
- package/dist/cmp/AgentGuideContent.d.ts +6 -4
- package/dist/cmp/AgentGuideContent.js +51 -32
- package/dist/cmp/AgentGuideContent.js.map +1 -1
- package/dist/cmp/AgentGuideFeature.js +7 -4
- package/dist/cmp/AgentGuideFeature.js.map +1 -1
- package/dist/cmp/AgentGuideTop.js +84 -46
- package/dist/cmp/AgentGuideTop.js.map +1 -1
- package/dist/cmp/Changelog.js +12 -1
- package/dist/cmp/Changelog.js.map +1 -1
- package/dist/cmp/Deploy.js +22 -20
- package/dist/cmp/Deploy.js.map +1 -1
- package/dist/cmp/ExternalTarget.js +5 -5
- package/dist/cmp/ExternalTarget.js.map +1 -1
- package/dist/cmp/Feature.js +10 -3
- package/dist/cmp/Feature.js.map +1 -1
- package/dist/cmp/FeatureDocs.d.ts +6 -4
- package/dist/cmp/FeatureDocs.js +14 -39
- package/dist/cmp/FeatureDocs.js.map +1 -1
- package/dist/cmp/FeatureHook.d.ts +7 -1
- package/dist/cmp/FeatureHook.js +34 -1
- package/dist/cmp/FeatureHook.js.map +1 -1
- package/dist/cmp/PublishWorkflow.js +30 -6
- package/dist/cmp/PublishWorkflow.js.map +1 -1
- package/dist/cmp/ReadmeErrors.js +521 -18
- package/dist/cmp/ReadmeErrors.js.map +1 -1
- package/dist/cmp/ReadmeExplanation.js +280 -44
- package/dist/cmp/ReadmeExplanation.js.map +1 -1
- package/dist/cmp/ReadmeFeatures.js +16 -7
- package/dist/cmp/ReadmeFeatures.js.map +1 -1
- package/dist/cmp/ReadmeIntro.js +3 -2
- package/dist/cmp/ReadmeIntro.js.map +1 -1
- package/dist/cmp/ReadmeRefFeatures.js +34 -24
- package/dist/cmp/ReadmeRefFeatures.js.map +1 -1
- package/dist/cmp/ReadmeStation.js +11 -8
- package/dist/cmp/ReadmeStation.js.map +1 -1
- package/dist/cmp/ReadmeTop.js +472 -373
- package/dist/cmp/ReadmeTop.js.map +1 -1
- package/dist/cmp/ReadmeUnions.js +8 -2
- package/dist/cmp/ReadmeUnions.js.map +1 -1
- package/dist/cmp/Security.js +3 -2
- package/dist/cmp/Security.js.map +1 -1
- package/dist/helpers/applicability.d.ts +2 -1
- package/dist/helpers/applicability.js +26 -0
- package/dist/helpers/applicability.js.map +1 -1
- package/dist/helpers/copymerge.d.ts +3 -0
- package/dist/helpers/copymerge.js +43 -10
- package/dist/helpers/copymerge.js.map +1 -1
- package/dist/helpers/doccheck.d.ts +11 -0
- package/dist/helpers/doccheck.js +146 -0
- package/dist/helpers/doccheck.js.map +1 -0
- package/dist/helpers/doctext.d.ts +11 -0
- package/dist/helpers/doctext.js +84 -0
- package/dist/helpers/doctext.js.map +1 -0
- package/dist/helpers/exampleCall.d.ts +16 -0
- package/dist/helpers/exampleCall.js +334 -0
- package/dist/helpers/exampleCall.js.map +1 -0
- package/dist/helpers/exportnames.d.ts +4 -0
- package/dist/helpers/exportnames.js +35 -0
- package/dist/helpers/exportnames.js.map +1 -0
- package/dist/helpers/facts.d.ts +4 -0
- package/dist/helpers/facts.js +92 -0
- package/dist/helpers/facts.js.map +1 -0
- package/dist/helpers/modelcheck.d.ts +2 -1
- package/dist/helpers/modelcheck.js +13 -0
- package/dist/helpers/modelcheck.js.map +1 -1
- package/dist/helpers/opExample.d.ts +9 -2
- package/dist/helpers/opExample.js +22 -2
- package/dist/helpers/opExample.js.map +1 -1
- package/dist/helpers/opShape.d.ts +2 -1
- package/dist/helpers/opShape.js +12 -0
- package/dist/helpers/opShape.js.map +1 -1
- package/dist/helpers/packageMeta.js +21 -8
- package/dist/helpers/packageMeta.js.map +1 -1
- package/dist/helpers/semver.d.ts +2 -1
- package/dist/helpers/semver.js +7 -0
- package/dist/helpers/semver.js.map +1 -1
- package/dist/helpers/shipped.d.ts +2 -1
- package/dist/helpers/shipped.js +4 -0
- package/dist/helpers/shipped.js.map +1 -1
- package/dist/sdkgen.d.ts +2 -1
- package/dist/sdkgen.js +29 -6
- package/dist/sdkgen.js.map +1 -1
- package/dist/testkit.d.ts +1 -0
- package/dist/testkit.js +23 -19
- package/dist/testkit.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.js +2 -1
- package/dist/utility.js.map +1 -1
- package/model/fact.aontu +59 -0
- package/model/sdkgen.aontu +6 -2
- package/package.json +3 -1
- package/project/.sdk/src/cmp/c/ReadmeQuick_c.ts +1 -1
- package/project/.sdk/src/cmp/c/ReadmeTopQuick_c.ts +1 -1
- package/project/.sdk/src/cmp/clojure/ReadmeEntity_clojure.ts +12 -3
- package/project/.sdk/src/cmp/scala/ReadmeRef_scala.ts +4 -1
- package/project/.sdk/src/cmp/swift/ReadmeQuick_swift.ts +1 -0
- package/project/.sdk/src/cmp/swift/ReadmeRef_swift.ts +3 -0
- package/project/.sdk/src/cmp/swift/ReadmeTopQuick_swift.ts +2 -1
- package/project/.sdk/src/cmp/zig/ReadmeOptions_zig.ts +1 -1
- package/project/.sdk/src/cmp/zig/ReadmeQuick_zig.ts +2 -2
- package/project/.sdk/src/cmp/zig/ReadmeTopQuick_zig.ts +2 -2
- package/project/sdkgen-package.json +1 -1
- package/src/action/check.ts +21 -0
- package/src/action/copies.ts +2 -0
- package/src/action/doctor.ts +244 -13
- package/src/action/package.ts +10 -0
- package/src/action/remove.ts +2 -1
- package/src/action/target.ts +66 -15
- package/src/cmp/AgentGuide.ts +24 -10
- package/src/cmp/AgentGuideContent.ts +53 -32
- package/src/cmp/AgentGuideFeature.ts +8 -5
- package/src/cmp/AgentGuideTop.ts +108 -47
- package/src/cmp/Changelog.ts +13 -2
- package/src/cmp/Deploy.ts +23 -21
- package/src/cmp/ExternalTarget.ts +6 -6
- package/src/cmp/Feature.ts +11 -4
- package/src/cmp/FeatureDocs.ts +21 -40
- package/src/cmp/FeatureHook.ts +38 -1
- package/src/cmp/PublishWorkflow.ts +33 -7
- package/src/cmp/ReadmeErrors.ts +555 -25
- package/src/cmp/ReadmeExplanation.ts +316 -52
- package/src/cmp/ReadmeFeatures.ts +18 -8
- package/src/cmp/ReadmeIntro.ts +3 -2
- package/src/cmp/ReadmeRefFeatures.ts +39 -27
- package/src/cmp/ReadmeStation.ts +12 -14
- package/src/cmp/ReadmeTop.ts +528 -387
- package/src/cmp/ReadmeUnions.ts +10 -2
- package/src/cmp/Security.ts +3 -2
- package/src/helpers/applicability.ts +28 -0
- package/src/helpers/copymerge.ts +58 -10
- package/src/helpers/doccheck.ts +174 -0
- package/src/helpers/doctext.ts +113 -0
- package/src/helpers/exampleCall.ts +415 -0
- package/src/helpers/exportnames.ts +47 -0
- package/src/helpers/facts.ts +119 -0
- package/src/helpers/modelcheck.ts +16 -0
- package/src/helpers/opExample.ts +34 -2
- package/src/helpers/opShape.ts +13 -0
- package/src/helpers/packageMeta.ts +21 -8
- package/src/helpers/semver.ts +9 -0
- package/src/helpers/shipped.ts +5 -0
- package/src/sdkgen.ts +31 -2
- package/src/testkit.ts +30 -20
- package/src/utility.ts +2 -1
package/src/cmp/ReadmeUnions.ts
CHANGED
|
@@ -6,14 +6,21 @@ import {
|
|
|
6
6
|
getModelPath
|
|
7
7
|
} from '../types'
|
|
8
8
|
|
|
9
|
+
import { CANON_UNION_JOIN } from '../helpers/canonType'
|
|
10
|
+
import { originName } from '../helpers/packageMeta'
|
|
11
|
+
|
|
9
12
|
|
|
10
13
|
const MIN_REPORTED_BRANCHES = 3
|
|
11
14
|
|
|
12
15
|
|
|
13
16
|
const ReadmeUnions = cmp(function ReadmeUnions(props: any) {
|
|
14
|
-
const { ctx
|
|
17
|
+
const { ctx$, target } = props
|
|
15
18
|
const { model } = ctx$
|
|
16
19
|
|
|
20
|
+
// Where a language cannot join a union's branches, a two-variant field is
|
|
21
|
+
// an open value too, though it is below the table's threshold.
|
|
22
|
+
const joins = null != (CANON_UNION_JOIN as any)[originName(model, target?.name)]
|
|
23
|
+
|
|
17
24
|
const entity = getModelPath(model, `main.${KIT}.entity`)
|
|
18
25
|
|
|
19
26
|
const rows: { entity: string, field: string, branches: number, depth: number }[] = []
|
|
@@ -65,7 +72,8 @@ ${rows.map((r) =>
|
|
|
65
72
|
|
|
66
73
|
These values round-trip unchanged — read them, modify them, send them back. If
|
|
67
74
|
the API adds a \`discriminator\` to the definition, regenerating will type them.
|
|
68
|
-
Every other field is typed normally.
|
|
75
|
+
${joins ? 'Every other field is typed normally.' :
|
|
76
|
+
'A field with two variants is an open value here too; every other field is\ntyped normally.'}
|
|
69
77
|
`)
|
|
70
78
|
})
|
|
71
79
|
|
package/src/cmp/Security.ts
CHANGED
|
@@ -10,7 +10,8 @@ const Security = cmp(function Security(props: any) {
|
|
|
10
10
|
const { ctx$ } = props
|
|
11
11
|
const { model } = ctx$
|
|
12
12
|
|
|
13
|
-
const { issuesUrl } = repoInfo(model)
|
|
13
|
+
const { issuesUrl, host, hostName } = repoInfo(model)
|
|
14
|
+
const publicIssues = hostName === host ? `public issues on ${host}` : `public ${hostName} issues`
|
|
14
15
|
const publisher = publisherInfo(model)
|
|
15
16
|
|
|
16
17
|
// Voxgig's own response commitment, which another publisher has not made.
|
|
@@ -24,7 +25,7 @@ const Security = cmp(function Security(props: any) {
|
|
|
24
25
|
|
|
25
26
|
Please report security issues ${securityContact(model)}.
|
|
26
27
|
|
|
27
|
-
Do not open
|
|
28
|
+
Do not open ${publicIssues} for suspected vulnerabilities.${promise}
|
|
28
29
|
|
|
29
30
|
For non-security bugs, use the issue tracker: ${issuesUrl}
|
|
30
31
|
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
|
|
2
|
+
import Fs from 'node:fs'
|
|
3
|
+
|
|
4
|
+
import { Aontu } from 'aontu'
|
|
2
5
|
import { KIT, getModelPath } from '@voxgig/apidef'
|
|
3
6
|
|
|
7
|
+
import { definitionPathAny, migrateIncludes } from './definition'
|
|
8
|
+
import { scaffoldFolder } from './shipped'
|
|
9
|
+
|
|
4
10
|
|
|
5
11
|
function tags(val: any): string[] {
|
|
6
12
|
if (Array.isArray(val)) {
|
|
@@ -53,6 +59,27 @@ function targetFeatures(model: any, target: any): Record<string, any> {
|
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
|
|
62
|
+
const shipped = new Map<string, string[]>()
|
|
63
|
+
|
|
64
|
+
// The tags this package's own copy of a target provides; a project's older
|
|
65
|
+
// copy of the same target may lack them.
|
|
66
|
+
function shippedProvides(origin: string): string[] {
|
|
67
|
+
if (!shipped.has(origin)) {
|
|
68
|
+
const path = definitionPathAny(Fs, scaffoldFolder(), 'target', origin)
|
|
69
|
+
let provides: string[] = []
|
|
70
|
+
if (Fs.existsSync(path)) {
|
|
71
|
+
const errs: any[] = []
|
|
72
|
+
const model = new Aontu().generate(migrateIncludes(Fs.readFileSync(path, 'utf8')), { path, errs })
|
|
73
|
+
if (0 === errs.length) {
|
|
74
|
+
provides = tags(model?.main?.[KIT]?.target?.[origin]?.provides)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
shipped.set(origin, provides)
|
|
78
|
+
}
|
|
79
|
+
return shipped.get(origin) as string[]
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
56
83
|
const TAGS = [
|
|
57
84
|
// A vendored sekreto port lives in this target's feature container.
|
|
58
85
|
'sekreto',
|
|
@@ -69,6 +96,7 @@ function unknownTags(val: any): string[] {
|
|
|
69
96
|
|
|
70
97
|
export {
|
|
71
98
|
featureApplies,
|
|
99
|
+
shippedProvides,
|
|
72
100
|
targetFeatures,
|
|
73
101
|
tags as featureTags,
|
|
74
102
|
unknownTags,
|
package/src/helpers/copymerge.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { execFileSync } from 'node:child_process'
|
|
|
4
4
|
|
|
5
5
|
import { DiffUtil } from 'jostraca'
|
|
6
6
|
|
|
7
|
+
import { isTypeScript, missingExports } from './exportnames'
|
|
8
|
+
|
|
7
9
|
|
|
8
10
|
// How a toolchain write treats a project file the project changed after the
|
|
9
11
|
// toolchain last wrote it.
|
|
@@ -39,6 +41,10 @@ type GuardSpec = {
|
|
|
39
41
|
// Earlier versions of a file, newest first, for a base the store lacks.
|
|
40
42
|
versions?: (abs: string) => Iterable<Buffer>
|
|
41
43
|
|
|
44
|
+
// Drops the record of files kept with no base, which the run recorded as
|
|
45
|
+
// written.
|
|
46
|
+
forget?: (rels: string[]) => void
|
|
47
|
+
|
|
42
48
|
error?: (msg: string) => Error
|
|
43
49
|
}
|
|
44
50
|
|
|
@@ -53,6 +59,13 @@ type Conflict = {
|
|
|
53
59
|
type MergeOutcome = {
|
|
54
60
|
merged: string[]
|
|
55
61
|
kept: string[]
|
|
62
|
+
|
|
63
|
+
// Kept with no base, so nothing records them: an add stops on them again.
|
|
64
|
+
unrecorded: string[]
|
|
65
|
+
|
|
66
|
+
// Kept TypeScript files, by the names the incoming copy exports and they lack.
|
|
67
|
+
lacking: Record<string, string[]>
|
|
68
|
+
|
|
56
69
|
retained: string[]
|
|
57
70
|
spared: string[]
|
|
58
71
|
}
|
|
@@ -385,7 +398,9 @@ class CopyGuard {
|
|
|
385
398
|
|
|
386
399
|
|
|
387
400
|
finish(): MergeOutcome {
|
|
388
|
-
const outcome: MergeOutcome = {
|
|
401
|
+
const outcome: MergeOutcome = {
|
|
402
|
+
merged: [], kept: [], unrecorded: [], lacking: {}, retained: [], spared: this.spared,
|
|
403
|
+
}
|
|
389
404
|
const conflicts: Conflict[] = []
|
|
390
405
|
const writes: [string, Buffer][] = []
|
|
391
406
|
const bases = new Map<string, Buffer>()
|
|
@@ -422,7 +437,21 @@ class CopyGuard {
|
|
|
422
437
|
|
|
423
438
|
if (null != conflict && true === this.spec.keep) {
|
|
424
439
|
outcome.kept.push(rel)
|
|
425
|
-
|
|
440
|
+
|
|
441
|
+
// Recording the incoming copy as a base would pass a stale copy off as
|
|
442
|
+
// a customization.
|
|
443
|
+
if ('nobase' === conflict.why) {
|
|
444
|
+
outcome.unrecorded.push(rel)
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
bases.set(rel, incoming)
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const names = isTypeScript(rel) ?
|
|
451
|
+
missingExports(incoming.toString('utf8'), local.toString('utf8')) : []
|
|
452
|
+
if (0 < names.length) {
|
|
453
|
+
outcome.lacking[rel] = names
|
|
454
|
+
}
|
|
426
455
|
}
|
|
427
456
|
else if (null != conflict) {
|
|
428
457
|
conflicts.push(conflict)
|
|
@@ -447,6 +476,9 @@ class CopyGuard {
|
|
|
447
476
|
}
|
|
448
477
|
|
|
449
478
|
this.keepBases(bases)
|
|
479
|
+
if (0 < outcome.unrecorded.length) {
|
|
480
|
+
this.spec.forget?.(outcome.unrecorded)
|
|
481
|
+
}
|
|
450
482
|
clearConflicts(this.spec)
|
|
451
483
|
this.report(outcome)
|
|
452
484
|
|
|
@@ -534,17 +566,26 @@ class CopyGuard {
|
|
|
534
566
|
}
|
|
535
567
|
|
|
536
568
|
const shown = this.spec.conflictdir
|
|
569
|
+
const nobase = conflicts.filter((c: Conflict) => 'nobase' === c.why).length
|
|
537
570
|
|
|
538
571
|
const msg = this.spec.what + ': ' + conflicts.length +
|
|
539
572
|
' locally changed file(s) cannot take the incoming copy, so nothing was changed:\n ' +
|
|
540
573
|
conflicts.map((c: Conflict) => c.rel + ' (' + why[c.why] + ')').join('\n ') +
|
|
541
574
|
'\n\n The incoming copies are in ' + shown + '/, with conflict markers where ' +
|
|
542
|
-
'both sides changed the same lines.
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
575
|
+
'both sides changed the same lines. ' +
|
|
576
|
+
(0 < nobase ?
|
|
577
|
+
'Nothing records what an add wrote to ' +
|
|
578
|
+
(nobase === conflicts.length ? 'them' : nobase + ' of them') +
|
|
579
|
+
', so nothing shows whether they hold a local change or an older ' +
|
|
580
|
+
'copy this update would replace, and --keep would leave them as they ' +
|
|
581
|
+
'are, unrecorded. Commit, then re-run with --force, which takes the ' +
|
|
582
|
+
'incoming copies; `git diff` then shows any local change to restore.' :
|
|
583
|
+
'Then either:' +
|
|
584
|
+
'\n - fold the incoming change into the local file by hand and re-run with ' +
|
|
585
|
+
'--keep, which keeps the local files and records the incoming copies as ' +
|
|
586
|
+
'their base;' +
|
|
587
|
+
'\n - or re-run with --force, which takes the incoming copies and discards ' +
|
|
588
|
+
'the local changes.')
|
|
548
589
|
|
|
549
590
|
return null == this.spec.error ? new Error(msg) : this.spec.error(msg)
|
|
550
591
|
}
|
|
@@ -563,9 +604,16 @@ class CopyGuard {
|
|
|
563
604
|
|
|
564
605
|
if (0 < outcome.kept.length) {
|
|
565
606
|
log.warn({
|
|
566
|
-
point: 'copy-merge-kept', files: outcome.kept,
|
|
607
|
+
point: 'copy-merge-kept', files: outcome.kept, unrecorded: outcome.unrecorded,
|
|
608
|
+
lacking: outcome.lacking,
|
|
567
609
|
note: this.spec.what + ': --keep, kept ' + outcome.kept.length +
|
|
568
|
-
' local file(s) as they are: ' + outcome.kept.join(', ')
|
|
610
|
+
' local file(s) as they are: ' + outcome.kept.join(', ') +
|
|
611
|
+
(0 === outcome.unrecorded.length ? '' :
|
|
612
|
+
'; nothing records what an add wrote to ' + outcome.unrecorded.join(', ') +
|
|
613
|
+
', so they stay unrecorded until an add with --force replaces them') +
|
|
614
|
+
Object.entries(outcome.lacking).map(([rel, names]: [string, string[]]) =>
|
|
615
|
+
'; ' + rel + ' lacks ' + names.join(', ') + ', which the incoming copy ' +
|
|
616
|
+
'exports').join('')
|
|
569
617
|
})
|
|
570
618
|
}
|
|
571
619
|
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import Path from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { claimedFiles } from './generated'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
type DocFinding = {
|
|
7
|
+
point: 'doc-link-dangling' | 'doc-table-broken'
|
|
8
|
+
file: string
|
|
9
|
+
line: number
|
|
10
|
+
note: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// GitHub's heading anchors, which is what a reader's browser follows.
|
|
15
|
+
function slug(heading: string): string {
|
|
16
|
+
return heading.trim().toLowerCase()
|
|
17
|
+
.replace(/`/g, '')
|
|
18
|
+
.replace(/[^\p{L}\p{N}\s_-]/gu, '')
|
|
19
|
+
.replace(/\s/g, '-')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function anchors(text: string): Set<string> {
|
|
24
|
+
const out = new Set<string>()
|
|
25
|
+
const seen = new Map<string, number>()
|
|
26
|
+
let fence = false
|
|
27
|
+
for (const line of text.split('\n')) {
|
|
28
|
+
if (/^\s*(```|~~~)/.test(line)) fence = !fence
|
|
29
|
+
if (fence) continue
|
|
30
|
+
const m = /^#{1,6}\s+(.*)$/.exec(line)
|
|
31
|
+
if (!m) continue
|
|
32
|
+
const s = slug(m[1])
|
|
33
|
+
const n = seen.get(s) ?? 0
|
|
34
|
+
out.add(0 === n ? s : s + '-' + n)
|
|
35
|
+
seen.set(s, n + 1)
|
|
36
|
+
}
|
|
37
|
+
return out
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
// The lines of a document outside its fenced blocks, numbered from one.
|
|
42
|
+
function prose(text: string): [number, string][] {
|
|
43
|
+
const out: [number, string][] = []
|
|
44
|
+
let fence = ''
|
|
45
|
+
text.split('\n').forEach((line, i) => {
|
|
46
|
+
const open = /^ {0,3}(`{3,}|~{3,})/.exec(line)
|
|
47
|
+
if (open && ('' === fence || open[1].startsWith(fence))) {
|
|
48
|
+
fence = '' === fence ? open[1] : ''
|
|
49
|
+
}
|
|
50
|
+
else if ('' === fence) {
|
|
51
|
+
out.push([i + 1, line])
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
return out
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
function cells(row: string): number {
|
|
59
|
+
return (row.trim().match(/(?<!\\)\|/g) || []).length
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
const DELIMITER = /^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)*\|?\s*$/
|
|
64
|
+
|
|
65
|
+
// Each row of a table ends as its header ends and holds as many cells; a
|
|
66
|
+
// row with no header before it is the second half of a row a line break cut.
|
|
67
|
+
function tables(file: string, text: string): DocFinding[] {
|
|
68
|
+
const out: DocFinding[] = []
|
|
69
|
+
const lines = prose(text)
|
|
70
|
+
let header: string | null = null
|
|
71
|
+
for (let i = 0; i < lines.length; i++) {
|
|
72
|
+
const [num, line] = lines[i]
|
|
73
|
+
if (!/^ {0,3}\|/.test(line)) {
|
|
74
|
+
header = null
|
|
75
|
+
}
|
|
76
|
+
else if (null == header) {
|
|
77
|
+
if (DELIMITER.test(lines[i + 1]?.[1] ?? '')) {
|
|
78
|
+
header = line
|
|
79
|
+
i++
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
out.push({ point: 'doc-table-broken', file, line: num, note: 'a row outside a table: ' + line })
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (cells(line) !== cells(header) ||
|
|
86
|
+
line.trim().endsWith('|') !== header.trim().endsWith('|')) {
|
|
87
|
+
out.push({ point: 'doc-table-broken', file, line: num, note: line })
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return out
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
// A malformed escape such as `100%.md` is a path as written, as a browser reads it.
|
|
95
|
+
function decoded(rel: string): string {
|
|
96
|
+
try {
|
|
97
|
+
return decodeURI(rel)
|
|
98
|
+
}
|
|
99
|
+
catch (_err) {
|
|
100
|
+
return rel
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
function links(file: string, text: string, docs: Map<string, string>,
|
|
106
|
+
exists: (rel: string) => boolean): DocFinding[] {
|
|
107
|
+
const out: DocFinding[] = []
|
|
108
|
+
const dir = Path.posix.dirname(file)
|
|
109
|
+
for (const [num, line] of prose(text)) {
|
|
110
|
+
const bare = line.replace(/(`+)[^`][\s\S]*?\1/g, '')
|
|
111
|
+
for (const m of bare.matchAll(/\]\(<?([^)\s>]+)>?(?:\s+"[^"]*")?\)/g)) {
|
|
112
|
+
const href = m[1]
|
|
113
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith('/')) continue
|
|
114
|
+
const [rel, frag] = href.split('#')
|
|
115
|
+
const target = '' === rel ? file : Path.posix.normalize(Path.posix.join(dir, decoded(rel)))
|
|
116
|
+
if ('' !== rel && !exists(target)) {
|
|
117
|
+
out.push({ point: 'doc-link-dangling', file, line: num, note: target })
|
|
118
|
+
}
|
|
119
|
+
else if (null != frag && '' !== frag && docs.has(target) && !anchors(docs.get(target)!).has(frag)) {
|
|
120
|
+
out.push({ point: 'doc-link-dangling', file, line: num, note: target + '#' + frag })
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return out
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
function walk(node: any, visit: (node: any) => void): void {
|
|
129
|
+
if (null == node) return
|
|
130
|
+
visit(node)
|
|
131
|
+
for (const child of node.children ?? []) walk(child, visit)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
// Every Markdown file a pass kept, checked against what the pass wrote and
|
|
136
|
+
// what is already in `folder`: a relative link that resolves nowhere, and a
|
|
137
|
+
// table row that a line break or a pipe has broken. A dry run copies nothing,
|
|
138
|
+
// so there a path under a copy's destination counts as written.
|
|
139
|
+
function docFindings(root: any, folder: string, onDisk: (path: string) => boolean,
|
|
140
|
+
dryrun = false): DocFinding[] {
|
|
141
|
+
const rel = (full: string) =>
|
|
142
|
+
Path.relative(Path.resolve(folder), Path.resolve(full)).split(Path.sep).join('/')
|
|
143
|
+
const claims = claimedFiles(root, folder)
|
|
144
|
+
const written = new Set<string>(Object.keys(claims.files).map(rel))
|
|
145
|
+
const copied = claims.copies.map((c: any) => rel(c.to))
|
|
146
|
+
|
|
147
|
+
const docs = new Map<string, string>()
|
|
148
|
+
walk(root, (node: any) => {
|
|
149
|
+
if ('file' === node.kind && 'string' === typeof node.fullpath && node.fullpath.endsWith('.md') &&
|
|
150
|
+
Array.isArray(node.content)) {
|
|
151
|
+
docs.set(rel(node.fullpath), node.content.join(''))
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
const exists = (path: string): boolean => written.has(path) ||
|
|
156
|
+
[...written].some((p) => p.startsWith(path + '/')) ||
|
|
157
|
+
(dryrun && copied.some((c) => path === c || path.startsWith(c + '/'))) ||
|
|
158
|
+
onDisk(Path.join(folder, path))
|
|
159
|
+
|
|
160
|
+
const out: DocFinding[] = []
|
|
161
|
+
for (const [file, text] of docs) {
|
|
162
|
+
out.push(...tables(file, text), ...links(file, text, docs, exists))
|
|
163
|
+
}
|
|
164
|
+
return out
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
export {
|
|
169
|
+
anchors,
|
|
170
|
+
docFindings,
|
|
171
|
+
slug,
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export type { DocFinding }
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { KIT } from '@voxgig/apidef'
|
|
2
|
+
|
|
3
|
+
import { modelText } from './text'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// One text a neutral document prints. `vendor` marks text from the spec, whose
|
|
7
|
+
// relative links resolve against the spec's site rather than this repository.
|
|
8
|
+
type DocText = {
|
|
9
|
+
raw: string
|
|
10
|
+
vendor: boolean
|
|
11
|
+
at: any
|
|
12
|
+
path: string[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// A struct.validate sentinel as a reader's word for it: '`$FUNCTION`' ->
|
|
17
|
+
// 'function'. A union renders its members, so netsim's latency reads
|
|
18
|
+
// 'number | map'. Anything unrecognised renders verbatim rather than being
|
|
19
|
+
// dropped — a doc table that silently omits an option is the failure this
|
|
20
|
+
// whole path exists to fix.
|
|
21
|
+
function sentinelName(v: any): string {
|
|
22
|
+
if (Array.isArray(v)) {
|
|
23
|
+
const members = v.slice(1).map((m: any) => sentinelName(m))
|
|
24
|
+
.filter((m: string) => 'one' !== m)
|
|
25
|
+
return 0 === members.length ? 'any' : members.join(' | ')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if ('string' !== typeof v) {
|
|
29
|
+
return 'any'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const bare = v.replace(/[`$]/g, '').trim().toLowerCase()
|
|
33
|
+
return '' === bare ? 'any' : bare
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
function renderValue(v: any): string {
|
|
38
|
+
if (null == v) { return '' }
|
|
39
|
+
if (Array.isArray(v)) { return '[' + v.map((x) => renderValue(x)).join(', ') + ']' }
|
|
40
|
+
if ('object' === typeof v) {
|
|
41
|
+
const keys = Object.keys(v)
|
|
42
|
+
return 0 === keys.length ? '{}' :
|
|
43
|
+
'{' + keys.map((k) => k + ': ' + renderValue(v[k])).join(', ') + '}'
|
|
44
|
+
}
|
|
45
|
+
if ('string' === typeof v) { return `'${v}'` }
|
|
46
|
+
return String(v)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
function given(value: any): boolean {
|
|
51
|
+
return null != value && '' !== value
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
function str(value: any, trim = false): string {
|
|
56
|
+
return !given(value) ? '' : trim ? String(value).trim() : String(value)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
// Every text the neutral documents print from the model, as they print it,
|
|
61
|
+
// with the node its escaped forms are written beside.
|
|
62
|
+
function docTexts(model: any): DocText[] {
|
|
63
|
+
const kit = model.main[KIT]
|
|
64
|
+
const info = modelText(model)
|
|
65
|
+
const own = kit.text || {}
|
|
66
|
+
const def = model.main.def || {}
|
|
67
|
+
const texts: DocText[] = []
|
|
68
|
+
|
|
69
|
+
const add = (at: any, path: string[], raw: string, vendor: boolean) =>
|
|
70
|
+
texts.push({ raw, vendor, at, path })
|
|
71
|
+
|
|
72
|
+
const slot = (name: string, raw: string) =>
|
|
73
|
+
add(kit, ['text', name], raw, !given(own[name]))
|
|
74
|
+
|
|
75
|
+
slot('title', str(info.title))
|
|
76
|
+
slot('tagline', str(info.tagline) || str(def.tagline))
|
|
77
|
+
slot('summary', str(info.summary, true))
|
|
78
|
+
slot('about_md', str(info.about_md, true))
|
|
79
|
+
slot('website', str(info.website, true))
|
|
80
|
+
slot('meta_source', str(info.meta_source, true))
|
|
81
|
+
slot('docs_url', str(info.docs_url))
|
|
82
|
+
add(kit, ['text', 'desc'], str(def.desc), true)
|
|
83
|
+
add(kit, ['text', 'upstream'], str(info.contact?.url) || str(info.servers?.[0]?.url) ||
|
|
84
|
+
str(info.homepage), true)
|
|
85
|
+
|
|
86
|
+
for (const [name, ent] of Object.entries(kit.entity || {}) as [string, any][]) {
|
|
87
|
+
add(ent, ['desc'], str(info.entity_desc[name]) || str(ent.short) || str(ent.desc),
|
|
88
|
+
!given(own.entity_desc?.[name]))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for (const f of Object.values(kit.feature || {}) as any[]) {
|
|
92
|
+
add(f, ['title'], str(f.title), false)
|
|
93
|
+
const opts = f.config?.options || {}
|
|
94
|
+
const spec = f.config?.optspec || {}
|
|
95
|
+
for (const k of Object.keys(opts)) {
|
|
96
|
+
add(f, ['option', k, 'value'], renderValue(opts[k]), false)
|
|
97
|
+
}
|
|
98
|
+
for (const k of Object.keys(spec).filter((k) => null == opts[k])) {
|
|
99
|
+
add(f, ['option', k, 'type'], sentinelName(spec[k]), false)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return texts
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
docTexts,
|
|
109
|
+
renderValue,
|
|
110
|
+
sentinelName,
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export type { DocText }
|