@glasshome/widget-cli 0.4.4 → 0.4.5
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/package.json
CHANGED
package/src/commands/add.ts
CHANGED
|
@@ -15,11 +15,10 @@ export function scaffoldWidget(
|
|
|
15
15
|
cwd: string,
|
|
16
16
|
opts: {
|
|
17
17
|
widgetName: string;
|
|
18
|
-
tag: string;
|
|
19
18
|
description: string;
|
|
20
19
|
},
|
|
21
20
|
): void {
|
|
22
|
-
const { widgetName,
|
|
21
|
+
const { widgetName, description } = opts;
|
|
23
22
|
const widgetDir = resolve(cwd, "src", widgetName);
|
|
24
23
|
|
|
25
24
|
if (existsSync(widgetDir)) {
|
|
@@ -34,13 +33,11 @@ export function scaffoldWidget(
|
|
|
34
33
|
// Read index.tsx template from the template directory
|
|
35
34
|
const templateDir = resolve(import.meta.dir, "../../template");
|
|
36
35
|
let srcContent = readFileSync(resolve(templateDir, "src/index.tsx.template"), "utf-8");
|
|
37
|
-
srcContent = srcContent.replace(/WIDGET_TAG/g, tag);
|
|
38
36
|
srcContent = srcContent.replace(/WIDGET_NAME/g, displayName);
|
|
39
37
|
writeFileSync(resolve(widgetDir, "index.tsx"), srcContent);
|
|
40
38
|
|
|
41
39
|
// Generate manifest.json
|
|
42
40
|
const manifest = {
|
|
43
|
-
tag,
|
|
44
41
|
name: displayName,
|
|
45
42
|
description: widgetDescription,
|
|
46
43
|
minSize: { w: 1, h: 1 },
|
|
@@ -55,7 +52,6 @@ export function scaffoldWidget(
|
|
|
55
52
|
/** Interactive prompts for widget details. Returns null if cancelled. */
|
|
56
53
|
export async function promptWidgetDetails(defaults?: { widgetName?: string }): Promise<{
|
|
57
54
|
widgetName: string;
|
|
58
|
-
tag: string;
|
|
59
55
|
description: string;
|
|
60
56
|
} | null> {
|
|
61
57
|
const widgetName = await text({
|
|
@@ -75,23 +71,6 @@ export async function promptWidgetDetails(defaults?: { widgetName?: string }): P
|
|
|
75
71
|
return null;
|
|
76
72
|
}
|
|
77
73
|
|
|
78
|
-
const tag = await text({
|
|
79
|
-
message: "Custom element tag",
|
|
80
|
-
placeholder: `glasshome-${widgetName}`,
|
|
81
|
-
defaultValue: `glasshome-${widgetName}`,
|
|
82
|
-
validate(value) {
|
|
83
|
-
if (!value) return "Tag is required";
|
|
84
|
-
if (!/^[a-z]/.test(value)) return "Tag must start with a lowercase letter";
|
|
85
|
-
if (!value.includes("-")) return "Custom element tags must contain a hyphen";
|
|
86
|
-
if (!/^[a-z][a-z0-9]*(-[a-z0-9]+)+$/.test(value))
|
|
87
|
-
return "Tag must be lowercase alphanumeric with hyphens (e.g. glasshome-my-widget)";
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
if (isCancel(tag)) {
|
|
91
|
-
cancel("Operation cancelled.");
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
74
|
const description = await text({
|
|
96
75
|
message: "Description (optional)",
|
|
97
76
|
placeholder: "A GlassHome dashboard widget",
|
|
@@ -104,7 +83,6 @@ export async function promptWidgetDetails(defaults?: { widgetName?: string }): P
|
|
|
104
83
|
|
|
105
84
|
return {
|
|
106
85
|
widgetName: widgetName as string,
|
|
107
|
-
tag: tag as string,
|
|
108
86
|
description: description as string,
|
|
109
87
|
};
|
|
110
88
|
}
|
|
@@ -56,7 +56,7 @@ PROJECT_NAME/
|
|
|
56
56
|
Each widget subdirectory contains:
|
|
57
57
|
|
|
58
58
|
- **`index.tsx`** — SolidJS component + `defineWidget()` registration
|
|
59
|
-
- **`manifest.json`** — metadata (
|
|
59
|
+
- **`manifest.json`** — metadata (name, description, size, version)
|
|
60
60
|
|
|
61
61
|
## CLI commands
|
|
62
62
|
|