@ikas/component-cli 1.4.0-beta.9 → 1.4.0-beta.90
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/add-to-page.d.ts +3 -0
- package/dist/commands/add-to-page.d.ts.map +1 -0
- package/dist/commands/add-to-page.js +41 -0
- package/dist/commands/add-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 +112 -4
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/create-design-tokens.d.ts +24 -0
- package/dist/commands/create-design-tokens.d.ts.map +1 -0
- package/dist/commands/create-design-tokens.js +297 -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/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +77 -49
- package/dist/commands/dev.js.map +1 -1
- 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/import.d.ts +3 -0
- package/dist/commands/import.d.ts.map +1 -0
- package/dist/commands/import.js +25 -0
- package/dist/commands/import.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-imported.d.ts +3 -0
- package/dist/commands/list-imported.d.ts.map +1 -0
- package/dist/commands/list-imported.js +25 -0
- package/dist/commands/list-imported.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-pages.d.ts +3 -0
- package/dist/commands/list-pages.d.ts.map +1 -0
- package/dist/commands/list-pages.js +21 -0
- package/dist/commands/list-pages.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 +55 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +11 -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 +530 -62
- package/dist/utils/compile.js.map +1 -1
- package/dist/utils/component-helpers.d.ts +21 -3
- package/dist/utils/component-helpers.d.ts.map +1 -1
- package/dist/utils/component-helpers.js +111 -4
- package/dist/utils/component-helpers.js.map +1 -1
- package/dist/utils/editor-action-client.d.ts +28 -0
- package/dist/utils/editor-action-client.d.ts.map +1 -0
- package/dist/utils/editor-action-client.js +116 -0
- package/dist/utils/editor-action-client.js.map +1 -0
- package/dist/utils/forbid-deep-imports.d.ts +3 -0
- package/dist/utils/forbid-deep-imports.d.ts.map +1 -0
- package/dist/utils/forbid-deep-imports.js +54 -0
- package/dist/utils/forbid-deep-imports.js.map +1 -0
- 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 +40 -2
- package/dist/utils/websocket-server.d.ts.map +1 -1
- package/dist/utils/websocket-server.js +59 -1
- package/dist/utils/websocket-server.js.map +1 -1
- package/package.json +1 -1
- package/templates/add/section.css +11 -0
- package/dist/commands/create.d.ts +0 -9
- package/dist/commands/create.d.ts.map +0 -1
- package/dist/commands/create.js +0 -9
- package/dist/commands/create.js.map +0 -1
- package/dist/commands/proxy.d.ts +0 -39
- package/dist/commands/proxy.d.ts.map +0 -1
- package/dist/commands/proxy.js +0 -212
- package/dist/commands/proxy.js.map +0 -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,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAQ1C,KAAK,UAAU,oBAAoB,CAAC,OAAiC;IACnE,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1D,iBAAiB,CAAC,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC,CAAC;IAC1F,CAAC;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vT;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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-to-page.d.ts","sourceRoot":"","sources":["../../src/commands/add-to-page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA6CpC,wBAAgB,sBAAsB,IAAI,OAAO,CAYhD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { printErrorAndExit, printResultAndExit, runEditorAction, } from "../utils/editor-action-client.js";
|
|
3
|
+
async function runAddToPage(options) {
|
|
4
|
+
if (!options.componentId || typeof options.componentId !== "string") {
|
|
5
|
+
printErrorAndExit(new Error("--component-id is required"));
|
|
6
|
+
}
|
|
7
|
+
if (!options.pageId || typeof options.pageId !== "string") {
|
|
8
|
+
printErrorAndExit(new Error("--page-id is required (use `ikas-component list-pages` to discover ids)"));
|
|
9
|
+
}
|
|
10
|
+
let index;
|
|
11
|
+
if (options.index !== undefined) {
|
|
12
|
+
index = parseInt(options.index, 10);
|
|
13
|
+
if (Number.isNaN(index) || index < 0) {
|
|
14
|
+
printErrorAndExit(new Error("--index must be a non-negative integer"));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const port = options.port ? parseInt(options.port, 10) : undefined;
|
|
18
|
+
try {
|
|
19
|
+
const result = await runEditorAction("add-section-to-page", {
|
|
20
|
+
componentId: options.componentId,
|
|
21
|
+
pageId: options.pageId,
|
|
22
|
+
...(typeof index === "number" ? { index } : {}),
|
|
23
|
+
}, port ? { port } : {});
|
|
24
|
+
printResultAndExit(result);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
printErrorAndExit(e);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function createAddToPageCommand() {
|
|
31
|
+
const cmd = new Command("add-to-page");
|
|
32
|
+
cmd
|
|
33
|
+
.description("Place a section-type code component on a page. Requires the component to be imported first (see `ikas-component import`).")
|
|
34
|
+
.requiredOption("--component-id <id>", "Code component id (from `ikas-component list-imported`)")
|
|
35
|
+
.requiredOption("--page-id <id>", "Page id (from `ikas-component list-pages`)")
|
|
36
|
+
.option("--index <n>", "Zero-based insertion index in the page; appends when omitted")
|
|
37
|
+
.option("--port <port>", "Dev server WebSocket port", "5201")
|
|
38
|
+
.action(runAddToPage);
|
|
39
|
+
return cmd;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=add-to-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-to-page.js","sourceRoot":"","sources":["../../src/commands/add-to-page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAS1C,KAAK,UAAU,YAAY,CAAC,OAAyB;IACnD,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,OAAO,CAAC,WAAW,KAAK,QAAQ,EAAE,CAAC;QACpE,iBAAiB,CAAC,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1D,iBAAiB,CAAC,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC,CAAC;IAC1G,CAAC;IACD,IAAI,KAAyB,CAAC;IAC9B,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAChC,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC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-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,CAAC;AACtB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,mFAAmF;AACnF,sFAAsF;AACtF,yFAAyF;AACzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAMvD,SAAS,YAAY;IACnB,MAAM,OAAO,GAAG,GAAG,CAAC,kCAAkC,CAAC,CAAC,KAAK,EAAE,CAAC;IAChE,IAAI,CAAC;QACH,QAAQ,CAAC,kBAAkB,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QACpE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC;QA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AAM,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
|
@@ -144,6 +144,19 @@ function camelCaseToDisplayName(name) {
|
|
|
144
144
|
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
145
145
|
.replace(/^./, (c) => c.toUpperCase());
|
|
146
146
|
}
|
|
147
|
+
const ALLOWED_PROP_FIELDS = new Set([
|
|
148
|
+
"name",
|
|
149
|
+
"displayName",
|
|
150
|
+
"type",
|
|
151
|
+
"required",
|
|
152
|
+
"description",
|
|
153
|
+
"defaultValue",
|
|
154
|
+
"groupId",
|
|
155
|
+
"typeId",
|
|
156
|
+
"enumTypeId",
|
|
157
|
+
"filteredComponentIds",
|
|
158
|
+
"privateVarMap",
|
|
159
|
+
]);
|
|
147
160
|
/**
|
|
148
161
|
* Parse and validate the --props JSON flag for add-component.
|
|
149
162
|
* Returns validated ComponentProp[] or exits with error.
|
|
@@ -171,6 +184,16 @@ async function parsePropsFlag(propsJson, config, configPath) {
|
|
|
171
184
|
const props = [];
|
|
172
185
|
for (const raw of rawProps) {
|
|
173
186
|
const r = raw;
|
|
187
|
+
const unknownFields = Object.keys(r).filter((k) => !ALLOWED_PROP_FIELDS.has(k));
|
|
188
|
+
if (unknownFields.length > 0) {
|
|
189
|
+
console.log(JSON.stringify({
|
|
190
|
+
success: false,
|
|
191
|
+
error: `Unknown field(s) in --props entry: ${unknownFields.join(", ")}. ` +
|
|
192
|
+
`Allowed: ${[...ALLOWED_PROP_FIELDS].join(", ")}. ` +
|
|
193
|
+
`Note: use "groupId" (not "group") and "defaultValue" (not "default") in --props JSON.`,
|
|
194
|
+
}));
|
|
195
|
+
process.exit(1);
|
|
196
|
+
}
|
|
174
197
|
if (!r.name || typeof r.name !== "string") {
|
|
175
198
|
console.log(JSON.stringify({
|
|
176
199
|
success: false,
|
|
@@ -211,6 +234,14 @@ async function parsePropsFlag(propsJson, config, configPath) {
|
|
|
211
234
|
}));
|
|
212
235
|
process.exit(1);
|
|
213
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
|
+
}
|
|
214
245
|
// Auto-generate displayName if omitted
|
|
215
246
|
const displayName = typeof r.displayName === "string" && r.displayName
|
|
216
247
|
? r.displayName
|
|
@@ -466,14 +497,22 @@ async function addProp(ref, options) {
|
|
|
466
497
|
process.exit(1);
|
|
467
498
|
}
|
|
468
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
|
+
}
|
|
469
508
|
const newProp = {
|
|
470
509
|
name: options.name,
|
|
471
510
|
displayName: options.displayName,
|
|
472
511
|
type: propType,
|
|
473
512
|
required: options.required ?? false,
|
|
474
513
|
...(options.description ? { description: options.description } : {}),
|
|
475
|
-
...(
|
|
476
|
-
? { defaultValue:
|
|
514
|
+
...(parsedDefaultValue !== undefined
|
|
515
|
+
? { defaultValue: parsedDefaultValue }
|
|
477
516
|
: {}),
|
|
478
517
|
...(options.group ? { groupId: options.group } : {}),
|
|
479
518
|
...(options.typeId ? { typeId: options.typeId } : {}),
|
|
@@ -507,10 +546,70 @@ function parseDefaultValue(value, propType) {
|
|
|
507
546
|
return Number(value);
|
|
508
547
|
case "BOOLEAN":
|
|
509
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
|
+
}
|
|
510
560
|
default:
|
|
511
561
|
return value;
|
|
512
562
|
}
|
|
513
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
|
+
}
|
|
514
613
|
function updateProp(ref, options) {
|
|
515
614
|
const { config, configPath } = loadConfig();
|
|
516
615
|
const component = resolveComponent(config, ref);
|
|
@@ -544,7 +643,15 @@ function updateProp(ref, options) {
|
|
|
544
643
|
prop.description = options.description || undefined;
|
|
545
644
|
}
|
|
546
645
|
if (options.defaultValue !== undefined) {
|
|
547
|
-
|
|
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;
|
|
548
655
|
}
|
|
549
656
|
if (options.group !== undefined) {
|
|
550
657
|
if (options.group === "" || options.group === "none") {
|
|
@@ -1112,7 +1219,8 @@ export function createConfigCommand() {
|
|
|
1112
1219
|
.option("--type <type>", "Component type: section or component", "component")
|
|
1113
1220
|
.option("--isHeader", "Mark this section as the store header (only for type: section)")
|
|
1114
1221
|
.option("--isFooter", "Mark this section as the store footer (only for type: section)")
|
|
1115
|
-
.option("--props <json>", "JSON array of props
|
|
1222
|
+
.option("--props <json>", "JSON array of props. Required per entry: name, type. Optional: displayName (auto from name), required, description, defaultValue, groupId, typeId (TYPE props), enumTypeId (ENUM props), filteredComponentIds, privateVarMap. " +
|
|
1223
|
+
"Example: '[{\"name\":\"title\",\"type\":\"TEXT\",\"required\":true,\"defaultValue\":\"Hello\",\"groupId\":\"basic\"}]'")
|
|
1116
1224
|
.action((options) => {
|
|
1117
1225
|
addComponent(options.name, options);
|
|
1118
1226
|
});
|