@tokens-studio/tokenscript-schemas 0.1.1 → 0.1.3
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 +31 -7
- package/dist/cli/index.cjs +21 -35
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +21 -35
- 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/bundle.test.ts +95 -1
- package/src/cli/commands/bundle.ts +11 -1
- package/src/cli/index.ts +1 -0
- package/src/cli/version-info.ts +16 -18
- 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
|
@@ -39,12 +39,19 @@ npx @tokens-studio/tokenscript-schemas bundle --config schemas.json
|
|
|
39
39
|
# Preview what would be bundled (dry-run)
|
|
40
40
|
npx @tokens-studio/tokenscript-schemas bundle oklch-color rgb-color --dry-run
|
|
41
41
|
|
|
42
|
+
# Bundle from custom schema directory
|
|
43
|
+
npx @tokens-studio/tokenscript-schemas bundle type:my-color -o ./schemas.js --schemas-dir ./my-schemas
|
|
44
|
+
|
|
42
45
|
# List available schemas
|
|
43
46
|
npx @tokens-studio/tokenscript-schemas list
|
|
44
47
|
npx @tokens-studio/tokenscript-schemas list --types
|
|
45
48
|
npx @tokens-studio/tokenscript-schemas list --functions
|
|
46
49
|
```
|
|
47
50
|
|
|
51
|
+
#### Docs
|
|
52
|
+
|
|
53
|
+
- [Custom Schema Directories Documentation](docs/cli/custom-schemas.md) - Bundle schemas from custom directories
|
|
54
|
+
|
|
48
55
|
### Available Presets
|
|
49
56
|
|
|
50
57
|
- **`preset:css`** - Modern CSS color types (CSS Color Level 4+)
|
|
@@ -120,19 +127,36 @@ src/schemas/types/srgb-color/
|
|
|
120
127
|
- Tests use runtime bundling - no build step required
|
|
121
128
|
- The bundler inlines script content for distribution
|
|
122
129
|
|
|
130
|
+
## Working with Custom Schemas
|
|
131
|
+
|
|
132
|
+
You can use the bundler with your own custom schema directories, useful for:
|
|
133
|
+
- Developing experimental schemas without modifying the main repository
|
|
134
|
+
- Working with schemas from external projects
|
|
135
|
+
- Testing new color types before committing them
|
|
136
|
+
|
|
137
|
+
See **[Custom Schema Directories Documentation](docs/cli/custom-schemas.md)** for detailed examples and usage.
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# Bundle from custom directory
|
|
141
|
+
npm run cli -- bundle my-color -o ./output.js --schemas-dir ./path/to/custom/schemas
|
|
142
|
+
|
|
143
|
+
# Build from custom directory
|
|
144
|
+
npm run build-schemas -- --schemas-dir ./path/to/custom/schemas
|
|
145
|
+
```
|
|
146
|
+
|
|
123
147
|
## Scripts
|
|
124
148
|
|
|
125
|
-
###
|
|
149
|
+
### Build Schemas
|
|
126
150
|
|
|
127
151
|
```bash
|
|
128
|
-
npm run
|
|
152
|
+
npm run build-schemas
|
|
129
153
|
```
|
|
130
154
|
|
|
131
|
-
|
|
155
|
+
Builds all schemas using the **shared build logic** from `@/bundler/build-schema.ts`:
|
|
132
156
|
- Reads `schema.json` from each schema directory
|
|
133
157
|
- Finds all `./file.tokenscript` references in the schema
|
|
134
158
|
- Reads and inlines the script file content
|
|
135
|
-
- Outputs
|
|
159
|
+
- Outputs built schemas to `result/` directory:
|
|
136
160
|
- `registry.json` - Complete registry
|
|
137
161
|
- `types.json` - All type schemas
|
|
138
162
|
- `functions.json` - All function schemas
|
|
@@ -163,9 +187,9 @@ npm test -- src/schemas/types/rgb-color/unit.test.ts
|
|
|
163
187
|
- Logs are **disabled by default** to reduce noise (only errors shown)
|
|
164
188
|
- Use `LOG_LEVEL` environment variable to enable logs: `debug`, `info`, `warn`, `error`
|
|
165
189
|
- 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
|
|
190
|
+
- Tests use `buildSchemaFromDirectory()` from `@/bundler/build-schema.ts`
|
|
191
|
+
- No build step required - schemas are built on-demand
|
|
192
|
+
- Same build logic as build-time for consistency
|
|
169
193
|
|
|
170
194
|
## Links
|
|
171
195
|
|
package/dist/cli/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ var ulog = require('ulog');
|
|
|
6
6
|
var promises = require('fs/promises');
|
|
7
7
|
var path = require('path');
|
|
8
8
|
var url = require('url');
|
|
9
|
-
|
|
9
|
+
require('child_process');
|
|
10
10
|
var fs = require('fs');
|
|
11
11
|
|
|
12
12
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -64,7 +64,7 @@ function expandPresetSchemas(schemas) {
|
|
|
64
64
|
}
|
|
65
65
|
return expanded;
|
|
66
66
|
}
|
|
67
|
-
async function
|
|
67
|
+
async function buildSchemaFromDirectory(schemaDir, options) {
|
|
68
68
|
const schemaJsonPath = path.join(schemaDir, "schema.json");
|
|
69
69
|
const schemaContent = await promises.readFile(schemaJsonPath, "utf-8");
|
|
70
70
|
const schema = JSON.parse(schemaContent);
|
|
@@ -290,7 +290,7 @@ async function collectRequiredSchemas(slugOrUri, type, options = {}) {
|
|
|
290
290
|
const categoryDir = effectiveType === "type" ? "types" : "functions";
|
|
291
291
|
const resolvedSchemasDir = schemasDir || process.env.SCHEMAS_DIR || path.join(process.cwd(), "src/schemas");
|
|
292
292
|
const schemaDir = path.join(resolvedSchemasDir, categoryDir, slug);
|
|
293
|
-
spec = await
|
|
293
|
+
spec = await buildSchemaFromDirectory(schemaDir, baseUrl ? { baseUrl } : void 0);
|
|
294
294
|
} catch (error) {
|
|
295
295
|
log.warn(`Failed to load schema ${slug} (${effectiveType}):`, error);
|
|
296
296
|
return;
|
|
@@ -344,7 +344,7 @@ async function collectDependencyTree(schemas, options = {}) {
|
|
|
344
344
|
const resolvedSchemasDir = schemasDir || process.env.SCHEMAS_DIR || path.join(process.cwd(), "src/schemas");
|
|
345
345
|
const schemaDir = path.join(resolvedSchemasDir, categoryDir, schema.slug);
|
|
346
346
|
try {
|
|
347
|
-
const spec = await
|
|
347
|
+
const spec = await buildSchemaFromDirectory(schemaDir, baseUrl ? { baseUrl } : void 0);
|
|
348
348
|
const requirements = extractRequirements(spec, extractOptions);
|
|
349
349
|
const dependencySlugs = requirements.map((uri) => {
|
|
350
350
|
const ref = resolveSchemaReference(uri);
|
|
@@ -418,7 +418,7 @@ async function bundleSelectiveSchemas(options) {
|
|
|
418
418
|
const bundledSchemas = [];
|
|
419
419
|
for (const typeSlug of deps.types) {
|
|
420
420
|
const schemaDir = path.join(schemasDir, "types", typeSlug);
|
|
421
|
-
const bundled = await
|
|
421
|
+
const bundled = await buildSchemaFromDirectory(schemaDir, { baseUrl });
|
|
422
422
|
if (bundled.type === "color") {
|
|
423
423
|
const uri = `${baseUrl}/api/v1/core/${typeSlug}/0/`;
|
|
424
424
|
bundledSchemas.push({
|
|
@@ -429,7 +429,7 @@ async function bundleSelectiveSchemas(options) {
|
|
|
429
429
|
}
|
|
430
430
|
for (const funcSlug of deps.functions) {
|
|
431
431
|
const schemaDir = path.join(schemasDir, "functions", funcSlug);
|
|
432
|
-
const bundled = await
|
|
432
|
+
const bundled = await buildSchemaFromDirectory(schemaDir, { baseUrl });
|
|
433
433
|
if (bundled.type === "function") {
|
|
434
434
|
const uri = `${baseUrl}/api/v1/function/${funcSlug}/0/`;
|
|
435
435
|
bundledSchemas.push({
|
|
@@ -474,26 +474,6 @@ function validateBundleConfig(data) {
|
|
|
474
474
|
}
|
|
475
475
|
var __filename$1 = 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)));
|
|
476
476
|
var __dirname$1 = path.dirname(__filename$1);
|
|
477
|
-
function getGitSha() {
|
|
478
|
-
try {
|
|
479
|
-
return child_process.execSync("git rev-parse --short HEAD", {
|
|
480
|
-
encoding: "utf-8",
|
|
481
|
-
stdio: ["pipe", "pipe", "ignore"]
|
|
482
|
-
}).trim();
|
|
483
|
-
} catch {
|
|
484
|
-
return null;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
function isGitRepo() {
|
|
488
|
-
try {
|
|
489
|
-
child_process.execSync("git rev-parse --git-dir", {
|
|
490
|
-
stdio: ["pipe", "pipe", "ignore"]
|
|
491
|
-
});
|
|
492
|
-
return true;
|
|
493
|
-
} catch {
|
|
494
|
-
return false;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
477
|
function getPackageVersion() {
|
|
498
478
|
try {
|
|
499
479
|
const paths = [
|
|
@@ -516,13 +496,12 @@ function getPackageVersion() {
|
|
|
516
496
|
}
|
|
517
497
|
function getVersionInfo() {
|
|
518
498
|
const githubUrl = "https://github.com/tokens-studio/tokenscript-schemas";
|
|
519
|
-
const
|
|
499
|
+
const packageVersion = getPackageVersion();
|
|
520
500
|
let version;
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
version =
|
|
524
|
-
|
|
525
|
-
version = getPackageVersion();
|
|
501
|
+
let isLocal;
|
|
502
|
+
{
|
|
503
|
+
version = `@tokens-studio/tokenscript-schemas@v${packageVersion}`;
|
|
504
|
+
isLocal = false;
|
|
526
505
|
}
|
|
527
506
|
return {
|
|
528
507
|
version,
|
|
@@ -647,7 +626,7 @@ function findSchemasDir() {
|
|
|
647
626
|
return fromDist;
|
|
648
627
|
}
|
|
649
628
|
async function bundleSchemas(schemas, schemasDir, cliArgs) {
|
|
650
|
-
const resolvedSchemasDir = findSchemasDir();
|
|
629
|
+
const resolvedSchemasDir = schemasDir || findSchemasDir();
|
|
651
630
|
log2.info("Bundling schemas:", schemas);
|
|
652
631
|
log2.debug("Schemas directory:", resolvedSchemasDir);
|
|
653
632
|
const result = await bundleSelectiveSchemas({
|
|
@@ -698,9 +677,16 @@ async function handleBundleCommand(schemas, options = {}) {
|
|
|
698
677
|
if (options.dryRun) {
|
|
699
678
|
cliArgs.push("--dry-run");
|
|
700
679
|
}
|
|
680
|
+
if (options.schemasDir) {
|
|
681
|
+
cliArgs.push("--schemas-dir", options.schemasDir);
|
|
682
|
+
}
|
|
683
|
+
const customSchemasDir = options.schemasDir;
|
|
684
|
+
if (customSchemasDir) {
|
|
685
|
+
log2.info(`Using custom schema directory: ${customSchemasDir}`);
|
|
686
|
+
}
|
|
701
687
|
const { output, metadata, dependencyTree } = await bundleSchemas(
|
|
702
688
|
configSchemas,
|
|
703
|
-
|
|
689
|
+
customSchemasDir,
|
|
704
690
|
cliArgs
|
|
705
691
|
);
|
|
706
692
|
console.log("");
|
|
@@ -853,7 +839,7 @@ async function handlePresetsCommand() {
|
|
|
853
839
|
// src/cli/index.ts
|
|
854
840
|
var log5 = ulog__default.default("cli");
|
|
855
841
|
var cli = cac__default.default("tokenscript-schemas");
|
|
856
|
-
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) => {
|
|
842
|
+
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) => {
|
|
857
843
|
try {
|
|
858
844
|
await handleBundleCommand(schemas, options);
|
|
859
845
|
} catch (error) {
|