@ikas/component-cli 0.15.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/bin/create-ikas-component.js +8 -0
- package/bin/ikas-component.js +8 -0
- package/dist/commands/add.d.ts +3 -0
- package/dist/commands/add.d.ts.map +1 -0
- package/dist/commands/add.js +156 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/build.d.ts +3 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +273 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/create.d.ts +4 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +572 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/dev.d.ts +3 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +381 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/publish.d.ts +3 -0
- package/dist/commands/publish.d.ts.map +1 -0
- package/dist/commands/publish.js +136 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/compile.d.ts +25 -0
- package/dist/utils/compile.d.ts.map +1 -0
- package/dist/utils/compile.js +420 -0
- package/dist/utils/compile.js.map +1 -0
- package/dist/utils/component-helpers.d.ts +23 -0
- package/dist/utils/component-helpers.d.ts.map +1 -0
- package/dist/utils/component-helpers.js +177 -0
- package/dist/utils/component-helpers.js.map +1 -0
- package/dist/utils/css-import-resolver.d.ts +10 -0
- package/dist/utils/css-import-resolver.d.ts.map +1 -0
- package/dist/utils/css-import-resolver.js +40 -0
- package/dist/utils/css-import-resolver.js.map +1 -0
- package/dist/utils/esm-transform.d.ts +29 -0
- package/dist/utils/esm-transform.d.ts.map +1 -0
- package/dist/utils/esm-transform.js +216 -0
- package/dist/utils/esm-transform.js.map +1 -0
- package/dist/utils/observer-runtime.d.ts +3 -0
- package/dist/utils/observer-runtime.d.ts.map +1 -0
- package/dist/utils/observer-runtime.js +52 -0
- package/dist/utils/observer-runtime.js.map +1 -0
- package/dist/utils/websocket-server.d.ts +180 -0
- package/dist/utils/websocket-server.d.ts.map +1 -0
- package/dist/utils/websocket-server.js +287 -0
- package/dist/utils/websocket-server.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import * as crypto from "crypto";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
/**
|
|
5
|
+
* Generate an 8-character random alphanumeric project ID (lowercase + digits).
|
|
6
|
+
* Used to namespace component IDs across independent CLI projects.
|
|
7
|
+
*/
|
|
8
|
+
export function generateProjectId() {
|
|
9
|
+
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
10
|
+
const bytes = crypto.randomBytes(8);
|
|
11
|
+
let result = "";
|
|
12
|
+
for (let i = 0; i < 8; i++) {
|
|
13
|
+
result += chars[bytes[i] % chars.length];
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generate a component ID namespaced by projectId.
|
|
19
|
+
* Format: `${projectId}-${kebabName}`
|
|
20
|
+
*/
|
|
21
|
+
export function generateComponentId(projectId, kebabName) {
|
|
22
|
+
return `${projectId}-${kebabName}`;
|
|
23
|
+
}
|
|
24
|
+
export const PROP_TYPES = [
|
|
25
|
+
"TEXT",
|
|
26
|
+
"NUMBER",
|
|
27
|
+
"BOOLEAN",
|
|
28
|
+
"IMAGE",
|
|
29
|
+
"LINK",
|
|
30
|
+
"LIST_OF_LINK",
|
|
31
|
+
"COLOR",
|
|
32
|
+
"SELECT",
|
|
33
|
+
"PRODUCT",
|
|
34
|
+
"PRODUCT_LIST",
|
|
35
|
+
"CATEGORY",
|
|
36
|
+
"CATEGORY_LIST",
|
|
37
|
+
"BRAND",
|
|
38
|
+
"BRAND_LIST",
|
|
39
|
+
"BLOG_POST",
|
|
40
|
+
"BLOG_POST_LIST"
|
|
41
|
+
];
|
|
42
|
+
export const PROP_TYPE_TO_TS = {
|
|
43
|
+
TEXT: "string",
|
|
44
|
+
NUMBER: "number",
|
|
45
|
+
BOOLEAN: "boolean",
|
|
46
|
+
IMAGE: "IkasImage | null",
|
|
47
|
+
LINK: "IkasLink | null",
|
|
48
|
+
LIST_OF_LINK: "IkasNavigationLinkList",
|
|
49
|
+
COLOR: "string",
|
|
50
|
+
SELECT: "string",
|
|
51
|
+
PRODUCT: "IkasProduct | null",
|
|
52
|
+
PRODUCT_LIST: "IkasProductList",
|
|
53
|
+
CATEGORY: "IkasCategory | null",
|
|
54
|
+
CATEGORY_LIST: "IkasCategoryList",
|
|
55
|
+
BRAND: "IkasBrand | null",
|
|
56
|
+
BRAND_LIST: "IkasBrandList",
|
|
57
|
+
BLOG_POST: "IkasBlogPost | null",
|
|
58
|
+
BLOG_POST_LIST: "IkasBlogPostList"
|
|
59
|
+
};
|
|
60
|
+
export function toKebabCase(str) {
|
|
61
|
+
return str
|
|
62
|
+
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
63
|
+
.replace(/[\s_]+/g, "-")
|
|
64
|
+
.toLowerCase();
|
|
65
|
+
}
|
|
66
|
+
export function toPascalCase(str) {
|
|
67
|
+
return str
|
|
68
|
+
.split(/[-_\s]+/)
|
|
69
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
70
|
+
.join("");
|
|
71
|
+
}
|
|
72
|
+
export function generateTypesFile(componentName, props, type) {
|
|
73
|
+
const imports = new Set();
|
|
74
|
+
props.forEach((prop) => {
|
|
75
|
+
const tsType = PROP_TYPE_TO_TS[prop.type];
|
|
76
|
+
if (tsType?.includes("Ikas")) {
|
|
77
|
+
const matches = tsType.match(/Ikas\w+/g);
|
|
78
|
+
matches?.forEach((m) => imports.add(m));
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const interfaceName = "Props";
|
|
82
|
+
let content = "";
|
|
83
|
+
if (imports.size > 0) {
|
|
84
|
+
const importsList = Array.from(imports).join(", ");
|
|
85
|
+
content += `import type { ${importsList} } from "@ikas/bp-storefront";\n\n`;
|
|
86
|
+
}
|
|
87
|
+
content += `export interface ${interfaceName} {\n`;
|
|
88
|
+
props.forEach((prop) => {
|
|
89
|
+
const tsType = PROP_TYPE_TO_TS[prop.type] || "unknown";
|
|
90
|
+
const optional = prop.required ? "" : "?";
|
|
91
|
+
if (prop.description) {
|
|
92
|
+
content += ` /** ${prop.description} */\n`;
|
|
93
|
+
}
|
|
94
|
+
content += ` ${prop.name}${optional}: ${tsType};\n`;
|
|
95
|
+
});
|
|
96
|
+
content += `}\n`;
|
|
97
|
+
return content;
|
|
98
|
+
}
|
|
99
|
+
export function generateComponentFile(componentName, props, type) {
|
|
100
|
+
const propsDestructure = props.map((p) => p.name).join(", ");
|
|
101
|
+
const kebabName = toKebabCase(componentName);
|
|
102
|
+
const interfaceName = "Props";
|
|
103
|
+
if (type === "section") {
|
|
104
|
+
return `import { ${interfaceName} } from "./types";
|
|
105
|
+
|
|
106
|
+
export function ${componentName}({ ${propsDestructure} }: ${interfaceName}) {
|
|
107
|
+
return (
|
|
108
|
+
<section className="${kebabName}">
|
|
109
|
+
<div className="${kebabName}-inner">
|
|
110
|
+
<h2>${componentName}</h2>
|
|
111
|
+
{/* Add your section implementation here */}
|
|
112
|
+
</div>
|
|
113
|
+
</section>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
`;
|
|
117
|
+
}
|
|
118
|
+
return `import { ${interfaceName} } from "./types";
|
|
119
|
+
|
|
120
|
+
export function ${componentName}({ ${propsDestructure} }: ${interfaceName}) {
|
|
121
|
+
return (
|
|
122
|
+
<div className="${kebabName}">
|
|
123
|
+
<h2>${componentName}</h2>
|
|
124
|
+
{/* Add your component implementation here */}
|
|
125
|
+
</div>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
`;
|
|
129
|
+
}
|
|
130
|
+
export function generateStylesFile(componentName, type) {
|
|
131
|
+
const kebabName = toKebabCase(componentName);
|
|
132
|
+
if (type === "section") {
|
|
133
|
+
return `.${kebabName} {
|
|
134
|
+
width: 100%;
|
|
135
|
+
padding: 64px 24px;
|
|
136
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.${kebabName}-inner {
|
|
140
|
+
max-width: 1200px;
|
|
141
|
+
margin: 0 auto;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.${kebabName} h2 {
|
|
145
|
+
margin: 0 0 16px 0;
|
|
146
|
+
font-size: 32px;
|
|
147
|
+
font-weight: 700;
|
|
148
|
+
color: #111827;
|
|
149
|
+
}
|
|
150
|
+
`;
|
|
151
|
+
}
|
|
152
|
+
return `.${kebabName} {
|
|
153
|
+
padding: 16px;
|
|
154
|
+
border-radius: 8px;
|
|
155
|
+
background: #f9fafb;
|
|
156
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.${kebabName} h2 {
|
|
160
|
+
margin: 0 0 12px 0;
|
|
161
|
+
font-size: 20px;
|
|
162
|
+
font-weight: 600;
|
|
163
|
+
color: #111827;
|
|
164
|
+
}
|
|
165
|
+
`;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Update the barrel export file (src/components/index.ts) to include all components
|
|
169
|
+
*/
|
|
170
|
+
export function updateBarrelExport(projectRoot, componentNames) {
|
|
171
|
+
const indexPath = path.resolve(projectRoot, "src/components/index.ts");
|
|
172
|
+
const content = componentNames
|
|
173
|
+
.map((name) => `export { ${name} } from "./${name}/index";`)
|
|
174
|
+
.join("\n") + "\n";
|
|
175
|
+
fs.writeFileSync(indexPath, content);
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=component-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-helpers.js","sourceRoot":"","sources":["../../src/utils/component-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAG7B;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,KAAK,GAAG,sCAAsC,CAAC;IACrD,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACpC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAiB,EAAE,SAAiB;IACtE,OAAO,GAAG,SAAS,IAAI,SAAS,EAAE,CAAC;AACrC,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,MAAM;IACN,QAAQ;IACR,SAAS;IACT,OAAO;IACP,MAAM;IACN,cAAc;IACd,OAAO;IACP,QAAQ;IACR,SAAS;IACT,cAAc;IACd,UAAU;IACV,eAAe;IACf,OAAO;IACP,YAAY;IACZ,WAAW;IACX,gBAAgB;CACR,CAAC;AAEX,MAAM,CAAC,MAAM,eAAe,GAA2B;IACrD,IAAI,EAAE,QAAQ;IACd,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,kBAAkB;IACzB,IAAI,EAAE,iBAAiB;IACvB,YAAY,EAAE,wBAAwB;IACtC,KAAK,EAAE,QAAQ;IACf,MAAM,EAAE,QA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/C,SAAS;wBACX,SAAS;cACnB,aAAa;;;;;;CAM1B,CAAC;IACA,CAAC;IAED,OAAO,YAAY,aAAa;;kBAEhB,aAAa,MAAM,gBAAgB,OAAO,aAAa;;sBAEnD,SAAS;YACnB,aAAa;;;;;CAKxB,CAAC;AACF,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,aAAqB,EAAE,IAA8B;IACtF,MAAM,SAAS,GAAG,WAAW,CAAC,aAAa,CAAC,CAAC;IAE7C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,IAAI,SAAS;;;;;;GAMrB,SAAS;;;;;GAKT,SAAS;;;;;;CAMX,CAAC;IACA,CAAC;IAED,OAAO,IAAI,SAAS;;;;;;;GAOnB,SAAS;;;;;;CAMX,CAAC;AACF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAmB,EAAE,cAAwB;IAC9E,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,yBAAyB,CAAC,CAAC;IACvE,MAAM,OAAO,GAAG,cAAc;SAC3B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,IAAI,cAAc,IAAI,UAAU,CAAC;SAC3D,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACrB,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves CSS @import statements by inlining the imported file contents.
|
|
3
|
+
* Handles relative paths and nested imports recursively.
|
|
4
|
+
*
|
|
5
|
+
* @param css - The CSS content to process
|
|
6
|
+
* @param cssFilePath - The absolute path to the CSS file (used to resolve relative imports)
|
|
7
|
+
* @returns The CSS with all @import statements replaced by the imported content
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveCssImports(css: string, cssFilePath: string): string;
|
|
10
|
+
//# sourceMappingURL=css-import-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-import-resolver.d.ts","sourceRoot":"","sources":["../../src/utils/css-import-resolver.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAoC1E"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
/**
|
|
4
|
+
* Resolves CSS @import statements by inlining the imported file contents.
|
|
5
|
+
* Handles relative paths and nested imports recursively.
|
|
6
|
+
*
|
|
7
|
+
* @param css - The CSS content to process
|
|
8
|
+
* @param cssFilePath - The absolute path to the CSS file (used to resolve relative imports)
|
|
9
|
+
* @returns The CSS with all @import statements replaced by the imported content
|
|
10
|
+
*/
|
|
11
|
+
export function resolveCssImports(css, cssFilePath) {
|
|
12
|
+
const importRegex = /@import\s+["']([^"']+)["']\s*;?/g;
|
|
13
|
+
const processedPaths = new Set();
|
|
14
|
+
function resolveImports(content, currentDir) {
|
|
15
|
+
return content.replace(importRegex, (match, importPath) => {
|
|
16
|
+
// Resolve the imported file path
|
|
17
|
+
const resolvedPath = path.resolve(currentDir, importPath);
|
|
18
|
+
// Prevent circular imports
|
|
19
|
+
if (processedPaths.has(resolvedPath)) {
|
|
20
|
+
console.warn(`Circular CSS import detected: ${resolvedPath}`);
|
|
21
|
+
return `/* Circular import skipped: ${importPath} */`;
|
|
22
|
+
}
|
|
23
|
+
// Check if file exists
|
|
24
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
25
|
+
console.warn(`CSS import not found: ${importPath} (resolved to ${resolvedPath})`);
|
|
26
|
+
return `/* Import not found: ${importPath} */`;
|
|
27
|
+
}
|
|
28
|
+
processedPaths.add(resolvedPath);
|
|
29
|
+
// Read and recursively resolve imports in the imported file
|
|
30
|
+
const importedCss = fs.readFileSync(resolvedPath, "utf-8");
|
|
31
|
+
const importedDir = path.dirname(resolvedPath);
|
|
32
|
+
const resolvedCss = resolveImports(importedCss, importedDir);
|
|
33
|
+
return `/* Imported from: ${importPath} */\n${resolvedCss}\n/* End import: ${importPath} */`;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
// Add the main file to processed paths to prevent self-import
|
|
37
|
+
processedPaths.add(path.resolve(cssFilePath));
|
|
38
|
+
return resolveImports(css, path.dirname(cssFilePath));
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=css-import-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-import-resolver.js","sourceRoot":"","sources":["../../src/utils/css-import-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAW,EAAE,WAAmB;IAChE,MAAM,WAAW,GAAG,kCAAkC,CAAC;IACvD,MAAM,cAAc,GAAG,IAAI,GAAG,EAAU,CAAC;IAEzC,SAAS,cAAc,CAAC,OAAe,EAAE,UAAkB;QACzD,OAAO,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;YACxD,iCAAiC;YACjC,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;YAE1D,2BAA2B;YAC3B,IAAI,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;gBACrC,OAAO,CAAC,IAAI,CAAC,iCAAiC,YAAY,EAAE,CAAC,CAAC;gBAC9D,OAAO,+BAA+B,UAAU,KAAK,CAAC;YACxD,CAAC;YAED,uBAAuB;YACvB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;gBACjC,OAAO,CAAC,IAAI,CAAC,yBAAyB,UAAU,iBAAiB,YAAY,GAAG,CAAC,CAAC;gBAClF,OAAO,wBAAwB,UAAU,KAAK,CAAC;YACjD,CAAC;YAED,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YAEjC,4DAA4D;YAC5D,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;YAC3D,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC/C,MAAM,WAAW,GAAG,cAAc,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;YAE7D,OAAO,qBAAqB,UAAU,QAAQ,WAAW,oBAAoB,UAAU,KAAK,CAAC;QAC/F,CAAC,CAAC,CAAC;IACL,CAAC;IAED,8DAA8D;IAC9D,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IAE9C,OAAO,cAAc,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform ESM imports/exports to window globals for canvas mode.
|
|
3
|
+
* This allows pre-compiled code to run in the editor canvas where
|
|
4
|
+
* dependencies are provided via window globals.
|
|
5
|
+
*/
|
|
6
|
+
export interface TransformOptions {
|
|
7
|
+
/**
|
|
8
|
+
* When set, chunk imports (from "./chunk-*.js") are resolved via window.__cc_chunks.
|
|
9
|
+
* Map of chunkFileName (e.g. "chunk-ABCD") to the registry key used in window.__cc_chunks.
|
|
10
|
+
*/
|
|
11
|
+
chunkMapping?: Map<string, string>;
|
|
12
|
+
}
|
|
13
|
+
export declare function transformEsmToWindowGlobals(code: string, options?: TransformOptions): string;
|
|
14
|
+
/**
|
|
15
|
+
* Transform a chunk file's ESM code for canvas mode.
|
|
16
|
+
* External imports → window globals (same as entry files).
|
|
17
|
+
* Exports → stored in window.__cc_chunks[chunkId].
|
|
18
|
+
*/
|
|
19
|
+
export declare function transformChunkForCanvas(code: string, chunkId: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Build a chunk mapping from esbuild output by scanning entry files
|
|
22
|
+
* for relative imports to chunk files.
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildChunkMapping(chunkIds: string[], projectId?: string): Map<string, string>;
|
|
25
|
+
/**
|
|
26
|
+
* Get the scope class name for a component ID
|
|
27
|
+
*/
|
|
28
|
+
export declare function getScopeClassName(componentId: string): string;
|
|
29
|
+
//# sourceMappingURL=esm-transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esm-transform.d.ts","sourceRoot":"","sources":["../../src/utils/esm-transform.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA2EH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAyK5F;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAQ7E;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAAE,EAClB,SAAS,CAAC,EAAE,MAAM,GACjB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAQrB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE7D"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform ESM imports/exports to window globals for canvas mode.
|
|
3
|
+
* This allows pre-compiled code to run in the editor canvas where
|
|
4
|
+
* dependencies are provided via window globals.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Mapping of module names to their window global equivalents (exact match)
|
|
8
|
+
*/
|
|
9
|
+
const MODULE_TO_GLOBAL = {
|
|
10
|
+
"preact": "window.Preact",
|
|
11
|
+
"preact/hooks": "window.PreactHooks",
|
|
12
|
+
"preact/compat": "window.Preact",
|
|
13
|
+
"preact/jsx-runtime": "window.Preact",
|
|
14
|
+
"mobx": "window.Mobx",
|
|
15
|
+
"@ikas/bp-storefront": "window.IkasStorefront",
|
|
16
|
+
"@ikas/bp-storefront-models": "window.IkasStorefrontModels",
|
|
17
|
+
"@ikas/bp-storefront-config": "window.IkasStorefrontConfig"
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Prefix-based fallback mapping. When no exact match exists, the longest
|
|
21
|
+
* matching prefix wins. Entries are sorted longest-first at lookup time.
|
|
22
|
+
*/
|
|
23
|
+
const MODULE_PREFIX_TO_GLOBAL = {
|
|
24
|
+
"preact": "window.Preact",
|
|
25
|
+
"@ikas/bp-storefront": "window.IkasStorefront"
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Resolve a module name to its window global. Tries exact match first,
|
|
29
|
+
* then falls back to longest-prefix match.
|
|
30
|
+
*/
|
|
31
|
+
function resolveModuleGlobal(moduleName) {
|
|
32
|
+
// Exact match
|
|
33
|
+
if (MODULE_TO_GLOBAL[moduleName]) {
|
|
34
|
+
return MODULE_TO_GLOBAL[moduleName];
|
|
35
|
+
}
|
|
36
|
+
// Longest-prefix match
|
|
37
|
+
const prefixes = Object.keys(MODULE_PREFIX_TO_GLOBAL).sort((a, b) => b.length - a.length);
|
|
38
|
+
for (const prefix of prefixes) {
|
|
39
|
+
if (moduleName === prefix || moduleName.startsWith(prefix + "/")) {
|
|
40
|
+
return MODULE_PREFIX_TO_GLOBAL[prefix];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Transform ESM imports to window global assignments.
|
|
47
|
+
* Example:
|
|
48
|
+
* import { h, Fragment } from "preact";
|
|
49
|
+
* Becomes:
|
|
50
|
+
* const { h, Fragment } = window.Preact;
|
|
51
|
+
*
|
|
52
|
+
* And:
|
|
53
|
+
* import { useState } from "preact/hooks";
|
|
54
|
+
* Becomes:
|
|
55
|
+
* const { useState } = window.PreactHooks;
|
|
56
|
+
*/
|
|
57
|
+
/**
|
|
58
|
+
* Check if a module specifier is a relative chunk import (e.g., "./chunk-ABCD.js")
|
|
59
|
+
*/
|
|
60
|
+
function isChunkImport(moduleName) {
|
|
61
|
+
return moduleName.startsWith("./chunk-");
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Extract chunk ID from a relative chunk import path.
|
|
65
|
+
* "./chunk-ABCD.js" → "chunk-ABCD"
|
|
66
|
+
*/
|
|
67
|
+
function chunkIdFromImport(moduleName) {
|
|
68
|
+
return moduleName.replace(/^\.\//, "").replace(/\.js$/, "");
|
|
69
|
+
}
|
|
70
|
+
export function transformEsmToWindowGlobals(code, options) {
|
|
71
|
+
let transformed = code;
|
|
72
|
+
const chunkMapping = options?.chunkMapping;
|
|
73
|
+
// Transform named imports: import { a, b } from "module";
|
|
74
|
+
transformed = transformed.replace(/import\s*\{([^}]+)\}\s*from\s*["']([^"']+)["']\s*;?/g, (match, imports, moduleName) => {
|
|
75
|
+
// Handle chunk imports
|
|
76
|
+
if (chunkMapping && isChunkImport(moduleName)) {
|
|
77
|
+
const chunkId = chunkIdFromImport(moduleName);
|
|
78
|
+
const registryKey = chunkMapping.get(chunkId) || chunkId;
|
|
79
|
+
const destructured = imports.replace(/([\w$]+)\s+as\s+([\w$]+)/g, "$1: $2");
|
|
80
|
+
return `const {${destructured}} = window.__cc_chunks["${registryKey}"];`;
|
|
81
|
+
}
|
|
82
|
+
const globalName = resolveModuleGlobal(moduleName);
|
|
83
|
+
if (globalName) {
|
|
84
|
+
// Convert ESM "as" renames to destructuring ":" renames
|
|
85
|
+
// e.g. "Reaction as t" → "Reaction: t"
|
|
86
|
+
const destructured = imports.replace(/([\w$]+)\s+as\s+([\w$]+)/g, "$1: $2");
|
|
87
|
+
return `const {${destructured}} = ${globalName};`;
|
|
88
|
+
}
|
|
89
|
+
// Keep unknown imports as-is (they'll error at runtime, which is expected)
|
|
90
|
+
return match;
|
|
91
|
+
});
|
|
92
|
+
// Transform default imports: import Something from "module";
|
|
93
|
+
transformed = transformed.replace(/import\s+([\w$]+)\s+from\s*["']([^"']+)["']\s*;?/g, (match, importName, moduleName) => {
|
|
94
|
+
if (chunkMapping && isChunkImport(moduleName)) {
|
|
95
|
+
const chunkId = chunkIdFromImport(moduleName);
|
|
96
|
+
const registryKey = chunkMapping.get(chunkId) || chunkId;
|
|
97
|
+
return `const ${importName} = window.__cc_chunks["${registryKey}"].default || window.__cc_chunks["${registryKey}"];`;
|
|
98
|
+
}
|
|
99
|
+
const globalName = resolveModuleGlobal(moduleName);
|
|
100
|
+
if (globalName) {
|
|
101
|
+
return `const ${importName} = ${globalName}.default || ${globalName};`;
|
|
102
|
+
}
|
|
103
|
+
return match;
|
|
104
|
+
});
|
|
105
|
+
// Transform namespace imports: import * as Something from "module";
|
|
106
|
+
transformed = transformed.replace(/import\s*\*\s*as\s+([\w$]+)\s+from\s*["']([^"']+)["']\s*;?/g, (match, importName, moduleName) => {
|
|
107
|
+
if (chunkMapping && isChunkImport(moduleName)) {
|
|
108
|
+
const chunkId = chunkIdFromImport(moduleName);
|
|
109
|
+
const registryKey = chunkMapping.get(chunkId) || chunkId;
|
|
110
|
+
return `const ${importName} = window.__cc_chunks["${registryKey}"];`;
|
|
111
|
+
}
|
|
112
|
+
const globalName = resolveModuleGlobal(moduleName);
|
|
113
|
+
if (globalName) {
|
|
114
|
+
return `const ${importName} = ${globalName};`;
|
|
115
|
+
}
|
|
116
|
+
return match;
|
|
117
|
+
});
|
|
118
|
+
// Transform mixed imports: import Default, { named } from "module";
|
|
119
|
+
transformed = transformed.replace(/import\s+([\w$]+)\s*,\s*\{([^}]+)\}\s*from\s*["']([^"']+)["']\s*;?/g, (match, defaultImport, namedImports, moduleName) => {
|
|
120
|
+
if (chunkMapping && isChunkImport(moduleName)) {
|
|
121
|
+
const chunkId = chunkIdFromImport(moduleName);
|
|
122
|
+
const registryKey = chunkMapping.get(chunkId) || chunkId;
|
|
123
|
+
const destructured = namedImports.replace(/([\w$]+)\s+as\s+([\w$]+)/g, "$1: $2");
|
|
124
|
+
return `const ${defaultImport} = window.__cc_chunks["${registryKey}"].default || window.__cc_chunks["${registryKey}"]; const {${destructured}} = window.__cc_chunks["${registryKey}"];`;
|
|
125
|
+
}
|
|
126
|
+
const globalName = resolveModuleGlobal(moduleName);
|
|
127
|
+
if (globalName) {
|
|
128
|
+
const destructured = namedImports.replace(/([\w$]+)\s+as\s+([\w$]+)/g, "$1: $2");
|
|
129
|
+
return `const ${defaultImport} = ${globalName}.default || ${globalName}; const {${destructured}} = ${globalName};`;
|
|
130
|
+
}
|
|
131
|
+
return match;
|
|
132
|
+
});
|
|
133
|
+
// Transform exports to __exports object
|
|
134
|
+
// Track names from `export default function/class` so we can append assignments
|
|
135
|
+
const defaultDeclNames = [];
|
|
136
|
+
// Handle `export default function Name(...){}` and `export default class Name{}`
|
|
137
|
+
// Must come before the simple `export default <identifier>` regex
|
|
138
|
+
transformed = transformed.replace(/export\s+default\s+(function|class)\s+([\w$]+)/g, (match, keyword, name) => {
|
|
139
|
+
defaultDeclNames.push(name);
|
|
140
|
+
return `${keyword} ${name}`;
|
|
141
|
+
});
|
|
142
|
+
// export default <identifier>; -> __exports.default = <identifier>;
|
|
143
|
+
// Require semicolon or end-of-string to avoid matching `export default function`
|
|
144
|
+
transformed = transformed.replace(/export\s+default\s+([\w$]+)\s*;/g, "__exports.default = $1;");
|
|
145
|
+
// Append __exports.default assignments for captured function/class names
|
|
146
|
+
for (const name of defaultDeclNames) {
|
|
147
|
+
transformed += `\n__exports.default = ${name};`;
|
|
148
|
+
}
|
|
149
|
+
// export { a, b }; -> __exports.a = a; __exports.b = b;
|
|
150
|
+
transformed = transformed.replace(/export\s*\{([^}]+)\}\s*;?/g, (match, exports) => {
|
|
151
|
+
const exportNames = exports.split(",").map((e) => e.trim());
|
|
152
|
+
return exportNames
|
|
153
|
+
.map((name) => {
|
|
154
|
+
// Handle "as" renames: export { foo as bar }
|
|
155
|
+
const parts = name.split(/\s+as\s+/);
|
|
156
|
+
const localName = parts[0].trim();
|
|
157
|
+
const exportName = (parts[1] || parts[0]).trim();
|
|
158
|
+
return `__exports.${exportName} = ${localName};`;
|
|
159
|
+
})
|
|
160
|
+
.join(" ");
|
|
161
|
+
});
|
|
162
|
+
// export const/let/var name = ...; -> const/let/var name = ...; __exports.name = name;
|
|
163
|
+
transformed = transformed.replace(/export\s+(const|let|var)\s+([\w$]+)\s*=/g, (match, declarationType, name) => {
|
|
164
|
+
return `${declarationType} ${name} =`;
|
|
165
|
+
});
|
|
166
|
+
// For exported functions/classes, we need to handle them separately
|
|
167
|
+
// export function name() {} -> function name() {} __exports.name = name;
|
|
168
|
+
transformed = transformed.replace(/export\s+(function|class)\s+([\w$]+)/g, "$1 $2");
|
|
169
|
+
// --- Catch-all safety nets ---
|
|
170
|
+
// Strip any remaining import statements that weren't handled above
|
|
171
|
+
transformed = transformed.replace(/import\s*(?:\{[^}]*\}|\*\s*as\s+[\w$]+|[\w$]+(?:\s*,\s*\{[^}]*\})?)\s*from\s*["'][^"']+["']\s*;?/g, (match) => {
|
|
172
|
+
console.warn(`[esm-transform] Unhandled import stripped: ${match}`);
|
|
173
|
+
return `/* stripped: ${match} */`;
|
|
174
|
+
});
|
|
175
|
+
// Strip any remaining bare `import "module"` side-effect imports
|
|
176
|
+
transformed = transformed.replace(/import\s*["'][^"']+["']\s*;?/g, (match) => {
|
|
177
|
+
console.warn(`[esm-transform] Side-effect import stripped: ${match}`);
|
|
178
|
+
return `/* stripped: ${match} */`;
|
|
179
|
+
});
|
|
180
|
+
// Strip any remaining `export` keywords as a final pass
|
|
181
|
+
transformed = transformed.replace(/\bexport\s+/g, "");
|
|
182
|
+
return transformed;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Transform a chunk file's ESM code for canvas mode.
|
|
186
|
+
* External imports → window globals (same as entry files).
|
|
187
|
+
* Exports → stored in window.__cc_chunks[chunkId].
|
|
188
|
+
*/
|
|
189
|
+
export function transformChunkForCanvas(code, chunkId) {
|
|
190
|
+
// First, transform external imports to window globals (no chunk mapping needed for chunks themselves)
|
|
191
|
+
const transformed = transformEsmToWindowGlobals(code);
|
|
192
|
+
// The transformed code has exports written to __exports.
|
|
193
|
+
// We need to register them in window.__cc_chunks.
|
|
194
|
+
// The IIFE wrapper in the canvas will handle this.
|
|
195
|
+
return transformed;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Build a chunk mapping from esbuild output by scanning entry files
|
|
199
|
+
* for relative imports to chunk files.
|
|
200
|
+
*/
|
|
201
|
+
export function buildChunkMapping(chunkIds, projectId) {
|
|
202
|
+
const mapping = new Map();
|
|
203
|
+
for (const chunkId of chunkIds) {
|
|
204
|
+
// When projectId is provided, namespace the registry key
|
|
205
|
+
const registryKey = projectId ? `${projectId}-${chunkId}` : chunkId;
|
|
206
|
+
mapping.set(chunkId, registryKey);
|
|
207
|
+
}
|
|
208
|
+
return mapping;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Get the scope class name for a component ID
|
|
212
|
+
*/
|
|
213
|
+
export function getScopeClassName(componentId) {
|
|
214
|
+
return `cc_${componentId.replace(/[^a-zA-Z0-9]/g, "_")}`;
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=esm-transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esm-transform.js","sourceRoot":"","sources":["../../src/utils/esm-transform.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,gBAAgB,GAA2B;IAC/C,QAAQ,EAAE,eAAe;IACzB,cAAc,EAAE,oBAAoB;IACpC,eAAe,EAAE,eAAe;IAChC,oBAAoB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EAAE,CACH,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAY,EAAE,OAAe;IACnE,sGAAsG;IACtG,MAAM,WAAW,GAAG,2BAA2B,CAAC,IAAI,CAAC,CAAC;IAEtD,yDAAyD;IACzD,kDAAkD;IAClD,mDAAmD;IACnD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,QAAkB,EAClB,SAAkB;IAElB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,yDAAyD;QACzD,MAAM,WAAW,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACpE,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,WAAmB;IACnD,OAAO,MAAM,WAAW,CAAC,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,EAAE,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observer-runtime.d.ts","sourceRoot":"","sources":["../../src/utils/observer-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAuCtC,wBAAgB,wBAAwB,IAAI,MAAM,CAcjD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const OBSERVER_SOURCE = `
|
|
2
|
+
import { Reaction } from "mobx";
|
|
3
|
+
import { useRef, useState, useEffect } from "preact/hooks";
|
|
4
|
+
|
|
5
|
+
export function observer(Component) {
|
|
6
|
+
var wrapped = function(props) {
|
|
7
|
+
var hookState = useState(0);
|
|
8
|
+
var setTick = hookState[1];
|
|
9
|
+
var reactionRef = useRef(null);
|
|
10
|
+
|
|
11
|
+
if (!reactionRef.current) {
|
|
12
|
+
reactionRef.current = new Reaction(
|
|
13
|
+
"observer(" + (Component.displayName || Component.name || "Component") + ")",
|
|
14
|
+
function() { setTick(function(t) { return t + 1; }); }
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
useEffect(function() {
|
|
19
|
+
return function() {
|
|
20
|
+
if (reactionRef.current) {
|
|
21
|
+
reactionRef.current.dispose();
|
|
22
|
+
reactionRef.current = null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}, []);
|
|
26
|
+
|
|
27
|
+
var result;
|
|
28
|
+
reactionRef.current.track(function() {
|
|
29
|
+
result = Component(props);
|
|
30
|
+
});
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
wrapped.displayName = "observer(" + (Component.displayName || Component.name || "Component") + ")";
|
|
34
|
+
return wrapped;
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
export function ikasComponentUtilsPlugin() {
|
|
38
|
+
return {
|
|
39
|
+
name: "ikas-component-utils",
|
|
40
|
+
setup(build) {
|
|
41
|
+
build.onResolve({ filter: /^@ikas\/component-utils$/ }, (args) => ({
|
|
42
|
+
path: args.path,
|
|
43
|
+
namespace: "ikas-component-utils",
|
|
44
|
+
}));
|
|
45
|
+
build.onLoad({ filter: /.*/, namespace: "ikas-component-utils" }, () => ({
|
|
46
|
+
contents: OBSERVER_SOURCE,
|
|
47
|
+
loader: "js",
|
|
48
|
+
}));
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=observer-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observer-runtime.js","sourceRoot":"","sources":["../../src/utils/observer-runtime.ts"],"names":[],"mappings":"AAEA,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCvB,CAAC;AAEF,MAAM,UAAU,wBAAwB;IACtC,OAAO;QACL,IAAI,EAAE,sBAAsB;QAC5B,KAAK,CAAC,KAAK;YACT,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,0BAA0B,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBACjE,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,SAAS,EAAE,sBAAsB;aAClC,CAAC,CAAC,CAAC;YACJ,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,sBAAsB,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;gBACvE,QAAQ,EAAE,eAAe;gBACzB,MAAM,EAAE,IAAI;aACb,CAAC,CAAC,CAAC;QACN,CAAC;KACF,CAAC;AACJ,CAAC"}
|