@usalyt/registry 0.0.0-stage → 0.0.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.
@@ -0,0 +1,172 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "urn:usalyt:registry-schema:0.0.1",
4
+ "title": "Usalyt component registry",
5
+ "description": "Schema for the packaged @usalyt/registry registry.json data file.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": [
9
+ "$schema",
10
+ "name",
11
+ "version",
12
+ "license",
13
+ "repository",
14
+ "dependencyLicenses",
15
+ "items"
16
+ ],
17
+ "properties": {
18
+ "$schema": {
19
+ "const": "./schema/registry.schema.json",
20
+ "description": "Local schema reference relative to the packaged registry.json."
21
+ },
22
+ "name": {
23
+ "const": "usalyt"
24
+ },
25
+ "version": {
26
+ "const": "0.0.1"
27
+ },
28
+ "license": {
29
+ "$ref": "#/$defs/license"
30
+ },
31
+ "repository": {
32
+ "type": "object",
33
+ "additionalProperties": false,
34
+ "required": ["type", "url", "directory"],
35
+ "properties": {
36
+ "type": {
37
+ "const": "git"
38
+ },
39
+ "url": {
40
+ "type": "string",
41
+ "minLength": 1
42
+ },
43
+ "directory": {
44
+ "type": "string",
45
+ "minLength": 1
46
+ }
47
+ }
48
+ },
49
+ "dependencyLicenses": {
50
+ "$ref": "#/$defs/licenseMap"
51
+ },
52
+ "items": {
53
+ "type": "array",
54
+ "minItems": 1,
55
+ "uniqueItems": true,
56
+ "items": {
57
+ "$ref": "#/$defs/item"
58
+ }
59
+ }
60
+ },
61
+ "$defs": {
62
+ "license": {
63
+ "const": "GPL-3.0-only"
64
+ },
65
+ "auditedLicense": {
66
+ "enum": ["Apache-2.0", "ISC", "MIT", "OFL-1.1"]
67
+ },
68
+ "licenseMap": {
69
+ "type": "object",
70
+ "minProperties": 1,
71
+ "propertyNames": {
72
+ "type": "string",
73
+ "minLength": 1
74
+ },
75
+ "additionalProperties": {
76
+ "$ref": "#/$defs/auditedLicense"
77
+ }
78
+ },
79
+ "stringList": {
80
+ "type": "array",
81
+ "items": {
82
+ "type": "string",
83
+ "minLength": 1
84
+ },
85
+ "uniqueItems": true
86
+ },
87
+ "sourcePath": {
88
+ "type": "string",
89
+ "pattern": "^(components/[a-z0-9]+(?:-[a-z0-9]+)*/[A-Za-z0-9._-]+|blocks/[a-z0-9]+(?:-[a-z0-9]+)*/[A-Za-z0-9._-]+|lib/[A-Za-z0-9._-]+)$"
90
+ },
91
+ "file": {
92
+ "type": "object",
93
+ "additionalProperties": false,
94
+ "required": ["path", "type", "content"],
95
+ "properties": {
96
+ "path": {
97
+ "$ref": "#/$defs/sourcePath"
98
+ },
99
+ "type": {
100
+ "enum": ["registry:ui", "registry:block", "registry:lib"]
101
+ },
102
+ "content": {
103
+ "type": "string",
104
+ "minLength": 1
105
+ }
106
+ }
107
+ },
108
+ "item": {
109
+ "type": "object",
110
+ "additionalProperties": false,
111
+ "required": [
112
+ "name",
113
+ "type",
114
+ "title",
115
+ "description",
116
+ "license",
117
+ "dependencies",
118
+ "devDependencies",
119
+ "registryDependencies",
120
+ "dependencyVersions",
121
+ "files"
122
+ ],
123
+ "properties": {
124
+ "name": {
125
+ "type": "string",
126
+ "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
127
+ },
128
+ "type": {
129
+ "enum": ["registry:ui", "registry:block", "registry:lib"]
130
+ },
131
+ "title": {
132
+ "type": "string",
133
+ "minLength": 1
134
+ },
135
+ "description": {
136
+ "type": "string",
137
+ "minLength": 1
138
+ },
139
+ "license": {
140
+ "$ref": "#/$defs/license"
141
+ },
142
+ "dependencies": {
143
+ "$ref": "#/$defs/stringList"
144
+ },
145
+ "devDependencies": {
146
+ "$ref": "#/$defs/stringList"
147
+ },
148
+ "registryDependencies": {
149
+ "$ref": "#/$defs/stringList"
150
+ },
151
+ "dependencyVersions": {
152
+ "type": "object",
153
+ "propertyNames": {
154
+ "type": "string",
155
+ "minLength": 1
156
+ },
157
+ "additionalProperties": {
158
+ "type": "string",
159
+ "minLength": 1
160
+ }
161
+ },
162
+ "files": {
163
+ "type": "array",
164
+ "minItems": 1,
165
+ "items": {
166
+ "$ref": "#/$defs/file"
167
+ }
168
+ }
169
+ }
170
+ }
171
+ }
172
+ }
@@ -0,0 +1,177 @@
1
+ import fs from "fs-extra";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ import Ajv2020 from "ajv/dist/2020.js";
6
+
7
+ import {
8
+ buildRegistry,
9
+ type Registry,
10
+ } from "../src/registry-builder.ts";
11
+
12
+ const PACKAGE_ROOT = path.resolve(
13
+ path.dirname(fileURLToPath(import.meta.url)),
14
+ ".."
15
+ );
16
+ const DEFAULT_SOURCE_ROOT = path.resolve(PACKAGE_ROOT, "../ui/src");
17
+ const DEFAULT_OUT = path.join(PACKAGE_ROOT, "registry.json");
18
+ const SCHEMA_PATH = path.join(PACKAGE_ROOT, "schema/registry.schema.json");
19
+
20
+ class UsageError extends Error {}
21
+
22
+ interface CliOptions {
23
+ sourceRoot: string;
24
+ outPath: string;
25
+ check: boolean;
26
+ help: boolean;
27
+ }
28
+
29
+ function printUsage(write: (message: string) => void): void {
30
+ write(`Usage: tsx scripts/build-registry.ts [options]
31
+
32
+ Build the deterministic @usalyt/registry registry.json from the Usalyt UI
33
+ source tree.
34
+
35
+ Options:
36
+ -s, --source <dir> UI source root containing components/, blocks/, and lib/
37
+ (default: ../ui/src relative to this package)
38
+ -o, --out <file> Output registry path
39
+ (default: registry.json in this package)
40
+ --check Regenerate in memory and exit non-zero when the output
41
+ file is missing or differs from the generated registry
42
+ -h, --help Show this help
43
+
44
+ Environment:
45
+ USALYT_SOURCE_ROOT Alternative source root when --source is omitted.
46
+ An explicit --source flag always wins.
47
+ `);
48
+ }
49
+
50
+ function parseArgs(argv: string[]): CliOptions {
51
+ let source: string | undefined;
52
+ let out: string | undefined;
53
+ let check = false;
54
+ let help = false;
55
+
56
+ for (let index = 0; index < argv.length; index += 1) {
57
+ const argument = argv[index];
58
+
59
+ switch (argument) {
60
+ case "--source":
61
+ case "-s": {
62
+ const value = argv[index + 1];
63
+ if (!value) {
64
+ throw new UsageError(`Missing value for ${argument}`);
65
+ }
66
+ source = value;
67
+ index += 1;
68
+ break;
69
+ }
70
+ case "--out":
71
+ case "-o": {
72
+ const value = argv[index + 1];
73
+ if (!value) {
74
+ throw new UsageError(`Missing value for ${argument}`);
75
+ }
76
+ out = value;
77
+ index += 1;
78
+ break;
79
+ }
80
+ case "--check":
81
+ check = true;
82
+ break;
83
+ case "--help":
84
+ case "-h":
85
+ help = true;
86
+ break;
87
+ default:
88
+ throw new UsageError(`Unknown option: ${argument}`);
89
+ }
90
+ }
91
+
92
+ const environmentSource = process.env.USALYT_SOURCE_ROOT;
93
+ const selectedSource = source ?? environmentSource ?? DEFAULT_SOURCE_ROOT;
94
+
95
+ return {
96
+ sourceRoot: path.resolve(selectedSource),
97
+ outPath: path.resolve(out ?? DEFAULT_OUT),
98
+ check,
99
+ help,
100
+ };
101
+ }
102
+
103
+ function assertRegistryMatchesSchema(registry: Registry): void {
104
+ const schema = fs.readJsonSync(SCHEMA_PATH);
105
+ const ajv = new Ajv2020({ allErrors: true, strict: false });
106
+ const validate = ajv.compile(schema);
107
+
108
+ if (!validate(registry)) {
109
+ const details = (validate.errors ?? [])
110
+ .slice(0, 5)
111
+ .map((error) => `${error.instancePath || "/"} ${error.message}`)
112
+ .join("; ");
113
+ throw new Error(`generated registry does not match the packaged schema: ${details}`);
114
+ }
115
+ }
116
+
117
+ async function main(): Promise<void> {
118
+ let options: CliOptions;
119
+
120
+ try {
121
+ options = parseArgs(process.argv.slice(2));
122
+ } catch (error) {
123
+ if (error instanceof UsageError) {
124
+ process.stderr.write(`Error: ${error.message}\n\n`);
125
+ printUsage((message) => process.stderr.write(message));
126
+ process.exitCode = 2;
127
+ return;
128
+ }
129
+ throw error;
130
+ }
131
+
132
+ if (options.help) {
133
+ printUsage((message) => process.stdout.write(message));
134
+ return;
135
+ }
136
+
137
+ const result = await buildRegistry({
138
+ sourceRoot: options.sourceRoot,
139
+ packageRoot: PACKAGE_ROOT,
140
+ });
141
+
142
+ assertRegistryMatchesSchema(result.registry);
143
+
144
+ if (options.check) {
145
+ if (!(await fs.pathExists(options.outPath))) {
146
+ process.stderr.write(
147
+ `Registry is missing: ${options.outPath}. Run the build command to generate it.\n`
148
+ );
149
+ process.exitCode = 1;
150
+ return;
151
+ }
152
+
153
+ const current = await fs.readFile(options.outPath, "utf8");
154
+ if (current !== result.json) {
155
+ process.stderr.write(
156
+ `Registry is out of date: ${options.outPath}. Run the build command to regenerate it.\n`
157
+ );
158
+ process.exitCode = 1;
159
+ return;
160
+ }
161
+
162
+ process.stdout.write(`Registry is up to date: ${options.outPath}\n`);
163
+ return;
164
+ }
165
+
166
+ await fs.outputFile(options.outPath, result.json);
167
+ const { primitives, blocks, libraries, items } = result.stats;
168
+ process.stdout.write(
169
+ `Registry written to ${options.outPath} (${primitives} primitives, ${blocks} blocks, ${libraries} shared library, ${items} items).\n`
170
+ );
171
+ }
172
+
173
+ main().catch((error: unknown) => {
174
+ const message = error instanceof Error ? error.message : String(error);
175
+ process.stderr.write(`Registry build failed: ${message}\n`);
176
+ process.exitCode = 1;
177
+ });