@tokens-studio/tokenscript-schemas 0.1.2 → 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 +36 -7
- package/dist/cli/index.cjs +142 -88
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +141 -87
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +19 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +19 -19
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/bundler/{bundle-schema.ts → build-schema.ts} +2 -2
- package/src/bundler/index.ts +25 -25
- package/src/bundler/schema-dependency-resolver.ts +3 -3
- package/src/bundler/selective-bundler.ts +3 -3
- package/src/cli/commands/build-dir.test.ts +354 -0
- package/src/cli/commands/build-dir.ts +90 -0
- package/src/cli/commands/bundle.test.ts +95 -1
- package/src/cli/commands/bundle.ts +22 -15
- package/src/cli/index.ts +16 -0
- package/bundled/functions/adjust_chroma.json +0 -60
- package/bundled/functions/adjust_hue.json +0 -60
- package/bundled/functions/adjust_lightness.json +0 -60
- package/bundled/functions/adjust_to_contrast.json +0 -67
- package/bundled/functions/alpha_blend.json +0 -31
- package/bundled/functions/alpha_scale.json +0 -27
- package/bundled/functions/analogous.json +0 -32
- package/bundled/functions/apca_contrast.json +0 -27
- package/bundled/functions/are_similar.json +0 -73
- package/bundled/functions/auto_text_color.json +0 -66
- package/bundled/functions/best_contrast.json +0 -28
- package/bundled/functions/chroma.json +0 -54
- package/bundled/functions/clamp_chroma.json +0 -66
- package/bundled/functions/clamp_lightness.json +0 -66
- package/bundled/functions/clamp_to_gamut.json +0 -23
- package/bundled/functions/complement.json +0 -24
- package/bundled/functions/contrast_ratio.json +0 -27
- package/bundled/functions/cooler.json +0 -52
- package/bundled/functions/darken.json +0 -28
- package/bundled/functions/delta_e_2000.json +0 -40
- package/bundled/functions/delta_e_76.json +0 -27
- package/bundled/functions/delta_e_ok.json +0 -27
- package/bundled/functions/desaturate.json +0 -28
- package/bundled/functions/distributed.json +0 -36
- package/bundled/functions/diverging.json +0 -36
- package/bundled/functions/grayscale.json +0 -24
- package/bundled/functions/harmonize.json +0 -65
- package/bundled/functions/hue.json +0 -54
- package/bundled/functions/hue_difference.json +0 -27
- package/bundled/functions/in_gamut.json +0 -27
- package/bundled/functions/interpolate.json +0 -66
- package/bundled/functions/invert.json +0 -23
- package/bundled/functions/is_cool.json +0 -23
- package/bundled/functions/is_dark.json +0 -27
- package/bundled/functions/is_light.json +0 -27
- package/bundled/functions/is_neutral.json +0 -65
- package/bundled/functions/is_warm.json +0 -23
- package/bundled/functions/lighten.json +0 -28
- package/bundled/functions/lightness.json +0 -61
- package/bundled/functions/luminance.json +0 -23
- package/bundled/functions/meets_contrast.json +0 -31
- package/bundled/functions/mix.json +0 -32
- package/bundled/functions/monochromatic.json +0 -28
- package/bundled/functions/muted.json +0 -59
- package/bundled/functions/neutral_variant.json +0 -59
- package/bundled/functions/relative_luminance.json +0 -61
- package/bundled/functions/rotate_hue.json +0 -28
- package/bundled/functions/saturate.json +0 -28
- package/bundled/functions/scale_chroma.json +0 -60
- package/bundled/functions/scale_lightness.json +0 -60
- package/bundled/functions/sepia.json +0 -59
- package/bundled/functions/set_chroma.json +0 -28
- package/bundled/functions/set_hue.json +0 -28
- package/bundled/functions/set_lightness.json +0 -28
- package/bundled/functions/shade_scale.json +0 -28
- package/bundled/functions/split_complement.json +0 -28
- package/bundled/functions/steps.json +0 -32
- package/bundled/functions/tetradic.json +0 -24
- package/bundled/functions/tint_scale.json +0 -36
- package/bundled/functions/to_gamut.json +0 -59
- package/bundled/functions/triadic.json +0 -24
- package/bundled/functions/vibrant.json +0 -59
- package/bundled/functions/warmer.json +0 -52
- package/bundled/functions/wcag_level.json +0 -60
- package/bundled/functions.json +0 -2624
- package/bundled/registry.json +0 -3833
- package/bundled/types/css-color.json +0 -151
- package/bundled/types/hex-color.json +0 -25
- package/bundled/types/hsl-color.json +0 -66
- package/bundled/types/hsv-color.json +0 -57
- package/bundled/types/hwb-color.json +0 -66
- package/bundled/types/lab-color.json +0 -57
- package/bundled/types/lch-color.json +0 -57
- package/bundled/types/okhsl-color.json +0 -57
- package/bundled/types/okhsv-color.json +0 -57
- package/bundled/types/oklab-color.json +0 -87
- package/bundled/types/oklch-color.json +0 -57
- package/bundled/types/p3-color.json +0 -57
- package/bundled/types/p3-linear-color.json +0 -57
- package/bundled/types/rgb-color.json +0 -73
- package/bundled/types/srgb-color.json +0 -77
- package/bundled/types/srgb-linear-color.json +0 -67
- package/bundled/types/xyz-d50-color.json +0 -57
- package/bundled/types/xyz-d65-color.json +0 -77
- package/bundled/types.json +0 -1207
package/dist/cli/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import cac from 'cac';
|
|
3
|
-
import
|
|
3
|
+
import anylogger from 'ulog';
|
|
4
|
+
import { existsSync, readFileSync } from 'fs';
|
|
4
5
|
import { mkdir, writeFile, readFile, readdir, access } from 'fs/promises';
|
|
5
6
|
import { dirname, join } from 'path';
|
|
6
7
|
import { fileURLToPath } from 'url';
|
|
7
8
|
import 'child_process';
|
|
8
|
-
import { readFileSync } from 'fs';
|
|
9
9
|
|
|
10
10
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
11
11
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -13,50 +13,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
13
13
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
14
14
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
15
15
|
});
|
|
16
|
-
|
|
17
|
-
// src/bundler/presets/css.ts
|
|
18
|
-
var css = {
|
|
19
|
-
name: "CSS",
|
|
20
|
-
description: "CSS color types",
|
|
21
|
-
types: [
|
|
22
|
-
"hex-color",
|
|
23
|
-
"rgb-color",
|
|
24
|
-
"hsl-color",
|
|
25
|
-
"oklch-color",
|
|
26
|
-
"oklab-color",
|
|
27
|
-
// Converting colors to css strings
|
|
28
|
-
"css-color"
|
|
29
|
-
],
|
|
30
|
-
functions: ["lighten", "darken", "saturate", "desaturate", "mix", "invert"]
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// src/bundler/presets/index.ts
|
|
34
|
-
var BUNDLE_PRESETS = {
|
|
35
|
-
css
|
|
36
|
-
};
|
|
37
|
-
function expandPresetSchemas(schemas) {
|
|
38
|
-
const expanded = [];
|
|
39
|
-
for (const schema of schemas) {
|
|
40
|
-
if (schema.startsWith("preset:")) {
|
|
41
|
-
const presetName = schema.slice(7);
|
|
42
|
-
const preset = BUNDLE_PRESETS[presetName];
|
|
43
|
-
if (preset) {
|
|
44
|
-
for (const type of preset.types) {
|
|
45
|
-
expanded.push(type === "*" ? "*" : `type:${type}`);
|
|
46
|
-
}
|
|
47
|
-
for (const func of preset.functions) {
|
|
48
|
-
expanded.push(func === "*" ? "*" : `function:${func}`);
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
console.warn(`\u26A0 Unknown preset: ${presetName}`);
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
expanded.push(schema);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return expanded;
|
|
58
|
-
}
|
|
59
|
-
async function bundleSchemaFromDirectory(schemaDir, options) {
|
|
16
|
+
async function buildSchemaFromDirectory(schemaDir, options) {
|
|
60
17
|
const schemaJsonPath = join(schemaDir, "schema.json");
|
|
61
18
|
const schemaContent = await readFile(schemaJsonPath, "utf-8");
|
|
62
19
|
const schema = JSON.parse(schemaContent);
|
|
@@ -126,6 +83,92 @@ function addBaseUrl(uri, baseUrl) {
|
|
|
126
83
|
}
|
|
127
84
|
return uri;
|
|
128
85
|
}
|
|
86
|
+
|
|
87
|
+
// src/cli/commands/build-dir.ts
|
|
88
|
+
var log = anylogger("build-dir");
|
|
89
|
+
async function buildSchemaDir(schemaDir, options = {}) {
|
|
90
|
+
const resolvedDir = resolveSchemaDir(schemaDir);
|
|
91
|
+
if (!existsSync(resolvedDir)) {
|
|
92
|
+
throw new Error(`Directory not found: ${resolvedDir}`);
|
|
93
|
+
}
|
|
94
|
+
const schemaJsonPath = join(resolvedDir, "schema.json");
|
|
95
|
+
if (!existsSync(schemaJsonPath)) {
|
|
96
|
+
throw new Error(`schema.json not found in: ${resolvedDir}`);
|
|
97
|
+
}
|
|
98
|
+
log.info(`Building schema from: ${resolvedDir}`);
|
|
99
|
+
const schema = await buildSchemaFromDirectory(resolvedDir);
|
|
100
|
+
const output = options.pretty ? JSON.stringify(schema, null, 2) : JSON.stringify(schema);
|
|
101
|
+
if (options.output) {
|
|
102
|
+
await mkdir(dirname(options.output), { recursive: true });
|
|
103
|
+
await writeFile(options.output, output, "utf-8");
|
|
104
|
+
log.info(`Output written to: ${options.output}`);
|
|
105
|
+
console.log(`\u2713 Built ${schema.type}:${schema.name} \u2192 ${options.output}`);
|
|
106
|
+
} else {
|
|
107
|
+
console.log(output);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function resolveSchemaDir(schemaDir) {
|
|
111
|
+
if (existsSync(schemaDir)) {
|
|
112
|
+
return schemaDir;
|
|
113
|
+
}
|
|
114
|
+
const cwd = process.cwd();
|
|
115
|
+
const fromCwd = join(cwd, schemaDir);
|
|
116
|
+
if (existsSync(fromCwd)) {
|
|
117
|
+
return fromCwd;
|
|
118
|
+
}
|
|
119
|
+
return schemaDir;
|
|
120
|
+
}
|
|
121
|
+
async function handleBuildCommand(schemaDir, options = {}) {
|
|
122
|
+
try {
|
|
123
|
+
await buildSchemaDir(schemaDir, options);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
log.error("Build failed:", error);
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/bundler/presets/css.ts
|
|
131
|
+
var css = {
|
|
132
|
+
name: "CSS",
|
|
133
|
+
description: "CSS color types",
|
|
134
|
+
types: [
|
|
135
|
+
"hex-color",
|
|
136
|
+
"rgb-color",
|
|
137
|
+
"hsl-color",
|
|
138
|
+
"oklch-color",
|
|
139
|
+
"oklab-color",
|
|
140
|
+
// Converting colors to css strings
|
|
141
|
+
"css-color"
|
|
142
|
+
],
|
|
143
|
+
functions: ["lighten", "darken", "saturate", "desaturate", "mix", "invert"]
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/bundler/presets/index.ts
|
|
147
|
+
var BUNDLE_PRESETS = {
|
|
148
|
+
css
|
|
149
|
+
};
|
|
150
|
+
function expandPresetSchemas(schemas) {
|
|
151
|
+
const expanded = [];
|
|
152
|
+
for (const schema of schemas) {
|
|
153
|
+
if (schema.startsWith("preset:")) {
|
|
154
|
+
const presetName = schema.slice(7);
|
|
155
|
+
const preset = BUNDLE_PRESETS[presetName];
|
|
156
|
+
if (preset) {
|
|
157
|
+
for (const type of preset.types) {
|
|
158
|
+
expanded.push(type === "*" ? "*" : `type:${type}`);
|
|
159
|
+
}
|
|
160
|
+
for (const func of preset.functions) {
|
|
161
|
+
expanded.push(func === "*" ? "*" : `function:${func}`);
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
console.warn(`\u26A0 Unknown preset: ${presetName}`);
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
expanded.push(schema);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return expanded;
|
|
171
|
+
}
|
|
129
172
|
var LOG_LEVELS = {
|
|
130
173
|
error: 1,
|
|
131
174
|
warn: 2,
|
|
@@ -133,9 +176,9 @@ var LOG_LEVELS = {
|
|
|
133
176
|
log: 4,
|
|
134
177
|
debug: 5
|
|
135
178
|
};
|
|
136
|
-
var
|
|
179
|
+
var log2 = anylogger("schema-registry");
|
|
137
180
|
var logLevel = process.env.LOG_LEVEL || "error";
|
|
138
|
-
|
|
181
|
+
log2.level = LOG_LEVELS[logLevel] || LOG_LEVELS.error;
|
|
139
182
|
|
|
140
183
|
// src/utils/type.ts
|
|
141
184
|
var isSome = (v) => {
|
|
@@ -267,7 +310,7 @@ async function collectRequiredSchemas(slugOrUri, type, options = {}) {
|
|
|
267
310
|
async function traverse(currentSlugOrUri, currentType) {
|
|
268
311
|
const ref = resolveSchemaReference(currentSlugOrUri);
|
|
269
312
|
if (!ref) {
|
|
270
|
-
|
|
313
|
+
log2.warn(`Could not resolve schema reference: ${currentSlugOrUri}`);
|
|
271
314
|
return;
|
|
272
315
|
}
|
|
273
316
|
const effectiveType = currentType || ref.type;
|
|
@@ -282,9 +325,9 @@ async function collectRequiredSchemas(slugOrUri, type, options = {}) {
|
|
|
282
325
|
const categoryDir = effectiveType === "type" ? "types" : "functions";
|
|
283
326
|
const resolvedSchemasDir = schemasDir || process.env.SCHEMAS_DIR || join(process.cwd(), "src/schemas");
|
|
284
327
|
const schemaDir = join(resolvedSchemasDir, categoryDir, slug);
|
|
285
|
-
spec = await
|
|
328
|
+
spec = await buildSchemaFromDirectory(schemaDir, baseUrl ? { baseUrl } : void 0);
|
|
286
329
|
} catch (error) {
|
|
287
|
-
|
|
330
|
+
log2.warn(`Failed to load schema ${slug} (${effectiveType}):`, error);
|
|
288
331
|
return;
|
|
289
332
|
}
|
|
290
333
|
const requirements = extractRequirements(spec, extractOptions);
|
|
@@ -336,7 +379,7 @@ async function collectDependencyTree(schemas, options = {}) {
|
|
|
336
379
|
const resolvedSchemasDir = schemasDir || process.env.SCHEMAS_DIR || join(process.cwd(), "src/schemas");
|
|
337
380
|
const schemaDir = join(resolvedSchemasDir, categoryDir, schema.slug);
|
|
338
381
|
try {
|
|
339
|
-
const spec = await
|
|
382
|
+
const spec = await buildSchemaFromDirectory(schemaDir, baseUrl ? { baseUrl } : void 0);
|
|
340
383
|
const requirements = extractRequirements(spec, extractOptions);
|
|
341
384
|
const dependencySlugs = requirements.map((uri) => {
|
|
342
385
|
const ref = resolveSchemaReference(uri);
|
|
@@ -349,7 +392,7 @@ async function collectDependencyTree(schemas, options = {}) {
|
|
|
349
392
|
dependencies: dependencySlugs
|
|
350
393
|
});
|
|
351
394
|
} catch (error) {
|
|
352
|
-
|
|
395
|
+
log2.warn(`Failed to load schema ${schema.slug} (${schema.type}):`, error);
|
|
353
396
|
}
|
|
354
397
|
}
|
|
355
398
|
return tree;
|
|
@@ -410,7 +453,7 @@ async function bundleSelectiveSchemas(options) {
|
|
|
410
453
|
const bundledSchemas = [];
|
|
411
454
|
for (const typeSlug of deps.types) {
|
|
412
455
|
const schemaDir = join(schemasDir, "types", typeSlug);
|
|
413
|
-
const bundled = await
|
|
456
|
+
const bundled = await buildSchemaFromDirectory(schemaDir, { baseUrl });
|
|
414
457
|
if (bundled.type === "color") {
|
|
415
458
|
const uri = `${baseUrl}/api/v1/core/${typeSlug}/0/`;
|
|
416
459
|
bundledSchemas.push({
|
|
@@ -421,7 +464,7 @@ async function bundleSelectiveSchemas(options) {
|
|
|
421
464
|
}
|
|
422
465
|
for (const funcSlug of deps.functions) {
|
|
423
466
|
const schemaDir = join(schemasDir, "functions", funcSlug);
|
|
424
|
-
const bundled = await
|
|
467
|
+
const bundled = await buildSchemaFromDirectory(schemaDir, { baseUrl });
|
|
425
468
|
if (bundled.type === "function") {
|
|
426
469
|
const uri = `${baseUrl}/api/v1/function/${funcSlug}/0/`;
|
|
427
470
|
bundledSchemas.push({
|
|
@@ -540,7 +583,7 @@ function generateOutput(options) {
|
|
|
540
583
|
}
|
|
541
584
|
|
|
542
585
|
// src/cli/commands/bundle.ts
|
|
543
|
-
var
|
|
586
|
+
var log3 = anylogger("bundle");
|
|
544
587
|
async function loadConfig(configPath) {
|
|
545
588
|
try {
|
|
546
589
|
const content = await readFile(configPath, "utf-8");
|
|
@@ -605,28 +648,24 @@ function findSchemasDir() {
|
|
|
605
648
|
const __dirname2 = dirname(__filename2);
|
|
606
649
|
const fromDist = join(__dirname2, "../../src/schemas");
|
|
607
650
|
const fromSource = join(__dirname2, "../../schemas");
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
if (fs.existsSync(fromDist)) {
|
|
611
|
-
return fromDist;
|
|
612
|
-
}
|
|
613
|
-
if (fs.existsSync(fromSource)) {
|
|
614
|
-
return fromSource;
|
|
615
|
-
}
|
|
616
|
-
} catch {
|
|
651
|
+
if (existsSync(fromSource)) {
|
|
652
|
+
return fromSource;
|
|
617
653
|
}
|
|
618
|
-
|
|
654
|
+
if (existsSync(fromDist)) {
|
|
655
|
+
return fromDist;
|
|
656
|
+
}
|
|
657
|
+
return fromSource;
|
|
619
658
|
}
|
|
620
659
|
async function bundleSchemas(schemas, schemasDir, cliArgs) {
|
|
621
|
-
const resolvedSchemasDir = findSchemasDir();
|
|
622
|
-
|
|
623
|
-
|
|
660
|
+
const resolvedSchemasDir = schemasDir || findSchemasDir();
|
|
661
|
+
log3.info("Bundling schemas:", schemas);
|
|
662
|
+
log3.debug("Schemas directory:", resolvedSchemasDir);
|
|
624
663
|
const result = await bundleSelectiveSchemas({
|
|
625
664
|
schemas,
|
|
626
665
|
schemasDir: resolvedSchemasDir,
|
|
627
666
|
cliArgs
|
|
628
667
|
});
|
|
629
|
-
|
|
668
|
+
log3.info(
|
|
630
669
|
`Resolved ${result.metadata.resolvedDependencies.length} schemas (including dependencies)`
|
|
631
670
|
);
|
|
632
671
|
const output = generateOutput({
|
|
@@ -645,7 +684,7 @@ async function handleBundleCommand(schemas, options = {}) {
|
|
|
645
684
|
let configSchemas = schemas;
|
|
646
685
|
let outputPath = options.output || "./tokenscript-schemas.js";
|
|
647
686
|
if (isSome(options.config)) {
|
|
648
|
-
|
|
687
|
+
log3.info(`Loading config from ${options.config}`);
|
|
649
688
|
const config = await loadConfig(options.config);
|
|
650
689
|
configSchemas = config.schemas;
|
|
651
690
|
if (config.output) {
|
|
@@ -669,9 +708,16 @@ async function handleBundleCommand(schemas, options = {}) {
|
|
|
669
708
|
if (options.dryRun) {
|
|
670
709
|
cliArgs.push("--dry-run");
|
|
671
710
|
}
|
|
711
|
+
if (options.schemasDir) {
|
|
712
|
+
cliArgs.push("--schemas-dir", options.schemasDir);
|
|
713
|
+
}
|
|
714
|
+
const customSchemasDir = options.schemasDir;
|
|
715
|
+
if (customSchemasDir) {
|
|
716
|
+
log3.info(`Using custom schema directory: ${customSchemasDir}`);
|
|
717
|
+
}
|
|
672
718
|
const { output, metadata, dependencyTree } = await bundleSchemas(
|
|
673
719
|
configSchemas,
|
|
674
|
-
|
|
720
|
+
customSchemasDir,
|
|
675
721
|
cliArgs
|
|
676
722
|
);
|
|
677
723
|
console.log("");
|
|
@@ -684,15 +730,15 @@ async function handleBundleCommand(schemas, options = {}) {
|
|
|
684
730
|
}
|
|
685
731
|
await mkdir(dirname(outputPath), { recursive: true });
|
|
686
732
|
await writeFile(outputPath, output, "utf-8");
|
|
687
|
-
|
|
688
|
-
|
|
733
|
+
log3.info(`Successfully bundled ${metadata.resolvedDependencies.length} schemas`);
|
|
734
|
+
log3.info(`Output written to: ${outputPath}`);
|
|
689
735
|
console.log(`\u2713 Bundled ${metadata.resolvedDependencies.length} schemas \u2192 ${outputPath}`);
|
|
690
736
|
} catch (error) {
|
|
691
|
-
|
|
737
|
+
log3.error("Bundle failed:", error);
|
|
692
738
|
throw error;
|
|
693
739
|
}
|
|
694
740
|
}
|
|
695
|
-
var
|
|
741
|
+
var log4 = anylogger("list");
|
|
696
742
|
function findSchemasDir2() {
|
|
697
743
|
const __filename2 = fileURLToPath(import.meta.url);
|
|
698
744
|
const __dirname2 = dirname(__filename2);
|
|
@@ -724,7 +770,7 @@ async function listSchemas(schemasDir, options = {}) {
|
|
|
724
770
|
...typeEntries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort()
|
|
725
771
|
);
|
|
726
772
|
} catch (error) {
|
|
727
|
-
|
|
773
|
+
log4.warn("Could not read types directory:", error);
|
|
728
774
|
}
|
|
729
775
|
}
|
|
730
776
|
if (showFunctions) {
|
|
@@ -735,7 +781,7 @@ async function listSchemas(schemasDir, options = {}) {
|
|
|
735
781
|
...funcEntries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort()
|
|
736
782
|
);
|
|
737
783
|
} catch (error) {
|
|
738
|
-
|
|
784
|
+
log4.warn("Could not read functions directory:", error);
|
|
739
785
|
}
|
|
740
786
|
}
|
|
741
787
|
return { types, functions };
|
|
@@ -767,7 +813,7 @@ async function handleListCommand(options = {}) {
|
|
|
767
813
|
const output = formatListOutput(result, options);
|
|
768
814
|
console.log(output);
|
|
769
815
|
}
|
|
770
|
-
var
|
|
816
|
+
var log5 = anylogger("presets");
|
|
771
817
|
function formatPresetInfo() {
|
|
772
818
|
const lines = [];
|
|
773
819
|
lines.push("=".repeat(60));
|
|
@@ -811,24 +857,32 @@ function formatPresetInfo() {
|
|
|
811
857
|
}
|
|
812
858
|
async function handlePresetsCommand() {
|
|
813
859
|
try {
|
|
814
|
-
|
|
860
|
+
log5.info("Listing available presets");
|
|
815
861
|
const output = formatPresetInfo();
|
|
816
862
|
console.log(output);
|
|
817
|
-
|
|
863
|
+
log5.info(`Listed ${Object.keys(BUNDLE_PRESETS).length} presets`);
|
|
818
864
|
} catch (error) {
|
|
819
|
-
|
|
865
|
+
log5.error("Failed to list presets:", error);
|
|
820
866
|
throw error;
|
|
821
867
|
}
|
|
822
868
|
}
|
|
823
869
|
|
|
824
870
|
// src/cli/index.ts
|
|
825
|
-
var
|
|
871
|
+
var log6 = anylogger("cli");
|
|
826
872
|
var cli = cac("tokenscript-schemas");
|
|
827
|
-
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").action(async (schemas, options) => {
|
|
873
|
+
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) => {
|
|
828
874
|
try {
|
|
829
875
|
await handleBundleCommand(schemas, options);
|
|
830
876
|
} catch (error) {
|
|
831
|
-
|
|
877
|
+
log6.error("Error:", error);
|
|
878
|
+
process.exit(1);
|
|
879
|
+
}
|
|
880
|
+
});
|
|
881
|
+
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) => {
|
|
882
|
+
try {
|
|
883
|
+
await handleBuildCommand(directory, options);
|
|
884
|
+
} catch (error) {
|
|
885
|
+
log6.error("Error:", error);
|
|
832
886
|
process.exit(1);
|
|
833
887
|
}
|
|
834
888
|
});
|
|
@@ -836,7 +890,7 @@ cli.command("list", "List available schemas").option("--types", "List only type
|
|
|
836
890
|
try {
|
|
837
891
|
await handleListCommand(options);
|
|
838
892
|
} catch (error) {
|
|
839
|
-
|
|
893
|
+
log6.error("Error:", error);
|
|
840
894
|
process.exit(1);
|
|
841
895
|
}
|
|
842
896
|
});
|
|
@@ -844,7 +898,7 @@ cli.command("presets", "List available bundle presets").action(async () => {
|
|
|
844
898
|
try {
|
|
845
899
|
await handlePresetsCommand();
|
|
846
900
|
} catch (error) {
|
|
847
|
-
|
|
901
|
+
log6.error("Error:", error);
|
|
848
902
|
process.exit(1);
|
|
849
903
|
}
|
|
850
904
|
});
|