@ikas/component-cli 2.3.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/add-sections-to-page.d.ts +3 -0
- package/dist/commands/add-sections-to-page.d.ts.map +1 -0
- package/dist/commands/add-sections-to-page.js +39 -0
- package/dist/commands/add-sections-to-page.js.map +1 -0
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +5 -165
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +87 -3
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/create-design-tokens.d.ts +7 -0
- package/dist/commands/create-design-tokens.d.ts.map +1 -0
- package/dist/commands/create-design-tokens.js +127 -0
- package/dist/commands/create-design-tokens.js.map +1 -0
- package/dist/commands/create-global-variable.d.ts +3 -0
- package/dist/commands/create-global-variable.d.ts.map +1 -0
- package/dist/commands/create-global-variable.js +53 -0
- package/dist/commands/create-global-variable.js.map +1 -0
- package/dist/commands/create-page.d.ts +3 -0
- package/dist/commands/create-page.d.ts.map +1 -0
- package/dist/commands/create-page.js +31 -0
- package/dist/commands/create-page.js.map +1 -0
- package/dist/commands/delete-theme-globals.d.ts +4 -0
- package/dist/commands/delete-theme-globals.d.ts.map +1 -0
- package/dist/commands/delete-theme-globals.js +48 -0
- package/dist/commands/delete-theme-globals.js.map +1 -0
- package/dist/commands/get-component-props.d.ts +3 -0
- package/dist/commands/get-component-props.d.ts.map +1 -0
- package/dist/commands/get-component-props.js +32 -0
- package/dist/commands/get-component-props.js.map +1 -0
- package/dist/commands/get-page-by-type.d.ts +3 -0
- package/dist/commands/get-page-by-type.d.ts.map +1 -0
- package/dist/commands/get-page-by-type.js +25 -0
- package/dist/commands/get-page-by-type.js.map +1 -0
- package/dist/commands/get-section-values.d.ts +3 -0
- package/dist/commands/get-section-values.d.ts.map +1 -0
- package/dist/commands/get-section-values.js +39 -0
- package/dist/commands/get-section-values.js.map +1 -0
- package/dist/commands/list-entities.d.ts +3 -0
- package/dist/commands/list-entities.d.ts.map +1 -0
- package/dist/commands/list-entities.js +32 -0
- package/dist/commands/list-entities.js.map +1 -0
- package/dist/commands/list-page-sections.d.ts +3 -0
- package/dist/commands/list-page-sections.d.ts.map +1 -0
- package/dist/commands/list-page-sections.js +25 -0
- package/dist/commands/list-page-sections.js.map +1 -0
- package/dist/commands/list-theme-globals.d.ts +3 -0
- package/dist/commands/list-theme-globals.d.ts.map +1 -0
- package/dist/commands/list-theme-globals.js +22 -0
- package/dist/commands/list-theme-globals.js.map +1 -0
- package/dist/commands/publish-theme.d.ts +3 -0
- package/dist/commands/publish-theme.d.ts.map +1 -0
- package/dist/commands/publish-theme.js +29 -0
- package/dist/commands/publish-theme.js.map +1 -0
- package/dist/commands/search-products.d.ts +3 -0
- package/dist/commands/search-products.d.ts.map +1 -0
- package/dist/commands/search-products.js +40 -0
- package/dist/commands/search-products.js.map +1 -0
- package/dist/commands/update-global-variable.d.ts +3 -0
- package/dist/commands/update-global-variable.d.ts.map +1 -0
- package/dist/commands/update-global-variable.js +47 -0
- package/dist/commands/update-global-variable.js.map +1 -0
- package/dist/commands/update-page-sections.d.ts +3 -0
- package/dist/commands/update-page-sections.d.ts.map +1 -0
- package/dist/commands/update-page-sections.js +39 -0
- package/dist/commands/update-page-sections.js.map +1 -0
- package/dist/commands/update-section-prop.d.ts +3 -0
- package/dist/commands/update-section-prop.d.ts.map +1 -0
- package/dist/commands/update-section-prop.js +59 -0
- package/dist/commands/update-section-prop.js.map +1 -0
- package/dist/commands/upload-image.d.ts +3 -0
- package/dist/commands/upload-image.d.ts.map +1 -0
- package/dist/commands/upload-image.js +38 -0
- package/dist/commands/upload-image.js.map +1 -0
- package/dist/commands/upload-images.d.ts +3 -0
- package/dist/commands/upload-images.d.ts.map +1 -0
- package/dist/commands/upload-images.js +48 -0
- package/dist/commands/upload-images.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/compile.d.ts +4 -1
- package/dist/utils/compile.d.ts.map +1 -1
- package/dist/utils/compile.js +517 -48
- package/dist/utils/compile.js.map +1 -1
- package/dist/utils/component-helpers.d.ts +1 -1
- package/dist/utils/component-helpers.d.ts.map +1 -1
- package/dist/utils/component-helpers.js +4 -0
- package/dist/utils/component-helpers.js.map +1 -1
- package/dist/utils/editor-action-client.d.ts +1 -1
- package/dist/utils/editor-action-client.d.ts.map +1 -1
- package/dist/utils/editor-action-client.js +23 -8
- package/dist/utils/editor-action-client.js.map +1 -1
- package/dist/utils/load-image.d.ts +16 -0
- package/dist/utils/load-image.d.ts.map +1 -0
- package/dist/utils/load-image.js +50 -0
- package/dist/utils/load-image.js.map +1 -0
- package/dist/utils/websocket-server.d.ts +2 -2
- package/dist/utils/websocket-server.d.ts.map +1 -1
- package/dist/utils/websocket-server.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-sections-to-page.d.ts","sourceRoot":"","sources":["../../src/commands/add-sections-to-page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA+CpC,wBAAgB,8BAA8B,IAAI,OAAO,CAcxD"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { printErrorAndExit, printResultAndExit, runEditorAction, } from "../utils/editor-action-client.js";
|
|
3
|
+
async function runAddSectionsToPage(options) {
|
|
4
|
+
if (!options.pageId || typeof options.pageId !== "string") {
|
|
5
|
+
printErrorAndExit(new Error("--page-id is required (use `ikas-component list-pages`)"));
|
|
6
|
+
}
|
|
7
|
+
if (options.sections === undefined) {
|
|
8
|
+
printErrorAndExit(new Error('--sections is required: a JSON array, e.g. \'[{"componentId":"<id>","updates":[{"propName":"heading","value":{"value":"Hi"}}]}]\''));
|
|
9
|
+
}
|
|
10
|
+
let sections;
|
|
11
|
+
try {
|
|
12
|
+
sections = JSON.parse(options.sections);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
printErrorAndExit(new Error(`--sections must be valid JSON. Received: ${options.sections}`));
|
|
16
|
+
}
|
|
17
|
+
if (!Array.isArray(sections) || sections.length === 0) {
|
|
18
|
+
printErrorAndExit(new Error("--sections must be a non-empty JSON array of { componentId, index?, updates? } objects."));
|
|
19
|
+
}
|
|
20
|
+
const port = options.port ? parseInt(options.port, 10) : undefined;
|
|
21
|
+
try {
|
|
22
|
+
const result = await runEditorAction("add-sections-to-page", { pageId: options.pageId, sections }, { ...(port ? { port } : {}), timeoutMs: 30_000 });
|
|
23
|
+
printResultAndExit(result);
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
printErrorAndExit(e);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function createAddSectionsToPageCommand() {
|
|
30
|
+
const cmd = new Command("add-sections-to-page");
|
|
31
|
+
cmd
|
|
32
|
+
.description("Place MANY sections on a page in one call, each optionally with its prop values set at placement time. --sections is a JSON array of { componentId, index?, updates?: [{ propId|propName, value }] }. Returns the new elementId for each placement. Built-but-unimported section/child components are auto-imported.")
|
|
33
|
+
.requiredOption("--page-id <id>", "Page id (from `ikas-component list-pages`)")
|
|
34
|
+
.requiredOption("--sections <json>", 'JSON array, e.g. \'[{"componentId":"<id>","updates":[{"propName":"heading","value":{"value":"Hi"}}]}]\'')
|
|
35
|
+
.option("--port <port>", "Dev server WebSocket port", "5201")
|
|
36
|
+
.action(runAddSectionsToPage);
|
|
37
|
+
return cmd;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=add-sections-to-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-sections-to-page.js","sourceRoot":"","sources":["../../src/commands/add-sections-to-page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,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AAE,SAAS,EAAE,MAAM,EAAE,CACjD,CAAC;QACF,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,iBAAiB,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,8BAA8B;IAC5C,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAChD,GAAG;SACA,WAAW,CACV,sTAAsT,CACvT;SACA,cAAc,CAAC,gBAAgB,EAAE,4CAA4C,CAAC;SAC9E,cAAc,CACb,mBAAmB,EACnB,yGAAyG,CAC1G;SACA,MAAM,CAAC,eAAe,EAAE,2BAA2B,EAAE,MAAM,CAAC;SAC5D,MAAM,CAAC,oBAAoB,CAAC,CAAC;IAChC,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmIpC,wBAAgB,kBAAkB,IAAI,OAAO,CAK5C"}
|
package/dist/commands/build.js
CHANGED
|
@@ -2,172 +2,12 @@ import { Command } from "commander";
|
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import ora from "ora";
|
|
4
4
|
import * as fs from "fs";
|
|
5
|
-
import * as os from "os";
|
|
6
5
|
import * as path from "path";
|
|
7
|
-
import * as esbuild from "esbuild";
|
|
8
6
|
import { execSync } from "child_process";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
async function compileComponent(componentId, entryPath, stylesPath) {
|
|
14
|
-
const componentDir = path.dirname(path.resolve(process.cwd(), entryPath));
|
|
15
|
-
try {
|
|
16
|
-
// Build server bundle (for SSR with preact-render-to-string)
|
|
17
|
-
const serverResult = await esbuild.build({
|
|
18
|
-
entryPoints: [path.resolve(process.cwd(), entryPath)],
|
|
19
|
-
bundle: true,
|
|
20
|
-
format: "esm",
|
|
21
|
-
platform: "node",
|
|
22
|
-
target: "node18",
|
|
23
|
-
write: false,
|
|
24
|
-
external: [
|
|
25
|
-
"preact",
|
|
26
|
-
"preact/hooks",
|
|
27
|
-
"preact-render-to-string",
|
|
28
|
-
"mobx",
|
|
29
|
-
"@ikas/bp-storefront",
|
|
30
|
-
"@ikas/bp-storefront-models",
|
|
31
|
-
"@ikas/bp-storefront-config",
|
|
32
|
-
"@ikas/bp-storefront-api"
|
|
33
|
-
],
|
|
34
|
-
plugins: [ikasComponentUtilsPlugin()],
|
|
35
|
-
jsx: "transform",
|
|
36
|
-
jsxFactory: "h",
|
|
37
|
-
jsxFragment: "Fragment",
|
|
38
|
-
inject: [PREACT_JSX_SHIM],
|
|
39
|
-
tsconfigRaw: {
|
|
40
|
-
compilerOptions: {
|
|
41
|
-
jsx: "react",
|
|
42
|
-
jsxFactory: "h",
|
|
43
|
-
jsxFragmentFactory: "Fragment"
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
minify: true,
|
|
47
|
-
sourcemap: false,
|
|
48
|
-
});
|
|
49
|
-
// Build client bundle (for hydration)
|
|
50
|
-
const clientResult = await esbuild.build({
|
|
51
|
-
entryPoints: [path.resolve(process.cwd(), entryPath)],
|
|
52
|
-
bundle: true,
|
|
53
|
-
format: "esm",
|
|
54
|
-
platform: "browser",
|
|
55
|
-
target: "es2020",
|
|
56
|
-
write: false,
|
|
57
|
-
external: [
|
|
58
|
-
"preact",
|
|
59
|
-
"preact/hooks",
|
|
60
|
-
"mobx",
|
|
61
|
-
"@ikas/bp-storefront",
|
|
62
|
-
"@ikas/bp-storefront-models",
|
|
63
|
-
"@ikas/bp-storefront-config"
|
|
64
|
-
],
|
|
65
|
-
plugins: [ikasComponentUtilsPlugin()],
|
|
66
|
-
jsx: "transform",
|
|
67
|
-
jsxFactory: "h",
|
|
68
|
-
jsxFragment: "Fragment",
|
|
69
|
-
inject: [PREACT_JSX_SHIM],
|
|
70
|
-
tsconfigRaw: {
|
|
71
|
-
compilerOptions: {
|
|
72
|
-
jsx: "react",
|
|
73
|
-
jsxFactory: "h",
|
|
74
|
-
jsxFragmentFactory: "Fragment"
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
minify: true,
|
|
78
|
-
sourcemap: false,
|
|
79
|
-
});
|
|
80
|
-
// Read and scope CSS (with import resolution)
|
|
81
|
-
const cssPath = path.resolve(process.cwd(), stylesPath);
|
|
82
|
-
let css = "";
|
|
83
|
-
if (fs.existsSync(cssPath)) {
|
|
84
|
-
const rawCss = fs.readFileSync(cssPath, "utf-8");
|
|
85
|
-
css = resolveCssImports(rawCss, cssPath);
|
|
86
|
-
}
|
|
87
|
-
// Scope CSS with component ID prefix
|
|
88
|
-
const scopedCss = scopeCSS(css, componentId);
|
|
89
|
-
return {
|
|
90
|
-
success: true,
|
|
91
|
-
serverJs: serverResult.outputFiles[0]?.text || "",
|
|
92
|
-
clientJs: clientResult.outputFiles[0]?.text || "",
|
|
93
|
-
scopedCss
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
return {
|
|
98
|
-
success: false,
|
|
99
|
-
serverJs: "",
|
|
100
|
-
clientJs: "",
|
|
101
|
-
scopedCss: "",
|
|
102
|
-
error: error instanceof Error ? error.message : String(error)
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
function scopeCSS(css, componentId) {
|
|
107
|
-
// Add a scoping class to all selectors
|
|
108
|
-
const scopeClass = `cc_${componentId.replace(/[^a-zA-Z0-9]/g, "_")}`;
|
|
109
|
-
// Simple CSS scoping - prepend scope class to each rule
|
|
110
|
-
// This is a basic implementation; a production version would use a proper CSS parser
|
|
111
|
-
const lines = css.split("\n");
|
|
112
|
-
const scopedLines = [];
|
|
113
|
-
let inMediaQuery = false;
|
|
114
|
-
let keyframesDepth = 0;
|
|
115
|
-
for (const line of lines) {
|
|
116
|
-
const trimmed = line.trim();
|
|
117
|
-
// Skip empty lines
|
|
118
|
-
if (!trimmed) {
|
|
119
|
-
scopedLines.push(line);
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
// Handle @media queries
|
|
123
|
-
if (trimmed.startsWith("@media")) {
|
|
124
|
-
inMediaQuery = true;
|
|
125
|
-
scopedLines.push(line);
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
// Handle @keyframes
|
|
129
|
-
if (trimmed.startsWith("@keyframes") || trimmed.startsWith("@-webkit-keyframes")) {
|
|
130
|
-
keyframesDepth = 1;
|
|
131
|
-
scopedLines.push(line);
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
// Inside @keyframes: track brace depth, pass lines through unscoped
|
|
135
|
-
if (keyframesDepth > 0) {
|
|
136
|
-
for (const ch of trimmed) {
|
|
137
|
-
if (ch === "{")
|
|
138
|
-
keyframesDepth++;
|
|
139
|
-
else if (ch === "}")
|
|
140
|
-
keyframesDepth--;
|
|
141
|
-
}
|
|
142
|
-
scopedLines.push(line);
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
// Handle closing braces for @media
|
|
146
|
-
if (trimmed === "}" && inMediaQuery) {
|
|
147
|
-
inMediaQuery = false;
|
|
148
|
-
scopedLines.push(line);
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
// Skip lines that don't contain selectors
|
|
152
|
-
if (!trimmed.includes("{") || trimmed.startsWith("@")) {
|
|
153
|
-
scopedLines.push(line);
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
// Scope the selector
|
|
157
|
-
const [selector, rest] = line.split("{");
|
|
158
|
-
if (selector && rest !== undefined) {
|
|
159
|
-
const scopedSelector = selector
|
|
160
|
-
.split(",")
|
|
161
|
-
.map((s) => `.${scopeClass} ${s.trim()}`)
|
|
162
|
-
.join(", ");
|
|
163
|
-
scopedLines.push(`${scopedSelector} {${rest}`);
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
scopedLines.push(line);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return scopedLines.join("\n");
|
|
170
|
-
}
|
|
7
|
+
// Single-source the per-component compile pipeline (esbuild config, externals, CSS
|
|
8
|
+
// scoping) from utils/compile.ts. This command previously carried its own copy, which
|
|
9
|
+
// is how the CSS-scoping fix could land in one place and not the other — keep it shared.
|
|
10
|
+
import { compileComponent } from "../utils/compile.js";
|
|
171
11
|
function runTypeCheck() {
|
|
172
12
|
const spinner = ora("Type checking with TypeScript...").start();
|
|
173
13
|
try {
|
|
@@ -213,7 +53,7 @@ async function buildComponents(options) {
|
|
|
213
53
|
// Build each component
|
|
214
54
|
for (const component of config.components) {
|
|
215
55
|
const spinner = ora(`Building ${component.name}...`).start();
|
|
216
|
-
const result = await compileComponent(component.
|
|
56
|
+
const result = await compileComponent(component.entry, component.styles, component.id);
|
|
217
57
|
if (result.success) {
|
|
218
58
|
// Write output files
|
|
219
59
|
const componentOutDir = path.join(outputPath, component.id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,KAAK,CA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IAE5F,UAAU;IACV,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAC3D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAExD,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAClD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,iBAAiB,UAAU,EAAE,CAAC,CAAC,CAAC;IACxD,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,MAAM,EAAE,CAAC,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,UAAU,IAAI,CAAC,CAAC,CAAC;IAEvD,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;SACxB,WAAW,CAAC,iCAAiC,CAAC;SAC9C,MAAM,CAAC,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,CAAC;SACxD,MAAM,CAAC,eAAe,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA0lDpC,wBAAgB,mBAAmB,IAAI,OAAO,CA2M7C"}
|
package/dist/commands/config.js
CHANGED
|
@@ -234,6 +234,14 @@ async function parsePropsFlag(propsJson, config, configPath) {
|
|
|
234
234
|
}));
|
|
235
235
|
process.exit(1);
|
|
236
236
|
}
|
|
237
|
+
// Validate LINK / LIST_OF_LINK defaultValue shape (reject JSON strings and legacy { href })
|
|
238
|
+
if ((propType === "LINK" || propType === "LIST_OF_LINK") && r.defaultValue !== undefined) {
|
|
239
|
+
const linkError = validateLinkDefaultValue(propType, r.defaultValue, r.name);
|
|
240
|
+
if (linkError) {
|
|
241
|
+
console.log(JSON.stringify({ success: false, error: linkError }));
|
|
242
|
+
process.exit(1);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
237
245
|
// Auto-generate displayName if omitted
|
|
238
246
|
const displayName = typeof r.displayName === "string" && r.displayName
|
|
239
247
|
? r.displayName
|
|
@@ -489,14 +497,22 @@ async function addProp(ref, options) {
|
|
|
489
497
|
process.exit(1);
|
|
490
498
|
}
|
|
491
499
|
}
|
|
500
|
+
const parsedDefaultValue = options.defaultValue !== undefined ? parseDefaultValue(options.defaultValue, propType) : undefined;
|
|
501
|
+
if ((propType === "LINK" || propType === "LIST_OF_LINK") && parsedDefaultValue !== undefined) {
|
|
502
|
+
const linkError = validateLinkDefaultValue(propType, parsedDefaultValue, options.name);
|
|
503
|
+
if (linkError) {
|
|
504
|
+
console.log(JSON.stringify({ success: false, error: linkError }));
|
|
505
|
+
process.exit(1);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
492
508
|
const newProp = {
|
|
493
509
|
name: options.name,
|
|
494
510
|
displayName: options.displayName,
|
|
495
511
|
type: propType,
|
|
496
512
|
required: options.required ?? false,
|
|
497
513
|
...(options.description ? { description: options.description } : {}),
|
|
498
|
-
...(
|
|
499
|
-
? { defaultValue:
|
|
514
|
+
...(parsedDefaultValue !== undefined
|
|
515
|
+
? { defaultValue: parsedDefaultValue }
|
|
500
516
|
: {}),
|
|
501
517
|
...(options.group ? { groupId: options.group } : {}),
|
|
502
518
|
...(options.typeId ? { typeId: options.typeId } : {}),
|
|
@@ -530,10 +546,70 @@ function parseDefaultValue(value, propType) {
|
|
|
530
546
|
return Number(value);
|
|
531
547
|
case "BOOLEAN":
|
|
532
548
|
return value === "true";
|
|
549
|
+
case "LINK":
|
|
550
|
+
case "LIST_OF_LINK":
|
|
551
|
+
// The --default-value flag arrives as a string; LINK values must be stored as a
|
|
552
|
+
// typed object. Parse it here; if it is not valid JSON, return the raw string so
|
|
553
|
+
// validateLinkDefaultValue can report a precise error.
|
|
554
|
+
try {
|
|
555
|
+
return JSON.parse(value);
|
|
556
|
+
}
|
|
557
|
+
catch {
|
|
558
|
+
return value;
|
|
559
|
+
}
|
|
533
560
|
default:
|
|
534
561
|
return value;
|
|
535
562
|
}
|
|
536
563
|
}
|
|
564
|
+
const VALID_LINK_TYPES = ["PAGE", "EXTERNAL", "FILE"];
|
|
565
|
+
const LINK_SHAPE_HELP = 'A link must be an object: { "linkType": "EXTERNAL", "label": "Text", "externalLink": "https://...", "subLinks": [] } ' +
|
|
566
|
+
'for external links, or { "linkType": "PAGE", "label": "Text", "pageType": "INDEX", "subLinks": [] } for store pages. ' +
|
|
567
|
+
"Do NOT pass a JSON string or a { label, href } shape.";
|
|
568
|
+
// Returns the index of the first array element that fails `fn`, as an error string, or null.
|
|
569
|
+
const firstError = (arr, fn) => arr.reduce((acc, item, index) => acc ?? fn(item, index), null);
|
|
570
|
+
const validateSingleLink = (link, propName, path) => {
|
|
571
|
+
const where = `defaultValue for prop "${propName}"${path}`;
|
|
572
|
+
if (typeof link === "string") {
|
|
573
|
+
return `${where} is a JSON string but must be an object. ${LINK_SHAPE_HELP}`;
|
|
574
|
+
}
|
|
575
|
+
if (!link || typeof link !== "object" || Array.isArray(link)) {
|
|
576
|
+
return `${where} must be a link object. ${LINK_SHAPE_HELP}`;
|
|
577
|
+
}
|
|
578
|
+
const l = link;
|
|
579
|
+
if ("href" in l && !("linkType" in l)) {
|
|
580
|
+
return `${where} uses a legacy { href } shape without "linkType". Use "linkType" + "externalLink"/"pageType" instead. ${LINK_SHAPE_HELP}`;
|
|
581
|
+
}
|
|
582
|
+
if (typeof l.linkType !== "string" || !VALID_LINK_TYPES.includes(l.linkType)) {
|
|
583
|
+
return `${where} must have a valid "linkType" (one of ${VALID_LINK_TYPES.join(", ")}). ${LINK_SHAPE_HELP}`;
|
|
584
|
+
}
|
|
585
|
+
if (l.subLinks !== undefined && !Array.isArray(l.subLinks)) {
|
|
586
|
+
return `${where}: "subLinks" must be an array (use [] when there are none).`;
|
|
587
|
+
}
|
|
588
|
+
if (Array.isArray(l.subLinks)) {
|
|
589
|
+
return firstError(l.subLinks, (sl, i) => validateSingleLink(sl, propName, `${path}.subLinks[${i}]`));
|
|
590
|
+
}
|
|
591
|
+
return null;
|
|
592
|
+
};
|
|
593
|
+
// Validates a LINK / LIST_OF_LINK defaultValue. Returns an error message, or null if valid.
|
|
594
|
+
// These defaults are a frequent source of bad data: agents tend to pass a JSON string or a
|
|
595
|
+
// legacy { label, href } shape. Rejecting them at authoring time keeps malformed link values
|
|
596
|
+
// out of published themes.
|
|
597
|
+
function validateLinkDefaultValue(propType, value, propName) {
|
|
598
|
+
if (value === undefined || value === null)
|
|
599
|
+
return null;
|
|
600
|
+
if (propType === "LINK") {
|
|
601
|
+
return validateSingleLink(value, propName, "");
|
|
602
|
+
}
|
|
603
|
+
// LIST_OF_LINK
|
|
604
|
+
if (typeof value === "string") {
|
|
605
|
+
return `defaultValue for prop "${propName}" is a JSON string but must be an object { "links": [...] }. ${LINK_SHAPE_HELP}`;
|
|
606
|
+
}
|
|
607
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || !Array.isArray(value.links)) {
|
|
608
|
+
return `defaultValue for prop "${propName}" must be an object with a "links" array: { "links": [ <link>, ... ] }. ${LINK_SHAPE_HELP}`;
|
|
609
|
+
}
|
|
610
|
+
const links = value.links;
|
|
611
|
+
return firstError(links, (link, i) => validateSingleLink(link, propName, `.links[${i}]`));
|
|
612
|
+
}
|
|
537
613
|
function updateProp(ref, options) {
|
|
538
614
|
const { config, configPath } = loadConfig();
|
|
539
615
|
const component = resolveComponent(config, ref);
|
|
@@ -567,7 +643,15 @@ function updateProp(ref, options) {
|
|
|
567
643
|
prop.description = options.description || undefined;
|
|
568
644
|
}
|
|
569
645
|
if (options.defaultValue !== undefined) {
|
|
570
|
-
|
|
646
|
+
const parsed = parseDefaultValue(options.defaultValue, prop.type);
|
|
647
|
+
if (prop.type === "LINK" || prop.type === "LIST_OF_LINK") {
|
|
648
|
+
const linkError = validateLinkDefaultValue(prop.type, parsed, prop.name);
|
|
649
|
+
if (linkError) {
|
|
650
|
+
console.log(JSON.stringify({ success: false, error: linkError }));
|
|
651
|
+
process.exit(1);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
prop.defaultValue = parsed;
|
|
571
655
|
}
|
|
572
656
|
if (options.group !== undefined) {
|
|
573
657
|
if (options.group === "" || options.group === "none") {
|