@topogram/cli 0.3.34
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/ARCHITECTURE.md +67 -0
- package/CHANGELOG.md +240 -0
- package/README.md +223 -0
- package/package.json +51 -0
- package/src/adoption/index.js +3 -0
- package/src/adoption/plan.js +702 -0
- package/src/adoption/reporting.js +464 -0
- package/src/adoption/review-groups.js +313 -0
- package/src/agent-ops/query-builders.js +5012 -0
- package/src/archive/archive.js +141 -0
- package/src/archive/compact.js +26 -0
- package/src/archive/jsonl.js +70 -0
- package/src/archive/resolver-bridge.js +82 -0
- package/src/archive/schema.js +87 -0
- package/src/archive/unarchive.js +108 -0
- package/src/catalog.js +752 -0
- package/src/cli/catalog-alias.js +166 -0
- package/src/cli.js +9738 -0
- package/src/component-behavior.js +173 -0
- package/src/example-implementation.js +91 -0
- package/src/format.js +19 -0
- package/src/generator/adapters.d.ts +4 -0
- package/src/generator/adapters.js +325 -0
- package/src/generator/api.d.ts +1 -0
- package/src/generator/api.js +1196 -0
- package/src/generator/check.js +355 -0
- package/src/generator/component-conformance.js +767 -0
- package/src/generator/components.js +39 -0
- package/src/generator/context/bundle.js +291 -0
- package/src/generator/context/diff.js +256 -0
- package/src/generator/context/digest.js +182 -0
- package/src/generator/context/domain-coverage.js +94 -0
- package/src/generator/context/domain-page.js +137 -0
- package/src/generator/context/index.js +42 -0
- package/src/generator/context/report.js +121 -0
- package/src/generator/context/shared.js +1397 -0
- package/src/generator/context/slice.js +703 -0
- package/src/generator/context/task-mode.js +466 -0
- package/src/generator/docs.js +327 -0
- package/src/generator/index.js +161 -0
- package/src/generator/native/parity-bundle.js +311 -0
- package/src/generator/output.js +300 -0
- package/src/generator/registry.js +482 -0
- package/src/generator/runtime/app-bundle.js +456 -0
- package/src/generator/runtime/bundle-shared.js +166 -0
- package/src/generator/runtime/compile-check.js +163 -0
- package/src/generator/runtime/deployment.js +287 -0
- package/src/generator/runtime/environment.js +635 -0
- package/src/generator/runtime/index.js +32 -0
- package/src/generator/runtime/runtime-check.js +554 -0
- package/src/generator/runtime/shared.js +515 -0
- package/src/generator/runtime/smoke.js +219 -0
- package/src/generator/schema.js +204 -0
- package/src/generator/sdlc/board.js +66 -0
- package/src/generator/sdlc/doc-page.js +53 -0
- package/src/generator/sdlc/index.js +23 -0
- package/src/generator/sdlc/release-notes.js +62 -0
- package/src/generator/sdlc/traceability-matrix.js +65 -0
- package/src/generator/shared.js +29 -0
- package/src/generator/surfaces/contracts.js +146 -0
- package/src/generator/surfaces/databases/contract.js +40 -0
- package/src/generator/surfaces/databases/index.js +84 -0
- package/src/generator/surfaces/databases/lifecycle-shared.d.ts +1 -0
- package/src/generator/surfaces/databases/lifecycle-shared.js +612 -0
- package/src/generator/surfaces/databases/migration-plan.js +281 -0
- package/src/generator/surfaces/databases/postgres/capabilities.js +14 -0
- package/src/generator/surfaces/databases/postgres/drizzle.js +99 -0
- package/src/generator/surfaces/databases/postgres/index.js +9 -0
- package/src/generator/surfaces/databases/postgres/lifecycle.js +16 -0
- package/src/generator/surfaces/databases/postgres/prisma.js +159 -0
- package/src/generator/surfaces/databases/postgres/sql-migration.js +102 -0
- package/src/generator/surfaces/databases/postgres/sql-schema.js +34 -0
- package/src/generator/surfaces/databases/shared.d.ts +1 -0
- package/src/generator/surfaces/databases/shared.js +350 -0
- package/src/generator/surfaces/databases/snapshot.js +96 -0
- package/src/generator/surfaces/databases/sqlite/capabilities.js +14 -0
- package/src/generator/surfaces/databases/sqlite/index.js +8 -0
- package/src/generator/surfaces/databases/sqlite/lifecycle.js +16 -0
- package/src/generator/surfaces/databases/sqlite/prisma.js +143 -0
- package/src/generator/surfaces/databases/sqlite/sql-migration.js +65 -0
- package/src/generator/surfaces/databases/sqlite/sql-schema.js +27 -0
- package/src/generator/surfaces/index.js +25 -0
- package/src/generator/surfaces/native/swiftui-app.js +38 -0
- package/src/generator/surfaces/native/swiftui-templates/Package.swift.txt +20 -0
- package/src/generator/surfaces/native/swiftui-templates/README.generated.md +26 -0
- package/src/generator/surfaces/native/swiftui-templates/runtime/DynamicScreens.swift +682 -0
- package/src/generator/surfaces/native/swiftui-templates/runtime/TodoAPIClient.swift +156 -0
- package/src/generator/surfaces/native/swiftui-templates/runtime/TodoSwiftUIApp.swift +44 -0
- package/src/generator/surfaces/native/swiftui-templates/runtime/Visibility.swift +183 -0
- package/src/generator/surfaces/services/express.d.ts +1 -0
- package/src/generator/surfaces/services/express.js +766 -0
- package/src/generator/surfaces/services/hono.d.ts +1 -0
- package/src/generator/surfaces/services/hono.js +204 -0
- package/src/generator/surfaces/services/index.js +42 -0
- package/src/generator/surfaces/services/persistence-wiring.js +240 -0
- package/src/generator/surfaces/services/runtime-helpers.js +631 -0
- package/src/generator/surfaces/services/server-contract.js +80 -0
- package/src/generator/surfaces/services/stateless.d.ts +1 -0
- package/src/generator/surfaces/services/stateless.js +97 -0
- package/src/generator/surfaces/shared.js +64 -0
- package/src/generator/surfaces/web/api-client.js +1 -0
- package/src/generator/surfaces/web/forms.js +1 -0
- package/src/generator/surfaces/web/index.d.ts +2 -0
- package/src/generator/surfaces/web/index.js +53 -0
- package/src/generator/surfaces/web/react-components.js +248 -0
- package/src/generator/surfaces/web/react.js +538 -0
- package/src/generator/surfaces/web/routes.js +1 -0
- package/src/generator/surfaces/web/screens.js +1 -0
- package/src/generator/surfaces/web/shared.js +369 -0
- package/src/generator/surfaces/web/sveltekit-actions.js +28 -0
- package/src/generator/surfaces/web/sveltekit-components.js +234 -0
- package/src/generator/surfaces/web/sveltekit.js +426 -0
- package/src/generator/surfaces/web/ui-web-contract.js +65 -0
- package/src/generator/surfaces/web/vanilla.js +239 -0
- package/src/generator/verification.js +84 -0
- package/src/generator.js +1 -0
- package/src/import/core/context.js +52 -0
- package/src/import/core/contracts.js +23 -0
- package/src/import/core/registry.js +81 -0
- package/src/import/core/runner.js +646 -0
- package/src/import/core/shared.js +910 -0
- package/src/import/enrichers/auth-session.js +18 -0
- package/src/import/enrichers/django-rest.js +226 -0
- package/src/import/enrichers/doc-linking.js +20 -0
- package/src/import/enrichers/rails-controllers.js +246 -0
- package/src/import/enrichers/rails-models.js +130 -0
- package/src/import/enrichers/workflow-target-state.js +10 -0
- package/src/import/extractors/api/aspnet-core.js +304 -0
- package/src/import/extractors/api/django-routes.js +318 -0
- package/src/import/extractors/api/express.js +154 -0
- package/src/import/extractors/api/fastify.js +371 -0
- package/src/import/extractors/api/flutter-dio.js +135 -0
- package/src/import/extractors/api/generic-route-fallback.js +90 -0
- package/src/import/extractors/api/graphql-code-first.js +565 -0
- package/src/import/extractors/api/graphql-sdl.js +309 -0
- package/src/import/extractors/api/jaxrs.js +303 -0
- package/src/import/extractors/api/micronaut.js +213 -0
- package/src/import/extractors/api/next-route.js +50 -0
- package/src/import/extractors/api/next-server-action.js +51 -0
- package/src/import/extractors/api/nextauth.js +52 -0
- package/src/import/extractors/api/openapi-code.js +242 -0
- package/src/import/extractors/api/openapi.js +232 -0
- package/src/import/extractors/api/rails-routes.js +230 -0
- package/src/import/extractors/api/react-native-repository.js +128 -0
- package/src/import/extractors/api/retrofit.js +103 -0
- package/src/import/extractors/api/spring-web.js +372 -0
- package/src/import/extractors/api/swift-webapi.js +116 -0
- package/src/import/extractors/api/trpc.js +212 -0
- package/src/import/extractors/db/django-models.js +232 -0
- package/src/import/extractors/db/dotnet-models.js +93 -0
- package/src/import/extractors/db/drizzle.js +242 -0
- package/src/import/extractors/db/ef-core.js +221 -0
- package/src/import/extractors/db/flutter-entities.js +120 -0
- package/src/import/extractors/db/jpa.js +120 -0
- package/src/import/extractors/db/liquibase.js +180 -0
- package/src/import/extractors/db/mybatis-xml.js +145 -0
- package/src/import/extractors/db/prisma.js +185 -0
- package/src/import/extractors/db/rails-schema.js +175 -0
- package/src/import/extractors/db/react-native-entities.js +95 -0
- package/src/import/extractors/db/room.js +193 -0
- package/src/import/extractors/db/snapshot.js +112 -0
- package/src/import/extractors/db/sql.js +180 -0
- package/src/import/extractors/db/swiftdata.js +137 -0
- package/src/import/extractors/ui/android-compose.js +230 -0
- package/src/import/extractors/ui/backend-only.js +70 -0
- package/src/import/extractors/ui/blazor.js +227 -0
- package/src/import/extractors/ui/flutter-screens.js +152 -0
- package/src/import/extractors/ui/maui-xaml.js +135 -0
- package/src/import/extractors/ui/next-app-router.js +83 -0
- package/src/import/extractors/ui/next-pages-router.js +141 -0
- package/src/import/extractors/ui/razor-pages.js +181 -0
- package/src/import/extractors/ui/react-native-screens.js +166 -0
- package/src/import/extractors/ui/react-router.js +139 -0
- package/src/import/extractors/ui/sveltekit.js +123 -0
- package/src/import/extractors/ui/swiftui.js +193 -0
- package/src/import/extractors/ui/uikit.js +175 -0
- package/src/import/extractors/verification/generic.js +290 -0
- package/src/import/extractors/workflows/generic.js +137 -0
- package/src/import/index.js +7 -0
- package/src/import/provenance.js +158 -0
- package/src/new-project.js +2107 -0
- package/src/parser.js +439 -0
- package/src/policy/review-boundaries.js +165 -0
- package/src/project-config.js +535 -0
- package/src/proofs/backend-parity.js +19 -0
- package/src/proofs/contract-audit.js +220 -0
- package/src/proofs/ios-parity.js +7 -0
- package/src/proofs/issues-parity.js +10 -0
- package/src/proofs/web-parity.js +50 -0
- package/src/realization/api/build-api-realization.js +5 -0
- package/src/realization/api/index.js +1 -0
- package/src/realization/backend/build-backend-runtime-realization.js +82 -0
- package/src/realization/backend/index.d.ts +1 -0
- package/src/realization/backend/index.js +4 -0
- package/src/realization/db/build-db-realization.js +17 -0
- package/src/realization/db/index.js +3 -0
- package/src/realization/db/migration-plan.js +5 -0
- package/src/realization/db/snapshot.js +5 -0
- package/src/realization/ui/build-ui-shared-realization.js +305 -0
- package/src/realization/ui/build-web-realization.js +189 -0
- package/src/realization/ui/index.js +2 -0
- package/src/reconcile/docs.js +280 -0
- package/src/reconcile/index.js +3 -0
- package/src/reconcile/journeys.js +441 -0
- package/src/resolver/docs.js +1 -0
- package/src/resolver/enrich/acceptance-criterion.js +14 -0
- package/src/resolver/enrich/bug.js +12 -0
- package/src/resolver/enrich/component.js +2 -0
- package/src/resolver/enrich/index.js +1 -0
- package/src/resolver/enrich/pitch.js +18 -0
- package/src/resolver/enrich/requirement.js +20 -0
- package/src/resolver/enrich/task.js +16 -0
- package/src/resolver/expressions.js +1 -0
- package/src/resolver/index.js +2422 -0
- package/src/resolver/normalize.js +1 -0
- package/src/resolver.js +1 -0
- package/src/sdlc/adopt.js +65 -0
- package/src/sdlc/check.js +86 -0
- package/src/sdlc/dod/acceptance-criterion.js +22 -0
- package/src/sdlc/dod/bug.js +26 -0
- package/src/sdlc/dod/document.js +23 -0
- package/src/sdlc/dod/index.js +25 -0
- package/src/sdlc/dod/pitch.js +23 -0
- package/src/sdlc/dod/requirement.js +34 -0
- package/src/sdlc/dod/task.js +39 -0
- package/src/sdlc/explain.js +116 -0
- package/src/sdlc/history.js +80 -0
- package/src/sdlc/paths.js +11 -0
- package/src/sdlc/release.js +106 -0
- package/src/sdlc/scaffold.js +89 -0
- package/src/sdlc/status-filter.js +54 -0
- package/src/sdlc/transition.js +112 -0
- package/src/sdlc/transitions/acceptance-criterion.js +28 -0
- package/src/sdlc/transitions/bug.js +31 -0
- package/src/sdlc/transitions/document.js +29 -0
- package/src/sdlc/transitions/index.js +56 -0
- package/src/sdlc/transitions/pitch.js +34 -0
- package/src/sdlc/transitions/requirement.js +31 -0
- package/src/sdlc/transitions/task.js +34 -0
- package/src/template-trust.js +597 -0
- package/src/validator/expressions.js +1 -0
- package/src/validator/index.js +3424 -0
- package/src/validator/kinds.js +346 -0
- package/src/validator/per-kind/acceptance-criterion.js +91 -0
- package/src/validator/per-kind/bug.js +77 -0
- package/src/validator/per-kind/component.js +274 -0
- package/src/validator/per-kind/domain.js +205 -0
- package/src/validator/per-kind/pitch.js +101 -0
- package/src/validator/per-kind/requirement.js +75 -0
- package/src/validator/per-kind/task.js +96 -0
- package/src/validator/registry.js +1 -0
- package/src/validator/utils.js +12 -0
- package/src/validator.js +1 -0
- package/src/workflows.js +7597 -0
- package/src/workspace-docs.js +265 -0
- package/template-helpers/react.js +5 -0
- package/template-helpers/sveltekit.js +5 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
loadPackageGeneratorManifest,
|
|
9
|
+
validateGeneratorManifest
|
|
10
|
+
} from "./registry.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {import("./registry.js").GeneratorManifest} GeneratorManifest
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {Object} GeneratorCheckResult
|
|
18
|
+
* @property {boolean} ok
|
|
19
|
+
* @property {string} sourceSpec
|
|
20
|
+
* @property {"path"|"package"} source
|
|
21
|
+
* @property {string|null} packageName
|
|
22
|
+
* @property {string|null} packageRoot
|
|
23
|
+
* @property {string|null} manifestPath
|
|
24
|
+
* @property {GeneratorManifest|null} manifest
|
|
25
|
+
* @property {Array<{ name: string, ok: boolean, message: string }>} checks
|
|
26
|
+
* @property {string[]} errors
|
|
27
|
+
* @property {{ files: number, artifacts: number, diagnostics: number }|null} smoke
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} spec
|
|
32
|
+
* @param {string} cwd
|
|
33
|
+
* @returns {boolean}
|
|
34
|
+
*/
|
|
35
|
+
function isPathSpec(spec, cwd) {
|
|
36
|
+
return spec.startsWith(".") || spec.startsWith("/") || fs.existsSync(path.resolve(cwd, spec));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {string} spec
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
43
|
+
function packageNameFromSpec(spec) {
|
|
44
|
+
if (spec.startsWith("@")) {
|
|
45
|
+
const versionIndex = spec.indexOf("@", 1);
|
|
46
|
+
return versionIndex > 0 ? spec.slice(0, versionIndex) : spec;
|
|
47
|
+
}
|
|
48
|
+
const versionIndex = spec.indexOf("@");
|
|
49
|
+
return versionIndex > 0 ? spec.slice(0, versionIndex) : spec;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {any} moduleValue
|
|
54
|
+
* @param {string|null|undefined} exportName
|
|
55
|
+
* @returns {any}
|
|
56
|
+
*/
|
|
57
|
+
function selectPackageExport(moduleValue, exportName) {
|
|
58
|
+
if (exportName) {
|
|
59
|
+
return moduleValue?.[exportName] || moduleValue?.default?.[exportName] || null;
|
|
60
|
+
}
|
|
61
|
+
return moduleValue?.default || moduleValue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {string} root
|
|
66
|
+
* @param {GeneratorManifest} manifest
|
|
67
|
+
* @returns {{ adapter: any|null, error: string|null }}
|
|
68
|
+
*/
|
|
69
|
+
function loadLocalAdapter(root, manifest) {
|
|
70
|
+
try {
|
|
71
|
+
const packageJsonPath = path.join(root, "package.json");
|
|
72
|
+
const requireFromPackage = createRequire(packageJsonPath);
|
|
73
|
+
return {
|
|
74
|
+
adapter: selectPackageExport(requireFromPackage(root), manifest.export),
|
|
75
|
+
error: null
|
|
76
|
+
};
|
|
77
|
+
} catch (error) {
|
|
78
|
+
return {
|
|
79
|
+
adapter: null,
|
|
80
|
+
error: `Generator package export could not be loaded from '${root}': ${error instanceof Error ? error.message : String(error)}`
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param {string} packageName
|
|
87
|
+
* @param {string} rootDir
|
|
88
|
+
* @param {GeneratorManifest} manifest
|
|
89
|
+
* @returns {{ adapter: any|null, error: string|null }}
|
|
90
|
+
*/
|
|
91
|
+
function loadInstalledAdapter(packageName, rootDir, manifest) {
|
|
92
|
+
try {
|
|
93
|
+
const requireFromRoot = createRequire(path.join(rootDir, "package.json"));
|
|
94
|
+
return {
|
|
95
|
+
adapter: selectPackageExport(requireFromRoot(packageName), manifest.export),
|
|
96
|
+
error: null
|
|
97
|
+
};
|
|
98
|
+
} catch (error) {
|
|
99
|
+
return {
|
|
100
|
+
adapter: null,
|
|
101
|
+
error: `Generator package '${packageName}' export could not be loaded from '${rootDir}': ${error instanceof Error ? error.message : String(error)}`
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {GeneratorManifest} manifest
|
|
108
|
+
* @returns {Record<string, any>}
|
|
109
|
+
*/
|
|
110
|
+
function smokeProjection(manifest) {
|
|
111
|
+
const platform = manifest.projectionPlatforms[0] || "";
|
|
112
|
+
if (manifest.surface === "api") {
|
|
113
|
+
return {
|
|
114
|
+
id: "proj_generator_check_api",
|
|
115
|
+
platform: "api",
|
|
116
|
+
http: [{ method: "GET", path: "/generator-check", capabilityId: "cap_generator_check", success: 200 }]
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
id: `proj_generator_check_${manifest.surface}`,
|
|
121
|
+
platform
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @param {GeneratorManifest} manifest
|
|
127
|
+
* @param {Record<string, any>} projection
|
|
128
|
+
* @returns {Record<string, any>}
|
|
129
|
+
*/
|
|
130
|
+
function smokeContracts(manifest, projection) {
|
|
131
|
+
if (manifest.surface === "web" || manifest.surface === "native") {
|
|
132
|
+
return {
|
|
133
|
+
uiWeb: {
|
|
134
|
+
projection: { id: projection.id, platform: projection.platform },
|
|
135
|
+
appShell: { brand: "Generator Check" },
|
|
136
|
+
screens: [
|
|
137
|
+
{ id: "screen_generator_check_home", title: "Generator Check", route: "/" },
|
|
138
|
+
{ id: "screen_generator_check_detail", title: "Generator Detail", route: "/detail" }
|
|
139
|
+
],
|
|
140
|
+
navigation: {
|
|
141
|
+
items: [{ screenId: "screen_generator_check_home", label: "Home" }]
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
api: { projections: [] }
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if (manifest.surface === "api") {
|
|
148
|
+
return {
|
|
149
|
+
server: {
|
|
150
|
+
projection: { id: projection.id, platform: "api" },
|
|
151
|
+
routes: projection.http,
|
|
152
|
+
preconditions: [],
|
|
153
|
+
responses: []
|
|
154
|
+
},
|
|
155
|
+
api: { projections: [{ id: projection.id, http: projection.http }] }
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
if (manifest.surface === "database") {
|
|
159
|
+
return {
|
|
160
|
+
db: {
|
|
161
|
+
projection: { id: projection.id, platform: projection.platform },
|
|
162
|
+
tables: []
|
|
163
|
+
},
|
|
164
|
+
lifecyclePlan: {
|
|
165
|
+
projection: { id: projection.id, platform: projection.platform },
|
|
166
|
+
migrations: [],
|
|
167
|
+
seeds: []
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
return {};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @param {GeneratorManifest} manifest
|
|
176
|
+
* @returns {Record<string, any>}
|
|
177
|
+
*/
|
|
178
|
+
function smokeComponent(manifest) {
|
|
179
|
+
return {
|
|
180
|
+
id: `component_generator_check_${manifest.surface}`,
|
|
181
|
+
type: manifest.surface,
|
|
182
|
+
projection: `proj_generator_check_${manifest.surface}`,
|
|
183
|
+
generator: {
|
|
184
|
+
id: manifest.id,
|
|
185
|
+
version: manifest.version,
|
|
186
|
+
...(manifest.package ? { package: manifest.package } : {})
|
|
187
|
+
},
|
|
188
|
+
port: manifest.surface === "database" ? 5432 : manifest.surface === "api" ? 3000 : 5173
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* @param {any} result
|
|
194
|
+
* @returns {{ ok: boolean, message: string, smoke: GeneratorCheckResult["smoke"] }}
|
|
195
|
+
*/
|
|
196
|
+
function validateSmokeResult(result) {
|
|
197
|
+
if (!result || typeof result !== "object" || Array.isArray(result)) {
|
|
198
|
+
return { ok: false, message: "generate(context) must return an object", smoke: null };
|
|
199
|
+
}
|
|
200
|
+
if (!result.files || typeof result.files !== "object" || Array.isArray(result.files)) {
|
|
201
|
+
return { ok: false, message: "generate(context) result must include a files object", smoke: null };
|
|
202
|
+
}
|
|
203
|
+
for (const [filePath, content] of Object.entries(result.files)) {
|
|
204
|
+
const normalizedPath = typeof filePath === "string" ? path.normalize(filePath) : "";
|
|
205
|
+
if (typeof filePath !== "string" || filePath.length === 0 || path.isAbsolute(filePath) || normalizedPath === ".." || normalizedPath.startsWith(`..${path.sep}`)) {
|
|
206
|
+
return { ok: false, message: "generated file paths must be non-empty relative paths", smoke: null };
|
|
207
|
+
}
|
|
208
|
+
if (typeof content !== "string") {
|
|
209
|
+
return { ok: false, message: `generated file '${filePath}' content must be a string`, smoke: null };
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
ok: true,
|
|
214
|
+
message: `generate(context) returned ${Object.keys(result.files).length} file(s)`,
|
|
215
|
+
smoke: {
|
|
216
|
+
files: Object.keys(result.files).length,
|
|
217
|
+
artifacts: result.artifacts && typeof result.artifacts === "object" && !Array.isArray(result.artifacts) ? Object.keys(result.artifacts).length : 0,
|
|
218
|
+
diagnostics: Array.isArray(result.diagnostics) ? result.diagnostics.length : 0
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @param {string} sourceSpec
|
|
225
|
+
* @param {{ cwd?: string }} [options]
|
|
226
|
+
* @returns {GeneratorCheckResult}
|
|
227
|
+
*/
|
|
228
|
+
export function checkGeneratorPack(sourceSpec, options = {}) {
|
|
229
|
+
const cwd = path.resolve(options.cwd || process.cwd());
|
|
230
|
+
/** @type {GeneratorCheckResult} */
|
|
231
|
+
const payload = {
|
|
232
|
+
ok: false,
|
|
233
|
+
sourceSpec,
|
|
234
|
+
source: isPathSpec(sourceSpec, cwd) ? "path" : "package",
|
|
235
|
+
packageName: null,
|
|
236
|
+
packageRoot: null,
|
|
237
|
+
manifestPath: null,
|
|
238
|
+
manifest: null,
|
|
239
|
+
checks: [],
|
|
240
|
+
errors: [],
|
|
241
|
+
smoke: null
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/** @type {any|null} */
|
|
245
|
+
let adapter = null;
|
|
246
|
+
|
|
247
|
+
if (payload.source === "path") {
|
|
248
|
+
const packageRoot = path.resolve(cwd, sourceSpec);
|
|
249
|
+
payload.packageRoot = packageRoot;
|
|
250
|
+
payload.manifestPath = path.join(packageRoot, "topogram-generator.json");
|
|
251
|
+
if (!fs.existsSync(packageRoot) || !fs.statSync(packageRoot).isDirectory()) {
|
|
252
|
+
payload.errors.push(`Generator path '${packageRoot}' must be a directory.`);
|
|
253
|
+
payload.checks.push({ name: "package-root", ok: false, message: payload.errors[payload.errors.length - 1] });
|
|
254
|
+
return payload;
|
|
255
|
+
}
|
|
256
|
+
if (!fs.existsSync(payload.manifestPath)) {
|
|
257
|
+
payload.errors.push(`Generator path '${packageRoot}' is missing topogram-generator.json.`);
|
|
258
|
+
payload.checks.push({ name: "manifest-present", ok: false, message: payload.errors[payload.errors.length - 1] });
|
|
259
|
+
return payload;
|
|
260
|
+
}
|
|
261
|
+
payload.checks.push({ name: "manifest-present", ok: true, message: payload.manifestPath });
|
|
262
|
+
try {
|
|
263
|
+
payload.manifest = JSON.parse(fs.readFileSync(payload.manifestPath, "utf8"));
|
|
264
|
+
payload.packageName = payload.manifest?.package || null;
|
|
265
|
+
} catch (error) {
|
|
266
|
+
payload.errors.push(`Generator manifest could not be read: ${error instanceof Error ? error.message : String(error)}`);
|
|
267
|
+
payload.checks.push({ name: "manifest-json", ok: false, message: payload.errors[payload.errors.length - 1] });
|
|
268
|
+
return payload;
|
|
269
|
+
}
|
|
270
|
+
payload.checks.push({ name: "manifest-json", ok: true, message: "Manifest JSON parsed." });
|
|
271
|
+
} else {
|
|
272
|
+
const packageName = packageNameFromSpec(sourceSpec);
|
|
273
|
+
payload.packageName = packageName;
|
|
274
|
+
const loaded = loadPackageGeneratorManifest(packageName, cwd);
|
|
275
|
+
payload.manifest = loaded.manifest;
|
|
276
|
+
payload.manifestPath = loaded.manifestPath;
|
|
277
|
+
payload.packageRoot = loaded.packageRoot;
|
|
278
|
+
if (!loaded.manifest) {
|
|
279
|
+
payload.errors.push(...loaded.errors);
|
|
280
|
+
payload.checks.push({ name: "manifest-load", ok: false, message: loaded.errors.join(" ") || `Could not load ${packageName}.` });
|
|
281
|
+
return payload;
|
|
282
|
+
}
|
|
283
|
+
payload.checks.push({ name: "manifest-load", ok: true, message: loaded.manifestPath || packageName });
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const manifestValidation = validateGeneratorManifest(payload.manifest);
|
|
287
|
+
payload.checks.push({
|
|
288
|
+
name: "manifest-schema",
|
|
289
|
+
ok: manifestValidation.ok,
|
|
290
|
+
message: manifestValidation.ok ? "Manifest schema is valid." : manifestValidation.errors.join(" ")
|
|
291
|
+
});
|
|
292
|
+
if (!manifestValidation.ok || !payload.manifest) {
|
|
293
|
+
payload.errors.push(...manifestValidation.errors);
|
|
294
|
+
return payload;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (payload.source === "path") {
|
|
298
|
+
const loaded = loadLocalAdapter(payload.packageRoot || cwd, payload.manifest);
|
|
299
|
+
adapter = loaded.adapter;
|
|
300
|
+
if (loaded.error) {
|
|
301
|
+
payload.errors.push(loaded.error);
|
|
302
|
+
payload.checks.push({ name: "adapter-load", ok: false, message: loaded.error });
|
|
303
|
+
return payload;
|
|
304
|
+
}
|
|
305
|
+
} else if (payload.packageName) {
|
|
306
|
+
const loaded = loadInstalledAdapter(payload.packageName, cwd, payload.manifest);
|
|
307
|
+
adapter = loaded.adapter;
|
|
308
|
+
if (loaded.error) {
|
|
309
|
+
payload.errors.push(loaded.error);
|
|
310
|
+
payload.checks.push({ name: "adapter-load", ok: false, message: loaded.error });
|
|
311
|
+
return payload;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (!adapter || typeof adapter.generate !== "function") {
|
|
316
|
+
const message = "Generator package must export an adapter with generate(context).";
|
|
317
|
+
payload.errors.push(message);
|
|
318
|
+
payload.checks.push({ name: "adapter-shape", ok: false, message });
|
|
319
|
+
return payload;
|
|
320
|
+
}
|
|
321
|
+
if (!adapter.manifest || adapter.manifest.id !== payload.manifest.id || adapter.manifest.version !== payload.manifest.version) {
|
|
322
|
+
const message = "Generator adapter must export manifest matching topogram-generator.json.";
|
|
323
|
+
payload.errors.push(message);
|
|
324
|
+
payload.checks.push({ name: "adapter-manifest", ok: false, message });
|
|
325
|
+
return payload;
|
|
326
|
+
}
|
|
327
|
+
payload.checks.push({ name: "adapter-shape", ok: true, message: "Adapter exports manifest and generate(context)." });
|
|
328
|
+
|
|
329
|
+
try {
|
|
330
|
+
const projection = smokeProjection(payload.manifest);
|
|
331
|
+
const result = adapter.generate({
|
|
332
|
+
graph: {},
|
|
333
|
+
projection,
|
|
334
|
+
component: smokeComponent(payload.manifest),
|
|
335
|
+
topology: { components: [] },
|
|
336
|
+
contracts: smokeContracts(payload.manifest, projection),
|
|
337
|
+
implementation: null,
|
|
338
|
+
options: { check: true },
|
|
339
|
+
manifest: payload.manifest
|
|
340
|
+
});
|
|
341
|
+
const smoke = validateSmokeResult(result);
|
|
342
|
+
payload.checks.push({ name: "smoke-generate", ok: smoke.ok, message: smoke.message });
|
|
343
|
+
payload.smoke = smoke.smoke;
|
|
344
|
+
if (!smoke.ok) {
|
|
345
|
+
payload.errors.push(smoke.message);
|
|
346
|
+
}
|
|
347
|
+
} catch (error) {
|
|
348
|
+
const message = `generate(context) smoke failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
349
|
+
payload.errors.push(message);
|
|
350
|
+
payload.checks.push({ name: "smoke-generate", ok: false, message });
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
payload.ok = payload.errors.length === 0 && payload.checks.every((check) => check.ok);
|
|
354
|
+
return payload;
|
|
355
|
+
}
|