@tokens-studio/tokenscript-schemas 0.0.11 → 0.0.12
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/dist/cli/index.cjs +30 -4
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +29 -4
- package/dist/cli/index.js.map +1 -1
- package/package.json +2 -1
- package/src/bundler/bundle-schema.ts +146 -0
- package/src/bundler/index.ts +151 -0
- package/src/bundler/schema-dependency-resolver.ts +299 -0
- package/src/bundler/selective-bundler.test.ts +94 -0
- package/src/bundler/selective-bundler.ts +159 -0
- package/src/bundler/types.ts +93 -0
- package/src/bundler/utils.ts +74 -0
- package/src/cli/commands/bundle.integration.test.ts +153 -0
- package/src/cli/commands/bundle.test.ts +57 -0
- package/src/cli/commands/bundle.ts +240 -0
- package/src/cli/commands/list.ts +109 -0
- package/src/cli/config-schema.ts +36 -0
- package/src/cli/index.ts +50 -0
- package/src/cli/output-generator.ts +63 -0
- package/src/downloader/index.ts +248 -0
- package/src/downloader/types.ts +48 -0
- package/src/index.ts +8 -0
- package/src/schemas/functions/adjust_chroma/adjust-chroma.tokenscript +27 -0
- package/src/schemas/functions/adjust_chroma/schema.json +48 -0
- package/src/schemas/functions/adjust_chroma/unit.test.ts +76 -0
- package/src/schemas/functions/adjust_hue/adjust-hue.tokenscript +32 -0
- package/src/schemas/functions/adjust_hue/schema.json +48 -0
- package/src/schemas/functions/adjust_hue/unit.test.ts +68 -0
- package/src/schemas/functions/adjust_lightness/adjust-lightness.tokenscript +31 -0
- package/src/schemas/functions/adjust_lightness/schema.json +48 -0
- package/src/schemas/functions/adjust_lightness/unit.test.ts +88 -0
- package/src/schemas/functions/adjust_to_contrast/adjust-to-contrast.tokenscript +131 -0
- package/src/schemas/functions/adjust_to_contrast/schema.json +56 -0
- package/src/schemas/functions/adjust_to_contrast/unit.test.ts +81 -0
- package/src/schemas/functions/alpha_blend/alpha-blend.tokenscript +46 -0
- package/src/schemas/functions/alpha_blend/schema.json +28 -0
- package/src/schemas/functions/alpha_blend/unit.test.ts +135 -0
- package/src/schemas/functions/alpha_scale/alpha-scale.tokenscript +38 -0
- package/src/schemas/functions/alpha_scale/schema.json +24 -0
- package/src/schemas/functions/alpha_scale/unit.test.ts +50 -0
- package/src/schemas/functions/analogous/analogous.tokenscript +47 -0
- package/src/schemas/functions/analogous/schema.json +28 -0
- package/src/schemas/functions/analogous/unit.test.ts +64 -0
- package/src/schemas/functions/apca_contrast/apca-contrast.tokenscript +129 -0
- package/src/schemas/functions/apca_contrast/schema.json +24 -0
- package/src/schemas/functions/apca_contrast/unit.test.ts +259 -0
- package/src/schemas/functions/are_similar/are-similar.tokenscript +24 -0
- package/src/schemas/functions/are_similar/schema.json +57 -0
- package/src/schemas/functions/are_similar/unit.test.ts +57 -0
- package/src/schemas/functions/auto_text_color/auto-text-color.tokenscript +41 -0
- package/src/schemas/functions/auto_text_color/schema.json +53 -0
- package/src/schemas/functions/auto_text_color/unit.test.ts +122 -0
- package/src/schemas/functions/best_contrast/best-contrast.tokenscript +66 -0
- package/src/schemas/functions/best_contrast/schema.json +24 -0
- package/src/schemas/functions/best_contrast/unit.test.ts +64 -0
- package/src/schemas/functions/chroma/chroma.tokenscript +12 -0
- package/src/schemas/functions/chroma/schema.json +44 -0
- package/src/schemas/functions/chroma/unit.test.ts +86 -0
- package/src/schemas/functions/clamp_chroma/clamp-chroma.tokenscript +21 -0
- package/src/schemas/functions/clamp_chroma/schema.json +52 -0
- package/src/schemas/functions/clamp_chroma/unit.test.ts +60 -0
- package/src/schemas/functions/clamp_lightness/clamp-lightness.tokenscript +21 -0
- package/src/schemas/functions/clamp_lightness/schema.json +52 -0
- package/src/schemas/functions/clamp_lightness/unit.test.ts +76 -0
- package/src/schemas/functions/clamp_to_gamut/clamp-to-gamut.tokenscript +41 -0
- package/src/schemas/functions/clamp_to_gamut/schema.json +20 -0
- package/src/schemas/functions/clamp_to_gamut/unit.test.ts +167 -0
- package/src/schemas/functions/complement/complement.tokenscript +21 -0
- package/src/schemas/functions/complement/schema.json +20 -0
- package/src/schemas/functions/complement/unit.test.ts +81 -0
- package/src/schemas/functions/contrast_ratio/contrast-ratio.tokenscript +36 -0
- package/src/schemas/functions/contrast_ratio/schema.json +24 -0
- package/src/schemas/functions/contrast_ratio/unit.test.ts +91 -0
- package/src/schemas/functions/cooler/cooler.tokenscript +45 -0
- package/src/schemas/functions/cooler/schema.json +43 -0
- package/src/schemas/functions/cooler/unit.test.ts +69 -0
- package/src/schemas/functions/darken/darken.tokenscript +37 -0
- package/src/schemas/functions/darken/schema.json +24 -0
- package/src/schemas/functions/darken/unit.test.ts +105 -0
- package/src/schemas/functions/delta_e_2000/delta-e-2000.tokenscript +184 -0
- package/src/schemas/functions/delta_e_2000/schema.json +36 -0
- package/src/schemas/functions/delta_e_2000/unit.test.ts +243 -0
- package/src/schemas/functions/delta_e_76/delta-e-76.tokenscript +45 -0
- package/src/schemas/functions/delta_e_76/schema.json +24 -0
- package/src/schemas/functions/delta_e_76/unit.test.ts +123 -0
- package/src/schemas/functions/delta_e_ok/delta-e-ok.tokenscript +43 -0
- package/src/schemas/functions/delta_e_ok/schema.json +24 -0
- package/src/schemas/functions/delta_e_ok/unit.test.ts +235 -0
- package/src/schemas/functions/desaturate/desaturate.tokenscript +32 -0
- package/src/schemas/functions/desaturate/schema.json +24 -0
- package/src/schemas/functions/desaturate/unit.test.ts +54 -0
- package/src/schemas/functions/distributed/distributed.tokenscript +54 -0
- package/src/schemas/functions/distributed/schema.json +32 -0
- package/src/schemas/functions/distributed/unit.test.ts +58 -0
- package/src/schemas/functions/diverging/diverging.tokenscript +58 -0
- package/src/schemas/functions/diverging/schema.json +32 -0
- package/src/schemas/functions/diverging/unit.test.ts +70 -0
- package/src/schemas/functions/grayscale/grayscale.tokenscript +17 -0
- package/src/schemas/functions/grayscale/schema.json +20 -0
- package/src/schemas/functions/grayscale/unit.test.ts +79 -0
- package/src/schemas/functions/harmonize/harmonize.tokenscript +61 -0
- package/src/schemas/functions/harmonize/schema.json +52 -0
- package/src/schemas/functions/harmonize/unit.test.ts +56 -0
- package/src/schemas/functions/hue/hue.tokenscript +12 -0
- package/src/schemas/functions/hue/schema.json +44 -0
- package/src/schemas/functions/hue/unit.test.ts +75 -0
- package/src/schemas/functions/hue_difference/hue-difference.tokenscript +42 -0
- package/src/schemas/functions/hue_difference/schema.json +24 -0
- package/src/schemas/functions/hue_difference/unit.test.ts +125 -0
- package/src/schemas/functions/in_gamut/in-gamut.tokenscript +51 -0
- package/src/schemas/functions/in_gamut/schema.json +24 -0
- package/src/schemas/functions/in_gamut/unit.test.ts +178 -0
- package/src/schemas/functions/interpolate/interpolate.tokenscript +61 -0
- package/src/schemas/functions/interpolate/schema.json +52 -0
- package/src/schemas/functions/interpolate/unit.test.ts +96 -0
- package/src/schemas/functions/invert/invert-initializer.tokenscript +29 -0
- package/src/schemas/functions/invert/schema.json +20 -0
- package/src/schemas/functions/invert/unit.test.ts +216 -0
- package/src/schemas/functions/is_cool/is-cool.tokenscript +41 -0
- package/src/schemas/functions/is_cool/schema.json +20 -0
- package/src/schemas/functions/is_cool/unit.test.ts +189 -0
- package/src/schemas/functions/is_dark/is-dark.tokenscript +16 -0
- package/src/schemas/functions/is_dark/schema.json +24 -0
- package/src/schemas/functions/is_dark/unit.test.ts +87 -0
- package/src/schemas/functions/is_light/is-light.tokenscript +16 -0
- package/src/schemas/functions/is_light/schema.json +24 -0
- package/src/schemas/functions/is_light/unit.test.ts +86 -0
- package/src/schemas/functions/is_neutral/is-neutral.tokenscript +16 -0
- package/src/schemas/functions/is_neutral/schema.json +53 -0
- package/src/schemas/functions/is_neutral/unit.test.ts +85 -0
- package/src/schemas/functions/is_warm/is-warm.tokenscript +62 -0
- package/src/schemas/functions/is_warm/schema.json +20 -0
- package/src/schemas/functions/is_warm/unit.test.ts +161 -0
- package/src/schemas/functions/lighten/lighten.tokenscript +37 -0
- package/src/schemas/functions/lighten/schema.json +24 -0
- package/src/schemas/functions/lighten/unit.test.ts +109 -0
- package/src/schemas/functions/lightness/lightness.tokenscript +12 -0
- package/src/schemas/functions/lightness/schema.json +49 -0
- package/src/schemas/functions/lightness/unit.test.ts +99 -0
- package/src/schemas/functions/luminance/luminance.tokenscript +16 -0
- package/src/schemas/functions/luminance/schema.json +20 -0
- package/src/schemas/functions/luminance/unit.test.ts +105 -0
- package/src/schemas/functions/meets_contrast/meets-contrast.tokenscript +49 -0
- package/src/schemas/functions/meets_contrast/schema.json +28 -0
- package/src/schemas/functions/meets_contrast/unit.test.ts +170 -0
- package/src/schemas/functions/mix/mix.tokenscript +47 -0
- package/src/schemas/functions/mix/schema.json +28 -0
- package/src/schemas/functions/mix/unit.test.ts +95 -0
- package/src/schemas/functions/monochromatic/monochromatic.tokenscript +72 -0
- package/src/schemas/functions/monochromatic/schema.json +24 -0
- package/src/schemas/functions/monochromatic/unit.test.ts +91 -0
- package/src/schemas/functions/muted/muted.tokenscript +25 -0
- package/src/schemas/functions/muted/schema.json +48 -0
- package/src/schemas/functions/muted/unit.test.ts +100 -0
- package/src/schemas/functions/neutral_variant/neutral-variant.tokenscript +23 -0
- package/src/schemas/functions/neutral_variant/schema.json +48 -0
- package/src/schemas/functions/neutral_variant/unit.test.ts +102 -0
- package/src/schemas/functions/relative_luminance/relative-luminance.tokenscript +15 -0
- package/src/schemas/functions/relative_luminance/schema.json +49 -0
- package/src/schemas/functions/relative_luminance/unit.test.ts +104 -0
- package/src/schemas/functions/rotate_hue/rotate-hue.tokenscript +20 -0
- package/src/schemas/functions/rotate_hue/schema.json +24 -0
- package/src/schemas/functions/rotate_hue/unit.test.ts +86 -0
- package/src/schemas/functions/saturate/saturate.tokenscript +33 -0
- package/src/schemas/functions/saturate/schema.json +24 -0
- package/src/schemas/functions/saturate/unit.test.ts +59 -0
- package/src/schemas/functions/scale_chroma/scale-chroma.tokenscript +22 -0
- package/src/schemas/functions/scale_chroma/schema.json +48 -0
- package/src/schemas/functions/scale_chroma/unit.test.ts +79 -0
- package/src/schemas/functions/scale_lightness/scale-lightness.tokenscript +23 -0
- package/src/schemas/functions/scale_lightness/schema.json +48 -0
- package/src/schemas/functions/scale_lightness/unit.test.ts +73 -0
- package/src/schemas/functions/sepia/schema.json +48 -0
- package/src/schemas/functions/sepia/sepia.tokenscript +54 -0
- package/src/schemas/functions/sepia/unit.test.ts +88 -0
- package/src/schemas/functions/set_chroma/schema.json +24 -0
- package/src/schemas/functions/set_chroma/set-chroma.tokenscript +18 -0
- package/src/schemas/functions/set_chroma/unit.test.ts +79 -0
- package/src/schemas/functions/set_hue/schema.json +24 -0
- package/src/schemas/functions/set_hue/set-hue.tokenscript +18 -0
- package/src/schemas/functions/set_hue/unit.test.ts +90 -0
- package/src/schemas/functions/set_lightness/schema.json +24 -0
- package/src/schemas/functions/set_lightness/set-lightness.tokenscript +18 -0
- package/src/schemas/functions/set_lightness/unit.test.ts +80 -0
- package/src/schemas/functions/shade_scale/schema.json +24 -0
- package/src/schemas/functions/shade_scale/shade-scale.tokenscript +61 -0
- package/src/schemas/functions/shade_scale/unit.test.ts +64 -0
- package/src/schemas/functions/split_complement/schema.json +24 -0
- package/src/schemas/functions/split_complement/split-complement.tokenscript +38 -0
- package/src/schemas/functions/split_complement/unit.test.ts +53 -0
- package/src/schemas/functions/steps/schema.json +28 -0
- package/src/schemas/functions/steps/steps.tokenscript +54 -0
- package/src/schemas/functions/steps/unit.test.ts +71 -0
- package/src/schemas/functions/tetradic/schema.json +20 -0
- package/src/schemas/functions/tetradic/tetradic.tokenscript +40 -0
- package/src/schemas/functions/tetradic/unit.test.ts +50 -0
- package/src/schemas/functions/tint_scale/schema.json +32 -0
- package/src/schemas/functions/tint_scale/tint-scale.tokenscript +71 -0
- package/src/schemas/functions/tint_scale/unit.test.ts +64 -0
- package/src/schemas/functions/to_gamut/schema.json +48 -0
- package/src/schemas/functions/to_gamut/to-gamut.tokenscript +96 -0
- package/src/schemas/functions/to_gamut/unit.test.ts +97 -0
- package/src/schemas/functions/triadic/schema.json +20 -0
- package/src/schemas/functions/triadic/triadic.tokenscript +33 -0
- package/src/schemas/functions/triadic/unit.test.ts +64 -0
- package/src/schemas/functions/vibrant/schema.json +48 -0
- package/src/schemas/functions/vibrant/unit.test.ts +55 -0
- package/src/schemas/functions/vibrant/vibrant.tokenscript +29 -0
- package/src/schemas/functions/warmer/schema.json +43 -0
- package/src/schemas/functions/warmer/unit.test.ts +69 -0
- package/src/schemas/functions/warmer/warmer.tokenscript +45 -0
- package/src/schemas/functions/wcag_level/schema.json +48 -0
- package/src/schemas/functions/wcag_level/unit.test.ts +75 -0
- package/src/schemas/functions/wcag_level/wcag-level.tokenscript +50 -0
- package/src/schemas/types/css-color/from-hsl-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-hwb-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-lab-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-lch-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-oklab-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-oklch-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-p3-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-rgb-color.tokenscript +15 -0
- package/src/schemas/types/css-color/from-srgb-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-srgb-linear-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-xyz-d50-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-xyz-d65-color.tokenscript +16 -0
- package/src/schemas/types/css-color/initializer.tokenscript +13 -0
- package/src/schemas/types/css-color/schema.json +148 -0
- package/src/schemas/types/css-color/unit.test.ts +402 -0
- package/src/schemas/types/hex-color/initializer.tokenscript +3 -0
- package/src/schemas/types/hex-color/schema.json +24 -0
- package/src/schemas/types/hex-color/unit.test.ts +123 -0
- package/src/schemas/types/hsl-color/from-srgb.tokenscript +87 -0
- package/src/schemas/types/hsl-color/initializer.tokenscript +16 -0
- package/src/schemas/types/hsl-color/schema.json +48 -0
- package/src/schemas/types/hsl-color/unit.test.ts +201 -0
- package/src/schemas/types/hsv-color/from-srgb.tokenscript +80 -0
- package/src/schemas/types/hsv-color/initializer.tokenscript +16 -0
- package/src/schemas/types/hsv-color/schema.json +48 -0
- package/src/schemas/types/hsv-color/unit.test.ts +162 -0
- package/src/schemas/types/hwb-color/from-hsv.tokenscript +31 -0
- package/src/schemas/types/hwb-color/initializer.tokenscript +16 -0
- package/src/schemas/types/hwb-color/schema.json +48 -0
- package/src/schemas/types/hwb-color/unit.test.ts +150 -0
- package/src/schemas/types/lab-color/from-xyz-d50.tokenscript +78 -0
- package/src/schemas/types/lab-color/initializer.tokenscript +16 -0
- package/src/schemas/types/lab-color/schema.json +48 -0
- package/src/schemas/types/lab-color/unit.test.ts +263 -0
- package/src/schemas/types/lch-color/from-lab.tokenscript +44 -0
- package/src/schemas/types/lch-color/initializer.tokenscript +16 -0
- package/src/schemas/types/lch-color/schema.json +48 -0
- package/src/schemas/types/lch-color/unit.test.ts +173 -0
- package/src/schemas/types/okhsl-color/from-oklab.tokenscript +410 -0
- package/src/schemas/types/okhsl-color/initializer.tokenscript +24 -0
- package/src/schemas/types/okhsl-color/schema.json +48 -0
- package/src/schemas/types/okhsl-color/unit.test.ts +514 -0
- package/src/schemas/types/okhsv-color/from-oklab.tokenscript +286 -0
- package/src/schemas/types/okhsv-color/initializer.tokenscript +24 -0
- package/src/schemas/types/okhsv-color/schema.json +48 -0
- package/src/schemas/types/okhsv-color/unit.test.ts +499 -0
- package/src/schemas/types/oklab-color/from-okhsl.tokenscript +195 -0
- package/src/schemas/types/oklab-color/from-okhsv.tokenscript +197 -0
- package/src/schemas/types/oklab-color/from-oklch.tokenscript +39 -0
- package/src/schemas/types/oklab-color/from-xyz-d65.tokenscript +43 -0
- package/src/schemas/types/oklab-color/initializer.tokenscript +16 -0
- package/src/schemas/types/oklab-color/schema.json +78 -0
- package/src/schemas/types/oklab-color/unit.test.ts +345 -0
- package/src/schemas/types/oklch-color/from-oklab.tokenscript +45 -0
- package/src/schemas/types/oklch-color/initializer.tokenscript +16 -0
- package/src/schemas/types/oklch-color/schema.json +48 -0
- package/src/schemas/types/oklch-color/unit.test.ts +267 -0
- package/src/schemas/types/p3-color/from-p3-linear.tokenscript +59 -0
- package/src/schemas/types/p3-color/initializer.tokenscript +16 -0
- package/src/schemas/types/p3-color/schema.json +48 -0
- package/src/schemas/types/p3-color/unit.test.ts +119 -0
- package/src/schemas/types/p3-linear-color/from-xyz-d65.tokenscript +47 -0
- package/src/schemas/types/p3-linear-color/initializer.tokenscript +16 -0
- package/src/schemas/types/p3-linear-color/schema.json +48 -0
- package/src/schemas/types/p3-linear-color/unit.test.ts +82 -0
- package/src/schemas/types/rgb-color/from-hex.tokenscript +43 -0
- package/src/schemas/types/rgb-color/initializer.tokenscript +16 -0
- package/src/schemas/types/rgb-color/schema.json +55 -0
- package/src/schemas/types/rgb-color/to-hex.tokenscript +42 -0
- package/src/schemas/types/rgb-color/unit.test.ts +302 -0
- package/src/schemas/types/srgb-color/from-hsl.tokenscript +106 -0
- package/src/schemas/types/srgb-color/from-linear.tokenscript +58 -0
- package/src/schemas/types/srgb-color/from-rgb.tokenscript +20 -0
- package/src/schemas/types/srgb-color/initializer.tokenscript +16 -0
- package/src/schemas/types/srgb-color/schema.json +68 -0
- package/src/schemas/types/srgb-color/unit.test.ts +303 -0
- package/src/schemas/types/srgb-linear-color/from-srgb.tokenscript +55 -0
- package/src/schemas/types/srgb-linear-color/from-xyz-d65.tokenscript +34 -0
- package/src/schemas/types/srgb-linear-color/initializer.tokenscript +13 -0
- package/src/schemas/types/srgb-linear-color/schema.json +58 -0
- package/src/schemas/types/srgb-linear-color/unit.test.ts +291 -0
- package/src/schemas/types/xyz-d50-color/from-xyz-d65.tokenscript +36 -0
- package/src/schemas/types/xyz-d50-color/initializer.tokenscript +16 -0
- package/src/schemas/types/xyz-d50-color/schema.json +48 -0
- package/src/schemas/types/xyz-d50-color/unit.test.ts +240 -0
- package/src/schemas/types/xyz-d65-color/from-linear-p3.tokenscript +47 -0
- package/src/schemas/types/xyz-d65-color/from-linear-srgb.tokenscript +38 -0
- package/src/schemas/types/xyz-d65-color/from-oklab.tokenscript +44 -0
- package/src/schemas/types/xyz-d65-color/initializer.tokenscript +16 -0
- package/src/schemas/types/xyz-d65-color/schema.json +68 -0
- package/src/schemas/types/xyz-d65-color/unit.test.ts +319 -0
- package/src/utils/schema-uri.ts +192 -0
- package/src/utils/type.ts +194 -0
- package/dist/cli/index.d.cts +0 -1
- package/dist/cli/index.d.ts +0 -1
- package/dist/index.d.cts +0 -158
- package/dist/index.d.ts +0 -158
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for schema bundler
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface SchemaFile {
|
|
6
|
+
path: string;
|
|
7
|
+
content: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SchemaBundle {
|
|
11
|
+
slug: string;
|
|
12
|
+
name: string;
|
|
13
|
+
type: "type" | "function";
|
|
14
|
+
version: string;
|
|
15
|
+
schema?: unknown;
|
|
16
|
+
scripts: Record<string, string>;
|
|
17
|
+
metadata: {
|
|
18
|
+
id: string;
|
|
19
|
+
description: string;
|
|
20
|
+
contentType: string | null;
|
|
21
|
+
originalVersion: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Color specification types matching typescript-interpreter format
|
|
26
|
+
export interface ScriptBlock {
|
|
27
|
+
type: string;
|
|
28
|
+
script: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface Initializer {
|
|
32
|
+
title?: string;
|
|
33
|
+
keyword: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
schema?: unknown;
|
|
36
|
+
script: ScriptBlock;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface Conversion {
|
|
40
|
+
source: string;
|
|
41
|
+
target: string;
|
|
42
|
+
description?: string;
|
|
43
|
+
lossless: boolean;
|
|
44
|
+
script: ScriptBlock;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface SpecProperty {
|
|
48
|
+
type: "number" | "string" | "color";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface SpecSchema {
|
|
52
|
+
type: "object";
|
|
53
|
+
properties: Record<string, SpecProperty>;
|
|
54
|
+
required?: string[];
|
|
55
|
+
order?: string[];
|
|
56
|
+
additionalProperties?: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ColorSpecification {
|
|
60
|
+
name: string;
|
|
61
|
+
type: "color";
|
|
62
|
+
description?: string;
|
|
63
|
+
schema?: SpecSchema;
|
|
64
|
+
initializers: Initializer[];
|
|
65
|
+
conversions: Conversion[];
|
|
66
|
+
slug?: string; // Added for bundling purposes
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface FunctionSpecification {
|
|
70
|
+
name: string;
|
|
71
|
+
type: "function";
|
|
72
|
+
input?: {
|
|
73
|
+
type: "object";
|
|
74
|
+
properties?: Record<string, unknown>;
|
|
75
|
+
};
|
|
76
|
+
script: ScriptBlock;
|
|
77
|
+
keyword: string;
|
|
78
|
+
description?: string;
|
|
79
|
+
requirements?: string[];
|
|
80
|
+
slug?: string; // Added for bundling purposes
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type SchemaSpecification = ColorSpecification | FunctionSpecification;
|
|
84
|
+
|
|
85
|
+
export interface BundledRegistry {
|
|
86
|
+
version: string;
|
|
87
|
+
types: ColorSpecification[];
|
|
88
|
+
functions: FunctionSpecification[];
|
|
89
|
+
metadata: {
|
|
90
|
+
generatedAt: string;
|
|
91
|
+
totalSchemas: number;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundler utilities
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { readdir, readFile, stat } from "node:fs/promises";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Check if a path is a directory
|
|
10
|
+
*/
|
|
11
|
+
export async function isDirectory(path: string): Promise<boolean> {
|
|
12
|
+
try {
|
|
13
|
+
const stats = await stat(path);
|
|
14
|
+
return stats.isDirectory();
|
|
15
|
+
} catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get all subdirectories in a directory
|
|
22
|
+
*/
|
|
23
|
+
export async function getSubdirectories(dir: string): Promise<string[]> {
|
|
24
|
+
const entries = await readdir(dir);
|
|
25
|
+
const subdirs: string[] = [];
|
|
26
|
+
|
|
27
|
+
for (const entry of entries) {
|
|
28
|
+
const fullPath = join(dir, entry);
|
|
29
|
+
if (await isDirectory(fullPath)) {
|
|
30
|
+
subdirs.push(entry);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return subdirs;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Read all tokenscript files from a schema directory
|
|
39
|
+
*/
|
|
40
|
+
export async function readTokenScriptFiles(schemaDir: string): Promise<Record<string, string>> {
|
|
41
|
+
const entries = await readdir(schemaDir);
|
|
42
|
+
const scripts: Record<string, string> = {};
|
|
43
|
+
|
|
44
|
+
for (const entry of entries) {
|
|
45
|
+
if (entry.endsWith(".tokenscript")) {
|
|
46
|
+
const filePath = join(schemaDir, entry);
|
|
47
|
+
const content = await readFile(filePath, "utf-8");
|
|
48
|
+
const scriptName = entry.replace(".tokenscript", "");
|
|
49
|
+
scripts[scriptName] = content;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return scripts;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Read and parse a JSON file
|
|
58
|
+
*/
|
|
59
|
+
export async function readJsonFile<T = unknown>(filePath: string): Promise<T> {
|
|
60
|
+
const content = await readFile(filePath, "utf-8");
|
|
61
|
+
return JSON.parse(content) as T;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Check if a file exists
|
|
66
|
+
*/
|
|
67
|
+
export async function fileExists(filePath: string): Promise<boolean> {
|
|
68
|
+
try {
|
|
69
|
+
await stat(filePath);
|
|
70
|
+
return true;
|
|
71
|
+
} catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { unlink, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { afterAll, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { bundleSchemas } from "./bundle.js";
|
|
6
|
+
|
|
7
|
+
// Mock ulog to silence logs during tests
|
|
8
|
+
vi.mock("ulog", () => {
|
|
9
|
+
const mockLogger = () => {};
|
|
10
|
+
mockLogger.error = () => {};
|
|
11
|
+
mockLogger.warn = () => {};
|
|
12
|
+
mockLogger.info = () => {};
|
|
13
|
+
mockLogger.log = () => {};
|
|
14
|
+
mockLogger.debug = () => {};
|
|
15
|
+
mockLogger.trace = () => {};
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
default: () => mockLogger,
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("Bundle Integration Test", () => {
|
|
23
|
+
const testFiles: string[] = [];
|
|
24
|
+
|
|
25
|
+
const createTestFile = async (name: string, content: string) => {
|
|
26
|
+
const path = join(process.cwd(), `test-bundle-${name}-${Date.now()}.js`);
|
|
27
|
+
testFiles.push(path);
|
|
28
|
+
await writeFile(path, content, "utf-8");
|
|
29
|
+
return path;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
afterAll(async () => {
|
|
33
|
+
// Clean up all test files
|
|
34
|
+
await Promise.all(
|
|
35
|
+
testFiles.map(async (file) => {
|
|
36
|
+
try {
|
|
37
|
+
await unlink(file);
|
|
38
|
+
} catch {
|
|
39
|
+
// Ignore if file doesn't exist
|
|
40
|
+
}
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should create a valid bundle file that can be loaded and used", async () => {
|
|
46
|
+
// Step 1: Bundle schemas
|
|
47
|
+
const result = await bundleSchemas(["rgb-color", "function:invert"]);
|
|
48
|
+
|
|
49
|
+
expect(result.output).toBeTruthy();
|
|
50
|
+
expect(result.metadata.resolvedDependencies).toContain("rgb-color");
|
|
51
|
+
expect(result.metadata.resolvedDependencies).toContain("invert");
|
|
52
|
+
|
|
53
|
+
// Step 2: Write and import the bundle
|
|
54
|
+
const testFile = await createTestFile("basic", result.output);
|
|
55
|
+
const fileUrl = `${pathToFileURL(testFile).href}?t=${Date.now()}`;
|
|
56
|
+
const bundle = await import(fileUrl);
|
|
57
|
+
|
|
58
|
+
// Step 3: Verify exports exist
|
|
59
|
+
expect(bundle.SCHEMAS).toBeDefined();
|
|
60
|
+
expect(Array.isArray(bundle.SCHEMAS)).toBe(true);
|
|
61
|
+
expect(bundle.makeConfig).toBeDefined();
|
|
62
|
+
expect(typeof bundle.makeConfig).toBe("function");
|
|
63
|
+
|
|
64
|
+
// Step 4: Verify SCHEMAS structure
|
|
65
|
+
expect(bundle.SCHEMAS.length).toBeGreaterThan(0);
|
|
66
|
+
|
|
67
|
+
const firstSchema = bundle.SCHEMAS[0];
|
|
68
|
+
expect(firstSchema.uri).toBeDefined();
|
|
69
|
+
expect(firstSchema.schema).toBeDefined();
|
|
70
|
+
expect(typeof firstSchema.uri).toBe("string");
|
|
71
|
+
expect(typeof firstSchema.schema).toBe("object");
|
|
72
|
+
|
|
73
|
+
// Step 5: Create config using the helper
|
|
74
|
+
const config = bundle.makeConfig();
|
|
75
|
+
expect(config).toBeDefined();
|
|
76
|
+
|
|
77
|
+
// Step 6: Verify config has the schemas registered
|
|
78
|
+
// The config should be an instance of Config from @tokens-studio/tokenscript-interpreter
|
|
79
|
+
expect(config.constructor.name).toBe("Config");
|
|
80
|
+
|
|
81
|
+
// Step 7: Verify we can find our schemas in the config
|
|
82
|
+
const rgbColorUri = bundle.SCHEMAS.find((s: any) => s.uri.includes("rgb-color"))?.uri;
|
|
83
|
+
const invertUri = bundle.SCHEMAS.find((s: any) => s.uri.includes("/function/invert/"))?.uri;
|
|
84
|
+
|
|
85
|
+
expect(rgbColorUri).toBeDefined();
|
|
86
|
+
expect(invertUri).toBeDefined();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("should bundle function with dependencies and create working config", async () => {
|
|
90
|
+
// Bundle a function that has dependencies
|
|
91
|
+
const result = await bundleSchemas(["function:adjust_chroma"]);
|
|
92
|
+
|
|
93
|
+
expect(result.metadata.resolvedDependencies).toContain("adjust_chroma");
|
|
94
|
+
expect(result.metadata.resolvedDependencies).toContain("srgb-color");
|
|
95
|
+
expect(result.metadata.resolvedDependencies).toContain("oklch-color");
|
|
96
|
+
|
|
97
|
+
// Write and import the bundle
|
|
98
|
+
const testFile = await createTestFile("function-deps", result.output);
|
|
99
|
+
const fileUrl = `${pathToFileURL(testFile).href}?t=${Date.now()}`;
|
|
100
|
+
const bundle = await import(fileUrl);
|
|
101
|
+
|
|
102
|
+
// Verify key dependencies are in the bundle
|
|
103
|
+
// With includeColorTypeDependencies, this pulls in all conversion dependencies
|
|
104
|
+
expect(bundle.SCHEMAS.length).toBeGreaterThanOrEqual(3);
|
|
105
|
+
|
|
106
|
+
const schemaUris = bundle.SCHEMAS.map((s: any) => s.uri);
|
|
107
|
+
expect(schemaUris.some((uri: string) => uri.includes("adjust_chroma"))).toBe(true);
|
|
108
|
+
expect(schemaUris.some((uri: string) => uri.includes("srgb-color"))).toBe(true);
|
|
109
|
+
expect(schemaUris.some((uri: string) => uri.includes("oklch-color"))).toBe(true);
|
|
110
|
+
|
|
111
|
+
// Create config and verify it works
|
|
112
|
+
const config = bundle.makeConfig();
|
|
113
|
+
expect(config).toBeDefined();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("should handle multiple requested schemas correctly", async () => {
|
|
117
|
+
const result = await bundleSchemas(["rgb-color", "hex-color", "hsl-color"]);
|
|
118
|
+
|
|
119
|
+
// Write and import the bundle
|
|
120
|
+
const testFile = await createTestFile("multiple", result.output);
|
|
121
|
+
const fileUrl = `${pathToFileURL(testFile).href}?t=${Date.now()}`;
|
|
122
|
+
const bundle = await import(fileUrl);
|
|
123
|
+
|
|
124
|
+
// Should have the requested schemas plus their conversion dependencies
|
|
125
|
+
// With includeColorTypeDependencies, this pulls in all conversion dependencies
|
|
126
|
+
expect(bundle.SCHEMAS.length).toBeGreaterThanOrEqual(3);
|
|
127
|
+
|
|
128
|
+
const schemaUris = bundle.SCHEMAS.map((s: any) => s.uri);
|
|
129
|
+
expect(schemaUris.some((uri: string) => uri.includes("rgb-color"))).toBe(true);
|
|
130
|
+
expect(schemaUris.some((uri: string) => uri.includes("hex-color"))).toBe(true);
|
|
131
|
+
expect(schemaUris.some((uri: string) => uri.includes("hsl-color"))).toBe(true);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("should generate valid JavaScript with proper imports", async () => {
|
|
135
|
+
const result = await bundleSchemas(["rgb-color"]);
|
|
136
|
+
|
|
137
|
+
// Verify the output has the expected structure
|
|
138
|
+
expect(result.output).toContain(
|
|
139
|
+
'import { Config } from "@tokens-studio/tokenscript-interpreter"',
|
|
140
|
+
);
|
|
141
|
+
expect(result.output).toContain("export const SCHEMAS = [");
|
|
142
|
+
expect(result.output).toContain("export function makeConfig()");
|
|
143
|
+
expect(result.output).toContain("return new Config().registerSchemas(SCHEMAS)");
|
|
144
|
+
expect(result.output).toContain("Auto-generated by @tokens-studio/tokenscript-schemas");
|
|
145
|
+
|
|
146
|
+
// Write and verify it's valid JavaScript by importing it
|
|
147
|
+
const testFile = await createTestFile("valid-js", result.output);
|
|
148
|
+
const fileUrl = `${pathToFileURL(testFile).href}?t=${Date.now()}`;
|
|
149
|
+
|
|
150
|
+
// This will throw if the JavaScript is invalid
|
|
151
|
+
await expect(import(fileUrl)).resolves.toBeDefined();
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { bundleSchemas } from "./bundle.js";
|
|
3
|
+
|
|
4
|
+
// Mock ulog to silence logs during tests
|
|
5
|
+
vi.mock("ulog", () => {
|
|
6
|
+
const mockLogger = () => {};
|
|
7
|
+
mockLogger.error = () => {};
|
|
8
|
+
mockLogger.warn = () => {};
|
|
9
|
+
mockLogger.info = () => {};
|
|
10
|
+
mockLogger.log = () => {};
|
|
11
|
+
mockLogger.debug = () => {};
|
|
12
|
+
mockLogger.trace = () => {};
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
default: () => mockLogger,
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe("Bundle Command", () => {
|
|
20
|
+
it("should bundle schemas and return output", async () => {
|
|
21
|
+
const result = await bundleSchemas(["hex-color"]);
|
|
22
|
+
|
|
23
|
+
expect(result.output).toContain("export const SCHEMAS");
|
|
24
|
+
expect(result.output).toContain("export function makeConfig()");
|
|
25
|
+
expect(result.output).toContain("hex-color");
|
|
26
|
+
expect(result.metadata.requestedSchemas).toEqual(["hex-color"]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should bundle multiple schemas with dependencies", async () => {
|
|
30
|
+
const result = await bundleSchemas(["function:adjust_chroma"]);
|
|
31
|
+
|
|
32
|
+
expect(result.output).toContain("SCHEMAS");
|
|
33
|
+
expect(result.metadata.requestedSchemas).toEqual(["function:adjust_chroma"]);
|
|
34
|
+
|
|
35
|
+
// adjust_chroma requires srgb-color and oklch-color
|
|
36
|
+
// With includeColorTypeDependencies, this pulls in all conversion dependencies
|
|
37
|
+
expect(result.metadata.resolvedDependencies.length).toBeGreaterThanOrEqual(3);
|
|
38
|
+
expect(result.metadata.resolvedDependencies).toContain("adjust_chroma");
|
|
39
|
+
expect(result.metadata.resolvedDependencies).toContain("srgb-color");
|
|
40
|
+
expect(result.metadata.resolvedDependencies).toContain("oklch-color");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should bundle function schemas", async () => {
|
|
44
|
+
const result = await bundleSchemas(["function:invert"]);
|
|
45
|
+
|
|
46
|
+
expect(result.output).toContain("SCHEMAS");
|
|
47
|
+
expect(result.output).toContain("/function/invert/");
|
|
48
|
+
expect(result.metadata.requestedSchemas).toEqual(["function:invert"]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should include auto-generated header comment", async () => {
|
|
52
|
+
const result = await bundleSchemas(["hex-color"]);
|
|
53
|
+
|
|
54
|
+
expect(result.output).toContain("Auto-generated by @tokens-studio/tokenscript-schemas");
|
|
55
|
+
expect(result.output).toContain("Generated:");
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundle command - Bundle schemas into a JS file
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/// <reference types="../../../types/ulog" />
|
|
6
|
+
|
|
7
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import anylogger from "ulog";
|
|
11
|
+
import { bundleSelectiveSchemas } from "@/bundler/selective-bundler.js";
|
|
12
|
+
import { type BundleConfig, validateBundleConfig } from "@/cli/config-schema.js";
|
|
13
|
+
import { generateOutput } from "@/cli/output-generator.js";
|
|
14
|
+
import { isSome } from "@/utils/type.js";
|
|
15
|
+
|
|
16
|
+
const log = anylogger("bundle");
|
|
17
|
+
|
|
18
|
+
export interface BundleOptions {
|
|
19
|
+
config?: string;
|
|
20
|
+
output?: string;
|
|
21
|
+
dryRun?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Load config from file
|
|
26
|
+
*/
|
|
27
|
+
async function loadConfig(configPath: string): Promise<BundleConfig> {
|
|
28
|
+
try {
|
|
29
|
+
const content = await readFile(configPath, "utf-8");
|
|
30
|
+
const parsed = JSON.parse(content);
|
|
31
|
+
return validateBundleConfig(parsed);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
34
|
+
throw new Error(`Config file not found: ${configPath}`);
|
|
35
|
+
}
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Format dependency tree for display
|
|
42
|
+
*/
|
|
43
|
+
function formatDependencyTree(
|
|
44
|
+
tree: Map<string, import("@/bundler/schema-dependency-resolver.js").DependencyNode>,
|
|
45
|
+
requestedSchemas: string[],
|
|
46
|
+
): string {
|
|
47
|
+
const lines: string[] = [];
|
|
48
|
+
const visited = new Set<string>();
|
|
49
|
+
|
|
50
|
+
lines.push("Dependency tree:");
|
|
51
|
+
lines.push("");
|
|
52
|
+
|
|
53
|
+
// Helper to format a node
|
|
54
|
+
const formatNode = (key: string, indent: string = "", isLast: boolean = true) => {
|
|
55
|
+
if (visited.has(key)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
visited.add(key);
|
|
59
|
+
|
|
60
|
+
const node = tree.get(key);
|
|
61
|
+
if (!node) return;
|
|
62
|
+
|
|
63
|
+
const prefix = indent + (isLast ? "└── " : "├── ");
|
|
64
|
+
const label = `${node.type}:${node.slug}`;
|
|
65
|
+
lines.push(prefix + label);
|
|
66
|
+
|
|
67
|
+
if (node.dependencies.length > 0) {
|
|
68
|
+
const childIndent = indent + (isLast ? " " : "│ ");
|
|
69
|
+
node.dependencies.forEach((dep, idx) => {
|
|
70
|
+
const isLastChild = idx === node.dependencies.length - 1;
|
|
71
|
+
const childKey = dep;
|
|
72
|
+
|
|
73
|
+
if (visited.has(childKey)) {
|
|
74
|
+
const childPrefix = childIndent + (isLastChild ? "└── " : "├── ");
|
|
75
|
+
lines.push(`${childPrefix + childKey} (already visited)`);
|
|
76
|
+
} else {
|
|
77
|
+
formatNode(childKey, childIndent, isLastChild);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// Format requested schemas
|
|
84
|
+
requestedSchemas.forEach((schema, idx) => {
|
|
85
|
+
// Try to find the schema with different type prefixes
|
|
86
|
+
const typeKey = `type:${schema}`;
|
|
87
|
+
const funcKey = `function:${schema}`;
|
|
88
|
+
const key = tree.has(typeKey) ? typeKey : tree.has(funcKey) ? funcKey : schema;
|
|
89
|
+
|
|
90
|
+
formatNode(key, "", idx === requestedSchemas.length - 1);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return lines.join("\n");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Format bundle result for dry-run display
|
|
98
|
+
*/
|
|
99
|
+
function formatDryRunOutput(schemas: string[], resolvedDependencies: string[]): string {
|
|
100
|
+
const lines: string[] = [];
|
|
101
|
+
|
|
102
|
+
lines.push("Bundle preview:");
|
|
103
|
+
lines.push("");
|
|
104
|
+
lines.push(`Requested schemas: ${schemas.join(", ")}`);
|
|
105
|
+
lines.push(`Total schemas (with dependencies): ${resolvedDependencies.length}`);
|
|
106
|
+
lines.push("");
|
|
107
|
+
lines.push("Schemas to be bundled:");
|
|
108
|
+
|
|
109
|
+
for (const schema of resolvedDependencies.sort()) {
|
|
110
|
+
lines.push(` - ${schema}`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return lines.join("\n");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Find the schemas directory - works for both development/tests and installed package
|
|
118
|
+
*/
|
|
119
|
+
function findSchemasDir(): string {
|
|
120
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
121
|
+
const __dirname = dirname(__filename);
|
|
122
|
+
|
|
123
|
+
// From compiled dist/cli/index.js (bundled) to src/schemas
|
|
124
|
+
const fromDist = join(__dirname, "../../src/schemas");
|
|
125
|
+
|
|
126
|
+
// From source src/cli/commands/bundle.ts to src/schemas (for tests/dev)
|
|
127
|
+
const fromSource = join(__dirname, "../../schemas");
|
|
128
|
+
|
|
129
|
+
// Try to detect which one exists
|
|
130
|
+
try {
|
|
131
|
+
const fs = require("node:fs");
|
|
132
|
+
if (fs.existsSync(fromDist)) {
|
|
133
|
+
return fromDist;
|
|
134
|
+
}
|
|
135
|
+
if (fs.existsSync(fromSource)) {
|
|
136
|
+
return fromSource;
|
|
137
|
+
}
|
|
138
|
+
} catch {
|
|
139
|
+
// If fs checks fail, default to dist structure
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Default to dist structure (for installed package)
|
|
143
|
+
return fromDist;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Core bundle logic (testable)
|
|
148
|
+
*/
|
|
149
|
+
export async function bundleSchemas(
|
|
150
|
+
schemas: string[],
|
|
151
|
+
schemasDir?: string,
|
|
152
|
+
): Promise<{
|
|
153
|
+
output: string;
|
|
154
|
+
metadata: any;
|
|
155
|
+
dependencyTree: Map<string, import("@/bundler/schema-dependency-resolver.js").DependencyNode>;
|
|
156
|
+
}> {
|
|
157
|
+
// Use provided schemasDir or auto-detect
|
|
158
|
+
const resolvedSchemasDir = schemasDir || findSchemasDir();
|
|
159
|
+
|
|
160
|
+
log.info("Bundling schemas:", schemas);
|
|
161
|
+
log.debug("Schemas directory:", resolvedSchemasDir);
|
|
162
|
+
|
|
163
|
+
// Bundle schemas with dependencies
|
|
164
|
+
const result = await bundleSelectiveSchemas({
|
|
165
|
+
schemas,
|
|
166
|
+
schemasDir: resolvedSchemasDir,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
log.info(
|
|
170
|
+
`Resolved ${result.metadata.resolvedDependencies.length} schemas (including dependencies)`,
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
// Generate output
|
|
174
|
+
const output = generateOutput({
|
|
175
|
+
schemas: result.schemas,
|
|
176
|
+
includeHelper: true,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
output,
|
|
181
|
+
metadata: result.metadata,
|
|
182
|
+
dependencyTree: result.dependencyTree,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* CLI action handler for bundle command
|
|
188
|
+
*/
|
|
189
|
+
export async function handleBundleCommand(
|
|
190
|
+
schemas: string[],
|
|
191
|
+
options: BundleOptions = {},
|
|
192
|
+
): Promise<void> {
|
|
193
|
+
try {
|
|
194
|
+
// Load config if provided
|
|
195
|
+
let configSchemas: string[] = schemas;
|
|
196
|
+
let outputPath = options.output || "./tokenscript-schemas.js";
|
|
197
|
+
|
|
198
|
+
if (isSome(options.config)) {
|
|
199
|
+
log.info(`Loading config from ${options.config}`);
|
|
200
|
+
const config = await loadConfig(options.config);
|
|
201
|
+
configSchemas = config.schemas;
|
|
202
|
+
if (config.output) {
|
|
203
|
+
outputPath = config.output;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Validate we have schemas
|
|
208
|
+
if (!configSchemas || configSchemas.length === 0) {
|
|
209
|
+
throw new Error("No schemas specified. Provide schemas as arguments or via --config");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Bundle schemas
|
|
213
|
+
const { output, metadata, dependencyTree } = await bundleSchemas(configSchemas);
|
|
214
|
+
|
|
215
|
+
// Show dependency tree
|
|
216
|
+
console.log("");
|
|
217
|
+
console.log(formatDependencyTree(dependencyTree, metadata.requestedSchemas));
|
|
218
|
+
console.log("");
|
|
219
|
+
|
|
220
|
+
// Dry run - just show what would be bundled
|
|
221
|
+
if (options.dryRun) {
|
|
222
|
+
const preview = formatDryRunOutput(metadata.requestedSchemas, metadata.resolvedDependencies);
|
|
223
|
+
console.log(preview);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Write output file
|
|
228
|
+
await mkdir(dirname(outputPath), { recursive: true });
|
|
229
|
+
await writeFile(outputPath, output, "utf-8");
|
|
230
|
+
|
|
231
|
+
log.info(`Successfully bundled ${metadata.resolvedDependencies.length} schemas`);
|
|
232
|
+
log.info(`Output written to: ${outputPath}`);
|
|
233
|
+
|
|
234
|
+
// Summary
|
|
235
|
+
console.log(`✓ Bundled ${metadata.resolvedDependencies.length} schemas → ${outputPath}`);
|
|
236
|
+
} catch (error) {
|
|
237
|
+
log.error("Bundle failed:", error);
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
}
|