@plugmatica/plugin-build 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/LICENSE-APACHE +202 -0
- package/README.md +221 -2
- package/dev-target/README.md +20 -0
- package/dev-target/compose.yaml +119 -0
- package/dist/chunk-EOLUQEKQ.js +587 -0
- package/dist/chunk-QHTGR4ZB.js +9378 -0
- package/dist/chunk-TQNG5OZ3.js +3135 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +2606 -0
- package/dist/index.d.ts +2144 -0
- package/dist/index.js +230 -0
- package/dist/vite-WRwB4IG8.d.ts +929 -0
- package/dist/vite.d.ts +3 -0
- package/dist/vite.js +20 -0
- package/package.json +94 -4
- package/templates/README.md +29 -0
- package/templates/backend-capabilities/LICENSE.txt +231 -0
- package/templates/backend-capabilities/backend/Cargo.toml +21 -0
- package/templates/backend-capabilities/backend/src/lib.rs +179 -0
- package/templates/backend-capabilities/backend/tests/basic.rs +174 -0
- package/templates/backend-capabilities/manifest.source.json +64 -0
- package/templates/backend-capabilities/package.json +22 -0
- package/templates/backend-composition/LICENSE.txt +231 -0
- package/templates/backend-composition/backend/Cargo.toml +21 -0
- package/templates/backend-composition/backend/src/lib.rs +96 -0
- package/templates/backend-composition/backend/tests/basic.rs +75 -0
- package/templates/backend-composition/manifest.source.json +26 -0
- package/templates/backend-composition/package.json +22 -0
- package/templates/backend-entities/LICENSE.txt +231 -0
- package/templates/backend-entities/backend/Cargo.toml +20 -0
- package/templates/backend-entities/backend/src/lib.rs +77 -0
- package/templates/backend-entities/backend/tests/basic.rs +26 -0
- package/templates/backend-entities/manifest.source.json +15 -0
- package/templates/backend-entities/package.json +22 -0
- package/templates/backend-minimal/LICENSE.txt +231 -0
- package/templates/backend-minimal/backend/Cargo.toml +21 -0
- package/templates/backend-minimal/backend/src/lib.rs +69 -0
- package/templates/backend-minimal/backend/tests/basic.rs +67 -0
- package/templates/backend-minimal/manifest.source.json +15 -0
- package/templates/backend-minimal/package.json +22 -0
- package/templates/backend-operations/LICENSE.txt +231 -0
- package/templates/backend-operations/backend/Cargo.toml +21 -0
- package/templates/backend-operations/backend/src/lib.rs +117 -0
- package/templates/backend-operations/backend/tests/basic.rs +169 -0
- package/templates/backend-operations/manifest.source.json +15 -0
- package/templates/backend-operations/package.json +22 -0
- package/templates/frontend-entity/LICENSE.txt +27 -0
- package/templates/frontend-entity/README.md +46 -0
- package/templates/frontend-entity/frontend/i18n/en-GB.json +5 -0
- package/templates/frontend-entity/frontend/package.json +32 -0
- package/templates/frontend-entity/frontend/src/CustomerListPage.tsx +98 -0
- package/templates/frontend-entity/frontend/src/model.ts +5 -0
- package/templates/frontend-entity/frontend/tests/entityLifecycle.test.tsx +79 -0
- package/templates/frontend-entity/frontend/tsconfig.json +4 -0
- package/templates/frontend-entity/frontend/vite.config.ts +3 -0
- package/templates/frontend-entity/frontend/vitest.config.ts +9 -0
- package/templates/frontend-entity/manifest.source.json +53 -0
- package/templates/frontend-entity/package.json +22 -0
- package/templates/frontend-entity/pnpm-workspace.yaml +2 -0
- package/templates/frontend-extension/LICENSE.txt +27 -0
- package/templates/frontend-extension/README.md +7 -0
- package/templates/frontend-extension/frontend/i18n/en-GB.json +4 -0
- package/templates/frontend-extension/frontend/package.json +25 -0
- package/templates/frontend-extension/frontend/src/CustomerNotes.tsx +24 -0
- package/templates/frontend-extension/frontend/tsconfig.json +4 -0
- package/templates/frontend-extension/frontend/vite.config.ts +3 -0
- package/templates/frontend-extension/manifest.source.json +16 -0
- package/templates/frontend-extension/package.json +22 -0
- package/templates/frontend-extension/pnpm-workspace.yaml +2 -0
- package/templates/frontend-minimal/LICENSE.txt +27 -0
- package/templates/frontend-minimal/README.md +5 -0
- package/templates/frontend-minimal/frontend/i18n/en-GB.json +4 -0
- package/templates/frontend-minimal/frontend/package.json +25 -0
- package/templates/frontend-minimal/frontend/src/Page.tsx +16 -0
- package/templates/frontend-minimal/frontend/src/entry.ts +1 -0
- package/templates/frontend-minimal/frontend/tsconfig.json +4 -0
- package/templates/frontend-minimal/frontend/vite.config.ts +3 -0
- package/templates/frontend-minimal/manifest.source.json +51 -0
- package/templates/frontend-minimal/package.json +22 -0
- package/templates/frontend-minimal/pnpm-workspace.yaml +2 -0
- package/templates/frontend-provider-event/LICENSE.txt +27 -0
- package/templates/frontend-provider-event/README.md +7 -0
- package/templates/frontend-provider-event/frontend/i18n/en-GB.json +3 -0
- package/templates/frontend-provider-event/frontend/package.json +25 -0
- package/templates/frontend-provider-event/frontend/src/CustomerBadgeProvider.ts +24 -0
- package/templates/frontend-provider-event/frontend/src/CustomerSavedHandler.ts +22 -0
- package/templates/frontend-provider-event/frontend/tsconfig.json +4 -0
- package/templates/frontend-provider-event/frontend/vite.config.ts +3 -0
- package/templates/frontend-provider-event/manifest.source.json +16 -0
- package/templates/frontend-provider-event/package.json +22 -0
- package/templates/frontend-provider-event/pnpm-workspace.yaml +2 -0
- package/templates/full-stack-minimal/LICENSE.txt +231 -0
- package/templates/full-stack-minimal/README.md +49 -0
- package/templates/full-stack-minimal/backend/Cargo.toml +18 -0
- package/templates/full-stack-minimal/backend/src/lib.rs +49 -0
- package/templates/full-stack-minimal/backend/tests/basic.rs +49 -0
- package/templates/full-stack-minimal/frontend/i18n/en-GB.json +6 -0
- package/templates/full-stack-minimal/frontend/package.json +25 -0
- package/templates/full-stack-minimal/frontend/src/Page.tsx +29 -0
- package/templates/full-stack-minimal/frontend/src/entry.ts +1 -0
- package/templates/full-stack-minimal/frontend/tsconfig.json +4 -0
- package/templates/full-stack-minimal/frontend/vite.config.ts +3 -0
- package/templates/full-stack-minimal/manifest.source.json +55 -0
- package/templates/full-stack-minimal/package.json +24 -0
- package/templates/full-stack-minimal/pnpm-workspace.yaml +2 -0
- package/templates/full-stack-workflow-node/LICENSE.txt +231 -0
- package/templates/full-stack-workflow-node/README.md +111 -0
- package/templates/full-stack-workflow-node/backend/Cargo.toml +12 -0
- package/templates/full-stack-workflow-node/backend/src/lib.rs +70 -0
- package/templates/full-stack-workflow-node/frontend/i18n/en-GB.json +10 -0
- package/templates/full-stack-workflow-node/frontend/package.json +29 -0
- package/templates/full-stack-workflow-node/frontend/src/editors/FormatLabelEditor.tsx +25 -0
- package/templates/full-stack-workflow-node/frontend/src/entry.ts +2 -0
- package/templates/full-stack-workflow-node/frontend/src/nodes/FormatLabel.tsx +18 -0
- package/templates/full-stack-workflow-node/frontend/src/presentations/FormatLabelPresentation.tsx +7 -0
- package/templates/full-stack-workflow-node/frontend/tsconfig.json +4 -0
- package/templates/full-stack-workflow-node/frontend/vite.config.ts +5 -0
- package/templates/full-stack-workflow-node/manifest.source.json +18 -0
- package/templates/full-stack-workflow-node/package.json +25 -0
- package/templates/full-stack-workflow-node/pnpm-workspace.yaml +2 -0
- package/templates/localization-fr-fr/LICENSE.txt +27 -0
- package/templates/localization-fr-fr/README.md +5 -0
- package/templates/localization-fr-fr/localization/plugmatica.customer.fr-FR.json +4 -0
- package/templates/localization-fr-fr/manifest.source.json +36 -0
- package/templates/localization-fr-fr/package.json +18 -0
- package/templates/starter-projection.json +448 -0
- package/tsconfig.plugin.json +14 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,2606 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ExplicitContractBaselineProvider,
|
|
4
|
+
GitTagContractBaselineProvider,
|
|
5
|
+
InstalledPluginContractBaselineProvider,
|
|
6
|
+
RegistryContractBaselineProvider,
|
|
7
|
+
RepositoryContractBaselineProvider,
|
|
8
|
+
auditBuiltDeclarationDependencies,
|
|
9
|
+
auditFrontendPackageBoundaries,
|
|
10
|
+
auditPackageReleaseContract,
|
|
11
|
+
buildReleaseCompatibilityHistory,
|
|
12
|
+
checkContractCompatibility,
|
|
13
|
+
createPluginScaffold,
|
|
14
|
+
enforceStrictCompatibility,
|
|
15
|
+
formatCompatibilityReport,
|
|
16
|
+
formatExtensionInventory,
|
|
17
|
+
formatPackageBoundaryAudit,
|
|
18
|
+
formatPackageReleaseAudit,
|
|
19
|
+
formatPluginInspection,
|
|
20
|
+
formatProtocolParityReport,
|
|
21
|
+
formatWorkflowNodePackageInspection,
|
|
22
|
+
initRepositoryContractBaseline,
|
|
23
|
+
inspectPlugin,
|
|
24
|
+
inspectWorkflowNodePackage,
|
|
25
|
+
listPluginTemplates,
|
|
26
|
+
loadReleaseContractSnapshots,
|
|
27
|
+
updateRepositoryContractBaseline,
|
|
28
|
+
verifyFrontendProtocolAgainstRust,
|
|
29
|
+
writeReleaseCompatibilityHistory
|
|
30
|
+
} from "./chunk-TQNG5OZ3.js";
|
|
31
|
+
import {
|
|
32
|
+
PLUGIN_MANIFEST_VERSION,
|
|
33
|
+
PLUGIN_PROTOCOL_VERSION,
|
|
34
|
+
PluginManifestGenerationError,
|
|
35
|
+
assertBackendManifestProjection,
|
|
36
|
+
assertBackendProjectionSourceOwnership,
|
|
37
|
+
assertValidBackendDescriptorFile,
|
|
38
|
+
auditPluginI18n,
|
|
39
|
+
compilerPageRoutesFromManifest,
|
|
40
|
+
fixPluginI18n,
|
|
41
|
+
fixRedundantExtensionOverrides,
|
|
42
|
+
formatExtensionFixResult,
|
|
43
|
+
formatI18nFixResult,
|
|
44
|
+
formatPluginI18nAudit,
|
|
45
|
+
formatScanIssues,
|
|
46
|
+
generatePluginManifest,
|
|
47
|
+
projectBackendManifest,
|
|
48
|
+
renderPluginContractGraphMermaid
|
|
49
|
+
} from "./chunk-QHTGR4ZB.js";
|
|
50
|
+
|
|
51
|
+
// src/cli.ts
|
|
52
|
+
import fs4 from "fs";
|
|
53
|
+
import path4 from "path";
|
|
54
|
+
|
|
55
|
+
// src/cli/runtime.ts
|
|
56
|
+
import { parseArgs } from "util";
|
|
57
|
+
|
|
58
|
+
// src/cli/spec.ts
|
|
59
|
+
var PLUGIN_BUILD_CLI_NAME = "plugmatica";
|
|
60
|
+
var PLUGIN_BUILD_CLI_ALIASES = ["plugmatica-plugin-build"];
|
|
61
|
+
var sourceManifestOption = {
|
|
62
|
+
name: "manifest",
|
|
63
|
+
type: "string",
|
|
64
|
+
valueName: "path",
|
|
65
|
+
description: "Path to manifest.source.json.",
|
|
66
|
+
required: true
|
|
67
|
+
};
|
|
68
|
+
var sourceDirectoryOption = {
|
|
69
|
+
name: "src",
|
|
70
|
+
type: "string",
|
|
71
|
+
valueName: "directory",
|
|
72
|
+
description: "Path to the plugin frontend source directory.",
|
|
73
|
+
required: true
|
|
74
|
+
};
|
|
75
|
+
var jsonOutputOption = {
|
|
76
|
+
name: "json-out",
|
|
77
|
+
type: "string",
|
|
78
|
+
valueName: "path",
|
|
79
|
+
description: "Write the structured result as JSON to this path."
|
|
80
|
+
};
|
|
81
|
+
var projectRootOption = {
|
|
82
|
+
name: "project-root",
|
|
83
|
+
type: "string",
|
|
84
|
+
valueName: "directory",
|
|
85
|
+
description: "Plugin project root. Defaults to the source-manifest directory."
|
|
86
|
+
};
|
|
87
|
+
var defaultManifestOption = {
|
|
88
|
+
name: "manifest",
|
|
89
|
+
type: "string",
|
|
90
|
+
valueName: "path",
|
|
91
|
+
description: "Path to manifest.source.json.",
|
|
92
|
+
defaultValue: "manifest.source.json"
|
|
93
|
+
};
|
|
94
|
+
var frontendSourceOption = {
|
|
95
|
+
name: "src",
|
|
96
|
+
type: "string",
|
|
97
|
+
valueName: "directory",
|
|
98
|
+
description: "Frontend source directory. Defaults to frontend/src beside the source manifest."
|
|
99
|
+
};
|
|
100
|
+
var backendRootOption = {
|
|
101
|
+
name: "root",
|
|
102
|
+
type: "string",
|
|
103
|
+
valueName: "directory",
|
|
104
|
+
description: "Plugin package root.",
|
|
105
|
+
defaultValue: "."
|
|
106
|
+
};
|
|
107
|
+
var backendManifestOption = {
|
|
108
|
+
name: "manifest",
|
|
109
|
+
type: "string",
|
|
110
|
+
valueName: "path",
|
|
111
|
+
description: "Source manifest path relative to the plugin root.",
|
|
112
|
+
defaultValue: "manifest.source.json"
|
|
113
|
+
};
|
|
114
|
+
var descriptorOutOption = {
|
|
115
|
+
name: "descriptor-out",
|
|
116
|
+
type: "string",
|
|
117
|
+
valueName: "path",
|
|
118
|
+
description: "Generated backend descriptor path relative to the plugin root.",
|
|
119
|
+
defaultValue: "backend/descriptor.json"
|
|
120
|
+
};
|
|
121
|
+
var previousDescriptorOption = {
|
|
122
|
+
name: "previous-descriptor",
|
|
123
|
+
type: "string",
|
|
124
|
+
valueName: "path",
|
|
125
|
+
description: "Previous descriptor used for explicit schema-upgrade validation."
|
|
126
|
+
};
|
|
127
|
+
var describeBinOption = {
|
|
128
|
+
name: "describe-bin",
|
|
129
|
+
type: "string",
|
|
130
|
+
valueName: "path",
|
|
131
|
+
description: "Override the public plugmatica-plugin-describe executable."
|
|
132
|
+
};
|
|
133
|
+
var assembledPackageOption = {
|
|
134
|
+
name: "package",
|
|
135
|
+
type: "string",
|
|
136
|
+
valueName: "directory",
|
|
137
|
+
description: "Assembled package directory.",
|
|
138
|
+
defaultValue: "dist/plugin"
|
|
139
|
+
};
|
|
140
|
+
var devProjectOption = {
|
|
141
|
+
name: "project",
|
|
142
|
+
type: "string",
|
|
143
|
+
valueName: "name",
|
|
144
|
+
description: "Docker Compose project name.",
|
|
145
|
+
defaultValue: "plugmatica-plugin-dev"
|
|
146
|
+
};
|
|
147
|
+
var repositoryBaselineOption = {
|
|
148
|
+
name: "repository-baseline",
|
|
149
|
+
type: "string",
|
|
150
|
+
valueName: "path",
|
|
151
|
+
description: "Repository Contract Baseline path relative to the project root."
|
|
152
|
+
};
|
|
153
|
+
var graphJsonOutputOption = {
|
|
154
|
+
name: "graph-json-out",
|
|
155
|
+
type: "string",
|
|
156
|
+
valueName: "path",
|
|
157
|
+
description: "Write the contract graph as JSON."
|
|
158
|
+
};
|
|
159
|
+
var graphMermaidOutputOption = {
|
|
160
|
+
name: "graph-mermaid-out",
|
|
161
|
+
type: "string",
|
|
162
|
+
valueName: "path",
|
|
163
|
+
description: "Write the contract graph as Mermaid source."
|
|
164
|
+
};
|
|
165
|
+
var defaultLocaleOption = {
|
|
166
|
+
name: "default-locale",
|
|
167
|
+
type: "string",
|
|
168
|
+
valueName: "locale",
|
|
169
|
+
description: "Default locale used for generated localization content.",
|
|
170
|
+
defaultValue: "en-GB"
|
|
171
|
+
};
|
|
172
|
+
var localesDirOption = {
|
|
173
|
+
name: "locales-dir",
|
|
174
|
+
type: "string",
|
|
175
|
+
valueName: "directory",
|
|
176
|
+
description: "Override the plugin localization directory."
|
|
177
|
+
};
|
|
178
|
+
var contractComparisonOptions = [
|
|
179
|
+
sourceDirectoryOption,
|
|
180
|
+
sourceManifestOption,
|
|
181
|
+
projectRootOption,
|
|
182
|
+
{
|
|
183
|
+
name: "baseline",
|
|
184
|
+
type: "string",
|
|
185
|
+
valueName: "path",
|
|
186
|
+
description: "Explicit Contract Baseline file."
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: "git-tag",
|
|
190
|
+
type: "string",
|
|
191
|
+
valueName: "tag",
|
|
192
|
+
description: "Resolve a Contract Baseline from a Git tag."
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: "git-baseline",
|
|
196
|
+
type: "string",
|
|
197
|
+
valueName: "path",
|
|
198
|
+
description: "Baseline path inside the selected Git tag."
|
|
199
|
+
},
|
|
200
|
+
{ ...repositoryBaselineOption, description: "Repository Contract Baseline path." },
|
|
201
|
+
{
|
|
202
|
+
name: "no-repository-baseline",
|
|
203
|
+
type: "boolean",
|
|
204
|
+
description: "Do not use the repository Contract Baseline provider."
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
name: "registry-url",
|
|
208
|
+
type: "string",
|
|
209
|
+
valueName: "url",
|
|
210
|
+
description: "Registry endpoint used to resolve a published Contract Baseline."
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: "registry-cache",
|
|
214
|
+
type: "string",
|
|
215
|
+
valueName: "directory",
|
|
216
|
+
description: "Registry Contract Baseline cache directory."
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
name: "registry-name",
|
|
220
|
+
type: "string",
|
|
221
|
+
valueName: "name",
|
|
222
|
+
description: "Registry name recorded in baseline provenance."
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
name: "installed-baseline",
|
|
226
|
+
type: "string",
|
|
227
|
+
valueName: "paths",
|
|
228
|
+
description: "Comma-separated candidate Contract Baseline files from installed plugins."
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
name: "publish",
|
|
232
|
+
type: "boolean",
|
|
233
|
+
description: "Use publish-mode compatibility rules."
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
name: "offline",
|
|
237
|
+
type: "boolean",
|
|
238
|
+
description: "Do not perform network baseline resolution."
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: "strict",
|
|
242
|
+
type: "boolean",
|
|
243
|
+
description: "Fail when the resulting compatibility report contains breaking changes."
|
|
244
|
+
},
|
|
245
|
+
jsonOutputOption,
|
|
246
|
+
{
|
|
247
|
+
name: "no-devtools-report",
|
|
248
|
+
type: "boolean",
|
|
249
|
+
description: "Do not write the default frontend/generated/compatibility-report.json artifact."
|
|
250
|
+
}
|
|
251
|
+
];
|
|
252
|
+
var PLUGIN_BUILD_CLI_SPEC = [
|
|
253
|
+
{
|
|
254
|
+
id: "templates",
|
|
255
|
+
path: ["templates"],
|
|
256
|
+
summary: "List canonical Plugmatica plugin starters.",
|
|
257
|
+
description: "Lists the verified starter templates packaged with @plugmatica/plugin-build. Use --json for IDE, CI and AI-agent discovery including required template parameters.",
|
|
258
|
+
options: [
|
|
259
|
+
{
|
|
260
|
+
name: "json",
|
|
261
|
+
type: "boolean",
|
|
262
|
+
description: "Emit the canonical starter catalogue as machine-readable JSON."
|
|
263
|
+
}
|
|
264
|
+
],
|
|
265
|
+
examples: ["plugmatica templates", "plugmatica templates --json"]
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
id: "create",
|
|
269
|
+
path: ["create"],
|
|
270
|
+
summary: "Create a Plugmatica plugin from a verified starter.",
|
|
271
|
+
description: "Materializes a portable public projection of a canonical example and personalizes package identity. Select a canonical starter using --template or list available starters with plugmatica templates.",
|
|
272
|
+
positionals: [
|
|
273
|
+
{
|
|
274
|
+
name: "directory",
|
|
275
|
+
description: "Directory in which the plugin package will be created.",
|
|
276
|
+
required: true
|
|
277
|
+
}
|
|
278
|
+
],
|
|
279
|
+
options: [
|
|
280
|
+
{
|
|
281
|
+
name: "template",
|
|
282
|
+
type: "string",
|
|
283
|
+
valueName: "id",
|
|
284
|
+
description: "Canonical starter ID. Defaults to frontend-minimal; run 'plugmatica templates' to list IDs."
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
name: "plugin-key",
|
|
288
|
+
type: "string",
|
|
289
|
+
valueName: "key",
|
|
290
|
+
description: "Plugin key. Defaults to an example.* key derived from the directory name."
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
name: "name",
|
|
294
|
+
type: "string",
|
|
295
|
+
valueName: "name",
|
|
296
|
+
description: "Human-readable plugin name."
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
name: "description",
|
|
300
|
+
type: "string",
|
|
301
|
+
valueName: "text",
|
|
302
|
+
description: "Plugin description written to the source manifest."
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
name: "author",
|
|
306
|
+
type: "string",
|
|
307
|
+
valueName: "name",
|
|
308
|
+
description: "Plugin author written to the source manifest."
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
name: "module-name",
|
|
312
|
+
type: "string",
|
|
313
|
+
valueName: "name",
|
|
314
|
+
description: "Module Federation module name for frontend-bearing templates."
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
name: "target-surface",
|
|
318
|
+
type: "string",
|
|
319
|
+
valueName: "surface",
|
|
320
|
+
description: "Public UI surface type for the frontend-extension capability target."
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
name: "target-key",
|
|
324
|
+
type: "string",
|
|
325
|
+
valueName: "key",
|
|
326
|
+
description: "Public semantic surface key for the frontend-extension capability target."
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
name: "target-point",
|
|
330
|
+
type: "string",
|
|
331
|
+
valueName: "point",
|
|
332
|
+
description: "Public extension point for the frontend-extension capability target."
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
name: "target-contract-id",
|
|
336
|
+
type: "string",
|
|
337
|
+
valueName: "id",
|
|
338
|
+
description: "Versioned public UI contract identifier for the frontend-extension starter."
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
name: "target-contract-version",
|
|
342
|
+
type: "string",
|
|
343
|
+
valueName: "range",
|
|
344
|
+
description: "Compatible public UI contract version range (defaults to ^1.0.0)."
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
name: "provider-key",
|
|
348
|
+
type: "string",
|
|
349
|
+
valueName: "key",
|
|
350
|
+
description: "Public provider capability key for the frontend-provider-event starter."
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
name: "provider-contract-id",
|
|
354
|
+
type: "string",
|
|
355
|
+
valueName: "id",
|
|
356
|
+
description: "Versioned public provider contract identifier."
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
name: "provider-contract-version",
|
|
360
|
+
type: "string",
|
|
361
|
+
valueName: "range",
|
|
362
|
+
description: "Compatible public provider contract version range (defaults to ^1.0.0)."
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
name: "event-key",
|
|
366
|
+
type: "string",
|
|
367
|
+
valueName: "key",
|
|
368
|
+
description: "Public event capability key for the frontend-provider-event starter."
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
name: "event-contract-id",
|
|
372
|
+
type: "string",
|
|
373
|
+
valueName: "id",
|
|
374
|
+
description: "Versioned public event contract identifier."
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
name: "event-contract-version",
|
|
378
|
+
type: "string",
|
|
379
|
+
valueName: "range",
|
|
380
|
+
description: "Compatible public event contract version range (defaults to ^1.0.0)."
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
name: "force",
|
|
384
|
+
type: "boolean",
|
|
385
|
+
description: "Replace a non-empty destination directory instead of refusing to overwrite it."
|
|
386
|
+
}
|
|
387
|
+
],
|
|
388
|
+
examples: [
|
|
389
|
+
"plugmatica create ./my-plugin --template frontend-minimal",
|
|
390
|
+
'plugmatica create ./orders --template full-stack-minimal --plugin-key acme.orders --name "Orders"',
|
|
391
|
+
"plugmatica create ./customer-extension --template frontend-extension --target-surface tabs --target-key customer.detail.related --target-point items --target-contract-id plugmatica.ui.tabs"
|
|
392
|
+
]
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
id: "build",
|
|
396
|
+
path: ["build"],
|
|
397
|
+
summary: "Compile plugin source and generate manifest/build-time artifacts.",
|
|
398
|
+
description: "Runs the semantic compiler and writes the generated runtime manifest plus optional typed targets, compatibility contract, docs, graph and devtools artifacts.",
|
|
399
|
+
options: [
|
|
400
|
+
defaultManifestOption,
|
|
401
|
+
frontendSourceOption,
|
|
402
|
+
{
|
|
403
|
+
name: "out",
|
|
404
|
+
type: "string",
|
|
405
|
+
valueName: "path",
|
|
406
|
+
description: "Generated manifest output path. Defaults to manifest.json beside the source manifest."
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
name: "backend-descriptor",
|
|
410
|
+
type: "string",
|
|
411
|
+
valueName: "path",
|
|
412
|
+
description: "Optional backend descriptor to merge into build validation."
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
name: "fail-on-warnings",
|
|
416
|
+
type: "boolean",
|
|
417
|
+
description: "Treat compiler warnings as build failures."
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
name: "fix-i18n",
|
|
421
|
+
type: "boolean",
|
|
422
|
+
description: "Rewrite eligible raw UI strings into generated localization keys before compiling."
|
|
423
|
+
},
|
|
424
|
+
defaultLocaleOption,
|
|
425
|
+
localesDirOption,
|
|
426
|
+
{
|
|
427
|
+
name: "allow-raw-strings",
|
|
428
|
+
type: "boolean",
|
|
429
|
+
description: "Do not fail the build when raw user-visible strings remain."
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
name: "no-targets",
|
|
433
|
+
type: "boolean",
|
|
434
|
+
description: "Do not emit typed extension targets."
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
name: "targets-out",
|
|
438
|
+
type: "string",
|
|
439
|
+
valueName: "directory",
|
|
440
|
+
description: "Override the generated typed-target output directory."
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
name: "no-current-contract",
|
|
444
|
+
type: "boolean",
|
|
445
|
+
description: "Do not emit the Current Extension Contract."
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
name: "current-contract-out",
|
|
449
|
+
type: "string",
|
|
450
|
+
valueName: "path",
|
|
451
|
+
description: "Override the Current Extension Contract output path."
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
name: "devtools",
|
|
455
|
+
type: "boolean",
|
|
456
|
+
description: "Emit extension diagnostics for developer tooling."
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
name: "devtools-out",
|
|
460
|
+
type: "string",
|
|
461
|
+
valueName: "path",
|
|
462
|
+
description: "Override the extension devtools diagnostics output path and enable the artifact."
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
name: "no-docs",
|
|
466
|
+
type: "boolean",
|
|
467
|
+
description: "Do not emit generated extension developer documentation."
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
name: "docs-out",
|
|
471
|
+
type: "string",
|
|
472
|
+
valueName: "directory",
|
|
473
|
+
description: "Override the generated extension documentation directory."
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
name: "graph",
|
|
477
|
+
type: "boolean",
|
|
478
|
+
description: "Emit the extension contract graph."
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
name: "graph-out",
|
|
482
|
+
type: "string",
|
|
483
|
+
valueName: "directory",
|
|
484
|
+
description: "Override the extension graph output directory and enable graph generation."
|
|
485
|
+
}
|
|
486
|
+
],
|
|
487
|
+
examples: [
|
|
488
|
+
"plugmatica build --manifest manifest.source.json --src frontend/src",
|
|
489
|
+
"plugmatica build --fix-i18n --fail-on-warnings"
|
|
490
|
+
]
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
id: "backend-build",
|
|
494
|
+
path: ["backend", "build"],
|
|
495
|
+
summary: "Compile a backend facet to WASM and generate its descriptor.",
|
|
496
|
+
description: "Runs Cargo against the generated starter/project, copies the cdylib WASM to backend.entryPoint, then invokes the public plugmatica-plugin-describe tool. No Plugmatica source checkout is required.",
|
|
497
|
+
options: [
|
|
498
|
+
backendRootOption,
|
|
499
|
+
backendManifestOption,
|
|
500
|
+
{
|
|
501
|
+
name: "cargo-manifest",
|
|
502
|
+
type: "string",
|
|
503
|
+
valueName: "path",
|
|
504
|
+
description: "Backend Cargo manifest path relative to the plugin root.",
|
|
505
|
+
defaultValue: "backend/Cargo.toml"
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
name: "target",
|
|
509
|
+
type: "string",
|
|
510
|
+
valueName: "triple",
|
|
511
|
+
description: "Rust target used for the backend guest.",
|
|
512
|
+
defaultValue: "wasm32-unknown-unknown"
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
name: "profile",
|
|
516
|
+
type: "string",
|
|
517
|
+
valueName: "profile",
|
|
518
|
+
description: "Cargo build profile for the backend guest.",
|
|
519
|
+
choices: ["release", "debug"],
|
|
520
|
+
defaultValue: "release"
|
|
521
|
+
},
|
|
522
|
+
descriptorOutOption,
|
|
523
|
+
previousDescriptorOption,
|
|
524
|
+
describeBinOption
|
|
525
|
+
],
|
|
526
|
+
examples: [
|
|
527
|
+
"plugmatica backend build",
|
|
528
|
+
"plugmatica backend build --previous-descriptor ./previous-descriptor.json"
|
|
529
|
+
]
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
id: "backend-describe",
|
|
533
|
+
path: ["backend", "describe"],
|
|
534
|
+
summary: "Generate the backend descriptor from an existing plugin WASM.",
|
|
535
|
+
description: "Invokes the public plugmatica-plugin-describe binary against backend.entryPoint (or --wasm) and writes backend/descriptor.json by default.",
|
|
536
|
+
options: [
|
|
537
|
+
backendRootOption,
|
|
538
|
+
backendManifestOption,
|
|
539
|
+
{
|
|
540
|
+
name: "wasm",
|
|
541
|
+
type: "string",
|
|
542
|
+
valueName: "path",
|
|
543
|
+
description: "WASM path. Defaults to backend.entryPoint from the source manifest."
|
|
544
|
+
},
|
|
545
|
+
descriptorOutOption,
|
|
546
|
+
previousDescriptorOption,
|
|
547
|
+
describeBinOption
|
|
548
|
+
],
|
|
549
|
+
examples: [
|
|
550
|
+
"plugmatica backend describe",
|
|
551
|
+
"plugmatica backend describe --wasm backend/plugin.wasm --previous-descriptor previous.json"
|
|
552
|
+
]
|
|
553
|
+
},
|
|
554
|
+
{
|
|
555
|
+
id: "package",
|
|
556
|
+
path: ["package"],
|
|
557
|
+
summary: "Assemble the built facets/resources into one runtime plugin package.",
|
|
558
|
+
description: "Creates the immutable runtime package directory from public build outputs. Frontend projects should run their normal Vite build first; backend projects should run 'plugmatica backend build' first.",
|
|
559
|
+
options: [
|
|
560
|
+
{ ...backendRootOption, description: "Plugin source package root." },
|
|
561
|
+
backendManifestOption,
|
|
562
|
+
{
|
|
563
|
+
name: "generated-manifest",
|
|
564
|
+
type: "string",
|
|
565
|
+
valueName: "path",
|
|
566
|
+
description: "Frontend compiler-generated manifest path.",
|
|
567
|
+
defaultValue: "manifest.json"
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
name: "frontend-dist",
|
|
571
|
+
type: "string",
|
|
572
|
+
valueName: "directory",
|
|
573
|
+
description: "Built frontend output directory.",
|
|
574
|
+
defaultValue: "frontend/dist"
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
name: "backend-descriptor",
|
|
578
|
+
type: "string",
|
|
579
|
+
valueName: "path",
|
|
580
|
+
description: "Generated backend descriptor path.",
|
|
581
|
+
defaultValue: "backend/descriptor.json"
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
name: "out",
|
|
585
|
+
type: "string",
|
|
586
|
+
valueName: "directory",
|
|
587
|
+
description: "Assembled package output directory.",
|
|
588
|
+
defaultValue: "dist/plugin"
|
|
589
|
+
}
|
|
590
|
+
],
|
|
591
|
+
examples: [
|
|
592
|
+
"plugmatica package",
|
|
593
|
+
"plugmatica package --out ./dist/orders-plugin"
|
|
594
|
+
]
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
id: "install",
|
|
598
|
+
path: ["install"],
|
|
599
|
+
summary: "Install an assembled plugin into a runtime/dev-target bundle root.",
|
|
600
|
+
description: "Copies a validated assembled package to <bundle-root>/<plugin-key>/<version>. Use --bundle-root or PLUGMATICA_PLUGIN_BUNDLE_ROOT to select the target.",
|
|
601
|
+
options: [
|
|
602
|
+
assembledPackageOption,
|
|
603
|
+
{
|
|
604
|
+
name: "bundle-root",
|
|
605
|
+
type: "string",
|
|
606
|
+
valueName: "directory",
|
|
607
|
+
description: "Runtime/dev-target plugin bundle root. Falls back to PLUGMATICA_PLUGIN_BUNDLE_ROOT."
|
|
608
|
+
}
|
|
609
|
+
],
|
|
610
|
+
examples: [
|
|
611
|
+
"plugmatica install --bundle-root /srv/plugmatica/runtime-plugins",
|
|
612
|
+
"PLUGMATICA_PLUGIN_BUNDLE_ROOT=./runtime-plugins plugmatica install"
|
|
613
|
+
]
|
|
614
|
+
},
|
|
615
|
+
{
|
|
616
|
+
id: "dev-up",
|
|
617
|
+
path: ["dev", "up"],
|
|
618
|
+
summary: "Start the source-less local Plugmatica plugin development target.",
|
|
619
|
+
description: "Runs the packaged Docker Compose target using published Runtime API, Runtime Shell and Keycloak images. No Plugmatica source checkout is required.",
|
|
620
|
+
options: [
|
|
621
|
+
devProjectOption
|
|
622
|
+
],
|
|
623
|
+
examples: [
|
|
624
|
+
"plugmatica dev up",
|
|
625
|
+
"PLUGMATICA_DEV_RUNTIME_IMAGE=ghcr.io/plugmatica/runtime-api:beta plugmatica dev up"
|
|
626
|
+
]
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
id: "dev-status",
|
|
630
|
+
path: ["dev", "status"],
|
|
631
|
+
summary: "Show the local Plugmatica plugin development target status.",
|
|
632
|
+
options: [
|
|
633
|
+
devProjectOption
|
|
634
|
+
],
|
|
635
|
+
examples: ["plugmatica dev status"]
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
id: "dev-install",
|
|
639
|
+
path: ["dev", "install"],
|
|
640
|
+
summary: "Install and hot-reconcile a packaged plugin in the local development target.",
|
|
641
|
+
description: "Validates the assembled package, copies it into the Runtime API container and calls the authenticated plugin reconciliation endpoint. Development mode permits same-version refreshes.",
|
|
642
|
+
options: [
|
|
643
|
+
assembledPackageOption,
|
|
644
|
+
devProjectOption,
|
|
645
|
+
{
|
|
646
|
+
name: "runtime-url",
|
|
647
|
+
type: "string",
|
|
648
|
+
valueName: "url",
|
|
649
|
+
description: "Runtime API base URL. Defaults to the configured local dev-target port."
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
name: "keycloak-url",
|
|
653
|
+
type: "string",
|
|
654
|
+
valueName: "url",
|
|
655
|
+
description: "Keycloak base URL. Defaults to the configured local dev-target port."
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
name: "username",
|
|
659
|
+
type: "string",
|
|
660
|
+
valueName: "username",
|
|
661
|
+
description: "Development administrator username.",
|
|
662
|
+
defaultValue: "plugmatica-admin"
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
name: "password",
|
|
666
|
+
type: "string",
|
|
667
|
+
valueName: "password",
|
|
668
|
+
description: "Development administrator password.",
|
|
669
|
+
defaultValue: "plugmatica-dev-admin"
|
|
670
|
+
}
|
|
671
|
+
],
|
|
672
|
+
examples: [
|
|
673
|
+
"plugmatica dev install",
|
|
674
|
+
"plugmatica dev install --package ./dist/plugin"
|
|
675
|
+
]
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
id: "dev-logs",
|
|
679
|
+
path: ["dev", "logs"],
|
|
680
|
+
summary: "Show logs from the local Plugmatica plugin development target.",
|
|
681
|
+
options: [
|
|
682
|
+
devProjectOption,
|
|
683
|
+
{
|
|
684
|
+
name: "service",
|
|
685
|
+
type: "string",
|
|
686
|
+
valueName: "service",
|
|
687
|
+
description: "Optional Compose service, for example runtime-api or runtime-shell."
|
|
688
|
+
},
|
|
689
|
+
{
|
|
690
|
+
name: "follow",
|
|
691
|
+
type: "boolean",
|
|
692
|
+
description: "Follow log output until interrupted."
|
|
693
|
+
}
|
|
694
|
+
],
|
|
695
|
+
examples: [
|
|
696
|
+
"plugmatica dev logs --service runtime-api",
|
|
697
|
+
"plugmatica dev logs --follow"
|
|
698
|
+
]
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
id: "dev-stop",
|
|
702
|
+
path: ["dev", "stop"],
|
|
703
|
+
summary: "Stop the local Plugmatica plugin development target without deleting data.",
|
|
704
|
+
options: [
|
|
705
|
+
devProjectOption
|
|
706
|
+
],
|
|
707
|
+
examples: ["plugmatica dev stop"]
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
id: "dev-reset",
|
|
711
|
+
path: ["dev", "reset"],
|
|
712
|
+
summary: "Delete local Plugmatica plugin development target containers and data.",
|
|
713
|
+
options: [
|
|
714
|
+
devProjectOption
|
|
715
|
+
],
|
|
716
|
+
examples: ["plugmatica dev reset"]
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
id: "contract-init",
|
|
720
|
+
path: ["contract", "init"],
|
|
721
|
+
summary: "Create the repository Contract Baseline from the current plugin contract.",
|
|
722
|
+
options: [
|
|
723
|
+
sourceDirectoryOption,
|
|
724
|
+
sourceManifestOption,
|
|
725
|
+
projectRootOption,
|
|
726
|
+
repositoryBaselineOption
|
|
727
|
+
],
|
|
728
|
+
examples: [
|
|
729
|
+
"plugmatica contract init --src frontend/src --manifest manifest.source.json"
|
|
730
|
+
]
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
id: "contract-check",
|
|
734
|
+
path: ["contract", "check"],
|
|
735
|
+
summary: "Compare the current contract with available Contract Baselines.",
|
|
736
|
+
options: contractComparisonOptions,
|
|
737
|
+
examples: [
|
|
738
|
+
"plugmatica contract check --src frontend/src --manifest manifest.source.json --strict"
|
|
739
|
+
]
|
|
740
|
+
},
|
|
741
|
+
{
|
|
742
|
+
id: "contract-diff",
|
|
743
|
+
path: ["contract", "diff"],
|
|
744
|
+
summary: "Render the current compatibility difference against available Contract Baselines.",
|
|
745
|
+
description: "Uses the same baseline resolution and report model as contract check; add --strict when the diff must fail on breaking changes.",
|
|
746
|
+
options: contractComparisonOptions,
|
|
747
|
+
examples: [
|
|
748
|
+
"plugmatica contract diff --src frontend/src --manifest manifest.source.json --baseline ./previous.contract.json"
|
|
749
|
+
]
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
id: "contract-update",
|
|
753
|
+
path: ["contract", "update"],
|
|
754
|
+
summary: "Replace the repository Contract Baseline with the current plugin contract.",
|
|
755
|
+
options: [
|
|
756
|
+
sourceDirectoryOption,
|
|
757
|
+
sourceManifestOption,
|
|
758
|
+
projectRootOption,
|
|
759
|
+
repositoryBaselineOption
|
|
760
|
+
],
|
|
761
|
+
examples: [
|
|
762
|
+
"plugmatica contract update --src frontend/src --manifest manifest.source.json"
|
|
763
|
+
]
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
id: "contract-history",
|
|
767
|
+
path: ["contract", "history"],
|
|
768
|
+
summary: "Generate release-history compatibility visualisations from Contract Baselines.",
|
|
769
|
+
options: [
|
|
770
|
+
{
|
|
771
|
+
name: "baselines",
|
|
772
|
+
type: "string",
|
|
773
|
+
valueName: "paths",
|
|
774
|
+
description: "Comma-separated Contract Baseline files in release-history order.",
|
|
775
|
+
required: true
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
name: "out",
|
|
779
|
+
type: "string",
|
|
780
|
+
valueName: "directory",
|
|
781
|
+
description: "Output directory for Markdown, Mermaid and JSON history artifacts.",
|
|
782
|
+
defaultValue: "frontend/generated/contract-history"
|
|
783
|
+
}
|
|
784
|
+
],
|
|
785
|
+
examples: [
|
|
786
|
+
"plugmatica contract history --baselines v1.contract.json,v2.contract.json --out frontend/generated/contract-history"
|
|
787
|
+
]
|
|
788
|
+
},
|
|
789
|
+
{
|
|
790
|
+
id: "workflow-inspect",
|
|
791
|
+
path: ["workflow", "inspect"],
|
|
792
|
+
summary: "Inspect Workflow backend/UI facets in an assembled plugin package.",
|
|
793
|
+
description: "Offline package audit. Supply an API registry JSON snapshot to compare effective backend actions; actual browser loading must be tested separately.",
|
|
794
|
+
options: [
|
|
795
|
+
{ ...assembledPackageOption, description: "Assembled package directory containing manifest.json (default dist/plugin)." },
|
|
796
|
+
{
|
|
797
|
+
name: "registry-json",
|
|
798
|
+
type: "string",
|
|
799
|
+
valueName: "path",
|
|
800
|
+
description: "Saved /api/workflow-node-types API response for the intended scope and locale."
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
name: "require-ui",
|
|
804
|
+
type: "boolean",
|
|
805
|
+
description: "Require catalog/editor/presentation for every packaged action (backend-only actions are otherwise allowed)."
|
|
806
|
+
},
|
|
807
|
+
jsonOutputOption
|
|
808
|
+
],
|
|
809
|
+
examples: [
|
|
810
|
+
"plugmatica workflow inspect --package dist/plugin --require-ui",
|
|
811
|
+
"plugmatica workflow inspect --package dist/plugin --registry-json effective-nodes.json --json-out inspection.json"
|
|
812
|
+
]
|
|
813
|
+
},
|
|
814
|
+
{
|
|
815
|
+
id: "inspect",
|
|
816
|
+
path: ["inspect"],
|
|
817
|
+
summary: "Inspect the compiled plugin contract and dependency graph.",
|
|
818
|
+
options: [
|
|
819
|
+
sourceDirectoryOption,
|
|
820
|
+
sourceManifestOption,
|
|
821
|
+
jsonOutputOption,
|
|
822
|
+
graphJsonOutputOption,
|
|
823
|
+
graphMermaidOutputOption
|
|
824
|
+
],
|
|
825
|
+
examples: [
|
|
826
|
+
"plugmatica inspect --src frontend/src --manifest manifest.source.json"
|
|
827
|
+
]
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
id: "extensions",
|
|
831
|
+
path: ["extensions"],
|
|
832
|
+
summary: "List the plugin's compiled extension inventory.",
|
|
833
|
+
options: [
|
|
834
|
+
sourceDirectoryOption,
|
|
835
|
+
sourceManifestOption,
|
|
836
|
+
jsonOutputOption,
|
|
837
|
+
graphJsonOutputOption,
|
|
838
|
+
graphMermaidOutputOption
|
|
839
|
+
],
|
|
840
|
+
examples: [
|
|
841
|
+
"plugmatica extensions --src frontend/src --manifest manifest.source.json"
|
|
842
|
+
]
|
|
843
|
+
},
|
|
844
|
+
{
|
|
845
|
+
id: "extensions-fix",
|
|
846
|
+
path: ["extensions", "fix"],
|
|
847
|
+
summary: "Remove compiler-proven redundant extension overrides.",
|
|
848
|
+
description: "Removes only extension props whose public key is identical to the compiler-derived semantic identity. Intentional ABI overrides are left unchanged.",
|
|
849
|
+
options: [
|
|
850
|
+
defaultManifestOption,
|
|
851
|
+
frontendSourceOption,
|
|
852
|
+
{
|
|
853
|
+
name: "dry-run",
|
|
854
|
+
type: "boolean",
|
|
855
|
+
description: "Report safe removals without changing source files."
|
|
856
|
+
}
|
|
857
|
+
],
|
|
858
|
+
examples: [
|
|
859
|
+
"plugmatica extensions fix --manifest manifest.source.json --dry-run",
|
|
860
|
+
"plugmatica extensions fix --manifest manifest.source.json"
|
|
861
|
+
]
|
|
862
|
+
},
|
|
863
|
+
{
|
|
864
|
+
id: "protocol-verify",
|
|
865
|
+
path: ["protocol", "verify"],
|
|
866
|
+
summary: "Verify frontend protocol constants against the Rust backend contract.",
|
|
867
|
+
options: [
|
|
868
|
+
{
|
|
869
|
+
name: "backend-root",
|
|
870
|
+
type: "string",
|
|
871
|
+
valueName: "directory",
|
|
872
|
+
description: "Backend workspace root containing the canonical Rust protocol source.",
|
|
873
|
+
required: true
|
|
874
|
+
},
|
|
875
|
+
jsonOutputOption
|
|
876
|
+
],
|
|
877
|
+
examples: ["plugmatica protocol verify --backend-root ../../backend"]
|
|
878
|
+
},
|
|
879
|
+
{
|
|
880
|
+
id: "boundaries-check",
|
|
881
|
+
path: ["boundaries", "check"],
|
|
882
|
+
summary: "Audit public frontend package dependency boundaries.",
|
|
883
|
+
options: [
|
|
884
|
+
{ ...backendRootOption, description: "Frontend packages root to audit." }
|
|
885
|
+
],
|
|
886
|
+
examples: ["plugmatica boundaries check --root ."]
|
|
887
|
+
},
|
|
888
|
+
{
|
|
889
|
+
id: "i18n-doctor",
|
|
890
|
+
path: ["i18n", "doctor"],
|
|
891
|
+
summary: "Audit plugin translation ownership, duplication and catalogue drift.",
|
|
892
|
+
description: "Reports unused default-locale keys, exact duplicate copy, case/punctuation variants and messages that can use canonical $common vocabulary. The command is advisory unless --strict is supplied.",
|
|
893
|
+
options: [
|
|
894
|
+
defaultManifestOption,
|
|
895
|
+
frontendSourceOption,
|
|
896
|
+
{ ...defaultLocaleOption, description: "Default locale to audit." },
|
|
897
|
+
{ ...localesDirOption, description: "Override the runtime localization directory." },
|
|
898
|
+
{
|
|
899
|
+
name: "strict",
|
|
900
|
+
type: "boolean",
|
|
901
|
+
description: "Return a failing exit code when housekeeping findings remain."
|
|
902
|
+
},
|
|
903
|
+
jsonOutputOption
|
|
904
|
+
],
|
|
905
|
+
examples: [
|
|
906
|
+
"plugmatica i18n doctor --manifest manifest.source.json",
|
|
907
|
+
"plugmatica i18n doctor --manifest manifest.source.json --strict --json-out ./i18n-audit.json"
|
|
908
|
+
]
|
|
909
|
+
},
|
|
910
|
+
{
|
|
911
|
+
id: "i18n-fix",
|
|
912
|
+
path: ["i18n", "fix"],
|
|
913
|
+
summary: "Convert eligible raw plugin UI strings into localization keys.",
|
|
914
|
+
options: [
|
|
915
|
+
defaultManifestOption,
|
|
916
|
+
frontendSourceOption,
|
|
917
|
+
{ ...defaultLocaleOption, description: "Default locale receiving generated strings." },
|
|
918
|
+
{ ...localesDirOption, description: "Override the localization directory." },
|
|
919
|
+
{
|
|
920
|
+
name: "dry-run",
|
|
921
|
+
type: "boolean",
|
|
922
|
+
description: "Report rewrites without changing source or locale files."
|
|
923
|
+
}
|
|
924
|
+
],
|
|
925
|
+
examples: ["plugmatica i18n fix --manifest manifest.source.json --dry-run"]
|
|
926
|
+
},
|
|
927
|
+
{
|
|
928
|
+
id: "release-check",
|
|
929
|
+
path: ["release", "check"],
|
|
930
|
+
summary: "Audit public package release policy and built declaration dependencies.",
|
|
931
|
+
options: [
|
|
932
|
+
{ ...backendRootOption, description: "Repository root to audit." }
|
|
933
|
+
],
|
|
934
|
+
examples: ["plugmatica release check --root ."]
|
|
935
|
+
}
|
|
936
|
+
];
|
|
937
|
+
|
|
938
|
+
// src/cli/runtime.ts
|
|
939
|
+
function commandUsage(spec) {
|
|
940
|
+
const positionals = (spec.positionals ?? []).map((item) => item.required ? `<${item.name}>` : `[${item.name}]`).join(" ");
|
|
941
|
+
return [PLUGIN_BUILD_CLI_NAME, ...spec.path, positionals, "[options]"].filter(Boolean).join(" ");
|
|
942
|
+
}
|
|
943
|
+
function commandOptions(spec) {
|
|
944
|
+
return Object.fromEntries(
|
|
945
|
+
(spec.options ?? []).map((option) => [
|
|
946
|
+
option.name,
|
|
947
|
+
{
|
|
948
|
+
type: option.type
|
|
949
|
+
}
|
|
950
|
+
])
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
function validateParsedCommand(spec, options, positionals) {
|
|
954
|
+
const positionalSpec = spec.positionals ?? [];
|
|
955
|
+
const requiredPositionals = positionalSpec.filter(
|
|
956
|
+
(item) => item.required
|
|
957
|
+
).length;
|
|
958
|
+
if (positionals.length < requiredPositionals) {
|
|
959
|
+
const missing = positionalSpec[positionals.length];
|
|
960
|
+
throw new Error(
|
|
961
|
+
`Missing ${missing ? `<${missing.name}>` : "required positional argument"}.
|
|
962
|
+
Usage: ${commandUsage(spec)}`
|
|
963
|
+
);
|
|
964
|
+
}
|
|
965
|
+
if (positionals.length > positionalSpec.length) {
|
|
966
|
+
throw new Error(
|
|
967
|
+
`Unexpected positional argument '${positionals[positionalSpec.length]}'.
|
|
968
|
+
Usage: ${commandUsage(spec)}`
|
|
969
|
+
);
|
|
970
|
+
}
|
|
971
|
+
for (const option of spec.options ?? []) {
|
|
972
|
+
const value = options[option.name];
|
|
973
|
+
if (option.required && !value) {
|
|
974
|
+
throw new Error(
|
|
975
|
+
`Missing --${option.name}.
|
|
976
|
+
Usage: ${commandUsage(spec)}`
|
|
977
|
+
);
|
|
978
|
+
}
|
|
979
|
+
if (value && option.choices && !option.choices.includes(value)) {
|
|
980
|
+
throw new Error(
|
|
981
|
+
`Invalid --${option.name} '${value}'. Expected one of: ${option.choices.join(", ")}.`
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
function resolvePluginBuildCliCommand(argv) {
|
|
987
|
+
const candidates = [...PLUGIN_BUILD_CLI_SPEC].sort(
|
|
988
|
+
(left, right) => right.path.length - left.path.length
|
|
989
|
+
);
|
|
990
|
+
const matched = candidates.find(
|
|
991
|
+
(candidate) => candidate.path.every((part, index) => argv[index] === part)
|
|
992
|
+
);
|
|
993
|
+
if (matched) return { spec: matched, rest: argv.slice(matched.path.length) };
|
|
994
|
+
if (argv.length === 0 || argv[0]?.startsWith("--")) {
|
|
995
|
+
const build = PLUGIN_BUILD_CLI_SPEC.find(
|
|
996
|
+
(command) => command.id === "build"
|
|
997
|
+
);
|
|
998
|
+
if (!build) throw new Error("CLI build command specification is missing.");
|
|
999
|
+
return { spec: build, rest: argv };
|
|
1000
|
+
}
|
|
1001
|
+
throw new Error(
|
|
1002
|
+
`Unknown command '${argv.slice(0, 2).join(" ")}'.
|
|
1003
|
+
|
|
1004
|
+
${renderPluginBuildCliRootHelp()}`
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
function parsePluginBuildCliCommand(spec, argv) {
|
|
1008
|
+
const parsed = parseArgs({
|
|
1009
|
+
args: argv,
|
|
1010
|
+
options: {
|
|
1011
|
+
...commandOptions(spec),
|
|
1012
|
+
help: { type: "boolean" }
|
|
1013
|
+
},
|
|
1014
|
+
allowPositionals: true,
|
|
1015
|
+
strict: true
|
|
1016
|
+
});
|
|
1017
|
+
if (parsed.values.help) {
|
|
1018
|
+
return { spec, options: { help: "true" }, positionals: parsed.positionals };
|
|
1019
|
+
}
|
|
1020
|
+
const options = {};
|
|
1021
|
+
for (const option of spec.options ?? []) {
|
|
1022
|
+
const parsedValue = parsed.values[option.name];
|
|
1023
|
+
if (typeof parsedValue === "boolean") {
|
|
1024
|
+
if (parsedValue) options[option.name] = "true";
|
|
1025
|
+
} else if (typeof parsedValue === "string") {
|
|
1026
|
+
options[option.name] = parsedValue;
|
|
1027
|
+
} else if (option.defaultValue !== void 0) {
|
|
1028
|
+
options[option.name] = String(option.defaultValue);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
validateParsedCommand(spec, options, parsed.positionals);
|
|
1032
|
+
return { spec, options, positionals: parsed.positionals };
|
|
1033
|
+
}
|
|
1034
|
+
function renderPluginBuildCliCommandHelp(spec) {
|
|
1035
|
+
const lines = [commandUsage(spec), "", spec.summary];
|
|
1036
|
+
if (spec.description) lines.push("", spec.description);
|
|
1037
|
+
if (spec.positionals?.length) {
|
|
1038
|
+
lines.push("", "Arguments:");
|
|
1039
|
+
for (const positional of spec.positionals) {
|
|
1040
|
+
lines.push(
|
|
1041
|
+
` ${positional.required ? `<${positional.name}>` : `[${positional.name}]`} ${positional.description}`
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
if (spec.options?.length) {
|
|
1046
|
+
lines.push("", "Options:");
|
|
1047
|
+
for (const option of spec.options) {
|
|
1048
|
+
const value = option.type === "string" ? ` <${option.valueName ?? "value"}>` : "";
|
|
1049
|
+
const suffix = [
|
|
1050
|
+
option.required ? "required" : null,
|
|
1051
|
+
option.defaultValue !== void 0 ? `default: ${String(option.defaultValue)}` : null,
|
|
1052
|
+
option.choices?.length ? `choices: ${option.choices.join("|")}` : null
|
|
1053
|
+
].filter(Boolean);
|
|
1054
|
+
lines.push(
|
|
1055
|
+
` --${option.name}${value} ${option.description}${suffix.length ? ` (${suffix.join("; ")})` : ""}`
|
|
1056
|
+
);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
lines.push(" --help Show this command help.");
|
|
1060
|
+
if (spec.examples?.length) {
|
|
1061
|
+
lines.push("", "Examples:");
|
|
1062
|
+
for (const example of spec.examples) lines.push(` ${example}`);
|
|
1063
|
+
}
|
|
1064
|
+
return `${lines.join("\n")}
|
|
1065
|
+
`;
|
|
1066
|
+
}
|
|
1067
|
+
function renderPluginBuildCliRootHelp() {
|
|
1068
|
+
const lines = [
|
|
1069
|
+
`${PLUGIN_BUILD_CLI_NAME} <command> [options]`,
|
|
1070
|
+
"",
|
|
1071
|
+
"Build, validate, inspect and scaffold Plugmatica plugins.",
|
|
1072
|
+
"",
|
|
1073
|
+
"Commands:"
|
|
1074
|
+
];
|
|
1075
|
+
for (const command of PLUGIN_BUILD_CLI_SPEC) {
|
|
1076
|
+
lines.push(` ${command.path.join(" ")} ${command.summary}`);
|
|
1077
|
+
}
|
|
1078
|
+
lines.push(
|
|
1079
|
+
"",
|
|
1080
|
+
`Aliases: ${PLUGIN_BUILD_CLI_ALIASES.join(", ")}`,
|
|
1081
|
+
`Run '${PLUGIN_BUILD_CLI_NAME} <command> --help' for command options.`
|
|
1082
|
+
);
|
|
1083
|
+
return `${lines.join("\n")}
|
|
1084
|
+
`;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
// src/lifecycle.ts
|
|
1088
|
+
import { spawnSync } from "child_process";
|
|
1089
|
+
import fs2 from "fs";
|
|
1090
|
+
import path2 from "path";
|
|
1091
|
+
|
|
1092
|
+
// src/backend-workflow-compatibility.ts
|
|
1093
|
+
import fs from "fs";
|
|
1094
|
+
import path from "path";
|
|
1095
|
+
function records(value) {
|
|
1096
|
+
return Array.isArray(value) ? value : [];
|
|
1097
|
+
}
|
|
1098
|
+
function workflowVisible(event) {
|
|
1099
|
+
return event?.workflow?.triggerable === true || event?.workflow?.publishable === true;
|
|
1100
|
+
}
|
|
1101
|
+
function compareBackendWorkflowCompatibility(previous, candidate) {
|
|
1102
|
+
const changes = [];
|
|
1103
|
+
const currentNodes = new Map(records(candidate.workflowNodes).map((node) => [node.nodeType, node]));
|
|
1104
|
+
for (const oldNode of records(previous.workflowNodes)) {
|
|
1105
|
+
const next = currentNodes.get(oldNode.nodeType);
|
|
1106
|
+
if (!next) {
|
|
1107
|
+
changes.push({
|
|
1108
|
+
kind: "workflow_node",
|
|
1109
|
+
identity: oldNode.nodeType,
|
|
1110
|
+
change: "removed",
|
|
1111
|
+
breaking: true,
|
|
1112
|
+
reason: "Published workflows may pin this node type."
|
|
1113
|
+
});
|
|
1114
|
+
continue;
|
|
1115
|
+
}
|
|
1116
|
+
if ((next.contractVersion ?? 1) < (oldNode.contractVersion ?? 1)) {
|
|
1117
|
+
changes.push({
|
|
1118
|
+
kind: "workflow_node",
|
|
1119
|
+
identity: oldNode.nodeType,
|
|
1120
|
+
change: "version_regressed",
|
|
1121
|
+
breaking: true,
|
|
1122
|
+
reason: `contractVersion regressed from ${oldNode.contractVersion ?? 1} to ${next.contractVersion ?? 1}.`
|
|
1123
|
+
});
|
|
1124
|
+
} else if (oldNode.contractFingerprint !== next.contractFingerprint && (oldNode.contractVersion ?? 1) === (next.contractVersion ?? 1)) {
|
|
1125
|
+
changes.push({
|
|
1126
|
+
kind: "workflow_node",
|
|
1127
|
+
identity: oldNode.nodeType,
|
|
1128
|
+
change: "contract_changed_without_version",
|
|
1129
|
+
breaking: true,
|
|
1130
|
+
reason: `Executable fingerprint changed without increasing contractVersion from ${oldNode.contractVersion ?? 1}.`
|
|
1131
|
+
});
|
|
1132
|
+
} else if (oldNode.contractFingerprint !== next.contractFingerprint) {
|
|
1133
|
+
changes.push({
|
|
1134
|
+
kind: "workflow_node",
|
|
1135
|
+
identity: oldNode.nodeType,
|
|
1136
|
+
change: "contract_changed",
|
|
1137
|
+
breaking: false,
|
|
1138
|
+
reason: `Executable fingerprint changed with contractVersion ${oldNode.contractVersion ?? 1} -> ${next.contractVersion ?? 1}.`
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
const currentEvents = new Map(records(candidate.events).map((event) => [event.key, event]));
|
|
1143
|
+
for (const oldEvent of records(previous.events).filter(workflowVisible)) {
|
|
1144
|
+
const next = currentEvents.get(oldEvent.key);
|
|
1145
|
+
if (!next) {
|
|
1146
|
+
changes.push({
|
|
1147
|
+
kind: "workflow_event",
|
|
1148
|
+
identity: oldEvent.key,
|
|
1149
|
+
change: "removed",
|
|
1150
|
+
breaking: true,
|
|
1151
|
+
reason: "A Workflow-visible owned event contract was removed."
|
|
1152
|
+
});
|
|
1153
|
+
continue;
|
|
1154
|
+
}
|
|
1155
|
+
if (oldEvent.workflow?.triggerable === true && next.workflow?.triggerable !== true) {
|
|
1156
|
+
changes.push({
|
|
1157
|
+
kind: "workflow_event",
|
|
1158
|
+
identity: oldEvent.key,
|
|
1159
|
+
change: "trigger_delegation_removed",
|
|
1160
|
+
breaking: true,
|
|
1161
|
+
reason: "Workflow trigger delegation was removed."
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
if (oldEvent.workflow?.publishable === true && next.workflow?.publishable !== true) {
|
|
1165
|
+
changes.push({
|
|
1166
|
+
kind: "workflow_event",
|
|
1167
|
+
identity: oldEvent.key,
|
|
1168
|
+
change: "publish_delegation_removed",
|
|
1169
|
+
breaking: true,
|
|
1170
|
+
reason: "Workflow publication delegation was removed."
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
if ((next.contractVersion ?? 1) < (oldEvent.contractVersion ?? 1)) {
|
|
1174
|
+
changes.push({
|
|
1175
|
+
kind: "workflow_event",
|
|
1176
|
+
identity: oldEvent.key,
|
|
1177
|
+
change: "version_regressed",
|
|
1178
|
+
breaking: true,
|
|
1179
|
+
reason: `contractVersion regressed from ${oldEvent.contractVersion ?? 1} to ${next.contractVersion ?? 1}.`
|
|
1180
|
+
});
|
|
1181
|
+
} else if (oldEvent.contractFingerprint !== next.contractFingerprint && (oldEvent.contractVersion ?? 1) === (next.contractVersion ?? 1)) {
|
|
1182
|
+
changes.push({
|
|
1183
|
+
kind: "workflow_event",
|
|
1184
|
+
identity: oldEvent.key,
|
|
1185
|
+
change: "contract_changed_without_version",
|
|
1186
|
+
breaking: true,
|
|
1187
|
+
reason: `Executable fingerprint changed without increasing contractVersion from ${oldEvent.contractVersion ?? 1}.`
|
|
1188
|
+
});
|
|
1189
|
+
} else if (oldEvent.contractFingerprint !== next.contractFingerprint) {
|
|
1190
|
+
changes.push({
|
|
1191
|
+
kind: "workflow_event",
|
|
1192
|
+
identity: oldEvent.key,
|
|
1193
|
+
change: "contract_changed",
|
|
1194
|
+
breaking: false,
|
|
1195
|
+
reason: `Executable fingerprint changed with contractVersion ${oldEvent.contractVersion ?? 1} -> ${next.contractVersion ?? 1}.`
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
const addedNodes = records(candidate.workflowNodes).filter(
|
|
1200
|
+
(node) => !records(previous.workflowNodes).some((old) => old.nodeType === node.nodeType)
|
|
1201
|
+
);
|
|
1202
|
+
for (const node of addedNodes) {
|
|
1203
|
+
changes.push({
|
|
1204
|
+
kind: "workflow_node",
|
|
1205
|
+
identity: node.nodeType,
|
|
1206
|
+
change: "added",
|
|
1207
|
+
breaking: false,
|
|
1208
|
+
reason: "New Workflow node contract."
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
const addedEvents = records(candidate.events).filter(
|
|
1212
|
+
(event) => workflowVisible(event) && !records(previous.events).some((old) => old.key === event.key)
|
|
1213
|
+
);
|
|
1214
|
+
for (const event of addedEvents) {
|
|
1215
|
+
changes.push({
|
|
1216
|
+
kind: "workflow_event",
|
|
1217
|
+
identity: event.key,
|
|
1218
|
+
change: "added",
|
|
1219
|
+
breaking: false,
|
|
1220
|
+
reason: "New Workflow-visible event contract."
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
changes.sort((a, b) => `${a.kind}:${a.identity}:${a.change}`.localeCompare(`${b.kind}:${b.identity}:${b.change}`));
|
|
1224
|
+
const breaking = changes.filter((change) => change.breaking).length;
|
|
1225
|
+
return {
|
|
1226
|
+
formatVersion: 1,
|
|
1227
|
+
status: breaking > 0 ? "breaking" : "compatible",
|
|
1228
|
+
breaking,
|
|
1229
|
+
changes
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
function formatBackendWorkflowCompatibility(report) {
|
|
1233
|
+
if (report.changes.length === 0) return "Workflow compatibility: no Workflow-facing contract changes.";
|
|
1234
|
+
const lines = [
|
|
1235
|
+
`Workflow compatibility: ${report.status} (${report.breaking} breaking change(s)).`
|
|
1236
|
+
];
|
|
1237
|
+
for (const change of report.changes) {
|
|
1238
|
+
lines.push(
|
|
1239
|
+
`- ${change.kind} ${change.identity}: ${change.change}${change.breaking ? " [BREAKING]" : ""} \u2014 ${change.reason}`
|
|
1240
|
+
);
|
|
1241
|
+
}
|
|
1242
|
+
return lines.join("\n");
|
|
1243
|
+
}
|
|
1244
|
+
function writeBackendWorkflowCompatibilityReport(file, report) {
|
|
1245
|
+
const resolved = path.resolve(file);
|
|
1246
|
+
fs.mkdirSync(path.dirname(resolved), { recursive: true });
|
|
1247
|
+
fs.writeFileSync(resolved, `${JSON.stringify(report, null, 2)}
|
|
1248
|
+
`);
|
|
1249
|
+
return resolved;
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
// src/lifecycle.ts
|
|
1253
|
+
var DEFAULT_WASM_TARGET = "wasm32-unknown-unknown";
|
|
1254
|
+
var DEFAULT_BACKEND_PROFILE = "release";
|
|
1255
|
+
var DEFAULT_DESCRIBE_BINARY = "plugmatica-plugin-describe";
|
|
1256
|
+
function buildPluginBackend(options = {}) {
|
|
1257
|
+
const root = path2.resolve(options.root ?? process.cwd());
|
|
1258
|
+
const sourceManifestPath = resolveFrom(
|
|
1259
|
+
root,
|
|
1260
|
+
options.manifest ?? "manifest.source.json"
|
|
1261
|
+
);
|
|
1262
|
+
const source = readJsonObject(sourceManifestPath, "source manifest");
|
|
1263
|
+
const backend = requiredRecord(
|
|
1264
|
+
source.backend,
|
|
1265
|
+
"manifest.source.json backend"
|
|
1266
|
+
);
|
|
1267
|
+
const entryPoint = requiredString(backend.entryPoint, "backend.entryPoint");
|
|
1268
|
+
const wasmDestination = resolvePackagePath(
|
|
1269
|
+
root,
|
|
1270
|
+
entryPoint,
|
|
1271
|
+
"backend.entryPoint"
|
|
1272
|
+
);
|
|
1273
|
+
const cargoManifest = resolveFrom(
|
|
1274
|
+
root,
|
|
1275
|
+
options.cargoManifest ?? "backend/Cargo.toml"
|
|
1276
|
+
);
|
|
1277
|
+
assertRegularFile(cargoManifest, "backend Cargo manifest");
|
|
1278
|
+
const target = options.target ?? DEFAULT_WASM_TARGET;
|
|
1279
|
+
const profile = options.profile ?? DEFAULT_BACKEND_PROFILE;
|
|
1280
|
+
const targetDir = path2.resolve(path2.dirname(cargoManifest), "target");
|
|
1281
|
+
const targetName = backendTargetName(cargoManifest);
|
|
1282
|
+
const profileDir = profile === "release" ? "release" : "debug";
|
|
1283
|
+
const wasmSource = path2.join(
|
|
1284
|
+
targetDir,
|
|
1285
|
+
target,
|
|
1286
|
+
profileDir,
|
|
1287
|
+
`${targetName.replaceAll("-", "_")}.wasm`
|
|
1288
|
+
);
|
|
1289
|
+
const cargoArgs = [
|
|
1290
|
+
"build",
|
|
1291
|
+
"--manifest-path",
|
|
1292
|
+
cargoManifest,
|
|
1293
|
+
"--target",
|
|
1294
|
+
target,
|
|
1295
|
+
"--target-dir",
|
|
1296
|
+
targetDir
|
|
1297
|
+
];
|
|
1298
|
+
if (profile === "release") cargoArgs.push("--release");
|
|
1299
|
+
runCommand("cargo", cargoArgs, {
|
|
1300
|
+
cwd: root,
|
|
1301
|
+
missingHint: "Install Rust/Cargo before building backend starters."
|
|
1302
|
+
});
|
|
1303
|
+
assertRegularFile(wasmSource, "compiled backend WASM");
|
|
1304
|
+
fs2.mkdirSync(path2.dirname(wasmDestination), { recursive: true });
|
|
1305
|
+
fs2.copyFileSync(wasmSource, wasmDestination);
|
|
1306
|
+
const described = describePluginBackend({
|
|
1307
|
+
root,
|
|
1308
|
+
manifest: sourceManifestPath,
|
|
1309
|
+
wasm: wasmDestination,
|
|
1310
|
+
descriptorOut: options.descriptorOut,
|
|
1311
|
+
previousDescriptor: options.previousDescriptor,
|
|
1312
|
+
describeBin: options.describeBin,
|
|
1313
|
+
compatibilityReportOut: options.compatibilityReportOut
|
|
1314
|
+
});
|
|
1315
|
+
return {
|
|
1316
|
+
root,
|
|
1317
|
+
wasm: described.wasm,
|
|
1318
|
+
descriptor: described.descriptor,
|
|
1319
|
+
target,
|
|
1320
|
+
profile
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
function describePluginBackend(options = {}) {
|
|
1324
|
+
const root = path2.resolve(options.root ?? process.cwd());
|
|
1325
|
+
const sourceManifestPath = resolveFrom(
|
|
1326
|
+
root,
|
|
1327
|
+
options.manifest ?? "manifest.source.json"
|
|
1328
|
+
);
|
|
1329
|
+
const source = readJsonObject(sourceManifestPath, "source manifest");
|
|
1330
|
+
const backend = requiredRecord(
|
|
1331
|
+
source.backend,
|
|
1332
|
+
"manifest.source.json backend"
|
|
1333
|
+
);
|
|
1334
|
+
const entryPoint = requiredString(backend.entryPoint, "backend.entryPoint");
|
|
1335
|
+
const wasm = resolveFrom(root, options.wasm ?? entryPoint);
|
|
1336
|
+
const descriptor = resolveFrom(
|
|
1337
|
+
root,
|
|
1338
|
+
options.descriptorOut ?? "backend/descriptor.json"
|
|
1339
|
+
);
|
|
1340
|
+
assertRegularFile(wasm, "backend WASM");
|
|
1341
|
+
const binary = options.describeBin ?? process.env.PLUGMATICA_PLUGIN_DESCRIBE_BIN ?? DEFAULT_DESCRIBE_BINARY;
|
|
1342
|
+
const commandOptions2 = {
|
|
1343
|
+
cwd: root,
|
|
1344
|
+
missingHint: "Install the public descriptor tool with `cargo install --locked plugmatica-describe`, or set PLUGMATICA_PLUGIN_DESCRIBE_BIN."
|
|
1345
|
+
};
|
|
1346
|
+
const previousDescriptor = options.previousDescriptor ? resolveFrom(root, options.previousDescriptor) : fs2.existsSync(descriptor) ? descriptor : void 0;
|
|
1347
|
+
if (previousDescriptor) {
|
|
1348
|
+
assertRegularFile(previousDescriptor, "previous backend descriptor");
|
|
1349
|
+
const candidate = `${descriptor}.workflow-candidate`;
|
|
1350
|
+
fs2.rmSync(candidate, { force: true });
|
|
1351
|
+
runCommand(binary, [wasm, candidate], commandOptions2);
|
|
1352
|
+
assertRegularFile(candidate, "candidate backend descriptor");
|
|
1353
|
+
assertValidBackendDescriptorFile(candidate);
|
|
1354
|
+
const previous = readJsonObject(previousDescriptor, "previous backend descriptor");
|
|
1355
|
+
const next = readJsonObject(candidate, "candidate backend descriptor");
|
|
1356
|
+
const workflowReport = compareBackendWorkflowCompatibility(previous, next);
|
|
1357
|
+
const reportPath = writeBackendWorkflowCompatibilityReport(
|
|
1358
|
+
resolveFrom(
|
|
1359
|
+
root,
|
|
1360
|
+
options.compatibilityReportOut ?? "backend/generated/workflow-compatibility-report.json"
|
|
1361
|
+
),
|
|
1362
|
+
workflowReport
|
|
1363
|
+
);
|
|
1364
|
+
fs2.rmSync(candidate, { force: true });
|
|
1365
|
+
try {
|
|
1366
|
+
runCommand(
|
|
1367
|
+
binary,
|
|
1368
|
+
[wasm, descriptor, "--previous", previousDescriptor],
|
|
1369
|
+
commandOptions2
|
|
1370
|
+
);
|
|
1371
|
+
} catch (error) {
|
|
1372
|
+
throw new Error(
|
|
1373
|
+
`${formatBackendWorkflowCompatibility(workflowReport)}
|
|
1374
|
+
Report: ${path2.relative(root, reportPath)}
|
|
1375
|
+
|
|
1376
|
+
${error instanceof Error ? error.message : String(error)}`
|
|
1377
|
+
);
|
|
1378
|
+
}
|
|
1379
|
+
} else {
|
|
1380
|
+
runCommand(binary, [wasm, descriptor], commandOptions2);
|
|
1381
|
+
}
|
|
1382
|
+
assertRegularFile(descriptor, "backend descriptor");
|
|
1383
|
+
assertValidBackendDescriptorFile(descriptor);
|
|
1384
|
+
return { root, wasm, descriptor };
|
|
1385
|
+
}
|
|
1386
|
+
function packagePlugin(options = {}) {
|
|
1387
|
+
const root = path2.resolve(options.root ?? process.cwd());
|
|
1388
|
+
const sourceManifestPath = resolveFrom(
|
|
1389
|
+
root,
|
|
1390
|
+
options.manifest ?? "manifest.source.json"
|
|
1391
|
+
);
|
|
1392
|
+
const source = readJsonObject(sourceManifestPath, "source manifest");
|
|
1393
|
+
assertSourceManifestOwnership(source, sourceManifestPath);
|
|
1394
|
+
const pluginKey = requiredString(source.key, "plugin key");
|
|
1395
|
+
const version = requiredString(source.version, "plugin version");
|
|
1396
|
+
const hasFrontend = isRecord(source.frontend);
|
|
1397
|
+
const hasBackend = isRecord(source.backend);
|
|
1398
|
+
const hasLocalization = isRecord(source.localization);
|
|
1399
|
+
if (!hasFrontend && !hasBackend && !hasLocalization) {
|
|
1400
|
+
throw new Error(
|
|
1401
|
+
`${sourceManifestPath}: plugin declares no frontend, backend, or localization facet.`
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
1404
|
+
const packageRoot = resolveFrom(root, options.out ?? "dist/plugin");
|
|
1405
|
+
assertOutputOutsideInputs(root, packageRoot, sourceManifestPath);
|
|
1406
|
+
fs2.rmSync(packageRoot, { recursive: true, force: true });
|
|
1407
|
+
fs2.mkdirSync(packageRoot, { recursive: true });
|
|
1408
|
+
let manifest = materializeBaseManifest(source);
|
|
1409
|
+
if (hasFrontend) {
|
|
1410
|
+
const generatedManifestPath = resolveFrom(
|
|
1411
|
+
root,
|
|
1412
|
+
options.generatedManifest ?? "manifest.json"
|
|
1413
|
+
);
|
|
1414
|
+
const generated = readJsonObject(
|
|
1415
|
+
generatedManifestPath,
|
|
1416
|
+
"generated frontend manifest"
|
|
1417
|
+
);
|
|
1418
|
+
assertGeneratedManifestMatchesSource(
|
|
1419
|
+
source,
|
|
1420
|
+
generated,
|
|
1421
|
+
generatedManifestPath
|
|
1422
|
+
);
|
|
1423
|
+
manifest = generated;
|
|
1424
|
+
const frontendDist = resolveFrom(
|
|
1425
|
+
root,
|
|
1426
|
+
options.frontendDist ?? "frontend/dist"
|
|
1427
|
+
);
|
|
1428
|
+
assertDirectory(frontendDist, "frontend build output");
|
|
1429
|
+
copyRegularTree(frontendDist, path2.join(packageRoot, "frontend"));
|
|
1430
|
+
const frontendI18n = path2.join(root, "frontend", "i18n");
|
|
1431
|
+
if (fs2.existsSync(frontendI18n)) {
|
|
1432
|
+
assertDirectory(frontendI18n, "frontend localization directory");
|
|
1433
|
+
copyRegularTree(frontendI18n, path2.join(packageRoot, "frontend", "i18n"));
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
if (hasBackend) {
|
|
1437
|
+
const backend = requiredRecord(
|
|
1438
|
+
manifest.backend,
|
|
1439
|
+
"generated backend manifest"
|
|
1440
|
+
);
|
|
1441
|
+
if (Object.hasOwn(backend, "descriptor")) {
|
|
1442
|
+
throw new Error(
|
|
1443
|
+
"Generated/runtime manifest must not embed backend.descriptor; use backend/descriptor.json."
|
|
1444
|
+
);
|
|
1445
|
+
}
|
|
1446
|
+
const entryPoint = requiredString(backend.entryPoint, "backend.entryPoint");
|
|
1447
|
+
const wasm = resolvePackagePath(root, entryPoint, "backend.entryPoint");
|
|
1448
|
+
assertRegularFile(wasm, "backend entry point");
|
|
1449
|
+
copyRegularFile(
|
|
1450
|
+
wasm,
|
|
1451
|
+
resolvePackagePath(packageRoot, entryPoint, "backend.entryPoint")
|
|
1452
|
+
);
|
|
1453
|
+
const descriptor = resolveFrom(
|
|
1454
|
+
root,
|
|
1455
|
+
options.backendDescriptor ?? "backend/descriptor.json"
|
|
1456
|
+
);
|
|
1457
|
+
assertRegularFile(descriptor, "backend descriptor");
|
|
1458
|
+
assertValidBackendDescriptorFile(descriptor);
|
|
1459
|
+
const backendDescriptor = readJsonObject(descriptor, "backend descriptor");
|
|
1460
|
+
if (hasFrontend) {
|
|
1461
|
+
assertBackendManifestProjection(manifest, backendDescriptor);
|
|
1462
|
+
} else {
|
|
1463
|
+
Object.assign(manifest, projectBackendManifest(source, backendDescriptor));
|
|
1464
|
+
}
|
|
1465
|
+
copyRegularFile(
|
|
1466
|
+
descriptor,
|
|
1467
|
+
path2.join(packageRoot, "backend", "descriptor.json")
|
|
1468
|
+
);
|
|
1469
|
+
}
|
|
1470
|
+
const seeds = path2.join(root, "backend", "seeds");
|
|
1471
|
+
if (fs2.existsSync(seeds)) {
|
|
1472
|
+
assertDirectory(seeds, "backend seed directory");
|
|
1473
|
+
const development = path2.join(seeds, "development.yaml");
|
|
1474
|
+
assertRegularFile(development, "backend/seeds/development.yaml");
|
|
1475
|
+
copyRegularTree(seeds, path2.join(packageRoot, "backend", "seeds"));
|
|
1476
|
+
}
|
|
1477
|
+
copyDeclaredLocalizationResources(root, packageRoot, manifest);
|
|
1478
|
+
writeJson(path2.join(packageRoot, "manifest.json"), manifest);
|
|
1479
|
+
validateAssembledPackage(packageRoot, manifest);
|
|
1480
|
+
return {
|
|
1481
|
+
root,
|
|
1482
|
+
packageRoot,
|
|
1483
|
+
pluginKey,
|
|
1484
|
+
version,
|
|
1485
|
+
facets: {
|
|
1486
|
+
frontend: hasFrontend,
|
|
1487
|
+
backend: hasBackend,
|
|
1488
|
+
localization: hasLocalization
|
|
1489
|
+
}
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1492
|
+
function installPluginPackage(options = {}) {
|
|
1493
|
+
const packageRoot = path2.resolve(
|
|
1494
|
+
options.packageRoot ?? path2.join(process.cwd(), "dist/plugin")
|
|
1495
|
+
);
|
|
1496
|
+
assertDirectory(packageRoot, "assembled plugin package");
|
|
1497
|
+
const manifestPath = path2.join(packageRoot, "manifest.json");
|
|
1498
|
+
const manifest = readJsonObject(manifestPath, "assembled plugin manifest");
|
|
1499
|
+
const pluginKey = assertBundlePathSegment(
|
|
1500
|
+
requiredString(manifest.key, "plugin key"),
|
|
1501
|
+
"plugin key"
|
|
1502
|
+
);
|
|
1503
|
+
const version = assertBundlePathSegment(
|
|
1504
|
+
requiredString(manifest.version, "plugin version"),
|
|
1505
|
+
"plugin version"
|
|
1506
|
+
);
|
|
1507
|
+
validateAssembledPackage(packageRoot, manifest);
|
|
1508
|
+
const configuredBundleRoot = options.bundleRoot ?? process.env.PLUGMATICA_PLUGIN_BUNDLE_ROOT;
|
|
1509
|
+
if (!configuredBundleRoot?.trim()) {
|
|
1510
|
+
throw new Error(
|
|
1511
|
+
"A runtime/dev-target bundle root is required. Pass --bundle-root or set PLUGMATICA_PLUGIN_BUNDLE_ROOT."
|
|
1512
|
+
);
|
|
1513
|
+
}
|
|
1514
|
+
const bundleRoot = path2.resolve(configuredBundleRoot);
|
|
1515
|
+
const installRoot = path2.join(bundleRoot, pluginKey, version);
|
|
1516
|
+
if (pathsOverlap(packageRoot, installRoot)) {
|
|
1517
|
+
throw new Error(
|
|
1518
|
+
`Install destination '${installRoot}' overlaps assembled package '${packageRoot}'. Choose a separate bundle root.`
|
|
1519
|
+
);
|
|
1520
|
+
}
|
|
1521
|
+
fs2.mkdirSync(bundleRoot, { recursive: true });
|
|
1522
|
+
fs2.rmSync(installRoot, { recursive: true, force: true });
|
|
1523
|
+
copyRegularTree(packageRoot, installRoot);
|
|
1524
|
+
return { packageRoot, installRoot, pluginKey, version };
|
|
1525
|
+
}
|
|
1526
|
+
function backendTargetName(cargoManifest) {
|
|
1527
|
+
const output = runCommand(
|
|
1528
|
+
"cargo",
|
|
1529
|
+
[
|
|
1530
|
+
"metadata",
|
|
1531
|
+
"--manifest-path",
|
|
1532
|
+
cargoManifest,
|
|
1533
|
+
"--format-version",
|
|
1534
|
+
"1",
|
|
1535
|
+
"--no-deps"
|
|
1536
|
+
],
|
|
1537
|
+
{
|
|
1538
|
+
cwd: path2.dirname(cargoManifest),
|
|
1539
|
+
capture: true,
|
|
1540
|
+
missingHint: "Install Rust/Cargo before building backend starters."
|
|
1541
|
+
}
|
|
1542
|
+
);
|
|
1543
|
+
let metadata;
|
|
1544
|
+
try {
|
|
1545
|
+
metadata = JSON.parse(output);
|
|
1546
|
+
} catch {
|
|
1547
|
+
throw new Error(
|
|
1548
|
+
`cargo metadata returned invalid JSON for ${cargoManifest}.`
|
|
1549
|
+
);
|
|
1550
|
+
}
|
|
1551
|
+
const canonical = fs2.realpathSync(cargoManifest);
|
|
1552
|
+
const pkg = (metadata.packages ?? []).find((candidate) => {
|
|
1553
|
+
if (typeof candidate?.manifest_path !== "string") return false;
|
|
1554
|
+
try {
|
|
1555
|
+
return fs2.realpathSync(candidate.manifest_path) === canonical;
|
|
1556
|
+
} catch {
|
|
1557
|
+
return path2.resolve(candidate.manifest_path) === path2.resolve(cargoManifest);
|
|
1558
|
+
}
|
|
1559
|
+
});
|
|
1560
|
+
const target = pkg?.targets?.find(
|
|
1561
|
+
(candidate) => candidate?.crate_types?.includes("cdylib") || candidate?.kind?.includes("cdylib")
|
|
1562
|
+
);
|
|
1563
|
+
if (!target?.name)
|
|
1564
|
+
throw new Error(`Unable to determine cdylib target from ${cargoManifest}.`);
|
|
1565
|
+
return String(target.name);
|
|
1566
|
+
}
|
|
1567
|
+
function materializeBaseManifest(source) {
|
|
1568
|
+
return {
|
|
1569
|
+
manifestVersion: PLUGIN_MANIFEST_VERSION,
|
|
1570
|
+
protocolVersion: PLUGIN_PROTOCOL_VERSION,
|
|
1571
|
+
...source
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
function assertSourceManifestOwnership(source, file) {
|
|
1575
|
+
for (const field of ["kind", "manifestVersion", "protocolVersion"]) {
|
|
1576
|
+
if (Object.hasOwn(source, field)) {
|
|
1577
|
+
throw new Error(
|
|
1578
|
+
`${file}: source manifests must omit compiler-owned '${field}'.`
|
|
1579
|
+
);
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
if (isRecord(source.backend)) assertBackendProjectionSourceOwnership(source);
|
|
1583
|
+
if (isRecord(source.backend) && Object.hasOwn(source.backend, "descriptor")) {
|
|
1584
|
+
throw new Error(
|
|
1585
|
+
`${file}: backend.descriptor is generated and must not be authored.`
|
|
1586
|
+
);
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
function assertGeneratedManifestMatchesSource(source, generated, file) {
|
|
1590
|
+
if (requiredString(generated.key, "generated plugin key") !== requiredString(source.key, "plugin key")) {
|
|
1591
|
+
throw new Error(
|
|
1592
|
+
`${file}: generated plugin key does not match manifest.source.json.`
|
|
1593
|
+
);
|
|
1594
|
+
}
|
|
1595
|
+
if (requiredString(generated.version, "generated plugin version") !== requiredString(source.version, "plugin version")) {
|
|
1596
|
+
throw new Error(
|
|
1597
|
+
`${file}: generated plugin version does not match manifest.source.json.`
|
|
1598
|
+
);
|
|
1599
|
+
}
|
|
1600
|
+
if (generated.manifestVersion !== PLUGIN_MANIFEST_VERSION) {
|
|
1601
|
+
throw new Error(
|
|
1602
|
+
`${file}: manifestVersion must be ${PLUGIN_MANIFEST_VERSION}.`
|
|
1603
|
+
);
|
|
1604
|
+
}
|
|
1605
|
+
if (generated.protocolVersion !== PLUGIN_PROTOCOL_VERSION) {
|
|
1606
|
+
throw new Error(
|
|
1607
|
+
`${file}: protocolVersion must be '${PLUGIN_PROTOCOL_VERSION}'.`
|
|
1608
|
+
);
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
function validateAssembledPackage(packageRoot, manifest) {
|
|
1612
|
+
if (manifest.manifestVersion !== PLUGIN_MANIFEST_VERSION) {
|
|
1613
|
+
throw new Error(
|
|
1614
|
+
`Assembled manifest must use manifestVersion ${PLUGIN_MANIFEST_VERSION}.`
|
|
1615
|
+
);
|
|
1616
|
+
}
|
|
1617
|
+
if (manifest.protocolVersion !== PLUGIN_PROTOCOL_VERSION) {
|
|
1618
|
+
throw new Error(
|
|
1619
|
+
`Assembled manifest must use protocolVersion '${PLUGIN_PROTOCOL_VERSION}'.`
|
|
1620
|
+
);
|
|
1621
|
+
}
|
|
1622
|
+
if (isRecord(manifest.frontend)) {
|
|
1623
|
+
const entry = requiredString(
|
|
1624
|
+
manifest.frontend.entryPoint,
|
|
1625
|
+
"frontend.entryPoint"
|
|
1626
|
+
);
|
|
1627
|
+
assertRegularFile(
|
|
1628
|
+
resolvePackagePath(packageRoot, entry, "frontend.entryPoint"),
|
|
1629
|
+
"packaged frontend entry point"
|
|
1630
|
+
);
|
|
1631
|
+
}
|
|
1632
|
+
if (isRecord(manifest.backend)) {
|
|
1633
|
+
const entry = requiredString(
|
|
1634
|
+
manifest.backend.entryPoint,
|
|
1635
|
+
"backend.entryPoint"
|
|
1636
|
+
);
|
|
1637
|
+
assertRegularFile(
|
|
1638
|
+
resolvePackagePath(packageRoot, entry, "backend.entryPoint"),
|
|
1639
|
+
"packaged backend entry point"
|
|
1640
|
+
);
|
|
1641
|
+
const descriptor = path2.join(packageRoot, "backend", "descriptor.json");
|
|
1642
|
+
assertRegularFile(descriptor, "packaged backend descriptor");
|
|
1643
|
+
assertValidBackendDescriptorFile(descriptor);
|
|
1644
|
+
assertBackendManifestProjection(
|
|
1645
|
+
manifest,
|
|
1646
|
+
readJsonObject(descriptor, "packaged backend descriptor")
|
|
1647
|
+
);
|
|
1648
|
+
}
|
|
1649
|
+
for (const resource of localizationResourcePaths(manifest)) {
|
|
1650
|
+
assertRegularFile(
|
|
1651
|
+
resolvePackagePath(packageRoot, resource, "localization resource"),
|
|
1652
|
+
`packaged localization resource '${resource}'`
|
|
1653
|
+
);
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
function copyDeclaredLocalizationResources(sourceRoot, packageRoot, manifest) {
|
|
1657
|
+
for (const resource of localizationResourcePaths(manifest)) {
|
|
1658
|
+
const from = resolvePackagePath(
|
|
1659
|
+
sourceRoot,
|
|
1660
|
+
resource,
|
|
1661
|
+
"localization resource"
|
|
1662
|
+
);
|
|
1663
|
+
const to = resolvePackagePath(
|
|
1664
|
+
packageRoot,
|
|
1665
|
+
resource,
|
|
1666
|
+
"localization resource"
|
|
1667
|
+
);
|
|
1668
|
+
assertRegularFile(from, `localization resource '${resource}'`);
|
|
1669
|
+
copyRegularFile(from, to);
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
function localizationResourcePaths(manifest) {
|
|
1673
|
+
if (!isRecord(manifest.localization) || !Array.isArray(manifest.localization.resources))
|
|
1674
|
+
return [];
|
|
1675
|
+
return manifest.localization.resources.flatMap((entry) => {
|
|
1676
|
+
if (!isRecord(entry) || typeof entry.path !== "string" || !entry.path.trim())
|
|
1677
|
+
return [];
|
|
1678
|
+
return [entry.path.trim()];
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1681
|
+
function resolveFrom(root, value) {
|
|
1682
|
+
return path2.isAbsolute(value) ? path2.normalize(value) : path2.resolve(root, value);
|
|
1683
|
+
}
|
|
1684
|
+
function resolvePackagePath(root, relative, label) {
|
|
1685
|
+
if (path2.isAbsolute(relative))
|
|
1686
|
+
throw new Error(`${label} must be package-relative: ${relative}`);
|
|
1687
|
+
const normalized = relative.replaceAll("\\", "/");
|
|
1688
|
+
if (normalized === ".." || normalized.startsWith("../") || normalized.includes("/../") || normalized.endsWith("/..")) {
|
|
1689
|
+
throw new Error(`${label} escapes the plugin package: ${relative}`);
|
|
1690
|
+
}
|
|
1691
|
+
const resolved = path2.resolve(root, ...normalized.split("/"));
|
|
1692
|
+
const prefix = `${path2.resolve(root)}${path2.sep}`;
|
|
1693
|
+
if (resolved !== path2.resolve(root) && !resolved.startsWith(prefix)) {
|
|
1694
|
+
throw new Error(`${label} escapes the plugin package: ${relative}`);
|
|
1695
|
+
}
|
|
1696
|
+
return resolved;
|
|
1697
|
+
}
|
|
1698
|
+
function assertOutputOutsideInputs(root, output, manifestPath) {
|
|
1699
|
+
const resolvedRoot = path2.resolve(root);
|
|
1700
|
+
const resolvedOutput = path2.resolve(output);
|
|
1701
|
+
if (resolvedOutput === resolvedRoot || resolvedRoot.startsWith(`${resolvedOutput}${path2.sep}`)) {
|
|
1702
|
+
throw new Error(
|
|
1703
|
+
`Package output '${output}' would replace the plugin source root. Choose an output such as dist/plugin or a separate directory.`
|
|
1704
|
+
);
|
|
1705
|
+
}
|
|
1706
|
+
if (resolvedOutput === path2.resolve(manifestPath)) {
|
|
1707
|
+
throw new Error(
|
|
1708
|
+
`Package output '${output}' conflicts with the source manifest.`
|
|
1709
|
+
);
|
|
1710
|
+
}
|
|
1711
|
+
for (const protectedPath of [
|
|
1712
|
+
path2.join(root, "frontend"),
|
|
1713
|
+
path2.join(root, "backend"),
|
|
1714
|
+
path2.join(root, "localization")
|
|
1715
|
+
]) {
|
|
1716
|
+
if (pathsOverlap(output, protectedPath)) {
|
|
1717
|
+
throw new Error(
|
|
1718
|
+
`Package output '${output}' overlaps protected plugin input '${protectedPath}'. Choose an output such as dist/plugin or a directory outside the source package.`
|
|
1719
|
+
);
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
function pathsOverlap(left, right) {
|
|
1724
|
+
const a = path2.resolve(left);
|
|
1725
|
+
const b = path2.resolve(right);
|
|
1726
|
+
return a === b || a.startsWith(`${b}${path2.sep}`) || b.startsWith(`${a}${path2.sep}`);
|
|
1727
|
+
}
|
|
1728
|
+
function readJsonObject(file, label) {
|
|
1729
|
+
assertRegularFile(file, label);
|
|
1730
|
+
let value;
|
|
1731
|
+
try {
|
|
1732
|
+
value = JSON.parse(fs2.readFileSync(file, "utf8"));
|
|
1733
|
+
} catch (error) {
|
|
1734
|
+
throw new Error(
|
|
1735
|
+
`${label} ${file} is invalid JSON: ${error instanceof Error ? error.message : String(error)}`
|
|
1736
|
+
);
|
|
1737
|
+
}
|
|
1738
|
+
if (!isRecord(value))
|
|
1739
|
+
throw new Error(`${label} ${file} must be a JSON object.`);
|
|
1740
|
+
return value;
|
|
1741
|
+
}
|
|
1742
|
+
function requiredRecord(value, label) {
|
|
1743
|
+
if (!isRecord(value)) throw new Error(`${label} must be an object.`);
|
|
1744
|
+
return value;
|
|
1745
|
+
}
|
|
1746
|
+
function requiredString(value, label) {
|
|
1747
|
+
if (typeof value !== "string" || !value.trim())
|
|
1748
|
+
throw new Error(`${label} must be a non-empty string.`);
|
|
1749
|
+
return value.trim();
|
|
1750
|
+
}
|
|
1751
|
+
function assertBundlePathSegment(value, label) {
|
|
1752
|
+
if (value === "." || value === ".." || /[\/\\\x00-\x1f]/.test(value)) {
|
|
1753
|
+
throw new Error(`${label} must be a single filesystem path segment.`);
|
|
1754
|
+
}
|
|
1755
|
+
return value;
|
|
1756
|
+
}
|
|
1757
|
+
function assertRegularFile(file, label) {
|
|
1758
|
+
if (!fs2.existsSync(file) || !fs2.statSync(file).isFile()) {
|
|
1759
|
+
throw new Error(`${label} is missing: ${file}`);
|
|
1760
|
+
}
|
|
1761
|
+
if (fs2.lstatSync(file).isSymbolicLink())
|
|
1762
|
+
throw new Error(`${label} may not be a symlink: ${file}`);
|
|
1763
|
+
}
|
|
1764
|
+
function assertDirectory(directory, label) {
|
|
1765
|
+
if (!fs2.existsSync(directory) || !fs2.statSync(directory).isDirectory()) {
|
|
1766
|
+
throw new Error(`${label} is missing: ${directory}`);
|
|
1767
|
+
}
|
|
1768
|
+
if (fs2.lstatSync(directory).isSymbolicLink())
|
|
1769
|
+
throw new Error(`${label} may not be a symlink: ${directory}`);
|
|
1770
|
+
}
|
|
1771
|
+
function copyRegularFile(from, to) {
|
|
1772
|
+
assertRegularFile(from, "package artifact");
|
|
1773
|
+
fs2.mkdirSync(path2.dirname(to), { recursive: true });
|
|
1774
|
+
fs2.copyFileSync(from, to);
|
|
1775
|
+
}
|
|
1776
|
+
function copyRegularTree(from, to) {
|
|
1777
|
+
assertDirectory(from, "package source directory");
|
|
1778
|
+
fs2.mkdirSync(to, { recursive: true });
|
|
1779
|
+
for (const entry of fs2.readdirSync(from, { withFileTypes: true })) {
|
|
1780
|
+
const source = path2.join(from, entry.name);
|
|
1781
|
+
const target = path2.join(to, entry.name);
|
|
1782
|
+
const metadata = fs2.lstatSync(source);
|
|
1783
|
+
if (metadata.isSymbolicLink())
|
|
1784
|
+
throw new Error(
|
|
1785
|
+
`Plugin package resources may not contain symlinks: ${source}`
|
|
1786
|
+
);
|
|
1787
|
+
if (metadata.isDirectory()) copyRegularTree(source, target);
|
|
1788
|
+
else if (metadata.isFile()) copyRegularFile(source, target);
|
|
1789
|
+
else throw new Error(`Unsupported package resource: ${source}`);
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
function writeJson(file, value) {
|
|
1793
|
+
fs2.mkdirSync(path2.dirname(file), { recursive: true });
|
|
1794
|
+
fs2.writeFileSync(file, `${JSON.stringify(value, null, 2)}
|
|
1795
|
+
`, "utf8");
|
|
1796
|
+
}
|
|
1797
|
+
function runCommand(command, args, options) {
|
|
1798
|
+
const executable = process.platform === "win32" && command === "cargo" ? "cargo.exe" : command;
|
|
1799
|
+
const result = spawnSync(executable, args, {
|
|
1800
|
+
cwd: options.cwd,
|
|
1801
|
+
env: process.env,
|
|
1802
|
+
encoding: "utf8",
|
|
1803
|
+
stdio: options.capture ? ["ignore", "pipe", "pipe"] : "inherit",
|
|
1804
|
+
shell: false
|
|
1805
|
+
});
|
|
1806
|
+
if (result.error) {
|
|
1807
|
+
const hint = options.missingHint ? ` ${options.missingHint}` : "";
|
|
1808
|
+
throw new Error(
|
|
1809
|
+
`Unable to start '${command}': ${result.error.message}.${hint}`
|
|
1810
|
+
);
|
|
1811
|
+
}
|
|
1812
|
+
if (result.status !== 0) {
|
|
1813
|
+
const detail = options.capture ? `${result.stderr ?? ""}${result.stdout ?? ""}`.trim() : "";
|
|
1814
|
+
throw new Error(
|
|
1815
|
+
detail || `'${command}' exited with status ${result.status ?? "unknown"}.`
|
|
1816
|
+
);
|
|
1817
|
+
}
|
|
1818
|
+
return options.capture ? String(result.stdout ?? "").trim() : "";
|
|
1819
|
+
}
|
|
1820
|
+
function isRecord(value) {
|
|
1821
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
// src/dev-target.ts
|
|
1825
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
1826
|
+
import fs3 from "fs";
|
|
1827
|
+
import os from "os";
|
|
1828
|
+
import path3 from "path";
|
|
1829
|
+
import { fileURLToPath } from "url";
|
|
1830
|
+
var DEFAULT_PROJECT = "plugmatica-plugin-dev";
|
|
1831
|
+
var DEFAULT_RUNTIME_PORT = "5150";
|
|
1832
|
+
var DEFAULT_SHELL_PORT = "8081";
|
|
1833
|
+
var DEFAULT_KEYCLOAK_PORT = "8080";
|
|
1834
|
+
var DEFAULT_USERNAME = "plugmatica-admin";
|
|
1835
|
+
var DEFAULT_PASSWORD = "plugmatica-dev-admin";
|
|
1836
|
+
function pluginDevTargetComposePath() {
|
|
1837
|
+
return fileURLToPath(new URL("../dev-target/compose.yaml", import.meta.url));
|
|
1838
|
+
}
|
|
1839
|
+
function pluginDevTargetEndpoints() {
|
|
1840
|
+
const runtimePort = process.env.PLUGMATICA_DEV_RUNTIME_API_PORT ?? DEFAULT_RUNTIME_PORT;
|
|
1841
|
+
const shellPort = process.env.PLUGMATICA_DEV_SHELL_PORT ?? DEFAULT_SHELL_PORT;
|
|
1842
|
+
const keycloakPort = process.env.PLUGMATICA_DEV_KEYCLOAK_PORT ?? DEFAULT_KEYCLOAK_PORT;
|
|
1843
|
+
const mailpitPort = process.env.PLUGMATICA_DEV_MAILPIT_UI_PORT ?? "8025";
|
|
1844
|
+
return {
|
|
1845
|
+
shell: `http://localhost:${shellPort}`,
|
|
1846
|
+
runtimeApi: `http://localhost:${runtimePort}`,
|
|
1847
|
+
keycloak: `http://localhost:${keycloakPort}`,
|
|
1848
|
+
mailpit: `http://localhost:${mailpitPort}`
|
|
1849
|
+
};
|
|
1850
|
+
}
|
|
1851
|
+
async function startPluginDevTarget(options = {}) {
|
|
1852
|
+
assertDevTargetAsset();
|
|
1853
|
+
runDockerCompose(options, ["up", "-d", "--remove-orphans"]);
|
|
1854
|
+
const endpoints = pluginDevTargetEndpoints();
|
|
1855
|
+
await waitForHttp(
|
|
1856
|
+
`${endpoints.keycloak}/realms/plugmatica/.well-known/openid-configuration`,
|
|
1857
|
+
12e4
|
|
1858
|
+
);
|
|
1859
|
+
await waitForHttp(
|
|
1860
|
+
`${endpoints.runtimeApi}/api/me`,
|
|
1861
|
+
12e4,
|
|
1862
|
+
/* @__PURE__ */ new Set([200, 401, 403])
|
|
1863
|
+
);
|
|
1864
|
+
return endpoints;
|
|
1865
|
+
}
|
|
1866
|
+
function stopPluginDevTarget(options = {}) {
|
|
1867
|
+
assertDevTargetAsset();
|
|
1868
|
+
runDockerCompose(options, ["stop"]);
|
|
1869
|
+
}
|
|
1870
|
+
function resetPluginDevTarget(options = {}) {
|
|
1871
|
+
assertDevTargetAsset();
|
|
1872
|
+
runDockerCompose(options, ["down", "--volumes", "--remove-orphans"]);
|
|
1873
|
+
}
|
|
1874
|
+
function statusPluginDevTarget(options = {}) {
|
|
1875
|
+
assertDevTargetAsset();
|
|
1876
|
+
runDockerCompose(options, ["ps"]);
|
|
1877
|
+
}
|
|
1878
|
+
function logsPluginDevTarget(options = {}) {
|
|
1879
|
+
assertDevTargetAsset();
|
|
1880
|
+
const args = ["logs"];
|
|
1881
|
+
if (options.follow) args.push("--follow");
|
|
1882
|
+
if (options.service) args.push(options.service);
|
|
1883
|
+
runDockerCompose(options, args);
|
|
1884
|
+
}
|
|
1885
|
+
async function installIntoPluginDevTarget(options = {}) {
|
|
1886
|
+
assertDevTargetAsset();
|
|
1887
|
+
const packageRoot = path3.resolve(
|
|
1888
|
+
options.packageRoot ?? path3.join(process.cwd(), "dist/plugin")
|
|
1889
|
+
);
|
|
1890
|
+
const stagingRoot = fs3.mkdtempSync(
|
|
1891
|
+
path3.join(os.tmpdir(), "plugmatica-dev-install-")
|
|
1892
|
+
);
|
|
1893
|
+
try {
|
|
1894
|
+
const staged = installPluginPackage({
|
|
1895
|
+
packageRoot,
|
|
1896
|
+
bundleRoot: stagingRoot
|
|
1897
|
+
});
|
|
1898
|
+
const container = captureDockerCompose(options, [
|
|
1899
|
+
"ps",
|
|
1900
|
+
"-q",
|
|
1901
|
+
"runtime-api"
|
|
1902
|
+
]).trim();
|
|
1903
|
+
if (!container) {
|
|
1904
|
+
throw new Error(
|
|
1905
|
+
"Plugmatica development target is not running. Run `plugmatica dev up` first."
|
|
1906
|
+
);
|
|
1907
|
+
}
|
|
1908
|
+
const containerRoot = `/app/runtime-plugins/${staged.pluginKey}/${staged.version}`;
|
|
1909
|
+
runDocker(["exec", container, "rm", "-rf", containerRoot]);
|
|
1910
|
+
runDocker(["exec", container, "mkdir", "-p", containerRoot]);
|
|
1911
|
+
runDocker([
|
|
1912
|
+
"cp",
|
|
1913
|
+
`${staged.installRoot}${path3.sep}.`,
|
|
1914
|
+
`${container}:${containerRoot}`
|
|
1915
|
+
]);
|
|
1916
|
+
const endpoints = pluginDevTargetEndpoints();
|
|
1917
|
+
const runtimeUrl = options.runtimeUrl ?? endpoints.runtimeApi;
|
|
1918
|
+
const keycloakUrl = options.keycloakUrl ?? endpoints.keycloak;
|
|
1919
|
+
const token = await developmentAccessToken({
|
|
1920
|
+
keycloakUrl,
|
|
1921
|
+
username: options.username ?? DEFAULT_USERNAME,
|
|
1922
|
+
password: options.password ?? DEFAULT_PASSWORD
|
|
1923
|
+
});
|
|
1924
|
+
const response = await fetch(`${runtimeUrl}/api/admin/plugins/reconcile`, {
|
|
1925
|
+
method: "POST",
|
|
1926
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
1927
|
+
});
|
|
1928
|
+
const body = await responseBody(response);
|
|
1929
|
+
if (!response.ok) {
|
|
1930
|
+
throw new Error(
|
|
1931
|
+
`Runtime plugin reconciliation failed (${response.status}): ${formatBody(body)}`
|
|
1932
|
+
);
|
|
1933
|
+
}
|
|
1934
|
+
const inventoryResponse = await fetch(`${runtimeUrl}/api/admin/plugins`, {
|
|
1935
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
1936
|
+
});
|
|
1937
|
+
const inventory = await responseBody(inventoryResponse);
|
|
1938
|
+
if (!inventoryResponse.ok) {
|
|
1939
|
+
throw new Error(
|
|
1940
|
+
`Runtime plugin inventory failed (${inventoryResponse.status}): ${formatBody(inventory)}`
|
|
1941
|
+
);
|
|
1942
|
+
}
|
|
1943
|
+
const inventoryItem = Array.isArray(inventory) ? inventory.find(
|
|
1944
|
+
(item) => isRecord2(item) && item.key === staged.pluginKey && item.version === staged.version
|
|
1945
|
+
) : void 0;
|
|
1946
|
+
if (!isRecord2(inventoryItem)) {
|
|
1947
|
+
throw new Error(
|
|
1948
|
+
`Runtime did not expose ${staged.pluginKey}@${staged.version} after reconciliation.`
|
|
1949
|
+
);
|
|
1950
|
+
}
|
|
1951
|
+
if (inventoryItem.active !== true || inventoryItem.activeVersion !== staged.version) {
|
|
1952
|
+
throw new Error(
|
|
1953
|
+
`Runtime discovered ${staged.pluginKey}@${staged.version} but did not activate that release.`
|
|
1954
|
+
);
|
|
1955
|
+
}
|
|
1956
|
+
return {
|
|
1957
|
+
pluginKey: staged.pluginKey,
|
|
1958
|
+
version: staged.version,
|
|
1959
|
+
container,
|
|
1960
|
+
reconcile: body,
|
|
1961
|
+
inventory
|
|
1962
|
+
};
|
|
1963
|
+
} finally {
|
|
1964
|
+
fs3.rmSync(stagingRoot, { recursive: true, force: true });
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
function assertDevTargetAsset() {
|
|
1968
|
+
const compose = pluginDevTargetComposePath();
|
|
1969
|
+
if (!fs3.existsSync(compose)) {
|
|
1970
|
+
throw new Error(
|
|
1971
|
+
`Packaged Plugmatica development target is missing: ${compose}`
|
|
1972
|
+
);
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
function composePrefix(options) {
|
|
1976
|
+
return [
|
|
1977
|
+
"compose",
|
|
1978
|
+
"--project-name",
|
|
1979
|
+
options.project?.trim() || DEFAULT_PROJECT,
|
|
1980
|
+
"--file",
|
|
1981
|
+
pluginDevTargetComposePath()
|
|
1982
|
+
];
|
|
1983
|
+
}
|
|
1984
|
+
function runDockerCompose(options, args) {
|
|
1985
|
+
runDocker([...composePrefix(options), ...args]);
|
|
1986
|
+
}
|
|
1987
|
+
function captureDockerCompose(options, args) {
|
|
1988
|
+
return captureDocker([...composePrefix(options), ...args]);
|
|
1989
|
+
}
|
|
1990
|
+
function runDocker(args) {
|
|
1991
|
+
const result = spawnSync2("docker", args, {
|
|
1992
|
+
stdio: "inherit",
|
|
1993
|
+
env: process.env,
|
|
1994
|
+
shell: false
|
|
1995
|
+
});
|
|
1996
|
+
if (result.error) {
|
|
1997
|
+
throw new Error(
|
|
1998
|
+
`Docker is required for the Plugmatica development target: ${result.error.message}`
|
|
1999
|
+
);
|
|
2000
|
+
}
|
|
2001
|
+
if (result.status !== 0) {
|
|
2002
|
+
throw new Error(
|
|
2003
|
+
`docker ${args.join(" ")} failed with exit code ${String(result.status ?? 1)}.`
|
|
2004
|
+
);
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
function captureDocker(args) {
|
|
2008
|
+
const result = spawnSync2("docker", args, {
|
|
2009
|
+
encoding: "utf8",
|
|
2010
|
+
env: process.env,
|
|
2011
|
+
shell: false
|
|
2012
|
+
});
|
|
2013
|
+
if (result.error) {
|
|
2014
|
+
throw new Error(
|
|
2015
|
+
`Docker is required for the Plugmatica development target: ${result.error.message}`
|
|
2016
|
+
);
|
|
2017
|
+
}
|
|
2018
|
+
if (result.status !== 0) {
|
|
2019
|
+
throw new Error(
|
|
2020
|
+
(result.stderr || `docker ${args.join(" ")} failed`).trim()
|
|
2021
|
+
);
|
|
2022
|
+
}
|
|
2023
|
+
return result.stdout;
|
|
2024
|
+
}
|
|
2025
|
+
async function developmentAccessToken(input) {
|
|
2026
|
+
const response = await fetch(
|
|
2027
|
+
`${input.keycloakUrl}/realms/plugmatica/protocol/openid-connect/token`,
|
|
2028
|
+
{
|
|
2029
|
+
method: "POST",
|
|
2030
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
2031
|
+
body: new URLSearchParams({
|
|
2032
|
+
grant_type: "password",
|
|
2033
|
+
client_id: "plugmatica-web",
|
|
2034
|
+
username: input.username,
|
|
2035
|
+
password: input.password
|
|
2036
|
+
})
|
|
2037
|
+
}
|
|
2038
|
+
);
|
|
2039
|
+
const body = await responseBody(response);
|
|
2040
|
+
if (!response.ok || !isRecord2(body) || typeof body.access_token !== "string") {
|
|
2041
|
+
throw new Error(
|
|
2042
|
+
`Could not authenticate to the Plugmatica development target (${response.status}): ${formatBody(body)}`
|
|
2043
|
+
);
|
|
2044
|
+
}
|
|
2045
|
+
return body.access_token;
|
|
2046
|
+
}
|
|
2047
|
+
async function waitForHttp(url, timeoutMs, acceptedStatuses = /* @__PURE__ */ new Set([200])) {
|
|
2048
|
+
const started = Date.now();
|
|
2049
|
+
let lastError = "not reachable";
|
|
2050
|
+
while (Date.now() - started < timeoutMs) {
|
|
2051
|
+
try {
|
|
2052
|
+
const response = await fetch(url, { redirect: "manual" });
|
|
2053
|
+
if (acceptedStatuses.has(response.status)) return;
|
|
2054
|
+
lastError = `HTTP ${response.status}`;
|
|
2055
|
+
} catch (error) {
|
|
2056
|
+
lastError = error instanceof Error ? error.message : String(error);
|
|
2057
|
+
}
|
|
2058
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
2059
|
+
}
|
|
2060
|
+
throw new Error(`Timed out waiting for ${url}: ${lastError}`);
|
|
2061
|
+
}
|
|
2062
|
+
async function responseBody(response) {
|
|
2063
|
+
const text = await response.text();
|
|
2064
|
+
if (!text) return null;
|
|
2065
|
+
try {
|
|
2066
|
+
return JSON.parse(text);
|
|
2067
|
+
} catch {
|
|
2068
|
+
return text;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
function formatBody(body) {
|
|
2072
|
+
return typeof body === "string" ? body : JSON.stringify(body);
|
|
2073
|
+
}
|
|
2074
|
+
function isRecord2(value) {
|
|
2075
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
// src/cli.ts
|
|
2079
|
+
await main();
|
|
2080
|
+
async function main() {
|
|
2081
|
+
try {
|
|
2082
|
+
const argv = process.argv.slice(2);
|
|
2083
|
+
if (argv.length === 1 && argv[0] === "--help") {
|
|
2084
|
+
console.log(renderPluginBuildCliRootHelp());
|
|
2085
|
+
return;
|
|
2086
|
+
}
|
|
2087
|
+
const resolved = resolvePluginBuildCliCommand(argv);
|
|
2088
|
+
const parsed = parsePluginBuildCliCommand(resolved.spec, resolved.rest);
|
|
2089
|
+
if (booleanArg(parsed.options, "help")) {
|
|
2090
|
+
console.log(renderPluginBuildCliCommandHelp(resolved.spec));
|
|
2091
|
+
return;
|
|
2092
|
+
}
|
|
2093
|
+
switch (resolved.spec.id) {
|
|
2094
|
+
case "templates": {
|
|
2095
|
+
const templates = await listPluginTemplates();
|
|
2096
|
+
if (booleanArg(parsed.options, "json")) {
|
|
2097
|
+
console.log(JSON.stringify({ schemaVersion: 1, templates }, null, 2));
|
|
2098
|
+
} else {
|
|
2099
|
+
console.log(formatTemplateCatalogue(templates));
|
|
2100
|
+
}
|
|
2101
|
+
return;
|
|
2102
|
+
}
|
|
2103
|
+
case "create": {
|
|
2104
|
+
const directory = parsed.positionals[0];
|
|
2105
|
+
const result = await createPluginScaffold({
|
|
2106
|
+
directory,
|
|
2107
|
+
template: parsed.options.template,
|
|
2108
|
+
pluginKey: parsed.options["plugin-key"],
|
|
2109
|
+
name: parsed.options.name,
|
|
2110
|
+
description: parsed.options.description,
|
|
2111
|
+
author: parsed.options.author,
|
|
2112
|
+
moduleName: parsed.options["module-name"],
|
|
2113
|
+
targetSurface: parsed.options["target-surface"],
|
|
2114
|
+
targetKey: parsed.options["target-key"],
|
|
2115
|
+
targetPoint: parsed.options["target-point"],
|
|
2116
|
+
targetContractId: parsed.options["target-contract-id"],
|
|
2117
|
+
targetContractVersion: parsed.options["target-contract-version"],
|
|
2118
|
+
providerKey: parsed.options["provider-key"],
|
|
2119
|
+
providerContractId: parsed.options["provider-contract-id"],
|
|
2120
|
+
providerContractVersion: parsed.options["provider-contract-version"],
|
|
2121
|
+
eventKey: parsed.options["event-key"],
|
|
2122
|
+
eventContractId: parsed.options["event-contract-id"],
|
|
2123
|
+
eventContractVersion: parsed.options["event-contract-version"],
|
|
2124
|
+
force: booleanArg(parsed.options, "force")
|
|
2125
|
+
});
|
|
2126
|
+
console.log(`Created ${result.template} starter at ${result.root}.`);
|
|
2127
|
+
return;
|
|
2128
|
+
}
|
|
2129
|
+
case "backend-build": {
|
|
2130
|
+
const result = buildPluginBackend({
|
|
2131
|
+
root: parsed.options.root,
|
|
2132
|
+
manifest: parsed.options.manifest,
|
|
2133
|
+
cargoManifest: parsed.options["cargo-manifest"],
|
|
2134
|
+
target: parsed.options.target,
|
|
2135
|
+
profile: parsed.options.profile,
|
|
2136
|
+
descriptorOut: parsed.options["descriptor-out"],
|
|
2137
|
+
previousDescriptor: parsed.options["previous-descriptor"],
|
|
2138
|
+
describeBin: parsed.options["describe-bin"]
|
|
2139
|
+
});
|
|
2140
|
+
console.log(`Built backend WASM: ${result.wasm}`);
|
|
2141
|
+
console.log(`Generated backend descriptor: ${result.descriptor}`);
|
|
2142
|
+
return;
|
|
2143
|
+
}
|
|
2144
|
+
case "backend-describe": {
|
|
2145
|
+
const result = describePluginBackend({
|
|
2146
|
+
root: parsed.options.root,
|
|
2147
|
+
manifest: parsed.options.manifest,
|
|
2148
|
+
wasm: parsed.options.wasm,
|
|
2149
|
+
descriptorOut: parsed.options["descriptor-out"],
|
|
2150
|
+
previousDescriptor: parsed.options["previous-descriptor"],
|
|
2151
|
+
describeBin: parsed.options["describe-bin"]
|
|
2152
|
+
});
|
|
2153
|
+
console.log(`Generated backend descriptor: ${result.descriptor}`);
|
|
2154
|
+
return;
|
|
2155
|
+
}
|
|
2156
|
+
case "package": {
|
|
2157
|
+
const result = packagePlugin({
|
|
2158
|
+
root: parsed.options.root,
|
|
2159
|
+
manifest: parsed.options.manifest,
|
|
2160
|
+
generatedManifest: parsed.options["generated-manifest"],
|
|
2161
|
+
frontendDist: parsed.options["frontend-dist"],
|
|
2162
|
+
backendDescriptor: parsed.options["backend-descriptor"],
|
|
2163
|
+
out: parsed.options.out
|
|
2164
|
+
});
|
|
2165
|
+
console.log(
|
|
2166
|
+
`Packaged ${result.pluginKey}@${result.version}: ${result.packageRoot}`
|
|
2167
|
+
);
|
|
2168
|
+
return;
|
|
2169
|
+
}
|
|
2170
|
+
case "install": {
|
|
2171
|
+
const result = installPluginPackage({
|
|
2172
|
+
packageRoot: parsed.options.package,
|
|
2173
|
+
bundleRoot: parsed.options["bundle-root"]
|
|
2174
|
+
});
|
|
2175
|
+
console.log(
|
|
2176
|
+
`Installed ${result.pluginKey}@${result.version}: ${result.installRoot}`
|
|
2177
|
+
);
|
|
2178
|
+
return;
|
|
2179
|
+
}
|
|
2180
|
+
case "dev-up": {
|
|
2181
|
+
const endpoints = await startPluginDevTarget({
|
|
2182
|
+
project: parsed.options.project
|
|
2183
|
+
});
|
|
2184
|
+
console.log(`Plugmatica development target is ready.`);
|
|
2185
|
+
console.log(`Runtime Shell: ${endpoints.shell}`);
|
|
2186
|
+
console.log(`Runtime API: ${endpoints.runtimeApi}`);
|
|
2187
|
+
console.log(`Keycloak: ${endpoints.keycloak}`);
|
|
2188
|
+
return;
|
|
2189
|
+
}
|
|
2190
|
+
case "dev-status": {
|
|
2191
|
+
statusPluginDevTarget({ project: parsed.options.project });
|
|
2192
|
+
return;
|
|
2193
|
+
}
|
|
2194
|
+
case "dev-install": {
|
|
2195
|
+
const result = await installIntoPluginDevTarget({
|
|
2196
|
+
project: parsed.options.project,
|
|
2197
|
+
packageRoot: parsed.options.package,
|
|
2198
|
+
runtimeUrl: parsed.options["runtime-url"],
|
|
2199
|
+
keycloakUrl: parsed.options["keycloak-url"],
|
|
2200
|
+
username: parsed.options.username,
|
|
2201
|
+
password: parsed.options.password
|
|
2202
|
+
});
|
|
2203
|
+
console.log(
|
|
2204
|
+
`Installed and reconciled ${result.pluginKey}@${result.version} in the local development target.`
|
|
2205
|
+
);
|
|
2206
|
+
return;
|
|
2207
|
+
}
|
|
2208
|
+
case "dev-logs": {
|
|
2209
|
+
logsPluginDevTarget({
|
|
2210
|
+
project: parsed.options.project,
|
|
2211
|
+
service: parsed.options.service,
|
|
2212
|
+
follow: booleanArg(parsed.options, "follow")
|
|
2213
|
+
});
|
|
2214
|
+
return;
|
|
2215
|
+
}
|
|
2216
|
+
case "dev-stop": {
|
|
2217
|
+
stopPluginDevTarget({ project: parsed.options.project });
|
|
2218
|
+
return;
|
|
2219
|
+
}
|
|
2220
|
+
case "dev-reset": {
|
|
2221
|
+
resetPluginDevTarget({ project: parsed.options.project });
|
|
2222
|
+
return;
|
|
2223
|
+
}
|
|
2224
|
+
case "contract-init":
|
|
2225
|
+
case "contract-check":
|
|
2226
|
+
case "contract-diff":
|
|
2227
|
+
case "contract-update":
|
|
2228
|
+
await runContractCommand(
|
|
2229
|
+
resolved.spec.id.slice("contract-".length),
|
|
2230
|
+
parsed.options
|
|
2231
|
+
);
|
|
2232
|
+
return;
|
|
2233
|
+
case "contract-history":
|
|
2234
|
+
runContractHistoryCommand(parsed.options);
|
|
2235
|
+
return;
|
|
2236
|
+
case "workflow-inspect": {
|
|
2237
|
+
const report = inspectWorkflowNodePackage({
|
|
2238
|
+
packageRoot: path4.resolve(parsed.options.package ?? "dist/plugin"),
|
|
2239
|
+
registryJson: parsed.options["registry-json"],
|
|
2240
|
+
requireUi: booleanArg(parsed.options, "require-ui")
|
|
2241
|
+
});
|
|
2242
|
+
console.log(formatWorkflowNodePackageInspection(report));
|
|
2243
|
+
if (parsed.options["json-out"]) writeJson2(path4.resolve(parsed.options["json-out"]), report);
|
|
2244
|
+
if (report.packageStatus === "invalid" || report.registryStatus === "mismatch") process.exitCode = 1;
|
|
2245
|
+
return;
|
|
2246
|
+
}
|
|
2247
|
+
case "inspect":
|
|
2248
|
+
runInspectCommand(parsed.options, false);
|
|
2249
|
+
return;
|
|
2250
|
+
case "extensions":
|
|
2251
|
+
runInspectCommand(parsed.options, true);
|
|
2252
|
+
return;
|
|
2253
|
+
case "extensions-fix":
|
|
2254
|
+
runExtensionFixCommand(parsed.options);
|
|
2255
|
+
return;
|
|
2256
|
+
case "protocol-verify":
|
|
2257
|
+
runProtocolCommand(parsed.options);
|
|
2258
|
+
return;
|
|
2259
|
+
case "boundaries-check":
|
|
2260
|
+
runBoundariesCommand(parsed.options);
|
|
2261
|
+
return;
|
|
2262
|
+
case "i18n-doctor":
|
|
2263
|
+
runI18nDoctorCommand(parsed.options);
|
|
2264
|
+
return;
|
|
2265
|
+
case "i18n-fix":
|
|
2266
|
+
runI18nCommand(parsed.options);
|
|
2267
|
+
return;
|
|
2268
|
+
case "release-check":
|
|
2269
|
+
runReleaseCommand(parsed.options);
|
|
2270
|
+
return;
|
|
2271
|
+
case "build":
|
|
2272
|
+
runManifestGeneration(parsed.options);
|
|
2273
|
+
return;
|
|
2274
|
+
default:
|
|
2275
|
+
throw new Error(`Unsupported CLI command '${resolved.spec.id}'.`);
|
|
2276
|
+
}
|
|
2277
|
+
} catch (error) {
|
|
2278
|
+
if (error instanceof PluginManifestGenerationError) {
|
|
2279
|
+
console.error(formatScanIssues(error.issues));
|
|
2280
|
+
} else {
|
|
2281
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
2282
|
+
}
|
|
2283
|
+
process.exitCode = 1;
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
function pluginSourcePaths(args) {
|
|
2287
|
+
const manifestPath = path4.resolve(args.manifest ?? "manifest.source.json");
|
|
2288
|
+
return {
|
|
2289
|
+
manifestPath,
|
|
2290
|
+
sourceDir: path4.resolve(
|
|
2291
|
+
args.src ?? path4.join(path4.dirname(manifestPath), "frontend", "src")
|
|
2292
|
+
)
|
|
2293
|
+
};
|
|
2294
|
+
}
|
|
2295
|
+
function pluginLocaleOptions(args) {
|
|
2296
|
+
return {
|
|
2297
|
+
defaultLocale: args["default-locale"] ?? "en-GB",
|
|
2298
|
+
...args["locales-dir"] ? { localesDir: args["locales-dir"] } : {}
|
|
2299
|
+
};
|
|
2300
|
+
}
|
|
2301
|
+
function pluginI18nOptions(args, { manifestPath, sourceDir }) {
|
|
2302
|
+
const manifest = JSON.parse(fs4.readFileSync(manifestPath, "utf8"));
|
|
2303
|
+
const pluginKey = typeof manifest.key === "string" ? manifest.key.trim() : "";
|
|
2304
|
+
if (!pluginKey)
|
|
2305
|
+
throw new Error(`Manifest '${manifestPath}' is missing a non-empty key.`);
|
|
2306
|
+
return {
|
|
2307
|
+
pluginKey,
|
|
2308
|
+
sourceDir,
|
|
2309
|
+
frontendRoot: path4.join(path4.dirname(manifestPath), "frontend"),
|
|
2310
|
+
...pluginLocaleOptions(args)
|
|
2311
|
+
};
|
|
2312
|
+
}
|
|
2313
|
+
function runInspectCommand(args, extensionsOnly) {
|
|
2314
|
+
const inspection = inspectPlugin({
|
|
2315
|
+
sourceDir: path4.resolve(required(args, "src")),
|
|
2316
|
+
manifestPath: path4.resolve(required(args, "manifest"))
|
|
2317
|
+
});
|
|
2318
|
+
const text = extensionsOnly ? formatExtensionInventory(inspection) : formatPluginInspection(inspection);
|
|
2319
|
+
console.log(text);
|
|
2320
|
+
if (args["json-out"]) writeJson2(path4.resolve(args["json-out"]), inspection);
|
|
2321
|
+
if (args["graph-json-out"])
|
|
2322
|
+
writeJson2(path4.resolve(args["graph-json-out"]), inspection.graph);
|
|
2323
|
+
if (args["graph-mermaid-out"]) {
|
|
2324
|
+
writeText(
|
|
2325
|
+
path4.resolve(args["graph-mermaid-out"]),
|
|
2326
|
+
renderPluginContractGraphMermaid(inspection.graph)
|
|
2327
|
+
);
|
|
2328
|
+
}
|
|
2329
|
+
if (inspection.graphValidation.issues.some(
|
|
2330
|
+
(issue) => issue.severity === "error"
|
|
2331
|
+
)) {
|
|
2332
|
+
process.exitCode = 1;
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
function runProtocolCommand(args) {
|
|
2336
|
+
const report = verifyFrontendProtocolAgainstRust(
|
|
2337
|
+
path4.resolve(required(args, "backend-root"))
|
|
2338
|
+
);
|
|
2339
|
+
console.log(formatProtocolParityReport(report));
|
|
2340
|
+
if (args["json-out"]) writeJson2(path4.resolve(args["json-out"]), report);
|
|
2341
|
+
if (report.issues.length > 0) process.exitCode = 1;
|
|
2342
|
+
}
|
|
2343
|
+
function runBoundariesCommand(args) {
|
|
2344
|
+
const root = path4.resolve(args.root ?? process.cwd());
|
|
2345
|
+
const audit = auditFrontendPackageBoundaries(root);
|
|
2346
|
+
console.log(formatPackageBoundaryAudit(audit));
|
|
2347
|
+
if (audit.issues.length > 0) process.exitCode = 1;
|
|
2348
|
+
}
|
|
2349
|
+
function runReleaseCommand(args) {
|
|
2350
|
+
const root = path4.resolve(args.root ?? process.cwd());
|
|
2351
|
+
const audit = auditPackageReleaseContract(root);
|
|
2352
|
+
const declarationIssues = auditBuiltDeclarationDependencies(root);
|
|
2353
|
+
if (declarationIssues.length > 0) audit.issues.push(...declarationIssues);
|
|
2354
|
+
console.log(formatPackageReleaseAudit(audit));
|
|
2355
|
+
if (audit.issues.length > 0) process.exitCode = 1;
|
|
2356
|
+
}
|
|
2357
|
+
function runExtensionFixCommand(args) {
|
|
2358
|
+
const { manifestPath, sourceDir } = pluginSourcePaths(args);
|
|
2359
|
+
const manifest = JSON.parse(fs4.readFileSync(manifestPath, "utf8"));
|
|
2360
|
+
const result = fixRedundantExtensionOverrides({
|
|
2361
|
+
sourceDir,
|
|
2362
|
+
pageRoutes: compilerPageRoutesFromManifest(manifest),
|
|
2363
|
+
dryRun: booleanArg(args, "dry-run")
|
|
2364
|
+
});
|
|
2365
|
+
console.log(formatExtensionFixResult(result));
|
|
2366
|
+
}
|
|
2367
|
+
function runI18nDoctorCommand(args) {
|
|
2368
|
+
const { manifestPath, sourceDir } = pluginSourcePaths(args);
|
|
2369
|
+
const result = auditPluginI18n({
|
|
2370
|
+
...pluginI18nOptions(args, { manifestPath, sourceDir })
|
|
2371
|
+
});
|
|
2372
|
+
if (args["json-out"]) {
|
|
2373
|
+
const output = path4.resolve(args["json-out"]);
|
|
2374
|
+
fs4.mkdirSync(path4.dirname(output), { recursive: true });
|
|
2375
|
+
fs4.writeFileSync(output, `${JSON.stringify(result, null, 2)}
|
|
2376
|
+
`);
|
|
2377
|
+
}
|
|
2378
|
+
console.log(formatPluginI18nAudit(result));
|
|
2379
|
+
if (booleanArg(args, "strict")) {
|
|
2380
|
+
const hasFindings = result.stats.unusedKeys > 0 || result.stats.exactDuplicateGroups > 0 || result.stats.variantGroups > 0 || result.stats.sharedCandidates > 0 || result.scanIssues.some((issue) => issue.severity === "error");
|
|
2381
|
+
if (hasFindings) process.exitCode = 1;
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
function runI18nCommand(args) {
|
|
2385
|
+
const { manifestPath, sourceDir } = pluginSourcePaths(args);
|
|
2386
|
+
const result = fixPluginI18n({
|
|
2387
|
+
...pluginI18nOptions(args, { manifestPath, sourceDir }),
|
|
2388
|
+
dryRun: booleanArg(args, "dry-run")
|
|
2389
|
+
});
|
|
2390
|
+
console.log(formatI18nFixResult(result, booleanArg(args, "dry-run")));
|
|
2391
|
+
if (result.conflicts.length > 0 || result.skipped.length > 0)
|
|
2392
|
+
process.exitCode = 1;
|
|
2393
|
+
}
|
|
2394
|
+
function runManifestGeneration(args) {
|
|
2395
|
+
const { manifestPath, sourceDir } = pluginSourcePaths(args);
|
|
2396
|
+
const outputPath = path4.resolve(
|
|
2397
|
+
args.out ?? path4.join(path4.dirname(manifestPath), "manifest.json")
|
|
2398
|
+
);
|
|
2399
|
+
if (booleanArg(args, "fix-i18n")) {
|
|
2400
|
+
const fixResult = fixPluginI18n(
|
|
2401
|
+
pluginI18nOptions(args, { manifestPath, sourceDir })
|
|
2402
|
+
);
|
|
2403
|
+
console.log(formatI18nFixResult(fixResult));
|
|
2404
|
+
if (fixResult.conflicts.length > 0 || fixResult.skipped.length > 0) {
|
|
2405
|
+
throw new Error(
|
|
2406
|
+
"Cannot build until unresolved i18n strings and key conflicts are resolved."
|
|
2407
|
+
);
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
const result = generatePluginManifest({
|
|
2411
|
+
sourceDir,
|
|
2412
|
+
manifestPath,
|
|
2413
|
+
outputPath,
|
|
2414
|
+
failOnWarnings: booleanArg(args, "fail-on-warnings"),
|
|
2415
|
+
backendDescriptorPath: args["backend-descriptor"],
|
|
2416
|
+
targets: {
|
|
2417
|
+
emit: !booleanArg(args, "no-targets"),
|
|
2418
|
+
...args["targets-out"] ? { outputDir: args["targets-out"] } : {}
|
|
2419
|
+
},
|
|
2420
|
+
currentContract: {
|
|
2421
|
+
emit: !booleanArg(args, "no-current-contract"),
|
|
2422
|
+
...args["current-contract-out"] ? { outputPath: args["current-contract-out"] } : {}
|
|
2423
|
+
},
|
|
2424
|
+
devtools: {
|
|
2425
|
+
emit: booleanArg(args, "devtools") || Boolean(args["devtools-out"]),
|
|
2426
|
+
...args["devtools-out"] ? { outputPath: args["devtools-out"] } : {}
|
|
2427
|
+
},
|
|
2428
|
+
docs: {
|
|
2429
|
+
emit: !booleanArg(args, "no-docs"),
|
|
2430
|
+
...args["docs-out"] ? { outputDir: args["docs-out"] } : {}
|
|
2431
|
+
},
|
|
2432
|
+
graph: {
|
|
2433
|
+
emit: booleanArg(args, "graph") || Boolean(args["graph-out"]),
|
|
2434
|
+
...args["graph-out"] ? { outputDir: args["graph-out"] } : {}
|
|
2435
|
+
},
|
|
2436
|
+
i18n: {
|
|
2437
|
+
...pluginLocaleOptions(args),
|
|
2438
|
+
...booleanArg(args, "allow-raw-strings") ? { failOnRawStrings: false } : {}
|
|
2439
|
+
}
|
|
2440
|
+
});
|
|
2441
|
+
for (const issue of result.issues) console.warn(formatScanIssues([issue]));
|
|
2442
|
+
console.log(
|
|
2443
|
+
`Generated ${result.surfaceCount} standard extension surface(s) into ${result.outputPath}.`
|
|
2444
|
+
);
|
|
2445
|
+
if (result.currentExtensionContractPath) {
|
|
2446
|
+
console.log(
|
|
2447
|
+
`Generated Current Extension Contract at ${result.currentExtensionContractPath}.`
|
|
2448
|
+
);
|
|
2449
|
+
}
|
|
2450
|
+
if (result.targetArtifacts?.files) {
|
|
2451
|
+
console.log(
|
|
2452
|
+
`Generated typed extension targets '${result.targetArtifacts.namespace}' into ${path4.dirname(result.targetArtifacts.files.source)}.`
|
|
2453
|
+
);
|
|
2454
|
+
}
|
|
2455
|
+
if (result.devtoolsArtifactPath) {
|
|
2456
|
+
console.log(
|
|
2457
|
+
`Generated extension devtools diagnostics at ${result.devtoolsArtifactPath}.`
|
|
2458
|
+
);
|
|
2459
|
+
}
|
|
2460
|
+
if (result.documentationArtifacts?.files) {
|
|
2461
|
+
console.log(
|
|
2462
|
+
`Generated extension developer docs at ${path4.dirname(result.documentationArtifacts.files.index)}.`
|
|
2463
|
+
);
|
|
2464
|
+
}
|
|
2465
|
+
if (result.graphArtifacts?.files) {
|
|
2466
|
+
console.log(
|
|
2467
|
+
`Generated extension contract graph at ${path4.dirname(result.graphArtifacts.files.json)}.`
|
|
2468
|
+
);
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
async function runContractCommand(command, args) {
|
|
2472
|
+
const sourceDir = path4.resolve(required(args, "src"));
|
|
2473
|
+
const manifestPath = path4.resolve(required(args, "manifest"));
|
|
2474
|
+
const projectRoot = path4.resolve(
|
|
2475
|
+
args["project-root"] ?? path4.dirname(manifestPath)
|
|
2476
|
+
);
|
|
2477
|
+
const baselinePath = args["repository-baseline"];
|
|
2478
|
+
if (command === "init") {
|
|
2479
|
+
const result2 = initRepositoryContractBaseline({
|
|
2480
|
+
sourceDir,
|
|
2481
|
+
manifestPath,
|
|
2482
|
+
projectRoot,
|
|
2483
|
+
...baselinePath ? { baselinePath } : {}
|
|
2484
|
+
});
|
|
2485
|
+
console.log(`Initialized Repository Contract Baseline at ${result2.path}.`);
|
|
2486
|
+
return;
|
|
2487
|
+
}
|
|
2488
|
+
if (command === "update") {
|
|
2489
|
+
const result2 = updateRepositoryContractBaseline({
|
|
2490
|
+
sourceDir,
|
|
2491
|
+
manifestPath,
|
|
2492
|
+
projectRoot,
|
|
2493
|
+
...baselinePath ? { baselinePath } : {}
|
|
2494
|
+
});
|
|
2495
|
+
console.log(`Updated Repository Contract Baseline at ${result2.path}.`);
|
|
2496
|
+
return;
|
|
2497
|
+
}
|
|
2498
|
+
const providers = contractProviders(args, projectRoot);
|
|
2499
|
+
const result = await checkContractCompatibility({
|
|
2500
|
+
sourceDir,
|
|
2501
|
+
manifestPath,
|
|
2502
|
+
projectRoot,
|
|
2503
|
+
providers,
|
|
2504
|
+
mode: booleanArg(args, "publish") ? "publish" : "development",
|
|
2505
|
+
offline: booleanArg(args, "offline")
|
|
2506
|
+
});
|
|
2507
|
+
console.log(formatCompatibilityReport(result.report));
|
|
2508
|
+
const compatibilityOutput = args["json-out"] ? path4.resolve(args["json-out"]) : booleanArg(args, "no-devtools-report") ? null : path4.resolve(
|
|
2509
|
+
projectRoot,
|
|
2510
|
+
"frontend/generated/compatibility-report.json"
|
|
2511
|
+
);
|
|
2512
|
+
if (compatibilityOutput) writeJson2(compatibilityOutput, result.report);
|
|
2513
|
+
if (booleanArg(args, "strict")) enforceStrictCompatibility(result.report);
|
|
2514
|
+
}
|
|
2515
|
+
function runContractHistoryCommand(args) {
|
|
2516
|
+
const files = required(args, "baselines").split(",").map((value) => value.trim()).filter(Boolean).map((value) => path4.resolve(value));
|
|
2517
|
+
if (files.length === 0)
|
|
2518
|
+
throw new Error(
|
|
2519
|
+
"--baselines must contain at least one Contract Baseline file."
|
|
2520
|
+
);
|
|
2521
|
+
const history = buildReleaseCompatibilityHistory(
|
|
2522
|
+
loadReleaseContractSnapshots(files)
|
|
2523
|
+
);
|
|
2524
|
+
const outputDir = path4.resolve(
|
|
2525
|
+
args.out ?? "frontend/generated/contract-history"
|
|
2526
|
+
);
|
|
2527
|
+
const written = writeReleaseCompatibilityHistory({ history, outputDir });
|
|
2528
|
+
console.log(
|
|
2529
|
+
`Generated release-history compatibility visualisation for ${history.pluginId} at ${outputDir}.`
|
|
2530
|
+
);
|
|
2531
|
+
console.log(`- ${written.markdown}`);
|
|
2532
|
+
console.log(`- ${written.mermaid}`);
|
|
2533
|
+
console.log(`- ${written.json}`);
|
|
2534
|
+
}
|
|
2535
|
+
function contractProviders(args, projectRoot) {
|
|
2536
|
+
const providers = [];
|
|
2537
|
+
if (args.baseline) {
|
|
2538
|
+
providers.push(
|
|
2539
|
+
new ExplicitContractBaselineProvider(path4.resolve(args.baseline))
|
|
2540
|
+
);
|
|
2541
|
+
}
|
|
2542
|
+
if (args["git-tag"]) {
|
|
2543
|
+
providers.push(
|
|
2544
|
+
new GitTagContractBaselineProvider({
|
|
2545
|
+
tag: args["git-tag"],
|
|
2546
|
+
...args["git-baseline"] ? { baselinePath: args["git-baseline"] } : {}
|
|
2547
|
+
})
|
|
2548
|
+
);
|
|
2549
|
+
}
|
|
2550
|
+
if (!booleanArg(args, "no-repository-baseline")) {
|
|
2551
|
+
providers.push(
|
|
2552
|
+
new RepositoryContractBaselineProvider(
|
|
2553
|
+
args["repository-baseline"] ? path4.resolve(projectRoot, args["repository-baseline"]) : "plugmatica.contract.json"
|
|
2554
|
+
)
|
|
2555
|
+
);
|
|
2556
|
+
}
|
|
2557
|
+
if (args["registry-url"]) {
|
|
2558
|
+
providers.push(
|
|
2559
|
+
new RegistryContractBaselineProvider({
|
|
2560
|
+
endpoint: args["registry-url"],
|
|
2561
|
+
cacheDir: path4.resolve(
|
|
2562
|
+
args["registry-cache"] ?? path4.join(projectRoot, ".plugmatica", "cache", "contracts")
|
|
2563
|
+
),
|
|
2564
|
+
...args["registry-name"] ? { registryName: args["registry-name"] } : {}
|
|
2565
|
+
})
|
|
2566
|
+
);
|
|
2567
|
+
}
|
|
2568
|
+
if (args["installed-baseline"]) {
|
|
2569
|
+
const candidates = args["installed-baseline"].split(",").map((value) => value.trim()).filter(Boolean).map((value) => path4.resolve(value));
|
|
2570
|
+
providers.push(new InstalledPluginContractBaselineProvider(candidates));
|
|
2571
|
+
}
|
|
2572
|
+
return providers;
|
|
2573
|
+
}
|
|
2574
|
+
function formatTemplateCatalogue(templates) {
|
|
2575
|
+
const lines = ["Canonical Plugmatica starters:", ""];
|
|
2576
|
+
for (const template of templates) {
|
|
2577
|
+
const facets = template.facets.join(", ");
|
|
2578
|
+
lines.push(`${template.id} [${facets}]`);
|
|
2579
|
+
lines.push(` ${template.description}`);
|
|
2580
|
+
const required2 = template.templateParameters.filter((parameter) => parameter.required && !parameter.default).map(
|
|
2581
|
+
(parameter) => `--${parameter.name.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`)}`
|
|
2582
|
+
);
|
|
2583
|
+
if (required2.length) lines.push(` requires: ${required2.join(", ")}`);
|
|
2584
|
+
}
|
|
2585
|
+
lines.push(
|
|
2586
|
+
"",
|
|
2587
|
+
"Use 'plugmatica templates --json' for machine-readable metadata."
|
|
2588
|
+
);
|
|
2589
|
+
return lines.join("\n");
|
|
2590
|
+
}
|
|
2591
|
+
function booleanArg(values, key) {
|
|
2592
|
+
return values[key] === "true";
|
|
2593
|
+
}
|
|
2594
|
+
function required(values, key) {
|
|
2595
|
+
const value = values[key];
|
|
2596
|
+
if (!value) throw new Error(`Missing --${key}.`);
|
|
2597
|
+
return value;
|
|
2598
|
+
}
|
|
2599
|
+
function writeJson2(file, value) {
|
|
2600
|
+
writeText(file, `${JSON.stringify(value, null, 2)}
|
|
2601
|
+
`);
|
|
2602
|
+
}
|
|
2603
|
+
function writeText(file, value) {
|
|
2604
|
+
fs4.mkdirSync(path4.dirname(file), { recursive: true });
|
|
2605
|
+
fs4.writeFileSync(file, value);
|
|
2606
|
+
}
|