@voxgig/sdkgen 4.43.0 → 4.44.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/bin/voxgig-sdkgen +1 -1
- package/dist/action/feature.js +16 -0
- package/dist/action/feature.js.map +1 -1
- package/dist/action/kind.js +3 -0
- package/dist/action/kind.js.map +1 -1
- package/dist/action/remove.js +4 -0
- package/dist/action/remove.js.map +1 -1
- package/dist/action/resolve.d.ts +1 -0
- package/dist/action/resolve.js +30 -0
- package/dist/action/resolve.js.map +1 -1
- package/dist/action/target.js +10 -4
- package/dist/action/target.js.map +1 -1
- package/dist/cmp/AgentGuideContent.js +12 -6
- package/dist/cmp/AgentGuideContent.js.map +1 -1
- package/dist/cmp/PublishWorkflow.js +1 -1
- package/dist/cmp/PublishWorkflow.js.map +1 -1
- package/dist/cmp/ReadmeTop.js +24 -10
- package/dist/cmp/ReadmeTop.js.map +1 -1
- package/dist/helpers/packageMeta.d.ts +2 -1
- package/dist/helpers/packageMeta.js +12 -0
- package/dist/helpers/packageMeta.js.map +1 -1
- package/dist/sdkgen.d.ts +2 -2
- package/dist/sdkgen.js +3 -2
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/project/sdkgen-package.json +1 -1
- package/src/action/feature.ts +20 -0
- package/src/action/kind.ts +4 -0
- package/src/action/remove.ts +4 -0
- package/src/action/resolve.ts +41 -0
- package/src/action/target.ts +11 -4
- package/src/cmp/AgentGuideContent.ts +12 -6
- package/src/cmp/PublishWorkflow.ts +2 -2
- package/src/cmp/ReadmeTop.ts +25 -10
- package/src/helpers/packageMeta.ts +15 -0
- package/src/sdkgen.ts +2 -0
package/src/action/feature.ts
CHANGED
|
@@ -195,6 +195,14 @@ const FeatureRoot = cmp(function FeatureRoot(props: any) {
|
|
|
195
195
|
content: ctx$.meta.content.feature_index,
|
|
196
196
|
}))
|
|
197
197
|
|
|
198
|
+
if (source.owned) {
|
|
199
|
+
log.info({
|
|
200
|
+
point: 'feature-owned', feature: fname,
|
|
201
|
+
note: fname + ': defined in this project, so its files stay as they are'
|
|
202
|
+
})
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
|
|
198
206
|
each(target, (t) => {
|
|
199
207
|
// The target's OWN tree, under the name it has in ITS source — an
|
|
200
208
|
// aliased target's templates live at `tm/<origname>`, so searching
|
|
@@ -227,6 +235,18 @@ const FeatureRoot = cmp(function FeatureRoot(props: any) {
|
|
|
227
235
|
|
|
228
236
|
const tmfolder = 0 < overlay.length ? featuretm : owntm
|
|
229
237
|
|
|
238
|
+
// A target the project defines itself carries its own feature sources.
|
|
239
|
+
const inplace = 0 === sources.length && 0 < findFeatureSources(
|
|
240
|
+
fs, Path.join(ctx$.folder ?? '.', 'tm', t.name), [fname]).length
|
|
241
|
+
|
|
242
|
+
if (inplace) {
|
|
243
|
+
log.info({
|
|
244
|
+
point: 'feature-source-in-place', feature: fname, target: t.name,
|
|
245
|
+
note: fname + ': target ' + t.name + ' has its own source'
|
|
246
|
+
})
|
|
247
|
+
return
|
|
248
|
+
}
|
|
249
|
+
|
|
230
250
|
if (0 === sources.length) {
|
|
231
251
|
log.warn({
|
|
232
252
|
point: 'feature-source-missing', feature: fname, target: t.name,
|
package/src/action/kind.ts
CHANGED
package/src/action/remove.ts
CHANGED
|
@@ -200,6 +200,10 @@ async function planRemove(
|
|
|
200
200
|
plan.refused.push('(source not found: the copy cannot be compared with what' +
|
|
201
201
|
' `' + kind + ' add` wrote; every file below is deleted only under --force)')
|
|
202
202
|
}
|
|
203
|
+
else if (source.owned) {
|
|
204
|
+
plan.refused.push('(defined in this project: these files are its only' +
|
|
205
|
+
' source, and are deleted only under --force)')
|
|
206
|
+
}
|
|
203
207
|
|
|
204
208
|
// The feature being removed counts as selected, so its own source is
|
|
205
209
|
// compared rather than written off as stale — see checkTarget.
|
package/src/action/resolve.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { getelem } from '@voxgig/struct'
|
|
|
6
6
|
|
|
7
7
|
import { KIT } from '../types'
|
|
8
8
|
|
|
9
|
+
import { SdkGenError } from '../utility'
|
|
10
|
+
|
|
9
11
|
import { definitionPathAny } from '../helpers/definition'
|
|
10
12
|
import { readManifest, checkShape, ITEM_NAME_RE } from '../helpers/manifest'
|
|
11
13
|
|
|
@@ -33,6 +35,10 @@ type Source = {
|
|
|
33
35
|
|
|
34
36
|
// That package's version, read from the same manifest.
|
|
35
37
|
version?: string
|
|
38
|
+
|
|
39
|
+
// Defined in the project's own `.sdk` and provided by nothing else, so the
|
|
40
|
+
// project's files ARE the source: an add registers it and copies nothing.
|
|
41
|
+
owned?: boolean
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
|
|
@@ -109,6 +115,27 @@ function resolveSource(ref: string, kind: string, ctx$: any): Source {
|
|
|
109
115
|
capitalise(kind) + ' folder not found in:\n' + search.join('\n '))
|
|
110
116
|
}
|
|
111
117
|
|
|
118
|
+
if (insideProject(root, folder)) {
|
|
119
|
+
throw new SdkGenError(
|
|
120
|
+
capitalise(kind) + ' source ' + folder + ' is inside this project.' +
|
|
121
|
+
'\n A project\'s own ' + kind + ' lives in its .sdk: define it in ' +
|
|
122
|
+
'model/' + kind + '/' + origname + '.aontu, put its sources under tm/ ' +
|
|
123
|
+
'(and src/cmp/ for a target), and add it by name.' +
|
|
124
|
+
'\n A package is for sharing ' + kind + 's between projects: install ' +
|
|
125
|
+
'it from npm, or add it from a checkout outside the project.')
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const ownmodel = definitionPathAny(fs, root, kind, origname)
|
|
129
|
+
if (name === origname &&
|
|
130
|
+
Path.normalize(folder) === Path.normalize(Path.join(root, BUNDLED)) &&
|
|
131
|
+
!fs.existsSync(definitionPathAny(fs, folder, kind, origname)) &&
|
|
132
|
+
fs.existsSync(ownmodel)) {
|
|
133
|
+
return {
|
|
134
|
+
name, origname, folder: Path.normalize(root), base: '.', model: ownmodel,
|
|
135
|
+
owned: true,
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
112
139
|
// `base` is the folder relative to the project root. Compare with the
|
|
113
140
|
// PLATFORM separator: on Windows `root + '/'` never prefixes a normalised
|
|
114
141
|
// absolute path, so the root would not be stripped and `base` would stay
|
|
@@ -138,6 +165,20 @@ function resolveSource(ref: string, kind: string, ctx$: any): Source {
|
|
|
138
165
|
}
|
|
139
166
|
|
|
140
167
|
|
|
168
|
+
// A package folder beside `.sdk` in the same project, such as an `ext/`:
|
|
169
|
+
// the project's own items belong in `.sdk` itself.
|
|
170
|
+
function insideProject(root: string, folder: string): boolean {
|
|
171
|
+
const sdk = Path.resolve(root)
|
|
172
|
+
if ('.sdk' !== Path.basename(sdk)) {
|
|
173
|
+
return false
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const abs = Path.resolve(folder)
|
|
177
|
+
return abs.startsWith(Path.dirname(sdk) + Path.sep) &&
|
|
178
|
+
!abs.startsWith(Path.join(sdk, 'node_modules') + Path.sep)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
|
|
141
182
|
function sourcePackage(
|
|
142
183
|
fs: any, folder: string, kind: string, origname: string, ctx$: any,
|
|
143
184
|
): { name: string, version?: string } | undefined {
|
package/src/action/target.ts
CHANGED
|
@@ -175,8 +175,8 @@ const TargetRoot = cmp(function TargetRoot(props: any) {
|
|
|
175
175
|
const dryrun = !!actx?.opts?.dryrun
|
|
176
176
|
|
|
177
177
|
|
|
178
|
-
// `feature add`
|
|
179
|
-
//
|
|
178
|
+
// `feature add` copies nothing for a feature it cannot resolve or that the
|
|
179
|
+
// project defines itself, so the prune must not delete those files first.
|
|
180
180
|
const unresolved = unresolvedFeatures(features ?? [], ctx$)
|
|
181
181
|
|
|
182
182
|
Project({}, () => {
|
|
@@ -221,6 +221,14 @@ const TargetRoot = cmp(function TargetRoot(props: any) {
|
|
|
221
221
|
content: ctx$.meta.content.target_index,
|
|
222
222
|
}))
|
|
223
223
|
|
|
224
|
+
if (source.owned) {
|
|
225
|
+
log.info({
|
|
226
|
+
point: 'target-owned', target: tname,
|
|
227
|
+
note: tname + ': defined in this project, so its files stay as they are'
|
|
228
|
+
})
|
|
229
|
+
return
|
|
230
|
+
}
|
|
231
|
+
|
|
224
232
|
if (aliased) {
|
|
225
233
|
aliasCmpTree(ctx$, tfolder + '/src/cmp/' + torigname,
|
|
226
234
|
'src/cmp/' + tname, torigname, tname)
|
|
@@ -354,8 +362,7 @@ function aliasCmpTree(
|
|
|
354
362
|
function unresolvedFeatures(features: string[], ctx$: any): string[] {
|
|
355
363
|
return features.filter((fname: string) => {
|
|
356
364
|
try {
|
|
357
|
-
resolveKind(fname, 'feature', ctx$)
|
|
358
|
-
return false
|
|
365
|
+
return true === resolveKind(fname, 'feature', ctx$).owned
|
|
359
366
|
}
|
|
360
367
|
catch (err: any) {
|
|
361
368
|
return true
|
|
@@ -194,18 +194,24 @@ npm run add-feature <name> # e.g. log (comma-separated for several)
|
|
|
194
194
|
npm run build && npm run generate
|
|
195
195
|
\`\`\`
|
|
196
196
|
|
|
197
|
-
To author a **new** feature:
|
|
197
|
+
To author a **new** feature, when editing a template cannot make the change:
|
|
198
198
|
|
|
199
199
|
1. Define its model at \`.sdk/model/feature/<name>.aontu\` — \`name: key()\`,
|
|
200
200
|
\`title\`, \`version\`, \`active\`, \`config.options.active\`, a \`hook\`
|
|
201
201
|
map (\`<Stage>: active: true\`), and per-language \`deps\`.
|
|
202
|
-
2.
|
|
203
|
-
\`@"<name>.aontu"\`.
|
|
204
|
-
3. Provide the per-language runtime under that target's feature template dir
|
|
202
|
+
2. Provide the per-language runtime under that target's feature template dir
|
|
205
203
|
(\`.sdk/tm/<lang>/src/feature/<name>/\` for ts/js, \`.sdk/tm/<lang>/feature/\`
|
|
206
204
|
otherwise) — the \`FEATURE_Name\` / \`FEATURE_VERSION\` placeholders are
|
|
207
|
-
substituted
|
|
208
|
-
|
|
205
|
+
substituted when \`generate\` copies it.
|
|
206
|
+
3. \`npm run add-feature <name> && npm run build && npm run generate\`. No
|
|
207
|
+
package provides the name, so the add registers the feature in
|
|
208
|
+
\`feature-index.aontu\` and copies nothing: the files in \`.sdk\` are its
|
|
209
|
+
source.
|
|
210
|
+
|
|
211
|
+
A target of the project's own is written the same way:
|
|
212
|
+
\`.sdk/model/target/<name>.aontu\`, \`.sdk/src/cmp/<name>/\` and
|
|
213
|
+
\`.sdk/tm/<name>/\`, then \`npm run add-target <name>\`. Never put a package
|
|
214
|
+
folder such as \`ext/\` inside the project: sdkgen refuses it.
|
|
209
215
|
`
|
|
210
216
|
}
|
|
211
217
|
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
getModelPath
|
|
9
9
|
} from '../types'
|
|
10
10
|
|
|
11
|
-
import { packageName, packageVersion, repoInfo } from '../helpers/packageMeta'
|
|
11
|
+
import { hasPackageName, packageName, packageVersion, repoInfo } from '../helpers/packageMeta'
|
|
12
12
|
|
|
13
13
|
import { npmTrustScript } from '../admin/npm-trust'
|
|
14
14
|
|
|
@@ -28,7 +28,7 @@ const PublishWorkflow = cmp(function PublishWorkflow(props: any) {
|
|
|
28
28
|
if (false === t.active) {
|
|
29
29
|
return
|
|
30
30
|
}
|
|
31
|
-
if ('npm' === (t.publish?.registry?.name || '')) {
|
|
31
|
+
if ('npm' === (t.publish?.registry?.name || '') && hasPackageName(model, t.name)) {
|
|
32
32
|
npmTargets.push(t)
|
|
33
33
|
}
|
|
34
34
|
})
|
package/src/cmp/ReadmeTop.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { isConsumer } from '../helpers/alongside'
|
|
|
26
26
|
import {
|
|
27
27
|
installCommand as pkgInstall,
|
|
28
28
|
packageName,
|
|
29
|
+
hasPackageName,
|
|
29
30
|
registryState,
|
|
30
31
|
vendorCommand,
|
|
31
32
|
apiName,
|
|
@@ -172,7 +173,7 @@ const ReadmeTop = cmp(function ReadmeTop(props: any) {
|
|
|
172
173
|
const docTargets = ordered.filter((t: any) => !isCliOrMcp(t))
|
|
173
174
|
|
|
174
175
|
const pkgTargets = activeTargets
|
|
175
|
-
.
|
|
176
|
+
.filter((t: any) => hasPackageName(model, t.name))
|
|
176
177
|
.sort((a: any, b: any) => orderOf(a.name) - orderOf(b.name))
|
|
177
178
|
|
|
178
179
|
const langList = sdkTargets.map((t: any) => t.title).join(', ')
|
|
@@ -605,11 +606,24 @@ Pass custom features via the \`extend\` option at construction time.
|
|
|
605
606
|
`)
|
|
606
607
|
|
|
607
608
|
// 11c. Customization: model-driven declarations, in-repo templates and
|
|
608
|
-
// components, regeneration that overwrites,
|
|
609
|
-
// paths are the project's to edit. Every SDK repo carries
|
|
610
|
-
// generator, so this belongs in every README.
|
|
609
|
+
// components, regeneration that overwrites, customising in `.sdk`, and a
|
|
610
|
+
// map of which paths are the project's to edit. Every SDK repo carries
|
|
611
|
+
// its own generator, so this belongs in every README. A repository that
|
|
612
|
+
// regenerates `.sdk` in full says so, since its copies do not merge.
|
|
611
613
|
const mapTarget = sdkTargets[0] || docTargets[0]
|
|
612
614
|
const targetDir = mapTarget ? `\`<target>/\`, such as \`${mapTarget.name}/\`` : `\`<target>/\``
|
|
615
|
+
const merging = 'overwrite' !== model.main?.kit?.copies
|
|
616
|
+
const mergeNote = merging ?
|
|
617
|
+
`An add merges toolchain updates into the
|
|
618
|
+
edited copies, and \`voxgig-sdkgen doctor\` reports any drift from what a
|
|
619
|
+
resync would write.` :
|
|
620
|
+
`This repository regenerates \`.sdk\` in full
|
|
621
|
+
(\`main: kit: copies: 'overwrite'\`): set it to \`'merge'\` before
|
|
622
|
+
customising, so that an add merges toolchain updates into the edited
|
|
623
|
+
copies.`
|
|
624
|
+
const copiesRow = merging ?
|
|
625
|
+
`Yes. They are this project's copies, and \`target add\` merges toolchain updates into your edits.` :
|
|
626
|
+
`Only after setting \`copies\` to \`'merge'\`. This repository regenerates them in full.`
|
|
613
627
|
Content(`## Customizing this SDK
|
|
614
628
|
|
|
615
629
|
This repository contains its own generator (\`.sdk/\`), so the SDK is
|
|
@@ -630,10 +644,11 @@ customizable without forking any upstream tool:
|
|
|
630
644
|
(\`.sdk/model/project.aontu\`), or extend a target with a component of its
|
|
631
645
|
own in \`.sdk/src/cmp/<target>/\`, registered with \`registerComponent\`,
|
|
632
646
|
which \`voxgig-sdkgen doctor\` reports as an addition rather than drift.
|
|
633
|
-
- **
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
647
|
+
- **Customise in \`.sdk\`.** Edit the templates and components first. When
|
|
648
|
+
they cannot express a change, write a feature of this project's own, or
|
|
649
|
+
an entire custom target, in \`.sdk/model/\`, \`.sdk/tm/\` and
|
|
650
|
+
\`.sdk/src/cmp/\`, and add it by name (\`voxgig-sdkgen feature add\`,
|
|
651
|
+
\`voxgig-sdkgen target add\`). ${mergeNote}
|
|
637
652
|
|
|
638
653
|
### Project map
|
|
639
654
|
|
|
@@ -642,9 +657,9 @@ customizable without forking any upstream tool:
|
|
|
642
657
|
| \`.sdk/model/project.aontu\` | This project's own decisions: package names, versions, features and per-target settings | Yes. The scaffold writes it once and never again. |
|
|
643
658
|
| \`.sdk/model/text.aontu\` | The README wording, in \`main.kit.text\`: the tagline, the summary and the entity descriptions | Yes. The scaffold writes it once and never again. |
|
|
644
659
|
| \`.sdk/model/guide/guide.aontu\` | How the spec's paths map onto entities and operations | Yes. The scaffold writes it once and never again. |
|
|
645
|
-
| \`.sdk/model/\`, the rest | The API model built from the spec, and the target and feature definitions | Not by hand. Generation, \`target add\` and a new scaffold run rewrite it. |
|
|
660
|
+
| \`.sdk/model/\`, the rest | The API model built from the spec, and the target and feature definitions | Not by hand. Generation, \`target add\` and a new scaffold run rewrite it, apart from a feature or target this project defines itself. |
|
|
646
661
|
| \`.sdk/def/\` | The OpenAPI spec | Replace it when the API changes. Generation rebuilds the model from it. |
|
|
647
|
-
| \`.sdk/src/cmp/<target>/\`, \`.sdk/tm/<target>/\` | The components and templates that generate each target |
|
|
662
|
+
| \`.sdk/src/cmp/<target>/\`, \`.sdk/tm/<target>/\` | The components and templates that generate each target | ${copiesRow} |
|
|
648
663
|
| \`.sdk/test/\` | The shared test cases the generated tests run | No. |
|
|
649
664
|
| ${targetDir} | One generated SDK per target, with its own tests | No. Generation overwrites it. |
|
|
650
665
|
| \`README.md\`, \`LICENSE\`, \`Makefile\` and the other root files | The repository's generated files | No. Generation overwrites them. |
|
|
@@ -3,6 +3,7 @@ import { each } from 'jostraca'
|
|
|
3
3
|
|
|
4
4
|
import { KIT, nom } from '@voxgig/apidef'
|
|
5
5
|
|
|
6
|
+
import { isConsumer } from './alongside'
|
|
6
7
|
import { kindCollection } from './kindCollection'
|
|
7
8
|
import { modelText } from './text'
|
|
8
9
|
|
|
@@ -279,6 +280,19 @@ function packageName(model: any, eco: string): string {
|
|
|
279
280
|
}
|
|
280
281
|
}
|
|
281
282
|
|
|
283
|
+
|
|
284
|
+
// For any other consumer packageName would answer the SDK's own name.
|
|
285
|
+
const NAMED_CONSUMERS = ['go-cli', 'go-mcp', 'py-data']
|
|
286
|
+
|
|
287
|
+
function hasPackageName(model: any, target: string): boolean {
|
|
288
|
+
const declared = model?.main?.[KIT]?.target?.[target]
|
|
289
|
+
if (!isConsumer(declared)) {
|
|
290
|
+
return true
|
|
291
|
+
}
|
|
292
|
+
const pkg = declared?.publish?.registry?.package
|
|
293
|
+
return (null != pkg && '' !== pkg) || NAMED_CONSUMERS.includes(originName(model, target))
|
|
294
|
+
}
|
|
295
|
+
|
|
282
296
|
// Copy-paste install command for a target, using the REAL package name.
|
|
283
297
|
// Only a package that is actually live on its registry (isPublished) gets a
|
|
284
298
|
// registry install command; everything else (pending / inactive / tag-only,
|
|
@@ -416,6 +430,7 @@ export {
|
|
|
416
430
|
repoInfo,
|
|
417
431
|
apiName,
|
|
418
432
|
packageName,
|
|
433
|
+
hasPackageName,
|
|
419
434
|
installCommand,
|
|
420
435
|
registryState,
|
|
421
436
|
isPublished,
|
package/src/sdkgen.ts
CHANGED
|
@@ -127,6 +127,7 @@ import {
|
|
|
127
127
|
import type { Manifest, ManifestRead } from './helpers/manifest'
|
|
128
128
|
import {
|
|
129
129
|
packageName,
|
|
130
|
+
hasPackageName,
|
|
130
131
|
sdkName,
|
|
131
132
|
installCommand,
|
|
132
133
|
registryState,
|
|
@@ -1299,6 +1300,7 @@ export {
|
|
|
1299
1300
|
prefixLeadingDigit,
|
|
1300
1301
|
|
|
1301
1302
|
packageName,
|
|
1303
|
+
hasPackageName,
|
|
1302
1304
|
sdkName,
|
|
1303
1305
|
installCommand,
|
|
1304
1306
|
registryState,
|