cmssy-cli 0.19.6 → 0.20.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/cli.js +16 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/create.d.ts +12 -2
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +104 -64
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +5 -1
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/publish.d.ts.map +1 -1
- package/dist/commands/publish.js +157 -12
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/workspaces.d.ts.map +1 -1
- package/dist/commands/workspaces.js +9 -4
- package/dist/commands/workspaces.js.map +1 -1
- package/dist/dev-ui/app.js +247 -8
- package/dist/dev-ui/index.html +264 -0
- package/dist/utils/field-schema.d.ts.map +1 -1
- package/dist/utils/field-schema.js +21 -0
- package/dist/utils/field-schema.js.map +1 -1
- package/dist/utils/graphql.d.ts +1 -0
- package/dist/utils/graphql.d.ts.map +1 -1
- package/dist/utils/graphql.js +18 -0
- package/dist/utils/graphql.js.map +1 -1
- package/dist/utils/publish-helpers.d.ts +35 -0
- package/dist/utils/publish-helpers.d.ts.map +1 -0
- package/dist/utils/publish-helpers.js +141 -0
- package/dist/utils/publish-helpers.js.map +1 -0
- package/package.json +7 -2
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions for the publish command.
|
|
3
|
+
* Extracted for testability.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Convert block.config.ts schema to schemaFields array for GraphQL mutation.
|
|
7
|
+
*/
|
|
8
|
+
export declare function convertSchemaToFields(schema: Record<string, any>): any[];
|
|
9
|
+
/**
|
|
10
|
+
* Extract default content values from schema.
|
|
11
|
+
*/
|
|
12
|
+
export declare function extractDefaultContent(schema: Record<string, any>): any;
|
|
13
|
+
/**
|
|
14
|
+
* Extract block type from full package name.
|
|
15
|
+
* @example "@cmssy/blocks.hero" -> "hero"
|
|
16
|
+
* @example "@org/templates.landing" -> "landing"
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractBlockType(packageName: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Add __component to mount/update pattern for SSR compatibility.
|
|
21
|
+
* This makes blocks work in both dev environment (mount/update) and SSR (__component).
|
|
22
|
+
*/
|
|
23
|
+
export declare function addComponentForSSR(code: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Detect if a package is a template based on type.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isTemplate(packageType: "block" | "template"): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Parse pages.json data and convert to mutation input format.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parsePagesJson(pagesData: any): {
|
|
32
|
+
pages: any[];
|
|
33
|
+
layoutSlots: any[];
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=publish-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/publish-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,CAwDxE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,CAYtE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAK5D;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAsCvD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,OAAO,GAAG,UAAU,GAAG,OAAO,CAErE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,GAAG,GAAG;IAC9C,KAAK,EAAE,GAAG,EAAE,CAAC;IACb,WAAW,EAAE,GAAG,EAAE,CAAC;CACpB,CA0BA"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions for the publish command.
|
|
3
|
+
* Extracted for testability.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Convert block.config.ts schema to schemaFields array for GraphQL mutation.
|
|
7
|
+
*/
|
|
8
|
+
export function convertSchemaToFields(schema) {
|
|
9
|
+
const fields = [];
|
|
10
|
+
Object.entries(schema).forEach(([key, field]) => {
|
|
11
|
+
const baseField = {
|
|
12
|
+
key,
|
|
13
|
+
type: field.type,
|
|
14
|
+
label: field.label,
|
|
15
|
+
required: field.required || false,
|
|
16
|
+
};
|
|
17
|
+
// Add defaultValue if present
|
|
18
|
+
if (field.defaultValue !== undefined) {
|
|
19
|
+
baseField.defaultValue = field.defaultValue;
|
|
20
|
+
}
|
|
21
|
+
// Add placeholder if present
|
|
22
|
+
if (field.placeholder) {
|
|
23
|
+
baseField.placeholder = field.placeholder;
|
|
24
|
+
}
|
|
25
|
+
// Add helpText if present
|
|
26
|
+
if (field.helpText) {
|
|
27
|
+
baseField.helperText = field.helpText;
|
|
28
|
+
}
|
|
29
|
+
// Add group if present
|
|
30
|
+
if (field.group) {
|
|
31
|
+
baseField.group = field.group;
|
|
32
|
+
}
|
|
33
|
+
// Add showWhen conditional visibility
|
|
34
|
+
if (field.showWhen) {
|
|
35
|
+
baseField.showWhen = field.showWhen;
|
|
36
|
+
}
|
|
37
|
+
// Add validation rules
|
|
38
|
+
if (field.validation) {
|
|
39
|
+
baseField.validation = field.validation;
|
|
40
|
+
}
|
|
41
|
+
if (field.type === "select" && field.options) {
|
|
42
|
+
baseField.options = field.options;
|
|
43
|
+
}
|
|
44
|
+
if (field.type === "repeater" && field.schema) {
|
|
45
|
+
baseField.minItems = field.minItems;
|
|
46
|
+
baseField.maxItems = field.maxItems;
|
|
47
|
+
// Backend expects itemSchema to be a flat array of field definitions
|
|
48
|
+
baseField.itemSchema = convertSchemaToFields(field.schema);
|
|
49
|
+
}
|
|
50
|
+
fields.push(baseField);
|
|
51
|
+
});
|
|
52
|
+
return fields;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Extract default content values from schema.
|
|
56
|
+
*/
|
|
57
|
+
export function extractDefaultContent(schema) {
|
|
58
|
+
const content = {};
|
|
59
|
+
Object.entries(schema).forEach(([key, field]) => {
|
|
60
|
+
if (field.defaultValue !== undefined) {
|
|
61
|
+
content[key] = field.defaultValue;
|
|
62
|
+
}
|
|
63
|
+
else if (field.type === "repeater") {
|
|
64
|
+
content[key] = [];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return content;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Extract block type from full package name.
|
|
71
|
+
* @example "@cmssy/blocks.hero" -> "hero"
|
|
72
|
+
* @example "@org/templates.landing" -> "landing"
|
|
73
|
+
*/
|
|
74
|
+
export function extractBlockType(packageName) {
|
|
75
|
+
return packageName
|
|
76
|
+
.replace(/@[^/]+\//, "") // Remove @scope/
|
|
77
|
+
.replace(/^blocks\./, "") // Remove blocks. prefix
|
|
78
|
+
.replace(/^templates\./, ""); // Remove templates. prefix
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Add __component to mount/update pattern for SSR compatibility.
|
|
82
|
+
* This makes blocks work in both dev environment (mount/update) and SSR (__component).
|
|
83
|
+
*/
|
|
84
|
+
export function addComponentForSSR(code) {
|
|
85
|
+
// Check if code exports mount/update pattern
|
|
86
|
+
const hasPattern = /exports\.default\s*=\s*\{[^}]*mount\s*\([^)]*\)/s.test(code) ||
|
|
87
|
+
/module\.exports\s*=\s*\{[^}]*mount\s*\([^)]*\)/s.test(code);
|
|
88
|
+
if (!hasPattern) {
|
|
89
|
+
// No mount/update pattern - return as-is
|
|
90
|
+
return code;
|
|
91
|
+
}
|
|
92
|
+
// Find the component that's being used in mount()
|
|
93
|
+
// Pattern: export default { mount() { ... render(<Component ... /> or createElement(Component ...) } }
|
|
94
|
+
const componentMatch = code.match(/(?:render|createElement)\s*\(\s*(?:<\s*)?(\w+)/);
|
|
95
|
+
const componentName = componentMatch?.[1];
|
|
96
|
+
if (!componentName) {
|
|
97
|
+
console.warn("[CLI] Warning: Found mount/update pattern but could not extract component name for __component");
|
|
98
|
+
return code;
|
|
99
|
+
}
|
|
100
|
+
// Add __component to the exports object
|
|
101
|
+
// Replace: module.exports = { mount, update, unmount };
|
|
102
|
+
// With: module.exports = { mount, update, unmount, __component: ComponentName };
|
|
103
|
+
const updatedCode = code.replace(/((?:exports\.default|module\.exports)\s*=\s*\{[^}]*)(}\s*;)/s, `$1,\n // Auto-added by CLI for SSR compatibility\n __component: ${componentName}\n$2`);
|
|
104
|
+
if (updatedCode === code) {
|
|
105
|
+
console.warn("[CLI] Warning: Could not add __component to exports");
|
|
106
|
+
}
|
|
107
|
+
return updatedCode;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Detect if a package is a template based on type.
|
|
111
|
+
*/
|
|
112
|
+
export function isTemplate(packageType) {
|
|
113
|
+
return packageType === "template";
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Parse pages.json data and convert to mutation input format.
|
|
117
|
+
*/
|
|
118
|
+
export function parsePagesJson(pagesData) {
|
|
119
|
+
// Convert pages
|
|
120
|
+
const pages = (pagesData.pages || []).map((page) => ({
|
|
121
|
+
name: page.name,
|
|
122
|
+
slug: page.slug,
|
|
123
|
+
blocks: (page.blocks || []).map((block) => ({
|
|
124
|
+
type: block.type,
|
|
125
|
+
content: block.content || {},
|
|
126
|
+
})),
|
|
127
|
+
}));
|
|
128
|
+
// Convert layoutSlots to array format
|
|
129
|
+
const layoutSlots = [];
|
|
130
|
+
if (pagesData.layoutSlots) {
|
|
131
|
+
for (const [slot, data] of Object.entries(pagesData.layoutSlots)) {
|
|
132
|
+
layoutSlots.push({
|
|
133
|
+
slot,
|
|
134
|
+
type: data.type,
|
|
135
|
+
content: data.content || {},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return { pages, layoutSlots };
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=publish-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish-helpers.js","sourceRoot":"","sources":["../../src/utils/publish-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAA2B;IAC/D,MAAM,MAAM,GAAU,EAAE,CAAC;IAEzB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAgB,EAAE,EAAE;QAC7D,MAAM,SAAS,GAAQ;YACrB,GAAG;YACH,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,KAAK;SAClC,CAAC;QAEF,8BAA8B;QAC9B,IAAI,KAAK,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YACrC,SAAS,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC;QAC9C,CAAC;QAED,6BAA6B;QAC7B,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;YACtB,SAAS,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;QAC5C,CAAC;QAED,0BAA0B;QAC1B,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;YACnB,SAAS,CAAC,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC;QACxC,CAAC;QAED,uBAAuB;QACvB,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,SAAS,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAChC,CAAC;QAED,sCAAsC;QACtC,I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AACH,MAAM,UAAU,cAAc,CAAC,SAAc;IAI3C,gBAAgB;IAChB,MAAM,KAAK,GAAG,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,CAAC;QACxD,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,CAAC;YAC/C,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,EAAE;SAC7B,CAAC,CAAC;KACJ,CAAC,CAAC,CAAC;IAEJ,sCAAsC;IACtC,MAAM,WAAW,GAAU,EAAE,CAAC;IAC9B,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC;QAC1B,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CACvC,SAAS,CAAC,WAAkC,CAC7C,EAAE,CAAC;YACF,WAAW,CAAC,IAAI,CAAC;gBACf,IAAI;gBACJ,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,EAAE;aAC5B,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;AAChC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cmssy-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"description": "Unified CLI for building and publishing blocks to Cmssy marketplace",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "tsc && tsc config.ts --module esnext --target esnext --moduleResolution bundler && tsc config.ts --declaration --emitDeclarationOnly --module esnext --target esnext --moduleResolution bundler && cp -r src/dev-ui dist/",
|
|
16
16
|
"dev": "tsc --watch",
|
|
17
|
+
"test": "vitest run",
|
|
18
|
+
"test:watch": "vitest",
|
|
19
|
+
"test:coverage": "vitest run --coverage",
|
|
17
20
|
"prepare": "npm run build"
|
|
18
21
|
},
|
|
19
22
|
"keywords": [
|
|
@@ -71,6 +74,8 @@
|
|
|
71
74
|
"@types/node": "^22.10.2",
|
|
72
75
|
"@types/node-fetch": "^2.6.13",
|
|
73
76
|
"@types/semver": "^7.7.1",
|
|
74
|
-
"
|
|
77
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
78
|
+
"typescript": "^5.7.2",
|
|
79
|
+
"vitest": "^3.2.4"
|
|
75
80
|
}
|
|
76
81
|
}
|