@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/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
|
|
|
@@ -39,12 +44,19 @@ npx @tokens-studio/tokenscript-schemas bundle --config schemas.json
|
|
|
39
44
|
# Preview what would be bundled (dry-run)
|
|
40
45
|
npx @tokens-studio/tokenscript-schemas bundle oklch-color rgb-color --dry-run
|
|
41
46
|
|
|
47
|
+
# Bundle from custom schema directory
|
|
48
|
+
npx @tokens-studio/tokenscript-schemas bundle type:my-color -o ./schemas.js --schemas-dir ./my-schemas
|
|
49
|
+
|
|
42
50
|
# List available schemas
|
|
43
51
|
npx @tokens-studio/tokenscript-schemas list
|
|
44
52
|
npx @tokens-studio/tokenscript-schemas list --types
|
|
45
53
|
npx @tokens-studio/tokenscript-schemas list --functions
|
|
46
54
|
```
|
|
47
55
|
|
|
56
|
+
#### Docs
|
|
57
|
+
|
|
58
|
+
- [Custom Schema Directories Documentation](docs/cli/custom-schemas.md) - Bundle schemas from custom directories
|
|
59
|
+
|
|
48
60
|
### Available Presets
|
|
49
61
|
|
|
50
62
|
- **`preset:css`** - Modern CSS color types (CSS Color Level 4+)
|
|
@@ -120,19 +132,36 @@ src/schemas/types/srgb-color/
|
|
|
120
132
|
- Tests use runtime bundling - no build step required
|
|
121
133
|
- The bundler inlines script content for distribution
|
|
122
134
|
|
|
135
|
+
## Working with Custom Schemas
|
|
136
|
+
|
|
137
|
+
You can use the bundler with your own custom schema directories, useful for:
|
|
138
|
+
- Developing experimental schemas without modifying the main repository
|
|
139
|
+
- Working with schemas from external projects
|
|
140
|
+
- Testing new color types before committing them
|
|
141
|
+
|
|
142
|
+
See **[Custom Schema Directories Documentation](docs/cli/custom-schemas.md)** for detailed examples and usage.
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
# Bundle from custom directory
|
|
146
|
+
npm run cli -- bundle my-color -o ./output.js --schemas-dir ./path/to/custom/schemas
|
|
147
|
+
|
|
148
|
+
# Build from custom directory
|
|
149
|
+
npm run build-schemas -- --schemas-dir ./path/to/custom/schemas
|
|
150
|
+
```
|
|
151
|
+
|
|
123
152
|
## Scripts
|
|
124
153
|
|
|
125
|
-
###
|
|
154
|
+
### Build Schemas
|
|
126
155
|
|
|
127
156
|
```bash
|
|
128
|
-
npm run
|
|
157
|
+
npm run build-schemas
|
|
129
158
|
```
|
|
130
159
|
|
|
131
|
-
|
|
160
|
+
Builds all schemas using the **shared build logic** from `@/bundler/build-schema.ts`:
|
|
132
161
|
- Reads `schema.json` from each schema directory
|
|
133
162
|
- Finds all `./file.tokenscript` references in the schema
|
|
134
163
|
- Reads and inlines the script file content
|
|
135
|
-
- Outputs
|
|
164
|
+
- Outputs built schemas to `result/` directory:
|
|
136
165
|
- `registry.json` - Complete registry
|
|
137
166
|
- `types.json` - All type schemas
|
|
138
167
|
- `functions.json` - All function schemas
|
|
@@ -163,9 +192,9 @@ npm test -- src/schemas/types/rgb-color/unit.test.ts
|
|
|
163
192
|
- Logs are **disabled by default** to reduce noise (only errors shown)
|
|
164
193
|
- Use `LOG_LEVEL` environment variable to enable logs: `debug`, `info`, `warn`, `error`
|
|
165
194
|
- See [tests/helpers/LOGGING.md](tests/helpers/LOGGING.md) for detailed logging documentation
|
|
166
|
-
- Tests use `
|
|
167
|
-
- No build step required - schemas are
|
|
168
|
-
- Same
|
|
195
|
+
- Tests use `buildSchemaFromDirectory()` from `@/bundler/build-schema.ts`
|
|
196
|
+
- No build step required - schemas are built on-demand
|
|
197
|
+
- Same build logic as build-time for consistency
|
|
169
198
|
|
|
170
199
|
## Links
|
|
171
200
|
|
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,50 +21,7 @@ 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
|
-
async function bundleSchemaFromDirectory(schemaDir, options) {
|
|
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");
|
|
70
27
|
const schema = JSON.parse(schemaContent);
|
|
@@ -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;
|
|
@@ -290,9 +333,9 @@ async function collectRequiredSchemas(slugOrUri, type, options = {}) {
|
|
|
290
333
|
const categoryDir = effectiveType === "type" ? "types" : "functions";
|
|
291
334
|
const resolvedSchemasDir = schemasDir || process.env.SCHEMAS_DIR || path.join(process.cwd(), "src/schemas");
|
|
292
335
|
const schemaDir = path.join(resolvedSchemasDir, categoryDir, slug);
|
|
293
|
-
spec = await
|
|
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);
|
|
@@ -344,7 +387,7 @@ async function collectDependencyTree(schemas, options = {}) {
|
|
|
344
387
|
const resolvedSchemasDir = schemasDir || process.env.SCHEMAS_DIR || path.join(process.cwd(), "src/schemas");
|
|
345
388
|
const schemaDir = path.join(resolvedSchemasDir, categoryDir, schema.slug);
|
|
346
389
|
try {
|
|
347
|
-
const spec = await
|
|
390
|
+
const spec = await buildSchemaFromDirectory(schemaDir, baseUrl ? { baseUrl } : void 0);
|
|
348
391
|
const requirements = extractRequirements(spec, extractOptions);
|
|
349
392
|
const dependencySlugs = requirements.map((uri) => {
|
|
350
393
|
const ref = resolveSchemaReference(uri);
|
|
@@ -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;
|
|
@@ -418,7 +461,7 @@ async function bundleSelectiveSchemas(options) {
|
|
|
418
461
|
const bundledSchemas = [];
|
|
419
462
|
for (const typeSlug of deps.types) {
|
|
420
463
|
const schemaDir = path.join(schemasDir, "types", typeSlug);
|
|
421
|
-
const bundled = await
|
|
464
|
+
const bundled = await buildSchemaFromDirectory(schemaDir, { baseUrl });
|
|
422
465
|
if (bundled.type === "color") {
|
|
423
466
|
const uri = `${baseUrl}/api/v1/core/${typeSlug}/0/`;
|
|
424
467
|
bundledSchemas.push({
|
|
@@ -429,7 +472,7 @@ async function bundleSelectiveSchemas(options) {
|
|
|
429
472
|
}
|
|
430
473
|
for (const funcSlug of deps.functions) {
|
|
431
474
|
const schemaDir = path.join(schemasDir, "functions", funcSlug);
|
|
432
|
-
const bundled = await
|
|
475
|
+
const bundled = await buildSchemaFromDirectory(schemaDir, { baseUrl });
|
|
433
476
|
if (bundled.type === "function") {
|
|
434
477
|
const uri = `${baseUrl}/api/v1/function/${funcSlug}/0/`;
|
|
435
478
|
bundledSchemas.push({
|
|
@@ -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
|
-
const resolvedSchemasDir = findSchemasDir();
|
|
630
|
-
|
|
631
|
-
|
|
668
|
+
const resolvedSchemasDir = schemasDir || findSchemasDir();
|
|
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) {
|
|
@@ -677,9 +716,16 @@ async function handleBundleCommand(schemas, options = {}) {
|
|
|
677
716
|
if (options.dryRun) {
|
|
678
717
|
cliArgs.push("--dry-run");
|
|
679
718
|
}
|
|
719
|
+
if (options.schemasDir) {
|
|
720
|
+
cliArgs.push("--schemas-dir", options.schemasDir);
|
|
721
|
+
}
|
|
722
|
+
const customSchemasDir = options.schemasDir;
|
|
723
|
+
if (customSchemasDir) {
|
|
724
|
+
log3.info(`Using custom schema directory: ${customSchemasDir}`);
|
|
725
|
+
}
|
|
680
726
|
const { output, metadata, dependencyTree } = await bundleSchemas(
|
|
681
727
|
configSchemas,
|
|
682
|
-
|
|
728
|
+
customSchemasDir,
|
|
683
729
|
cliArgs
|
|
684
730
|
);
|
|
685
731
|
console.log("");
|
|
@@ -692,15 +738,15 @@ async function handleBundleCommand(schemas, options = {}) {
|
|
|
692
738
|
}
|
|
693
739
|
await promises.mkdir(path.dirname(outputPath), { recursive: true });
|
|
694
740
|
await promises.writeFile(outputPath, output, "utf-8");
|
|
695
|
-
|
|
696
|
-
|
|
741
|
+
log3.info(`Successfully bundled ${metadata.resolvedDependencies.length} schemas`);
|
|
742
|
+
log3.info(`Output written to: ${outputPath}`);
|
|
697
743
|
console.log(`\u2713 Bundled ${metadata.resolvedDependencies.length} schemas \u2192 ${outputPath}`);
|
|
698
744
|
} catch (error) {
|
|
699
|
-
|
|
745
|
+
log3.error("Bundle failed:", error);
|
|
700
746
|
throw error;
|
|
701
747
|
}
|
|
702
748
|
}
|
|
703
|
-
var
|
|
749
|
+
var log4 = anylogger__default.default("list");
|
|
704
750
|
function findSchemasDir2() {
|
|
705
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)));
|
|
706
752
|
const __dirname2 = path.dirname(__filename2);
|
|
@@ -732,7 +778,7 @@ async function listSchemas(schemasDir, options = {}) {
|
|
|
732
778
|
...typeEntries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort()
|
|
733
779
|
);
|
|
734
780
|
} catch (error) {
|
|
735
|
-
|
|
781
|
+
log4.warn("Could not read types directory:", error);
|
|
736
782
|
}
|
|
737
783
|
}
|
|
738
784
|
if (showFunctions) {
|
|
@@ -743,7 +789,7 @@ async function listSchemas(schemasDir, options = {}) {
|
|
|
743
789
|
...funcEntries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort()
|
|
744
790
|
);
|
|
745
791
|
} catch (error) {
|
|
746
|
-
|
|
792
|
+
log4.warn("Could not read functions directory:", error);
|
|
747
793
|
}
|
|
748
794
|
}
|
|
749
795
|
return { types, functions };
|
|
@@ -775,7 +821,7 @@ async function handleListCommand(options = {}) {
|
|
|
775
821
|
const output = formatListOutput(result, options);
|
|
776
822
|
console.log(output);
|
|
777
823
|
}
|
|
778
|
-
var
|
|
824
|
+
var log5 = anylogger__default.default("presets");
|
|
779
825
|
function formatPresetInfo() {
|
|
780
826
|
const lines = [];
|
|
781
827
|
lines.push("=".repeat(60));
|
|
@@ -819,24 +865,32 @@ function formatPresetInfo() {
|
|
|
819
865
|
}
|
|
820
866
|
async function handlePresetsCommand() {
|
|
821
867
|
try {
|
|
822
|
-
|
|
868
|
+
log5.info("Listing available presets");
|
|
823
869
|
const output = formatPresetInfo();
|
|
824
870
|
console.log(output);
|
|
825
|
-
|
|
871
|
+
log5.info(`Listed ${Object.keys(BUNDLE_PRESETS).length} presets`);
|
|
826
872
|
} catch (error) {
|
|
827
|
-
|
|
873
|
+
log5.error("Failed to list presets:", error);
|
|
828
874
|
throw error;
|
|
829
875
|
}
|
|
830
876
|
}
|
|
831
877
|
|
|
832
878
|
// src/cli/index.ts
|
|
833
|
-
var
|
|
879
|
+
var log6 = anylogger__default.default("cli");
|
|
834
880
|
var cli = cac__default.default("tokenscript-schemas");
|
|
835
|
-
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) => {
|
|
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) => {
|
|
836
882
|
try {
|
|
837
883
|
await handleBundleCommand(schemas, options);
|
|
838
884
|
} catch (error) {
|
|
839
|
-
|
|
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);
|
|
840
894
|
process.exit(1);
|
|
841
895
|
}
|
|
842
896
|
});
|
|
@@ -844,7 +898,7 @@ cli.command("list", "List available schemas").option("--types", "List only type
|
|
|
844
898
|
try {
|
|
845
899
|
await handleListCommand(options);
|
|
846
900
|
} catch (error) {
|
|
847
|
-
|
|
901
|
+
log6.error("Error:", error);
|
|
848
902
|
process.exit(1);
|
|
849
903
|
}
|
|
850
904
|
});
|
|
@@ -852,7 +906,7 @@ cli.command("presets", "List available bundle presets").action(async () => {
|
|
|
852
906
|
try {
|
|
853
907
|
await handlePresetsCommand();
|
|
854
908
|
} catch (error) {
|
|
855
|
-
|
|
909
|
+
log6.error("Error:", error);
|
|
856
910
|
process.exit(1);
|
|
857
911
|
}
|
|
858
912
|
});
|