@glasshome/widget-cli 0.3.0 → 0.3.2
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 +1 -1
- package/src/commands/info.ts +2 -2
- package/src/commands/publish.ts +1 -0
- package/src/commands/validate.ts +19 -17
- package/src/utils/hub-api.ts +4 -2
- package/src/utils/manifest.ts +2 -11
package/package.json
CHANGED
package/src/commands/info.ts
CHANGED
|
@@ -44,8 +44,8 @@ export async function runInfo(cwd: string, widgetName?: string): Promise<void> {
|
|
|
44
44
|
const manifest = readManifest(cwd, name);
|
|
45
45
|
log.info(` Tag: ${manifest.tag}`);
|
|
46
46
|
log.info(` Name: ${manifest.name}`);
|
|
47
|
-
log.info(`
|
|
48
|
-
log.info(` Size:
|
|
47
|
+
log.info(` Min Size: ${manifest.minSize.w}×${manifest.minSize.h}`);
|
|
48
|
+
log.info(` Max Size: ${manifest.maxSize.w}×${manifest.maxSize.h}`);
|
|
49
49
|
log.info(` SDK Version: ${manifest.sdkVersion}`);
|
|
50
50
|
if (manifest.version) {
|
|
51
51
|
log.info(` Version: ${manifest.version}`);
|
package/src/commands/publish.ts
CHANGED
|
@@ -161,6 +161,7 @@ export async function runPublish(cwd: string, hubUrlOverride?: string): Promise<
|
|
|
161
161
|
name: widgetName,
|
|
162
162
|
displayName: manifest.name,
|
|
163
163
|
description: manifest.description,
|
|
164
|
+
icon: manifest.icon,
|
|
164
165
|
minSize: manifest.minSize,
|
|
165
166
|
maxSize: manifest.maxSize,
|
|
166
167
|
sdkVersion: manifest.sdkVersion,
|
package/src/commands/validate.ts
CHANGED
|
@@ -27,49 +27,50 @@ function validateManifest(manifest: WidgetManifest): ValidationResult {
|
|
|
27
27
|
if (!manifest.name) errors.push("Missing required field: name");
|
|
28
28
|
if (!manifest.sdkVersion) errors.push("Missing required field: sdkVersion");
|
|
29
29
|
|
|
30
|
-
//
|
|
31
|
-
if (manifest.tag && !TAG_REGEX.test(manifest.tag)) {
|
|
32
|
-
errors.push(
|
|
33
|
-
`Invalid tag format "${manifest.tag}" — must match ${TAG_REGEX} (e.g. glasshome-my-widget)`,
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// minSize validation
|
|
30
|
+
// Size validation
|
|
38
31
|
if (
|
|
39
32
|
!manifest.minSize ||
|
|
40
|
-
typeof manifest.minSize !== "object" ||
|
|
41
33
|
typeof manifest.minSize.w !== "number" ||
|
|
42
34
|
typeof manifest.minSize.h !== "number"
|
|
43
35
|
) {
|
|
44
36
|
errors.push("minSize must be an object with numeric w and h properties");
|
|
45
37
|
}
|
|
46
|
-
|
|
47
|
-
// maxSize validation
|
|
48
38
|
if (
|
|
49
39
|
!manifest.maxSize ||
|
|
50
|
-
typeof manifest.maxSize !== "object" ||
|
|
51
40
|
typeof manifest.maxSize.w !== "number" ||
|
|
52
41
|
typeof manifest.maxSize.h !== "number"
|
|
53
42
|
) {
|
|
54
43
|
errors.push("maxSize must be an object with numeric w and h properties");
|
|
55
44
|
}
|
|
56
45
|
|
|
46
|
+
// Tag format (stricter than schema — enforces kebab-case with at least one hyphen)
|
|
47
|
+
if (manifest.tag && !TAG_REGEX.test(manifest.tag)) {
|
|
48
|
+
errors.push(
|
|
49
|
+
`Invalid tag format "${manifest.tag}" — must match ${TAG_REGEX} (e.g. glasshome-my-widget)`,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
57
53
|
// Schema validation
|
|
58
54
|
if (manifest.schema) {
|
|
59
55
|
if (typeof manifest.schema !== "object") {
|
|
60
56
|
errors.push("Schema must be an object");
|
|
61
57
|
} else {
|
|
62
|
-
if (manifest.schema.type !== "object") {
|
|
58
|
+
if ((manifest.schema as Record<string, unknown>).type !== "object") {
|
|
63
59
|
warnings.push('Schema type should be "object"');
|
|
64
60
|
}
|
|
65
|
-
if (
|
|
61
|
+
if (
|
|
62
|
+
!(manifest.schema as Record<string, unknown>).properties ||
|
|
63
|
+
typeof (manifest.schema as Record<string, unknown>).properties !== "object"
|
|
64
|
+
) {
|
|
66
65
|
warnings.push("Schema should have a properties object");
|
|
67
66
|
}
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
// Check defaultConfig matches schema properties
|
|
71
|
-
if (manifest.defaultConfig && manifest.schema.properties) {
|
|
72
|
-
const schemaKeys = Object.keys(
|
|
70
|
+
if (manifest.defaultConfig && (manifest.schema as Record<string, unknown>).properties) {
|
|
71
|
+
const schemaKeys = Object.keys(
|
|
72
|
+
(manifest.schema as Record<string, unknown>).properties as Record<string, unknown>,
|
|
73
|
+
);
|
|
73
74
|
const configKeys = Object.keys(manifest.defaultConfig);
|
|
74
75
|
for (const key of configKeys) {
|
|
75
76
|
if (!schemaKeys.includes(key)) {
|
|
@@ -134,7 +135,8 @@ export async function runValidate(
|
|
|
134
135
|
try {
|
|
135
136
|
manifest = readManifest(cwd, name);
|
|
136
137
|
} catch (err) {
|
|
137
|
-
if (!quiet)
|
|
138
|
+
if (!quiet)
|
|
139
|
+
log.error(` Failed to read manifest: ${err instanceof Error ? err.message : String(err)}`);
|
|
138
140
|
failed.push(name);
|
|
139
141
|
allPassed = false;
|
|
140
142
|
continue;
|
package/src/utils/hub-api.ts
CHANGED
|
@@ -15,14 +15,16 @@ export async function fetchScopes(hubUrl: string, token: string): Promise<Publis
|
|
|
15
15
|
return data.scopes;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
import type { GridSize } from "@glasshome/widget-sdk";
|
|
19
|
+
|
|
18
20
|
interface PublishRequestParams {
|
|
19
21
|
scope: string;
|
|
20
22
|
name: string;
|
|
21
23
|
displayName: string;
|
|
22
24
|
description?: string;
|
|
23
25
|
icon?: string;
|
|
24
|
-
minSize:
|
|
25
|
-
maxSize:
|
|
26
|
+
minSize: GridSize;
|
|
27
|
+
maxSize: GridSize;
|
|
26
28
|
sdkVersion: string;
|
|
27
29
|
version: string;
|
|
28
30
|
bundleSize: number;
|
package/src/utils/manifest.ts
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join, resolve } from "node:path";
|
|
3
3
|
import { gzipSync } from "node:zlib";
|
|
4
|
+
import type { WidgetManifest as SdkWidgetManifest } from "@glasshome/widget-sdk";
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
-
tag: string;
|
|
7
|
-
name: string;
|
|
8
|
-
minSize: { w: number; h: number };
|
|
9
|
-
maxSize: { w: number; h: number };
|
|
10
|
-
sdkVersion: string;
|
|
11
|
-
version?: string;
|
|
12
|
-
description?: string;
|
|
13
|
-
schema?: Record<string, unknown>;
|
|
14
|
-
defaultConfig?: Record<string, unknown>;
|
|
15
|
-
}
|
|
6
|
+
export type WidgetManifest = SdkWidgetManifest & { version?: string };
|
|
16
7
|
|
|
17
8
|
export interface Registry {
|
|
18
9
|
version: number;
|