@tokens-studio/tokenscript-schemas 0.1.3 → 0.2.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/README.md +5 -0
- package/dist/cli/index.cjs +128 -81
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +127 -80
- package/dist/cli/index.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/commands/build-dir.test.ts +354 -0
- package/src/cli/commands/build-dir.ts +90 -0
- package/src/cli/commands/bundle.ts +11 -14
- package/src/cli/index.ts +15 -0
package/README.md
CHANGED
|
@@ -30,6 +30,11 @@ npx @tokens-studio/tokenscript-schemas bundle oklch-color rgb-color -o ./schemas
|
|
|
30
30
|
# Bundle with functions
|
|
31
31
|
npx @tokens-studio/tokenscript-schemas bundle rgb-color function:invert -o ./schemas.js
|
|
32
32
|
|
|
33
|
+
# Build individual schema directory
|
|
34
|
+
npx @tokens-studio/tokenscript-schemas build ./src/schemas/types/css-color
|
|
35
|
+
npx @tokens-studio/tokenscript-schemas build ./src/schemas/types/css-color -o css-color.json
|
|
36
|
+
npx @tokens-studio/tokenscript-schemas build ./src/schemas/types/css-color --pretty -o css-color.json
|
|
37
|
+
|
|
33
38
|
# Combine presets with specific schemas
|
|
34
39
|
npx @tokens-studio/tokenscript-schemas bundle preset:css type:lab-color -o ./schemas.js
|
|
35
40
|
|
package/dist/cli/index.cjs
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var cac = require('cac');
|
|
5
|
-
var
|
|
5
|
+
var anylogger = require('ulog');
|
|
6
|
+
var fs = require('fs');
|
|
6
7
|
var promises = require('fs/promises');
|
|
7
8
|
var path = require('path');
|
|
8
9
|
var url = require('url');
|
|
9
10
|
require('child_process');
|
|
10
|
-
var fs = require('fs');
|
|
11
11
|
|
|
12
12
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
13
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
14
|
|
|
15
15
|
var cac__default = /*#__PURE__*/_interopDefault(cac);
|
|
16
|
-
var
|
|
16
|
+
var anylogger__default = /*#__PURE__*/_interopDefault(anylogger);
|
|
17
17
|
|
|
18
18
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
19
19
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -21,49 +21,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
21
21
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
22
22
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
23
23
|
});
|
|
24
|
-
|
|
25
|
-
// src/bundler/presets/css.ts
|
|
26
|
-
var css = {
|
|
27
|
-
name: "CSS",
|
|
28
|
-
description: "CSS color types",
|
|
29
|
-
types: [
|
|
30
|
-
"hex-color",
|
|
31
|
-
"rgb-color",
|
|
32
|
-
"hsl-color",
|
|
33
|
-
"oklch-color",
|
|
34
|
-
"oklab-color",
|
|
35
|
-
// Converting colors to css strings
|
|
36
|
-
"css-color"
|
|
37
|
-
],
|
|
38
|
-
functions: ["lighten", "darken", "saturate", "desaturate", "mix", "invert"]
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// src/bundler/presets/index.ts
|
|
42
|
-
var BUNDLE_PRESETS = {
|
|
43
|
-
css
|
|
44
|
-
};
|
|
45
|
-
function expandPresetSchemas(schemas) {
|
|
46
|
-
const expanded = [];
|
|
47
|
-
for (const schema of schemas) {
|
|
48
|
-
if (schema.startsWith("preset:")) {
|
|
49
|
-
const presetName = schema.slice(7);
|
|
50
|
-
const preset = BUNDLE_PRESETS[presetName];
|
|
51
|
-
if (preset) {
|
|
52
|
-
for (const type of preset.types) {
|
|
53
|
-
expanded.push(type === "*" ? "*" : `type:${type}`);
|
|
54
|
-
}
|
|
55
|
-
for (const func of preset.functions) {
|
|
56
|
-
expanded.push(func === "*" ? "*" : `function:${func}`);
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
console.warn(`\u26A0 Unknown preset: ${presetName}`);
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
expanded.push(schema);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return expanded;
|
|
66
|
-
}
|
|
67
24
|
async function buildSchemaFromDirectory(schemaDir, options) {
|
|
68
25
|
const schemaJsonPath = path.join(schemaDir, "schema.json");
|
|
69
26
|
const schemaContent = await promises.readFile(schemaJsonPath, "utf-8");
|
|
@@ -134,6 +91,92 @@ function addBaseUrl(uri, baseUrl) {
|
|
|
134
91
|
}
|
|
135
92
|
return uri;
|
|
136
93
|
}
|
|
94
|
+
|
|
95
|
+
// src/cli/commands/build-dir.ts
|
|
96
|
+
var log = anylogger__default.default("build-dir");
|
|
97
|
+
async function buildSchemaDir(schemaDir, options = {}) {
|
|
98
|
+
const resolvedDir = resolveSchemaDir(schemaDir);
|
|
99
|
+
if (!fs.existsSync(resolvedDir)) {
|
|
100
|
+
throw new Error(`Directory not found: ${resolvedDir}`);
|
|
101
|
+
}
|
|
102
|
+
const schemaJsonPath = path.join(resolvedDir, "schema.json");
|
|
103
|
+
if (!fs.existsSync(schemaJsonPath)) {
|
|
104
|
+
throw new Error(`schema.json not found in: ${resolvedDir}`);
|
|
105
|
+
}
|
|
106
|
+
log.info(`Building schema from: ${resolvedDir}`);
|
|
107
|
+
const schema = await buildSchemaFromDirectory(resolvedDir);
|
|
108
|
+
const output = options.pretty ? JSON.stringify(schema, null, 2) : JSON.stringify(schema);
|
|
109
|
+
if (options.output) {
|
|
110
|
+
await promises.mkdir(path.dirname(options.output), { recursive: true });
|
|
111
|
+
await promises.writeFile(options.output, output, "utf-8");
|
|
112
|
+
log.info(`Output written to: ${options.output}`);
|
|
113
|
+
console.log(`\u2713 Built ${schema.type}:${schema.name} \u2192 ${options.output}`);
|
|
114
|
+
} else {
|
|
115
|
+
console.log(output);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function resolveSchemaDir(schemaDir) {
|
|
119
|
+
if (fs.existsSync(schemaDir)) {
|
|
120
|
+
return schemaDir;
|
|
121
|
+
}
|
|
122
|
+
const cwd = process.cwd();
|
|
123
|
+
const fromCwd = path.join(cwd, schemaDir);
|
|
124
|
+
if (fs.existsSync(fromCwd)) {
|
|
125
|
+
return fromCwd;
|
|
126
|
+
}
|
|
127
|
+
return schemaDir;
|
|
128
|
+
}
|
|
129
|
+
async function handleBuildCommand(schemaDir, options = {}) {
|
|
130
|
+
try {
|
|
131
|
+
await buildSchemaDir(schemaDir, options);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
log.error("Build failed:", error);
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/bundler/presets/css.ts
|
|
139
|
+
var css = {
|
|
140
|
+
name: "CSS",
|
|
141
|
+
description: "CSS color types",
|
|
142
|
+
types: [
|
|
143
|
+
"hex-color",
|
|
144
|
+
"rgb-color",
|
|
145
|
+
"hsl-color",
|
|
146
|
+
"oklch-color",
|
|
147
|
+
"oklab-color",
|
|
148
|
+
// Converting colors to css strings
|
|
149
|
+
"css-color"
|
|
150
|
+
],
|
|
151
|
+
functions: ["lighten", "darken", "saturate", "desaturate", "mix", "invert"]
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// src/bundler/presets/index.ts
|
|
155
|
+
var BUNDLE_PRESETS = {
|
|
156
|
+
css
|
|
157
|
+
};
|
|
158
|
+
function expandPresetSchemas(schemas) {
|
|
159
|
+
const expanded = [];
|
|
160
|
+
for (const schema of schemas) {
|
|
161
|
+
if (schema.startsWith("preset:")) {
|
|
162
|
+
const presetName = schema.slice(7);
|
|
163
|
+
const preset = BUNDLE_PRESETS[presetName];
|
|
164
|
+
if (preset) {
|
|
165
|
+
for (const type of preset.types) {
|
|
166
|
+
expanded.push(type === "*" ? "*" : `type:${type}`);
|
|
167
|
+
}
|
|
168
|
+
for (const func of preset.functions) {
|
|
169
|
+
expanded.push(func === "*" ? "*" : `function:${func}`);
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
console.warn(`\u26A0 Unknown preset: ${presetName}`);
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
expanded.push(schema);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return expanded;
|
|
179
|
+
}
|
|
137
180
|
var LOG_LEVELS = {
|
|
138
181
|
error: 1,
|
|
139
182
|
warn: 2,
|
|
@@ -141,9 +184,9 @@ var LOG_LEVELS = {
|
|
|
141
184
|
log: 4,
|
|
142
185
|
debug: 5
|
|
143
186
|
};
|
|
144
|
-
var
|
|
187
|
+
var log2 = anylogger__default.default("schema-registry");
|
|
145
188
|
var logLevel = process.env.LOG_LEVEL || "error";
|
|
146
|
-
|
|
189
|
+
log2.level = LOG_LEVELS[logLevel] || LOG_LEVELS.error;
|
|
147
190
|
|
|
148
191
|
// src/utils/type.ts
|
|
149
192
|
var isSome = (v) => {
|
|
@@ -275,7 +318,7 @@ async function collectRequiredSchemas(slugOrUri, type, options = {}) {
|
|
|
275
318
|
async function traverse(currentSlugOrUri, currentType) {
|
|
276
319
|
const ref = resolveSchemaReference(currentSlugOrUri);
|
|
277
320
|
if (!ref) {
|
|
278
|
-
|
|
321
|
+
log2.warn(`Could not resolve schema reference: ${currentSlugOrUri}`);
|
|
279
322
|
return;
|
|
280
323
|
}
|
|
281
324
|
const effectiveType = currentType || ref.type;
|
|
@@ -292,7 +335,7 @@ async function collectRequiredSchemas(slugOrUri, type, options = {}) {
|
|
|
292
335
|
const schemaDir = path.join(resolvedSchemasDir, categoryDir, slug);
|
|
293
336
|
spec = await buildSchemaFromDirectory(schemaDir, baseUrl ? { baseUrl } : void 0);
|
|
294
337
|
} catch (error) {
|
|
295
|
-
|
|
338
|
+
log2.warn(`Failed to load schema ${slug} (${effectiveType}):`, error);
|
|
296
339
|
return;
|
|
297
340
|
}
|
|
298
341
|
const requirements = extractRequirements(spec, extractOptions);
|
|
@@ -357,7 +400,7 @@ async function collectDependencyTree(schemas, options = {}) {
|
|
|
357
400
|
dependencies: dependencySlugs
|
|
358
401
|
});
|
|
359
402
|
} catch (error) {
|
|
360
|
-
|
|
403
|
+
log2.warn(`Failed to load schema ${schema.slug} (${schema.type}):`, error);
|
|
361
404
|
}
|
|
362
405
|
}
|
|
363
406
|
return tree;
|
|
@@ -548,7 +591,7 @@ function generateOutput(options) {
|
|
|
548
591
|
}
|
|
549
592
|
|
|
550
593
|
// src/cli/commands/bundle.ts
|
|
551
|
-
var
|
|
594
|
+
var log3 = anylogger__default.default("bundle");
|
|
552
595
|
async function loadConfig(configPath) {
|
|
553
596
|
try {
|
|
554
597
|
const content = await promises.readFile(configPath, "utf-8");
|
|
@@ -613,28 +656,24 @@ function findSchemasDir() {
|
|
|
613
656
|
const __dirname2 = path.dirname(__filename2);
|
|
614
657
|
const fromDist = path.join(__dirname2, "../../src/schemas");
|
|
615
658
|
const fromSource = path.join(__dirname2, "../../schemas");
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
if (fs.existsSync(fromDist)) {
|
|
619
|
-
return fromDist;
|
|
620
|
-
}
|
|
621
|
-
if (fs.existsSync(fromSource)) {
|
|
622
|
-
return fromSource;
|
|
623
|
-
}
|
|
624
|
-
} catch {
|
|
659
|
+
if (fs.existsSync(fromSource)) {
|
|
660
|
+
return fromSource;
|
|
625
661
|
}
|
|
626
|
-
|
|
662
|
+
if (fs.existsSync(fromDist)) {
|
|
663
|
+
return fromDist;
|
|
664
|
+
}
|
|
665
|
+
return fromSource;
|
|
627
666
|
}
|
|
628
667
|
async function bundleSchemas(schemas, schemasDir, cliArgs) {
|
|
629
668
|
const resolvedSchemasDir = schemasDir || findSchemasDir();
|
|
630
|
-
|
|
631
|
-
|
|
669
|
+
log3.info("Bundling schemas:", schemas);
|
|
670
|
+
log3.debug("Schemas directory:", resolvedSchemasDir);
|
|
632
671
|
const result = await bundleSelectiveSchemas({
|
|
633
672
|
schemas,
|
|
634
673
|
schemasDir: resolvedSchemasDir,
|
|
635
674
|
cliArgs
|
|
636
675
|
});
|
|
637
|
-
|
|
676
|
+
log3.info(
|
|
638
677
|
`Resolved ${result.metadata.resolvedDependencies.length} schemas (including dependencies)`
|
|
639
678
|
);
|
|
640
679
|
const output = generateOutput({
|
|
@@ -653,7 +692,7 @@ async function handleBundleCommand(schemas, options = {}) {
|
|
|
653
692
|
let configSchemas = schemas;
|
|
654
693
|
let outputPath = options.output || "./tokenscript-schemas.js";
|
|
655
694
|
if (isSome(options.config)) {
|
|
656
|
-
|
|
695
|
+
log3.info(`Loading config from ${options.config}`);
|
|
657
696
|
const config = await loadConfig(options.config);
|
|
658
697
|
configSchemas = config.schemas;
|
|
659
698
|
if (config.output) {
|
|
@@ -682,7 +721,7 @@ async function handleBundleCommand(schemas, options = {}) {
|
|
|
682
721
|
}
|
|
683
722
|
const customSchemasDir = options.schemasDir;
|
|
684
723
|
if (customSchemasDir) {
|
|
685
|
-
|
|
724
|
+
log3.info(`Using custom schema directory: ${customSchemasDir}`);
|
|
686
725
|
}
|
|
687
726
|
const { output, metadata, dependencyTree } = await bundleSchemas(
|
|
688
727
|
configSchemas,
|
|
@@ -699,15 +738,15 @@ async function handleBundleCommand(schemas, options = {}) {
|
|
|
699
738
|
}
|
|
700
739
|
await promises.mkdir(path.dirname(outputPath), { recursive: true });
|
|
701
740
|
await promises.writeFile(outputPath, output, "utf-8");
|
|
702
|
-
|
|
703
|
-
|
|
741
|
+
log3.info(`Successfully bundled ${metadata.resolvedDependencies.length} schemas`);
|
|
742
|
+
log3.info(`Output written to: ${outputPath}`);
|
|
704
743
|
console.log(`\u2713 Bundled ${metadata.resolvedDependencies.length} schemas \u2192 ${outputPath}`);
|
|
705
744
|
} catch (error) {
|
|
706
|
-
|
|
745
|
+
log3.error("Bundle failed:", error);
|
|
707
746
|
throw error;
|
|
708
747
|
}
|
|
709
748
|
}
|
|
710
|
-
var
|
|
749
|
+
var log4 = anylogger__default.default("list");
|
|
711
750
|
function findSchemasDir2() {
|
|
712
751
|
const __filename2 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
713
752
|
const __dirname2 = path.dirname(__filename2);
|
|
@@ -739,7 +778,7 @@ async function listSchemas(schemasDir, options = {}) {
|
|
|
739
778
|
...typeEntries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort()
|
|
740
779
|
);
|
|
741
780
|
} catch (error) {
|
|
742
|
-
|
|
781
|
+
log4.warn("Could not read types directory:", error);
|
|
743
782
|
}
|
|
744
783
|
}
|
|
745
784
|
if (showFunctions) {
|
|
@@ -750,7 +789,7 @@ async function listSchemas(schemasDir, options = {}) {
|
|
|
750
789
|
...funcEntries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort()
|
|
751
790
|
);
|
|
752
791
|
} catch (error) {
|
|
753
|
-
|
|
792
|
+
log4.warn("Could not read functions directory:", error);
|
|
754
793
|
}
|
|
755
794
|
}
|
|
756
795
|
return { types, functions };
|
|
@@ -782,7 +821,7 @@ async function handleListCommand(options = {}) {
|
|
|
782
821
|
const output = formatListOutput(result, options);
|
|
783
822
|
console.log(output);
|
|
784
823
|
}
|
|
785
|
-
var
|
|
824
|
+
var log5 = anylogger__default.default("presets");
|
|
786
825
|
function formatPresetInfo() {
|
|
787
826
|
const lines = [];
|
|
788
827
|
lines.push("=".repeat(60));
|
|
@@ -826,24 +865,32 @@ function formatPresetInfo() {
|
|
|
826
865
|
}
|
|
827
866
|
async function handlePresetsCommand() {
|
|
828
867
|
try {
|
|
829
|
-
|
|
868
|
+
log5.info("Listing available presets");
|
|
830
869
|
const output = formatPresetInfo();
|
|
831
870
|
console.log(output);
|
|
832
|
-
|
|
871
|
+
log5.info(`Listed ${Object.keys(BUNDLE_PRESETS).length} presets`);
|
|
833
872
|
} catch (error) {
|
|
834
|
-
|
|
873
|
+
log5.error("Failed to list presets:", error);
|
|
835
874
|
throw error;
|
|
836
875
|
}
|
|
837
876
|
}
|
|
838
877
|
|
|
839
878
|
// src/cli/index.ts
|
|
840
|
-
var
|
|
879
|
+
var log6 = anylogger__default.default("cli");
|
|
841
880
|
var cli = cac__default.default("tokenscript-schemas");
|
|
842
881
|
cli.command("bundle [...schemas]", "Bundle schemas into a JS file").option("-c, --config <path>", "Path to config file").option("-o, --output <path>", "Output file path", { default: "./tokenscript-schemas.js" }).option("-d, --dry-run", "Preview what would be bundled without writing").option("-s, --schemas-dir <path>", "Custom schema directory (overrides default)").action(async (schemas, options) => {
|
|
843
882
|
try {
|
|
844
883
|
await handleBundleCommand(schemas, options);
|
|
845
884
|
} catch (error) {
|
|
846
|
-
|
|
885
|
+
log6.error("Error:", error);
|
|
886
|
+
process.exit(1);
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
cli.command("build <directory>", "Build an individual schema directory").option("-o, --output <path>", "Output file path (defaults to stdout)").option("-p, --pretty", "Pretty print JSON output").action(async (directory, options) => {
|
|
890
|
+
try {
|
|
891
|
+
await handleBuildCommand(directory, options);
|
|
892
|
+
} catch (error) {
|
|
893
|
+
log6.error("Error:", error);
|
|
847
894
|
process.exit(1);
|
|
848
895
|
}
|
|
849
896
|
});
|
|
@@ -851,7 +898,7 @@ cli.command("list", "List available schemas").option("--types", "List only type
|
|
|
851
898
|
try {
|
|
852
899
|
await handleListCommand(options);
|
|
853
900
|
} catch (error) {
|
|
854
|
-
|
|
901
|
+
log6.error("Error:", error);
|
|
855
902
|
process.exit(1);
|
|
856
903
|
}
|
|
857
904
|
});
|
|
@@ -859,7 +906,7 @@ cli.command("presets", "List available bundle presets").action(async () => {
|
|
|
859
906
|
try {
|
|
860
907
|
await handlePresetsCommand();
|
|
861
908
|
} catch (error) {
|
|
862
|
-
|
|
909
|
+
log6.error("Error:", error);
|
|
863
910
|
process.exit(1);
|
|
864
911
|
}
|
|
865
912
|
});
|