@tokens-studio/tokenscript-schemas 0.0.14 → 0.1.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 +21 -0
- package/bundled/functions/adjust_chroma.json +60 -0
- package/bundled/functions/adjust_hue.json +60 -0
- package/bundled/functions/adjust_lightness.json +60 -0
- package/bundled/functions/adjust_to_contrast.json +67 -0
- package/bundled/functions/alpha_blend.json +31 -0
- package/bundled/functions/alpha_scale.json +27 -0
- package/bundled/functions/analogous.json +32 -0
- package/bundled/functions/apca_contrast.json +27 -0
- package/bundled/functions/are_similar.json +73 -0
- package/bundled/functions/auto_text_color.json +66 -0
- package/bundled/functions/best_contrast.json +28 -0
- package/bundled/functions/chroma.json +54 -0
- package/bundled/functions/clamp_chroma.json +66 -0
- package/bundled/functions/clamp_lightness.json +66 -0
- package/bundled/functions/clamp_to_gamut.json +23 -0
- package/bundled/functions/complement.json +24 -0
- package/bundled/functions/contrast_ratio.json +27 -0
- package/bundled/functions/cooler.json +52 -0
- package/bundled/functions/darken.json +28 -0
- package/bundled/functions/delta_e_2000.json +40 -0
- package/bundled/functions/delta_e_76.json +27 -0
- package/bundled/functions/delta_e_ok.json +27 -0
- package/bundled/functions/desaturate.json +28 -0
- package/bundled/functions/distributed.json +36 -0
- package/bundled/functions/diverging.json +36 -0
- package/bundled/functions/grayscale.json +24 -0
- package/bundled/functions/harmonize.json +65 -0
- package/bundled/functions/hue.json +54 -0
- package/bundled/functions/hue_difference.json +27 -0
- package/bundled/functions/in_gamut.json +27 -0
- package/bundled/functions/interpolate.json +66 -0
- package/bundled/functions/invert.json +1 -1
- package/bundled/functions/is_cool.json +23 -0
- package/bundled/functions/is_dark.json +27 -0
- package/bundled/functions/is_light.json +27 -0
- package/bundled/functions/is_neutral.json +65 -0
- package/bundled/functions/is_warm.json +23 -0
- package/bundled/functions/lighten.json +28 -0
- package/bundled/functions/lightness.json +61 -0
- package/bundled/functions/luminance.json +23 -0
- package/bundled/functions/meets_contrast.json +31 -0
- package/bundled/functions/mix.json +32 -0
- package/bundled/functions/monochromatic.json +28 -0
- package/bundled/functions/muted.json +59 -0
- package/bundled/functions/neutral_variant.json +59 -0
- package/bundled/functions/relative_luminance.json +61 -0
- package/bundled/functions/rotate_hue.json +28 -0
- package/bundled/functions/saturate.json +28 -0
- package/bundled/functions/scale_chroma.json +60 -0
- package/bundled/functions/scale_lightness.json +60 -0
- package/bundled/functions/sepia.json +59 -0
- package/bundled/functions/set_chroma.json +28 -0
- package/bundled/functions/set_hue.json +28 -0
- package/bundled/functions/set_lightness.json +28 -0
- package/bundled/functions/shade_scale.json +28 -0
- package/bundled/functions/split_complement.json +28 -0
- package/bundled/functions/steps.json +32 -0
- package/bundled/functions/tetradic.json +24 -0
- package/bundled/functions/tint_scale.json +36 -0
- package/bundled/functions/to_gamut.json +59 -0
- package/bundled/functions/triadic.json +24 -0
- package/bundled/functions/vibrant.json +59 -0
- package/bundled/functions/warmer.json +52 -0
- package/bundled/functions/wcag_level.json +60 -0
- package/bundled/functions.json +2602 -6
- package/bundled/registry.json +3705 -84
- package/bundled/types/css-color.json +151 -0
- package/bundled/types/hsl-color.json +66 -0
- package/bundled/types/hsv-color.json +57 -0
- package/bundled/types/hwb-color.json +66 -0
- package/bundled/types/lab-color.json +57 -0
- package/bundled/types/lch-color.json +57 -0
- package/bundled/types/okhsl-color.json +57 -0
- package/bundled/types/okhsv-color.json +57 -0
- package/bundled/types/oklab-color.json +87 -0
- package/bundled/types/oklch-color.json +57 -0
- package/bundled/types/p3-color.json +57 -0
- package/bundled/types/p3-linear-color.json +57 -0
- package/bundled/types/rgb-color.json +12 -3
- package/bundled/types/srgb-color.json +77 -0
- package/bundled/types/srgb-linear-color.json +67 -0
- package/bundled/types/xyz-d50-color.json +57 -0
- package/bundled/types/xyz-d65-color.json +77 -0
- package/bundled/types.json +1067 -43
- package/dist/cli/index.cjs +213 -22
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +213 -22
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +5 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/src/bundler/index.ts +7 -0
- package/src/bundler/presets/css.ts +21 -0
- package/src/bundler/presets/index.ts +47 -0
- package/src/bundler/presets/types.ts +10 -0
- package/src/bundler/selective-bundler.ts +9 -0
- package/src/bundler/types.ts +1 -0
- package/src/cli/commands/bundle.test.ts +34 -0
- package/src/cli/commands/bundle.ts +37 -11
- package/src/cli/commands/presets.ts +81 -0
- package/src/cli/index.ts +11 -0
- package/src/cli/output-generator.ts +8 -2
- package/src/cli/version-info.ts +93 -0
- package/src/schemas/types/css-color/from-hsl-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-hwb-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-lab-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-lch-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-oklab-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-oklch-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-p3-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-rgb-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-srgb-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-xyz-d50-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-xyz-d65-color.tokenscript +17 -4
- package/src/schemas/types/css-color/unit.test.ts +216 -0
- package/src/schemas/types/hex-color/unit.test.ts +18 -0
- package/src/schemas/types/hsl-color/hsla-initializer.tokenscript +17 -0
- package/src/schemas/types/hsl-color/initializer.tokenscript +6 -1
- package/src/schemas/types/hsl-color/schema.json +9 -0
- package/src/schemas/types/hsl-color/unit.test.ts +95 -1
- package/src/schemas/types/hsv-color/initializer.tokenscript +6 -1
- package/src/schemas/types/hsv-color/unit.test.ts +44 -0
- package/src/schemas/types/hwb-color/hwba-initializer.tokenscript +17 -0
- package/src/schemas/types/hwb-color/initializer.tokenscript +6 -1
- package/src/schemas/types/hwb-color/schema.json +9 -0
- package/src/schemas/types/hwb-color/unit.test.ts +70 -0
- package/src/schemas/types/lab-color/initializer.tokenscript +6 -1
- package/src/schemas/types/lab-color/unit.test.ts +44 -0
- package/src/schemas/types/lch-color/initializer.tokenscript +6 -1
- package/src/schemas/types/lch-color/unit.test.ts +44 -0
- package/src/schemas/types/okhsl-color/initializer.tokenscript +8 -1
- package/src/schemas/types/okhsl-color/unit.test.ts +37 -0
- package/src/schemas/types/okhsv-color/initializer.tokenscript +8 -1
- package/src/schemas/types/okhsv-color/unit.test.ts +37 -0
- package/src/schemas/types/oklab-color/initializer.tokenscript +6 -1
- package/src/schemas/types/oklab-color/unit.test.ts +58 -0
- package/src/schemas/types/oklch-color/initializer.tokenscript +6 -1
- package/src/schemas/types/oklch-color/unit.test.ts +58 -0
- package/src/schemas/types/p3-color/initializer.tokenscript +6 -1
- package/src/schemas/types/p3-color/unit.test.ts +47 -0
- package/src/schemas/types/rgb-color/initializer.tokenscript +7 -1
- package/src/schemas/types/rgb-color/rgba-initializer.tokenscript +17 -0
- package/src/schemas/types/rgb-color/schema.json +9 -0
- package/src/schemas/types/rgb-color/unit.test.ts +110 -1
- package/src/schemas/types/srgb-color/initializer.tokenscript +6 -1
- package/src/schemas/types/srgb-color/unit.test.ts +89 -0
- package/bundled/types/rgba-color.json +0 -89
package/dist/index.d.cts
CHANGED
|
@@ -77,6 +77,7 @@ interface BundledRegistry {
|
|
|
77
77
|
metadata: {
|
|
78
78
|
generatedAt: string;
|
|
79
79
|
totalSchemas: number;
|
|
80
|
+
generatedBy: string;
|
|
80
81
|
};
|
|
81
82
|
}
|
|
82
83
|
|
|
@@ -87,7 +88,9 @@ interface BundledRegistry {
|
|
|
87
88
|
/**
|
|
88
89
|
* Bundle all schemas from the schemas directory
|
|
89
90
|
*/
|
|
90
|
-
declare function bundleAllSchemas(schemasDir: string, outputDir: string
|
|
91
|
+
declare function bundleAllSchemas(schemasDir: string, outputDir: string, options?: {
|
|
92
|
+
cliArgs?: string[];
|
|
93
|
+
}): Promise<BundledRegistry>;
|
|
91
94
|
|
|
92
95
|
/**
|
|
93
96
|
* Types for schema downloader
|
package/dist/index.d.ts
CHANGED
|
@@ -77,6 +77,7 @@ interface BundledRegistry {
|
|
|
77
77
|
metadata: {
|
|
78
78
|
generatedAt: string;
|
|
79
79
|
totalSchemas: number;
|
|
80
|
+
generatedBy: string;
|
|
80
81
|
};
|
|
81
82
|
}
|
|
82
83
|
|
|
@@ -87,7 +88,9 @@ interface BundledRegistry {
|
|
|
87
88
|
/**
|
|
88
89
|
* Bundle all schemas from the schemas directory
|
|
89
90
|
*/
|
|
90
|
-
declare function bundleAllSchemas(schemasDir: string, outputDir: string
|
|
91
|
+
declare function bundleAllSchemas(schemasDir: string, outputDir: string, options?: {
|
|
92
|
+
cliArgs?: string[];
|
|
93
|
+
}): Promise<BundledRegistry>;
|
|
91
94
|
|
|
92
95
|
/**
|
|
93
96
|
* Types for schema downloader
|
package/dist/index.js
CHANGED
|
@@ -135,7 +135,7 @@ async function bundleFunctionCategory(categoryDir) {
|
|
|
135
135
|
}
|
|
136
136
|
return bundles;
|
|
137
137
|
}
|
|
138
|
-
async function bundleAllSchemas(schemasDir, outputDir) {
|
|
138
|
+
async function bundleAllSchemas(schemasDir, outputDir, options) {
|
|
139
139
|
console.log("\nBundling type schemas...");
|
|
140
140
|
const typesDir = join(schemasDir, "types");
|
|
141
141
|
const types = await bundleTypeCategory(typesDir);
|
|
@@ -144,13 +144,16 @@ async function bundleAllSchemas(schemasDir, outputDir) {
|
|
|
144
144
|
const functionsDir = join(schemasDir, "functions");
|
|
145
145
|
const functions = await bundleFunctionCategory(functionsDir);
|
|
146
146
|
console.log(`\u2713 Bundled ${functions.length} function schemas`);
|
|
147
|
+
const baseCommand = "npx @tokens-studio/tokenscript-schemas bundle";
|
|
148
|
+
const generatedBy = options?.cliArgs?.length ? `${baseCommand} ${options.cliArgs.join(" ")}` : baseCommand;
|
|
147
149
|
const registry = {
|
|
148
150
|
version: "0.0.10",
|
|
149
151
|
types,
|
|
150
152
|
functions,
|
|
151
153
|
metadata: {
|
|
152
154
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
153
|
-
totalSchemas: types.length + functions.length
|
|
155
|
+
totalSchemas: types.length + functions.length,
|
|
156
|
+
generatedBy
|
|
154
157
|
}
|
|
155
158
|
};
|
|
156
159
|
await mkdir(outputDir, { recursive: true });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bundler/bundle-schema.ts","../src/bundler/utils.ts","../src/bundler/index.ts","../src/downloader/index.ts"],"names":["join","mkdir","writeFile"],"mappings":";;;;AA0BA,eAAsB,yBAAA,CACpB,WACA,OAAA,EAC8B;AAE9B,EAAA,MAAM,cAAA,GAAiB,IAAA,CAAK,SAAA,EAAW,aAAa,CAAA;AACpD,EAAA,MAAM,aAAA,GAAgB,MAAM,QAAA,CAAS,cAAA,EAAgB,OAAO,CAAA;AAC5D,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,KAAA,CAAM,aAAa,CAAA;AAEvC,EAAA,IAAI,MAAA,CAAO,SAAS,UAAA,EAAY;AAC9B,IAAA,OAAO,MAAM,8BAAA;AAAA,MACX,SAAA;AAAA,MACA,MAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF,CAAA,MAAO;AACL,IAAA,OAAO,MAAM,2BAAA,CAA4B,SAAA,EAAW,MAAA,EAA8B,OAAO,CAAA;AAAA,EAC3F;AACF;AAKA,eAAe,2BAAA,CACb,SAAA,EACA,MAAA,EACA,OAAA,EAC6B;AAC7B,EAAA,MAAM,SAAS,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,SAAA,CAAU,MAAM,CAAC,CAAA;AAGhD,EAAA,KAAA,MAAW,WAAA,IAAe,OAAO,YAAA,EAAc;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,GAAG,cAAA,EAAgB,GAAG,MAAA,EAAO;AAGlD,EAAA,MAAM,OAAA,GAAU,MAAM,eAAA,CAAgB,UAAU,CAAA;AAGhD,EAAA,KAAA,MAAW,UAAU,OAAA,EAAS;AAC5B,IAAA,IAAI;AACF,MAAA,MAAM,cAAA,CAAe,QAAQ,UAAU,CAAA;AAAA,IACzC,SAAS,KAAA,EAAO;AACd,MAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,mBAAA,EAAsB,MAAA,CAAO,IAAI,KAAK,KAAK,CAAA;AAAA,IAC3D;AAAA,EACF;AAEA,EAAA,OAAA,CAAQ,IAAI,+CAA0C,CAAA;AACxD","file":"index.js","sourcesContent":["/**\n * Shared schema bundling logic\n * Used by both the build-time bundler and runtime test helpers\n */\n\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport type {\n ColorSpecification,\n FunctionSpecification,\n SchemaSpecification,\n} from \"@/bundler/types.js\";\n\nexport interface BundleOptions {\n /**\n * Base URL to prepend to relative schema URIs\n * If provided, transforms /api/v1/... to https://domain.com/api/v1/...\n * If not provided, keeps URIs as-is (useful for tests)\n */\n baseUrl?: string;\n}\n\n/**\n * Replace script file references with actual content\n * This is the core bundling logic shared by build and runtime\n */\nexport async function bundleSchemaFromDirectory(\n schemaDir: string,\n options?: BundleOptions,\n): Promise<SchemaSpecification> {\n // Read schema.json which contains the full specification\n const schemaJsonPath = join(schemaDir, \"schema.json\");\n const schemaContent = await readFile(schemaJsonPath, \"utf-8\");\n const schema = JSON.parse(schemaContent) as SchemaSpecification;\n\n if (schema.type === \"function\") {\n return await inlineFunctionScriptReferences(\n schemaDir,\n schema as FunctionSpecification,\n options,\n );\n } else {\n return await inlineColorScriptReferences(schemaDir, schema as ColorSpecification, options);\n }\n}\n\n/**\n * Inline script file references in a color schema specification\n */\nasync function inlineColorScriptReferences(\n schemaDir: string,\n schema: ColorSpecification,\n options?: BundleOptions,\n): Promise<ColorSpecification> {\n const result = JSON.parse(JSON.stringify(schema)) as ColorSpecification;\n\n // Inline initializer scripts and transform URIs\n for (const initializer of result.initializers) {\n if (initializer.script.script.startsWith(\"./\")) {\n const scriptPath = join(schemaDir, initializer.script.script.slice(2));\n const scriptContent = await readFile(scriptPath, \"utf-8\");\n initializer.script.script = scriptContent.trim();\n }\n\n // Transform script type URI if baseUrl is provided\n if (options?.baseUrl) {\n initializer.script.type = addBaseUrl(initializer.script.type, options.baseUrl);\n }\n }\n\n // Inline conversion scripts and transform URIs\n for (const conversion of result.conversions) {\n if (conversion.script.script.startsWith(\"./\")) {\n const scriptPath = join(schemaDir, conversion.script.script.slice(2));\n const scriptContent = await readFile(scriptPath, \"utf-8\");\n conversion.script.script = scriptContent.trim();\n }\n\n // Transform URIs if baseUrl is provided\n if (options?.baseUrl) {\n conversion.script.type = addBaseUrl(conversion.script.type, options.baseUrl);\n\n // Transform source and target URIs (but not $self)\n if (conversion.source !== \"$self\") {\n conversion.source = addBaseUrl(conversion.source, options.baseUrl);\n }\n if (conversion.target !== \"$self\") {\n conversion.target = addBaseUrl(conversion.target, options.baseUrl);\n }\n }\n }\n\n return result;\n}\n\n/**\n * Inline script file references in a function specification\n */\nasync function inlineFunctionScriptReferences(\n schemaDir: string,\n schema: FunctionSpecification,\n options?: BundleOptions,\n): Promise<FunctionSpecification> {\n const result = JSON.parse(JSON.stringify(schema)) as FunctionSpecification;\n\n // Inline the main function script\n if (result.script.script.startsWith(\"./\")) {\n const scriptPath = join(schemaDir, result.script.script.slice(2));\n const scriptContent = await readFile(scriptPath, \"utf-8\");\n result.script.script = scriptContent.trim();\n }\n\n // Transform script type URI if baseUrl is provided\n if (options?.baseUrl) {\n result.script.type = addBaseUrl(result.script.type, options.baseUrl);\n\n // Transform requirement URIs\n if (result.requirements) {\n const baseUrl = options.baseUrl;\n result.requirements = result.requirements.map((req) => addBaseUrl(req, baseUrl));\n }\n }\n\n return result;\n}\n\n/**\n * Add base URL to relative schema URIs\n * Transforms /api/v1/... to https://domain.com/api/v1/...\n */\nfunction addBaseUrl(uri: string, baseUrl: string): string {\n // If URI already has a protocol, return as-is\n if (uri.includes(\"://\")) {\n return uri;\n }\n\n // If URI is relative (starts with /), prepend base URL\n if (uri.startsWith(\"/\")) {\n // Remove trailing slash from baseUrl if present\n const cleanBaseUrl = baseUrl.endsWith(\"/\") ? baseUrl.slice(0, -1) : baseUrl;\n return `${cleanBaseUrl}${uri}`;\n }\n\n // Otherwise return as-is (e.g., $self)\n return uri;\n}\n","/**\n * Bundler utilities\n */\n\nimport { readdir, readFile, stat } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\n/**\n * Check if a path is a directory\n */\nexport async function isDirectory(path: string): Promise<boolean> {\n try {\n const stats = await stat(path);\n return stats.isDirectory();\n } catch {\n return false;\n }\n}\n\n/**\n * Get all subdirectories in a directory\n */\nexport async function getSubdirectories(dir: string): Promise<string[]> {\n const entries = await readdir(dir);\n const subdirs: string[] = [];\n\n for (const entry of entries) {\n const fullPath = join(dir, entry);\n if (await isDirectory(fullPath)) {\n subdirs.push(entry);\n }\n }\n\n return subdirs;\n}\n\n/**\n * Read all tokenscript files from a schema directory\n */\nexport async function readTokenScriptFiles(schemaDir: string): Promise<Record<string, string>> {\n const entries = await readdir(schemaDir);\n const scripts: Record<string, string> = {};\n\n for (const entry of entries) {\n if (entry.endsWith(\".tokenscript\")) {\n const filePath = join(schemaDir, entry);\n const content = await readFile(filePath, \"utf-8\");\n const scriptName = entry.replace(\".tokenscript\", \"\");\n scripts[scriptName] = content;\n }\n }\n\n return scripts;\n}\n\n/**\n * Read and parse a JSON file\n */\nexport async function readJsonFile<T = unknown>(filePath: string): Promise<T> {\n const content = await readFile(filePath, \"utf-8\");\n return JSON.parse(content) as T;\n}\n\n/**\n * Check if a file exists\n */\nexport async function fileExists(filePath: string): Promise<boolean> {\n try {\n await stat(filePath);\n return true;\n } catch {\n return false;\n }\n}\n","/**\n * Schema bundler - bundles schemas for distribution\n */\n\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { bundleSchemaFromDirectory } from \"@/bundler/bundle-schema\";\nimport type {\n BundledRegistry,\n ColorSpecification,\n FunctionSpecification,\n SchemaSpecification,\n} from \"@/bundler/types.js\";\nimport { getSubdirectories } from \"@/bundler/utils\";\n\n/**\n * Default registry URL for build-time bundling\n */\nconst DEFAULT_REGISTRY_URL = \"https://schema.tokenscript.dev.gcp.tokens.studio\";\n\n/**\n * Bundle a single schema from its directory\n */\nasync function bundleSchema(schemaDir: string, schemaSlug: string): Promise<SchemaSpecification> {\n // Use shared bundling logic with baseUrl for build-time\n const bundled = await bundleSchemaFromDirectory(schemaDir, {\n baseUrl: DEFAULT_REGISTRY_URL,\n });\n\n // Add slug from folder name\n bundled.slug = schemaSlug;\n\n return bundled;\n}\n\n/**\n * Bundle all color type schemas from a category directory\n */\nasync function bundleTypeCategory(categoryDir: string): Promise<ColorSpecification[]> {\n const bundles: ColorSpecification[] = [];\n const schemaSlugs = await getSubdirectories(categoryDir);\n\n for (const slug of schemaSlugs) {\n const schemaDir = join(categoryDir, slug);\n console.log(` Bundling ${slug}...`);\n\n try {\n const bundle = await bundleSchema(schemaDir, slug);\n if (bundle.type === \"color\") {\n bundles.push(bundle as ColorSpecification);\n }\n } catch (error) {\n console.error(` ✗ Failed to bundle ${slug}:`, error);\n }\n }\n\n return bundles;\n}\n\n/**\n * Bundle all function schemas from a category directory\n */\nasync function bundleFunctionCategory(categoryDir: string): Promise<FunctionSpecification[]> {\n const bundles: FunctionSpecification[] = [];\n const schemaSlugs = await getSubdirectories(categoryDir);\n\n for (const slug of schemaSlugs) {\n const schemaDir = join(categoryDir, slug);\n console.log(` Bundling ${slug}...`);\n\n try {\n const bundle = await bundleSchema(schemaDir, slug);\n if (bundle.type === \"function\") {\n bundles.push(bundle as FunctionSpecification);\n }\n } catch (error) {\n console.error(` ✗ Failed to bundle ${slug}:`, error);\n }\n }\n\n return bundles;\n}\n\n/**\n * Bundle all schemas from the schemas directory\n */\nexport async function bundleAllSchemas(\n schemasDir: string,\n outputDir: string,\n): Promise<BundledRegistry> {\n // Bundle types\n console.log(\"\\nBundling type schemas...\");\n const typesDir = join(schemasDir, \"types\");\n const types = await bundleTypeCategory(typesDir);\n console.log(`✓ Bundled ${types.length} type schemas`);\n\n // Bundle functions\n console.log(\"\\nBundling function schemas...\");\n const functionsDir = join(schemasDir, \"functions\");\n const functions = await bundleFunctionCategory(functionsDir);\n console.log(`✓ Bundled ${functions.length} function schemas`);\n\n // Create bundled registry\n const registry: BundledRegistry = {\n version: \"0.0.10\",\n types,\n functions,\n metadata: {\n generatedAt: new Date().toISOString(),\n totalSchemas: types.length + functions.length,\n },\n };\n\n // Ensure output directory exists\n await mkdir(outputDir, { recursive: true });\n\n // Write complete registry\n const registryPath = join(outputDir, \"registry.json\");\n await writeFile(registryPath, JSON.stringify(registry, null, 2));\n console.log(`\\n✓ Written complete registry to ${registryPath}`);\n\n // Write individual category bundles\n const typesPath = join(outputDir, \"types.json\");\n await writeFile(typesPath, JSON.stringify({ version: registry.version, types }, null, 2));\n console.log(`✓ Written types bundle to ${typesPath}`);\n\n const functionsPath = join(outputDir, \"functions.json\");\n await writeFile(functionsPath, JSON.stringify({ version: registry.version, functions }, null, 2));\n console.log(`✓ Written functions bundle to ${functionsPath}`);\n\n // Write individual schema bundles\n const typesOutputDir = join(outputDir, \"types\");\n await mkdir(typesOutputDir, { recursive: true });\n for (const type of types) {\n const typePath = join(typesOutputDir, `${type.slug}.json`);\n await writeFile(typePath, JSON.stringify(type, null, 2));\n }\n console.log(`✓ Written ${types.length} individual type schemas`);\n\n const functionsOutputDir = join(outputDir, \"functions\");\n await mkdir(functionsOutputDir, { recursive: true });\n for (const func of functions) {\n const funcPath = join(functionsOutputDir, `${func.slug}.json`);\n await writeFile(funcPath, JSON.stringify(func, null, 2));\n }\n console.log(`✓ Written ${functions.length} individual function schemas`);\n\n return registry;\n}\n\nexport type * from \"@/bundler/types.js\";\n","/**\n * Schema downloader - fetches schemas from the TokenScript API\n */\n\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport type {\n SchemaConfig,\n SchemaDetails,\n SchemaListItem,\n SchemaVersion,\n} from \"@/downloader/types.js\";\n\nconst DEFAULT_CONFIG: SchemaConfig = {\n apiBaseUrl: \"https://schema.tokenscript.dev.gcp.tokens.studio/api/v1\",\n outputDir: \"src/schemas\",\n targetVersion: \"0.0.10\",\n};\n\n/**\n * Fetch all schemas from the API\n */\nexport async function fetchSchemaList(\n config: SchemaConfig = DEFAULT_CONFIG,\n): Promise<SchemaListItem[]> {\n const url = `${config.apiBaseUrl}/schema/?format=json`;\n\n console.log(`Fetching schema list from ${url}...`);\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch schemas: ${response.statusText}`);\n }\n\n const data = (await response.json()) as SchemaListItem[];\n console.log(`Found ${data.length} schemas`);\n\n return data;\n}\n\n/**\n * Fetch versions for a schema\n */\nexport async function fetchSchemaVersions(\n schemaSlug: string,\n config: SchemaConfig = DEFAULT_CONFIG,\n): Promise<SchemaVersion[]> {\n const url = `${config.apiBaseUrl}/schema/${schemaSlug}/versions/?format=json`;\n\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch versions for ${schemaSlug}: ${response.statusText}`);\n }\n\n return (await response.json()) as SchemaVersion[];\n}\n\n/**\n * Create the folder structure for a schema\n */\nasync function createSchemaFolder(\n schemaSlug: string,\n schemaType: \"type\" | \"function\",\n baseDir: string,\n): Promise<string> {\n const schemaPath = join(baseDir, schemaType === \"type\" ? \"types\" : \"functions\", schemaSlug);\n await mkdir(schemaPath, { recursive: true });\n return schemaPath;\n}\n\n/**\n * Write schema.json file\n */\nasync function writeSchemaJson(\n schemaPath: string,\n schema: SchemaDetails,\n targetVersion: string,\n): Promise<void> {\n const content = schema.content as any;\n\n const schemaJson = {\n id: schema.id,\n slug: schema.slug,\n name: schema.name,\n description: schema.description,\n type: schema.type,\n version: targetVersion,\n originalVersion: schema.version,\n contentType: content.type || null,\n metadata: schema.metadata || {},\n };\n\n await writeFile(join(schemaPath, \"schema.json\"), JSON.stringify(schemaJson, null, 2));\n}\n\n/**\n * Generate a unit test stub\n */\nasync function createUnitTestStub(\n schemaPath: string,\n schemaName: string,\n schemaType: \"type\" | \"function\",\n): Promise<void> {\n const testContent = `import { describe, test, expect } from \"vitest\";\n\ndescribe(\"${schemaName}\", () => {\n test.todo(\"should implement ${schemaType} functionality\");\n});\n`;\n\n await writeFile(join(schemaPath, \"unit.test.ts\"), testContent);\n}\n\n/**\n * Extract conversion script name from source/target\n */\nfunction getConversionFileName(source: string, target: string): string {\n // Extract the type name from URLs like \"https://schema.../core/hex-color/0/\"\n const extractType = (url: string): string => {\n const match = url.match(/\\/([^/]+)\\/\\d+\\/?$/);\n return match ? match[1] : url;\n };\n\n const sourceType = extractType(source);\n const targetType = extractType(target);\n\n if (target === \"$self\") {\n return `to-${sourceType}.tokenscript`;\n }\n if (source === \"$self\") {\n return `from-${targetType}.tokenscript`;\n }\n\n return `${sourceType}-to-${targetType}.tokenscript`;\n}\n\n/**\n * Write TokenScript files from schema content\n */\nasync function writeTokenScriptFiles(schemaPath: string, schema: SchemaDetails): Promise<void> {\n const content = schema.content as any;\n\n // Write the main schema definition as JSON\n if (content.schema) {\n await writeFile(\n join(schemaPath, \"schema-definition.json\"),\n JSON.stringify(content.schema, null, 2),\n );\n }\n\n // Extract and write conversion scripts\n if (content.conversions && Array.isArray(content.conversions)) {\n for (const conversion of content.conversions) {\n if (conversion.script?.script) {\n const fileName = getConversionFileName(conversion.source || \"\", conversion.target || \"\");\n\n // Add description as comment if available\n let scriptContent = \"\";\n if (conversion.description) {\n scriptContent += `# ${conversion.description}\\n`;\n scriptContent += `# Source: ${conversion.source}\\n`;\n scriptContent += `# Target: ${conversion.target}\\n`;\n scriptContent += `# Lossless: ${conversion.lossless || false}\\n\\n`;\n }\n\n scriptContent += conversion.script.script;\n\n await writeFile(join(schemaPath, fileName), scriptContent);\n }\n }\n }\n\n // Create initializer if no conversions found\n if (!content.conversions || content.conversions.length === 0) {\n const initializerContent = `# ${schema.name} Initializer\n# TODO: Implement initialization logic\n\n`;\n await writeFile(join(schemaPath, \"initializer.tokenscript\"), initializerContent);\n }\n}\n\n/**\n * Download and organize a single schema\n */\nexport async function downloadSchema(\n schema: SchemaListItem,\n config: SchemaConfig = DEFAULT_CONFIG,\n): Promise<void> {\n console.log(`Downloading ${schema.slug}...`);\n\n // Fetch all versions\n const versions = await fetchSchemaVersions(schema.slug, config);\n\n if (versions.length === 0) {\n console.warn(`No versions found for ${schema.slug}, skipping`);\n return;\n }\n\n // Get the latest version (first one)\n const latestVersion = versions[0];\n\n // Create folder structure\n const schemaPath = await createSchemaFolder(schema.slug, schema.type, config.outputDir);\n\n // Combine schema info with version info\n const details: SchemaDetails = {\n id: schema.id,\n slug: schema.slug,\n name: schema.name,\n description: schema.description,\n type: schema.type,\n version: latestVersion.version,\n content: latestVersion.content,\n };\n\n // Write files\n await writeSchemaJson(schemaPath, details, config.targetVersion);\n await writeTokenScriptFiles(schemaPath, details);\n await createUnitTestStub(schemaPath, schema.name, schema.type);\n\n console.log(`✓ Downloaded ${schema.slug} to ${schemaPath}`);\n}\n\n/**\n * Download all schemas from the API\n */\nexport async function downloadAllSchemas(config: Partial<SchemaConfig> = {}): Promise<void> {\n const fullConfig = { ...DEFAULT_CONFIG, ...config };\n\n // Fetch schema list\n const schemas = await fetchSchemaList(fullConfig);\n\n // Download each schema\n for (const schema of schemas) {\n try {\n await downloadSchema(schema, fullConfig);\n } catch (error) {\n console.error(`Failed to download ${schema.slug}:`, error);\n }\n }\n\n console.log(\"\\n✓ All schemas downloaded successfully!\");\n}\n\nexport { DEFAULT_CONFIG };\nexport type * from \"@/downloader/types.js\";\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/bundler/bundle-schema.ts","../src/bundler/utils.ts","../src/bundler/index.ts","../src/downloader/index.ts"],"names":["join","mkdir","writeFile"],"mappings":";;;;AA0B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CAAM,CAAA,mBAAA,EAAsB,MAAA,CAAO,IAAI,KAAK,KAAK,CAAA;AAAA,IAC3D;AAAA,EACF;AAEA,EAAA,OAAA,CAAQ,IAAI,+CAA0C,CAAA;AACxD","file":"index.js","sourcesContent":["/**\n * Shared schema bundling logic\n * Used by both the build-time bundler and runtime test helpers\n */\n\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport type {\n ColorSpecification,\n FunctionSpecification,\n SchemaSpecification,\n} from \"@/bundler/types.js\";\n\nexport interface BundleOptions {\n /**\n * Base URL to prepend to relative schema URIs\n * If provided, transforms /api/v1/... to https://domain.com/api/v1/...\n * If not provided, keeps URIs as-is (useful for tests)\n */\n baseUrl?: string;\n}\n\n/**\n * Replace script file references with actual content\n * This is the core bundling logic shared by build and runtime\n */\nexport async function bundleSchemaFromDirectory(\n schemaDir: string,\n options?: BundleOptions,\n): Promise<SchemaSpecification> {\n // Read schema.json which contains the full specification\n const schemaJsonPath = join(schemaDir, \"schema.json\");\n const schemaContent = await readFile(schemaJsonPath, \"utf-8\");\n const schema = JSON.parse(schemaContent) as SchemaSpecification;\n\n if (schema.type === \"function\") {\n return await inlineFunctionScriptReferences(\n schemaDir,\n schema as FunctionSpecification,\n options,\n );\n } else {\n return await inlineColorScriptReferences(schemaDir, schema as ColorSpecification, options);\n }\n}\n\n/**\n * Inline script file references in a color schema specification\n */\nasync function inlineColorScriptReferences(\n schemaDir: string,\n schema: ColorSpecification,\n options?: BundleOptions,\n): Promise<ColorSpecification> {\n const result = JSON.parse(JSON.stringify(schema)) as ColorSpecification;\n\n // Inline initializer scripts and transform URIs\n for (const initializer of result.initializers) {\n if (initializer.script.script.startsWith(\"./\")) {\n const scriptPath = join(schemaDir, initializer.script.script.slice(2));\n const scriptContent = await readFile(scriptPath, \"utf-8\");\n initializer.script.script = scriptContent.trim();\n }\n\n // Transform script type URI if baseUrl is provided\n if (options?.baseUrl) {\n initializer.script.type = addBaseUrl(initializer.script.type, options.baseUrl);\n }\n }\n\n // Inline conversion scripts and transform URIs\n for (const conversion of result.conversions) {\n if (conversion.script.script.startsWith(\"./\")) {\n const scriptPath = join(schemaDir, conversion.script.script.slice(2));\n const scriptContent = await readFile(scriptPath, \"utf-8\");\n conversion.script.script = scriptContent.trim();\n }\n\n // Transform URIs if baseUrl is provided\n if (options?.baseUrl) {\n conversion.script.type = addBaseUrl(conversion.script.type, options.baseUrl);\n\n // Transform source and target URIs (but not $self)\n if (conversion.source !== \"$self\") {\n conversion.source = addBaseUrl(conversion.source, options.baseUrl);\n }\n if (conversion.target !== \"$self\") {\n conversion.target = addBaseUrl(conversion.target, options.baseUrl);\n }\n }\n }\n\n return result;\n}\n\n/**\n * Inline script file references in a function specification\n */\nasync function inlineFunctionScriptReferences(\n schemaDir: string,\n schema: FunctionSpecification,\n options?: BundleOptions,\n): Promise<FunctionSpecification> {\n const result = JSON.parse(JSON.stringify(schema)) as FunctionSpecification;\n\n // Inline the main function script\n if (result.script.script.startsWith(\"./\")) {\n const scriptPath = join(schemaDir, result.script.script.slice(2));\n const scriptContent = await readFile(scriptPath, \"utf-8\");\n result.script.script = scriptContent.trim();\n }\n\n // Transform script type URI if baseUrl is provided\n if (options?.baseUrl) {\n result.script.type = addBaseUrl(result.script.type, options.baseUrl);\n\n // Transform requirement URIs\n if (result.requirements) {\n const baseUrl = options.baseUrl;\n result.requirements = result.requirements.map((req) => addBaseUrl(req, baseUrl));\n }\n }\n\n return result;\n}\n\n/**\n * Add base URL to relative schema URIs\n * Transforms /api/v1/... to https://domain.com/api/v1/...\n */\nfunction addBaseUrl(uri: string, baseUrl: string): string {\n // If URI already has a protocol, return as-is\n if (uri.includes(\"://\")) {\n return uri;\n }\n\n // If URI is relative (starts with /), prepend base URL\n if (uri.startsWith(\"/\")) {\n // Remove trailing slash from baseUrl if present\n const cleanBaseUrl = baseUrl.endsWith(\"/\") ? baseUrl.slice(0, -1) : baseUrl;\n return `${cleanBaseUrl}${uri}`;\n }\n\n // Otherwise return as-is (e.g., $self)\n return uri;\n}\n","/**\n * Bundler utilities\n */\n\nimport { readdir, readFile, stat } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\n/**\n * Check if a path is a directory\n */\nexport async function isDirectory(path: string): Promise<boolean> {\n try {\n const stats = await stat(path);\n return stats.isDirectory();\n } catch {\n return false;\n }\n}\n\n/**\n * Get all subdirectories in a directory\n */\nexport async function getSubdirectories(dir: string): Promise<string[]> {\n const entries = await readdir(dir);\n const subdirs: string[] = [];\n\n for (const entry of entries) {\n const fullPath = join(dir, entry);\n if (await isDirectory(fullPath)) {\n subdirs.push(entry);\n }\n }\n\n return subdirs;\n}\n\n/**\n * Read all tokenscript files from a schema directory\n */\nexport async function readTokenScriptFiles(schemaDir: string): Promise<Record<string, string>> {\n const entries = await readdir(schemaDir);\n const scripts: Record<string, string> = {};\n\n for (const entry of entries) {\n if (entry.endsWith(\".tokenscript\")) {\n const filePath = join(schemaDir, entry);\n const content = await readFile(filePath, \"utf-8\");\n const scriptName = entry.replace(\".tokenscript\", \"\");\n scripts[scriptName] = content;\n }\n }\n\n return scripts;\n}\n\n/**\n * Read and parse a JSON file\n */\nexport async function readJsonFile<T = unknown>(filePath: string): Promise<T> {\n const content = await readFile(filePath, \"utf-8\");\n return JSON.parse(content) as T;\n}\n\n/**\n * Check if a file exists\n */\nexport async function fileExists(filePath: string): Promise<boolean> {\n try {\n await stat(filePath);\n return true;\n } catch {\n return false;\n }\n}\n","/**\n * Schema bundler - bundles schemas for distribution\n */\n\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { bundleSchemaFromDirectory } from \"@/bundler/bundle-schema\";\nimport type {\n BundledRegistry,\n ColorSpecification,\n FunctionSpecification,\n SchemaSpecification,\n} from \"@/bundler/types.js\";\nimport { getSubdirectories } from \"@/bundler/utils\";\n\n/**\n * Default registry URL for build-time bundling\n */\nconst DEFAULT_REGISTRY_URL = \"https://schema.tokenscript.dev.gcp.tokens.studio\";\n\n/**\n * Bundle a single schema from its directory\n */\nasync function bundleSchema(schemaDir: string, schemaSlug: string): Promise<SchemaSpecification> {\n // Use shared bundling logic with baseUrl for build-time\n const bundled = await bundleSchemaFromDirectory(schemaDir, {\n baseUrl: DEFAULT_REGISTRY_URL,\n });\n\n // Add slug from folder name\n bundled.slug = schemaSlug;\n\n return bundled;\n}\n\n/**\n * Bundle all color type schemas from a category directory\n */\nasync function bundleTypeCategory(categoryDir: string): Promise<ColorSpecification[]> {\n const bundles: ColorSpecification[] = [];\n const schemaSlugs = await getSubdirectories(categoryDir);\n\n for (const slug of schemaSlugs) {\n const schemaDir = join(categoryDir, slug);\n console.log(` Bundling ${slug}...`);\n\n try {\n const bundle = await bundleSchema(schemaDir, slug);\n if (bundle.type === \"color\") {\n bundles.push(bundle as ColorSpecification);\n }\n } catch (error) {\n console.error(` ✗ Failed to bundle ${slug}:`, error);\n }\n }\n\n return bundles;\n}\n\n/**\n * Bundle all function schemas from a category directory\n */\nasync function bundleFunctionCategory(categoryDir: string): Promise<FunctionSpecification[]> {\n const bundles: FunctionSpecification[] = [];\n const schemaSlugs = await getSubdirectories(categoryDir);\n\n for (const slug of schemaSlugs) {\n const schemaDir = join(categoryDir, slug);\n console.log(` Bundling ${slug}...`);\n\n try {\n const bundle = await bundleSchema(schemaDir, slug);\n if (bundle.type === \"function\") {\n bundles.push(bundle as FunctionSpecification);\n }\n } catch (error) {\n console.error(` ✗ Failed to bundle ${slug}:`, error);\n }\n }\n\n return bundles;\n}\n\n/**\n * Bundle all schemas from the schemas directory\n */\nexport async function bundleAllSchemas(\n schemasDir: string,\n outputDir: string,\n options?: { cliArgs?: string[] },\n): Promise<BundledRegistry> {\n // Bundle types\n console.log(\"\\nBundling type schemas...\");\n const typesDir = join(schemasDir, \"types\");\n const types = await bundleTypeCategory(typesDir);\n console.log(`✓ Bundled ${types.length} type schemas`);\n\n // Bundle functions\n console.log(\"\\nBundling function schemas...\");\n const functionsDir = join(schemasDir, \"functions\");\n const functions = await bundleFunctionCategory(functionsDir);\n console.log(`✓ Bundled ${functions.length} function schemas`);\n\n // Create bundled registry\n const baseCommand = \"npx @tokens-studio/tokenscript-schemas bundle\";\n const generatedBy = options?.cliArgs?.length\n ? `${baseCommand} ${options.cliArgs.join(\" \")}`\n : baseCommand;\n\n const registry: BundledRegistry = {\n version: \"0.0.10\",\n types,\n functions,\n metadata: {\n generatedAt: new Date().toISOString(),\n totalSchemas: types.length + functions.length,\n generatedBy,\n },\n };\n\n // Ensure output directory exists\n await mkdir(outputDir, { recursive: true });\n\n // Write complete registry\n const registryPath = join(outputDir, \"registry.json\");\n await writeFile(registryPath, JSON.stringify(registry, null, 2));\n console.log(`\\n✓ Written complete registry to ${registryPath}`);\n\n // Write individual category bundles\n const typesPath = join(outputDir, \"types.json\");\n await writeFile(typesPath, JSON.stringify({ version: registry.version, types }, null, 2));\n console.log(`✓ Written types bundle to ${typesPath}`);\n\n const functionsPath = join(outputDir, \"functions.json\");\n await writeFile(functionsPath, JSON.stringify({ version: registry.version, functions }, null, 2));\n console.log(`✓ Written functions bundle to ${functionsPath}`);\n\n // Write individual schema bundles\n const typesOutputDir = join(outputDir, \"types\");\n await mkdir(typesOutputDir, { recursive: true });\n for (const type of types) {\n const typePath = join(typesOutputDir, `${type.slug}.json`);\n await writeFile(typePath, JSON.stringify(type, null, 2));\n }\n console.log(`✓ Written ${types.length} individual type schemas`);\n\n const functionsOutputDir = join(outputDir, \"functions\");\n await mkdir(functionsOutputDir, { recursive: true });\n for (const func of functions) {\n const funcPath = join(functionsOutputDir, `${func.slug}.json`);\n await writeFile(funcPath, JSON.stringify(func, null, 2));\n }\n console.log(`✓ Written ${functions.length} individual function schemas`);\n\n return registry;\n}\n\nexport type * from \"@/bundler/types.js\";\n","/**\n * Schema downloader - fetches schemas from the TokenScript API\n */\n\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport type {\n SchemaConfig,\n SchemaDetails,\n SchemaListItem,\n SchemaVersion,\n} from \"@/downloader/types.js\";\n\nconst DEFAULT_CONFIG: SchemaConfig = {\n apiBaseUrl: \"https://schema.tokenscript.dev.gcp.tokens.studio/api/v1\",\n outputDir: \"src/schemas\",\n targetVersion: \"0.0.10\",\n};\n\n/**\n * Fetch all schemas from the API\n */\nexport async function fetchSchemaList(\n config: SchemaConfig = DEFAULT_CONFIG,\n): Promise<SchemaListItem[]> {\n const url = `${config.apiBaseUrl}/schema/?format=json`;\n\n console.log(`Fetching schema list from ${url}...`);\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch schemas: ${response.statusText}`);\n }\n\n const data = (await response.json()) as SchemaListItem[];\n console.log(`Found ${data.length} schemas`);\n\n return data;\n}\n\n/**\n * Fetch versions for a schema\n */\nexport async function fetchSchemaVersions(\n schemaSlug: string,\n config: SchemaConfig = DEFAULT_CONFIG,\n): Promise<SchemaVersion[]> {\n const url = `${config.apiBaseUrl}/schema/${schemaSlug}/versions/?format=json`;\n\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch versions for ${schemaSlug}: ${response.statusText}`);\n }\n\n return (await response.json()) as SchemaVersion[];\n}\n\n/**\n * Create the folder structure for a schema\n */\nasync function createSchemaFolder(\n schemaSlug: string,\n schemaType: \"type\" | \"function\",\n baseDir: string,\n): Promise<string> {\n const schemaPath = join(baseDir, schemaType === \"type\" ? \"types\" : \"functions\", schemaSlug);\n await mkdir(schemaPath, { recursive: true });\n return schemaPath;\n}\n\n/**\n * Write schema.json file\n */\nasync function writeSchemaJson(\n schemaPath: string,\n schema: SchemaDetails,\n targetVersion: string,\n): Promise<void> {\n const content = schema.content as any;\n\n const schemaJson = {\n id: schema.id,\n slug: schema.slug,\n name: schema.name,\n description: schema.description,\n type: schema.type,\n version: targetVersion,\n originalVersion: schema.version,\n contentType: content.type || null,\n metadata: schema.metadata || {},\n };\n\n await writeFile(join(schemaPath, \"schema.json\"), JSON.stringify(schemaJson, null, 2));\n}\n\n/**\n * Generate a unit test stub\n */\nasync function createUnitTestStub(\n schemaPath: string,\n schemaName: string,\n schemaType: \"type\" | \"function\",\n): Promise<void> {\n const testContent = `import { describe, test, expect } from \"vitest\";\n\ndescribe(\"${schemaName}\", () => {\n test.todo(\"should implement ${schemaType} functionality\");\n});\n`;\n\n await writeFile(join(schemaPath, \"unit.test.ts\"), testContent);\n}\n\n/**\n * Extract conversion script name from source/target\n */\nfunction getConversionFileName(source: string, target: string): string {\n // Extract the type name from URLs like \"https://schema.../core/hex-color/0/\"\n const extractType = (url: string): string => {\n const match = url.match(/\\/([^/]+)\\/\\d+\\/?$/);\n return match ? match[1] : url;\n };\n\n const sourceType = extractType(source);\n const targetType = extractType(target);\n\n if (target === \"$self\") {\n return `to-${sourceType}.tokenscript`;\n }\n if (source === \"$self\") {\n return `from-${targetType}.tokenscript`;\n }\n\n return `${sourceType}-to-${targetType}.tokenscript`;\n}\n\n/**\n * Write TokenScript files from schema content\n */\nasync function writeTokenScriptFiles(schemaPath: string, schema: SchemaDetails): Promise<void> {\n const content = schema.content as any;\n\n // Write the main schema definition as JSON\n if (content.schema) {\n await writeFile(\n join(schemaPath, \"schema-definition.json\"),\n JSON.stringify(content.schema, null, 2),\n );\n }\n\n // Extract and write conversion scripts\n if (content.conversions && Array.isArray(content.conversions)) {\n for (const conversion of content.conversions) {\n if (conversion.script?.script) {\n const fileName = getConversionFileName(conversion.source || \"\", conversion.target || \"\");\n\n // Add description as comment if available\n let scriptContent = \"\";\n if (conversion.description) {\n scriptContent += `# ${conversion.description}\\n`;\n scriptContent += `# Source: ${conversion.source}\\n`;\n scriptContent += `# Target: ${conversion.target}\\n`;\n scriptContent += `# Lossless: ${conversion.lossless || false}\\n\\n`;\n }\n\n scriptContent += conversion.script.script;\n\n await writeFile(join(schemaPath, fileName), scriptContent);\n }\n }\n }\n\n // Create initializer if no conversions found\n if (!content.conversions || content.conversions.length === 0) {\n const initializerContent = `# ${schema.name} Initializer\n# TODO: Implement initialization logic\n\n`;\n await writeFile(join(schemaPath, \"initializer.tokenscript\"), initializerContent);\n }\n}\n\n/**\n * Download and organize a single schema\n */\nexport async function downloadSchema(\n schema: SchemaListItem,\n config: SchemaConfig = DEFAULT_CONFIG,\n): Promise<void> {\n console.log(`Downloading ${schema.slug}...`);\n\n // Fetch all versions\n const versions = await fetchSchemaVersions(schema.slug, config);\n\n if (versions.length === 0) {\n console.warn(`No versions found for ${schema.slug}, skipping`);\n return;\n }\n\n // Get the latest version (first one)\n const latestVersion = versions[0];\n\n // Create folder structure\n const schemaPath = await createSchemaFolder(schema.slug, schema.type, config.outputDir);\n\n // Combine schema info with version info\n const details: SchemaDetails = {\n id: schema.id,\n slug: schema.slug,\n name: schema.name,\n description: schema.description,\n type: schema.type,\n version: latestVersion.version,\n content: latestVersion.content,\n };\n\n // Write files\n await writeSchemaJson(schemaPath, details, config.targetVersion);\n await writeTokenScriptFiles(schemaPath, details);\n await createUnitTestStub(schemaPath, schema.name, schema.type);\n\n console.log(`✓ Downloaded ${schema.slug} to ${schemaPath}`);\n}\n\n/**\n * Download all schemas from the API\n */\nexport async function downloadAllSchemas(config: Partial<SchemaConfig> = {}): Promise<void> {\n const fullConfig = { ...DEFAULT_CONFIG, ...config };\n\n // Fetch schema list\n const schemas = await fetchSchemaList(fullConfig);\n\n // Download each schema\n for (const schema of schemas) {\n try {\n await downloadSchema(schema, fullConfig);\n } catch (error) {\n console.error(`Failed to download ${schema.slug}:`, error);\n }\n }\n\n console.log(\"\\n✓ All schemas downloaded successfully!\");\n}\n\nexport { DEFAULT_CONFIG };\nexport type * from \"@/downloader/types.js\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokens-studio/tokenscript-schemas",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Schema registry for TokenScript with bundled schemas and validation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -46,6 +46,8 @@
|
|
|
46
46
|
"format:check": "biome format .",
|
|
47
47
|
"fix": "biome check --write .",
|
|
48
48
|
"ts:typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.tests.json && tsc --noEmit -p tsconfig.scripts.json",
|
|
49
|
+
"cli": "tsx src/cli/index.ts",
|
|
50
|
+
"cli:presets": "tsx src/cli/index.ts",
|
|
49
51
|
"download": "tsx scripts/download-schemas.ts",
|
|
50
52
|
"update-versions": "tsx scripts/update-versions.ts",
|
|
51
53
|
"bundle": "tsx scripts/bundle-schemas.ts",
|
|
@@ -67,7 +69,7 @@
|
|
|
67
69
|
"author": "Tokens Studio (https://tokens.studio)",
|
|
68
70
|
"license": "MPL-2.0",
|
|
69
71
|
"dependencies": {
|
|
70
|
-
"@tokens-studio/tokenscript-interpreter": "^0.
|
|
72
|
+
"@tokens-studio/tokenscript-interpreter": "^0.17.1",
|
|
71
73
|
"arktype": "^2.1.25",
|
|
72
74
|
"cac": "^6.7.14",
|
|
73
75
|
"ulog": "^2.0.0-beta.19"
|
package/src/bundler/index.ts
CHANGED
|
@@ -87,6 +87,7 @@ async function bundleFunctionCategory(categoryDir: string): Promise<FunctionSpec
|
|
|
87
87
|
export async function bundleAllSchemas(
|
|
88
88
|
schemasDir: string,
|
|
89
89
|
outputDir: string,
|
|
90
|
+
options?: { cliArgs?: string[] },
|
|
90
91
|
): Promise<BundledRegistry> {
|
|
91
92
|
// Bundle types
|
|
92
93
|
console.log("\nBundling type schemas...");
|
|
@@ -101,6 +102,11 @@ export async function bundleAllSchemas(
|
|
|
101
102
|
console.log(`✓ Bundled ${functions.length} function schemas`);
|
|
102
103
|
|
|
103
104
|
// Create bundled registry
|
|
105
|
+
const baseCommand = "npx @tokens-studio/tokenscript-schemas bundle";
|
|
106
|
+
const generatedBy = options?.cliArgs?.length
|
|
107
|
+
? `${baseCommand} ${options.cliArgs.join(" ")}`
|
|
108
|
+
: baseCommand;
|
|
109
|
+
|
|
104
110
|
const registry: BundledRegistry = {
|
|
105
111
|
version: "0.0.10",
|
|
106
112
|
types,
|
|
@@ -108,6 +114,7 @@ export async function bundleAllSchemas(
|
|
|
108
114
|
metadata: {
|
|
109
115
|
generatedAt: new Date().toISOString(),
|
|
110
116
|
totalSchemas: types.length + functions.length,
|
|
117
|
+
generatedBy,
|
|
111
118
|
},
|
|
112
119
|
};
|
|
113
120
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS preset - Modern CSS color types and functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { BundlePreset } from "./types";
|
|
6
|
+
|
|
7
|
+
export const css: BundlePreset = {
|
|
8
|
+
name: "CSS",
|
|
9
|
+
description: "CSS color types",
|
|
10
|
+
types: [
|
|
11
|
+
"hex-color",
|
|
12
|
+
"rgb-color",
|
|
13
|
+
"hsl-color",
|
|
14
|
+
"oklch-color",
|
|
15
|
+
"oklab-color",
|
|
16
|
+
|
|
17
|
+
// Converting colors to css strings
|
|
18
|
+
"css-color",
|
|
19
|
+
],
|
|
20
|
+
functions: ["lighten", "darken", "saturate", "desaturate", "mix", "invert"],
|
|
21
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundle presets - predefined sets of schemas for common use cases
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { css } from "./css";
|
|
6
|
+
import type { BundlePreset } from "./types";
|
|
7
|
+
|
|
8
|
+
export type { BundlePreset };
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Available bundle presets
|
|
12
|
+
*/
|
|
13
|
+
export const BUNDLE_PRESETS: Record<string, BundlePreset> = {
|
|
14
|
+
css,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Expand schemas, replacing "preset:name" with actual schema list
|
|
19
|
+
*/
|
|
20
|
+
export function expandPresetSchemas(schemas: string[]): string[] {
|
|
21
|
+
const expanded: string[] = [];
|
|
22
|
+
|
|
23
|
+
for (const schema of schemas) {
|
|
24
|
+
if (schema.startsWith("preset:")) {
|
|
25
|
+
const presetName = schema.slice(7); // Remove "preset:"
|
|
26
|
+
const preset = BUNDLE_PRESETS[presetName];
|
|
27
|
+
|
|
28
|
+
if (preset) {
|
|
29
|
+
// Add all types from preset
|
|
30
|
+
for (const type of preset.types) {
|
|
31
|
+
expanded.push(type === "*" ? "*" : `type:${type}`);
|
|
32
|
+
}
|
|
33
|
+
// Add all functions from preset
|
|
34
|
+
for (const func of preset.functions) {
|
|
35
|
+
expanded.push(func === "*" ? "*" : `function:${func}`);
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
console.warn(`⚠ Unknown preset: ${presetName}`);
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
// Not a preset, keep as-is
|
|
42
|
+
expanded.push(schema);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return expanded;
|
|
47
|
+
}
|
|
@@ -17,6 +17,7 @@ export interface SelectiveBundleOptions {
|
|
|
17
17
|
schemas: string[]; // Schema slugs to bundle
|
|
18
18
|
schemasDir?: string; // Source directory (default: src/schemas)
|
|
19
19
|
baseUrl?: string; // Registry URL for URIs
|
|
20
|
+
cliArgs?: string[]; // CLI arguments used
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export interface BundledSchemaEntry {
|
|
@@ -30,6 +31,7 @@ export interface SelectiveBundleResult {
|
|
|
30
31
|
requestedSchemas: string[];
|
|
31
32
|
resolvedDependencies: string[];
|
|
32
33
|
generatedAt: string;
|
|
34
|
+
generatedBy?: string;
|
|
33
35
|
};
|
|
34
36
|
dependencyTree: Map<string, DependencyNode>;
|
|
35
37
|
}
|
|
@@ -147,12 +149,19 @@ export async function bundleSelectiveSchemas(
|
|
|
147
149
|
}
|
|
148
150
|
}
|
|
149
151
|
|
|
152
|
+
// Build generatedBy string if CLI args are provided
|
|
153
|
+
const baseCommand = "npx @tokens-studio/tokenscript-schemas bundle";
|
|
154
|
+
const generatedBy = options.cliArgs?.length
|
|
155
|
+
? `${baseCommand} ${options.cliArgs.join(" ")}`
|
|
156
|
+
: undefined;
|
|
157
|
+
|
|
150
158
|
return {
|
|
151
159
|
schemas: bundledSchemas,
|
|
152
160
|
metadata: {
|
|
153
161
|
requestedSchemas: options.schemas,
|
|
154
162
|
resolvedDependencies: allSchemas,
|
|
155
163
|
generatedAt: new Date().toISOString(),
|
|
164
|
+
generatedBy,
|
|
156
165
|
},
|
|
157
166
|
dependencyTree,
|
|
158
167
|
};
|
package/src/bundler/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { expandPresetSchemas } from "@/bundler/presets/index.js";
|
|
2
3
|
import { bundleSchemas } from "./bundle.js";
|
|
3
4
|
|
|
4
5
|
// Mock ulog to silence logs during tests
|
|
@@ -54,4 +55,37 @@ describe("Bundle Command", () => {
|
|
|
54
55
|
expect(result.output).toContain("Auto-generated by @tokens-studio/tokenscript-schemas");
|
|
55
56
|
expect(result.output).toContain("Generated:");
|
|
56
57
|
});
|
|
58
|
+
|
|
59
|
+
describe("Presets", () => {
|
|
60
|
+
it("should expand preset:css to schema list", () => {
|
|
61
|
+
const result = expandPresetSchemas(["preset:css"]);
|
|
62
|
+
|
|
63
|
+
expect(result).toContain("type:hex-color");
|
|
64
|
+
expect(result).toContain("type:rgb-color");
|
|
65
|
+
expect(result).toContain("type:hsl-color");
|
|
66
|
+
expect(result).toContain("type:oklch-color");
|
|
67
|
+
expect(result).toContain("type:css-color");
|
|
68
|
+
expect(result).toContain("function:lighten");
|
|
69
|
+
expect(result).toContain("function:darken");
|
|
70
|
+
expect(result.length).toBeGreaterThan(5);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should combine presets with specific schemas", () => {
|
|
74
|
+
const result = expandPresetSchemas(["preset:css", "type:lab-color"]);
|
|
75
|
+
|
|
76
|
+
expect(result).toContain("type:hex-color");
|
|
77
|
+
expect(result).toContain("type:lab-color");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("should handle unknown preset gracefully", () => {
|
|
81
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
82
|
+
|
|
83
|
+
const result = expandPresetSchemas(["preset:unknown"]);
|
|
84
|
+
|
|
85
|
+
expect(result).toEqual([]);
|
|
86
|
+
expect(warnSpy).toHaveBeenCalledWith("⚠ Unknown preset: unknown");
|
|
87
|
+
|
|
88
|
+
warnSpy.mockRestore();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
57
91
|
});
|
|
@@ -8,6 +8,7 @@ import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
|
8
8
|
import { dirname, join } from "node:path";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
import anylogger from "ulog";
|
|
11
|
+
import { expandPresetSchemas } from "@/bundler/presets/index.js";
|
|
11
12
|
import { bundleSelectiveSchemas } from "@/bundler/selective-bundler.js";
|
|
12
13
|
import { type BundleConfig, validateBundleConfig } from "@/cli/config-schema.js";
|
|
13
14
|
import { generateOutput } from "@/cli/output-generator.js";
|
|
@@ -117,27 +118,27 @@ function findSchemasDir(): string {
|
|
|
117
118
|
const __filename = fileURLToPath(import.meta.url);
|
|
118
119
|
const __dirname = dirname(__filename);
|
|
119
120
|
|
|
120
|
-
// From compiled dist/cli/index.js (bundled) to src/schemas
|
|
121
|
-
const fromDist = join(__dirname, "../../src/schemas");
|
|
122
|
-
|
|
123
121
|
// From source src/cli/commands/bundle.ts to src/schemas (for tests/dev)
|
|
124
122
|
const fromSource = join(__dirname, "../../schemas");
|
|
125
123
|
|
|
126
|
-
//
|
|
124
|
+
// From compiled dist/cli/commands/bundle.js to src/schemas
|
|
125
|
+
const fromDist = join(__dirname, "../../../src/schemas");
|
|
126
|
+
|
|
127
|
+
// Try to detect which one exists (check source first for dev)
|
|
127
128
|
try {
|
|
128
129
|
const fs = require("node:fs");
|
|
129
|
-
if (fs.existsSync(fromDist)) {
|
|
130
|
-
return fromDist;
|
|
131
|
-
}
|
|
132
130
|
if (fs.existsSync(fromSource)) {
|
|
133
131
|
return fromSource;
|
|
134
132
|
}
|
|
133
|
+
if (fs.existsSync(fromDist)) {
|
|
134
|
+
return fromDist;
|
|
135
|
+
}
|
|
135
136
|
} catch {
|
|
136
|
-
// If fs checks fail, default to
|
|
137
|
+
// If fs checks fail, default to source structure
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
// Default to
|
|
140
|
-
return
|
|
140
|
+
// Default to source structure (for development)
|
|
141
|
+
return fromSource;
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
/**
|
|
@@ -146,6 +147,7 @@ function findSchemasDir(): string {
|
|
|
146
147
|
export async function bundleSchemas(
|
|
147
148
|
schemas: string[],
|
|
148
149
|
schemasDir?: string,
|
|
150
|
+
cliArgs?: string[],
|
|
149
151
|
): Promise<{
|
|
150
152
|
output: string;
|
|
151
153
|
metadata: any;
|
|
@@ -161,6 +163,7 @@ export async function bundleSchemas(
|
|
|
161
163
|
const result = await bundleSelectiveSchemas({
|
|
162
164
|
schemas,
|
|
163
165
|
schemasDir: resolvedSchemasDir,
|
|
166
|
+
cliArgs,
|
|
164
167
|
});
|
|
165
168
|
|
|
166
169
|
log.info(
|
|
@@ -171,6 +174,7 @@ export async function bundleSchemas(
|
|
|
171
174
|
const output = generateOutput({
|
|
172
175
|
schemas: result.schemas,
|
|
173
176
|
includeHelper: true,
|
|
177
|
+
generatedBy: result.metadata.generatedBy,
|
|
174
178
|
});
|
|
175
179
|
|
|
176
180
|
return {
|
|
@@ -206,8 +210,30 @@ export async function handleBundleCommand(
|
|
|
206
210
|
throw new Error("No schemas specified. Provide schemas as arguments or via --config");
|
|
207
211
|
}
|
|
208
212
|
|
|
213
|
+
// Expand any presets (preset:name -> list of schemas)
|
|
214
|
+
configSchemas = expandPresetSchemas(configSchemas);
|
|
215
|
+
|
|
216
|
+
// Build CLI args array for generatedBy metadata
|
|
217
|
+
const cliArgs: string[] = [];
|
|
218
|
+
if (schemas.length > 0) {
|
|
219
|
+
cliArgs.push(...schemas);
|
|
220
|
+
}
|
|
221
|
+
if (options.config) {
|
|
222
|
+
cliArgs.push("--config", options.config);
|
|
223
|
+
}
|
|
224
|
+
if (options.output) {
|
|
225
|
+
cliArgs.push("--output", options.output);
|
|
226
|
+
}
|
|
227
|
+
if (options.dryRun) {
|
|
228
|
+
cliArgs.push("--dry-run");
|
|
229
|
+
}
|
|
230
|
+
|
|
209
231
|
// Bundle schemas
|
|
210
|
-
const { output, metadata, dependencyTree } = await bundleSchemas(
|
|
232
|
+
const { output, metadata, dependencyTree } = await bundleSchemas(
|
|
233
|
+
configSchemas,
|
|
234
|
+
undefined,
|
|
235
|
+
cliArgs,
|
|
236
|
+
);
|
|
211
237
|
|
|
212
238
|
// Show dependency tree
|
|
213
239
|
console.log("");
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presets command - list available bundle presets
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/// <reference types="../../../types/ulog" />
|
|
6
|
+
|
|
7
|
+
import anylogger from "ulog";
|
|
8
|
+
import { BUNDLE_PRESETS } from "@/bundler/presets/index";
|
|
9
|
+
|
|
10
|
+
const log = anylogger("presets");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Format preset information for display
|
|
14
|
+
*/
|
|
15
|
+
function formatPresetInfo(): string {
|
|
16
|
+
const lines: string[] = [];
|
|
17
|
+
|
|
18
|
+
lines.push("=".repeat(60));
|
|
19
|
+
lines.push("Available Bundle Presets");
|
|
20
|
+
lines.push("=".repeat(60));
|
|
21
|
+
|
|
22
|
+
for (const [key, preset] of Object.entries(BUNDLE_PRESETS)) {
|
|
23
|
+
lines.push("");
|
|
24
|
+
lines.push(`preset:${key}`);
|
|
25
|
+
lines.push(` ${preset.description}`);
|
|
26
|
+
|
|
27
|
+
// Types section
|
|
28
|
+
const typesCount =
|
|
29
|
+
preset.types.length === 1 && preset.types[0] === "*" ? "all" : preset.types.length;
|
|
30
|
+
lines.push("");
|
|
31
|
+
lines.push(` Types (${typesCount}):`);
|
|
32
|
+
if (preset.types.length > 0 && preset.types[0] !== "*") {
|
|
33
|
+
for (const type of preset.types) {
|
|
34
|
+
lines.push(` - ${type}`);
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
lines.push(` - all`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Functions section
|
|
41
|
+
const functionsCount =
|
|
42
|
+
preset.functions.length === 1 && preset.functions[0] === "*"
|
|
43
|
+
? "all"
|
|
44
|
+
: preset.functions.length;
|
|
45
|
+
lines.push("");
|
|
46
|
+
lines.push(` Functions (${functionsCount}):`);
|
|
47
|
+
if (preset.functions.length > 0 && preset.functions[0] !== "*") {
|
|
48
|
+
for (const func of preset.functions) {
|
|
49
|
+
lines.push(` - ${func}`);
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
lines.push(` - all`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
lines.push("");
|
|
57
|
+
lines.push("=".repeat(60));
|
|
58
|
+
lines.push("Usage Examples:");
|
|
59
|
+
lines.push("=".repeat(60));
|
|
60
|
+
lines.push("npx tokenscript-schemas bundle preset:css");
|
|
61
|
+
lines.push("npx tokenscript-schemas bundle preset:css type:oklab-color");
|
|
62
|
+
lines.push("npx tokenscript-schemas bundle type:hex-color function:lighten");
|
|
63
|
+
lines.push("");
|
|
64
|
+
lines.push("Note: You can combine multiple presets and specific schemas!");
|
|
65
|
+
|
|
66
|
+
return lines.join("\n");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function handlePresetsCommand(): Promise<void> {
|
|
70
|
+
try {
|
|
71
|
+
log.info("Listing available presets");
|
|
72
|
+
|
|
73
|
+
const output = formatPresetInfo();
|
|
74
|
+
console.log(output);
|
|
75
|
+
|
|
76
|
+
log.info(`Listed ${Object.keys(BUNDLE_PRESETS).length} presets`);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
log.error("Failed to list presets:", error);
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
package/src/cli/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import cac from "cac";
|
|
|
10
10
|
import anylogger from "ulog";
|
|
11
11
|
import { type BundleOptions, handleBundleCommand } from "./commands/bundle.js";
|
|
12
12
|
import { handleListCommand, type ListOptions } from "./commands/list.js";
|
|
13
|
+
import { handlePresetsCommand } from "./commands/presets.js";
|
|
13
14
|
|
|
14
15
|
const log = anylogger("cli");
|
|
15
16
|
|
|
@@ -44,6 +45,16 @@ cli
|
|
|
44
45
|
}
|
|
45
46
|
});
|
|
46
47
|
|
|
48
|
+
// Presets command
|
|
49
|
+
cli.command("presets", "List available bundle presets").action(async () => {
|
|
50
|
+
try {
|
|
51
|
+
await handlePresetsCommand();
|
|
52
|
+
} catch (error) {
|
|
53
|
+
log.error("Error:", error);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
47
58
|
cli.help();
|
|
48
59
|
cli.version("0.0.14");
|
|
49
60
|
|