@tokens-studio/tokenscript-schemas 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -7
- package/dist/cli/index.cjs +142 -88
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +141 -87
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +19 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +19 -19
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/bundler/{bundle-schema.ts → build-schema.ts} +2 -2
- package/src/bundler/index.ts +25 -25
- package/src/bundler/schema-dependency-resolver.ts +3 -3
- package/src/bundler/selective-bundler.ts +3 -3
- package/src/cli/commands/build-dir.test.ts +354 -0
- package/src/cli/commands/build-dir.ts +90 -0
- package/src/cli/commands/bundle.test.ts +95 -1
- package/src/cli/commands/bundle.ts +22 -15
- package/src/cli/index.ts +16 -0
- package/bundled/functions/adjust_chroma.json +0 -60
- package/bundled/functions/adjust_hue.json +0 -60
- package/bundled/functions/adjust_lightness.json +0 -60
- package/bundled/functions/adjust_to_contrast.json +0 -67
- package/bundled/functions/alpha_blend.json +0 -31
- package/bundled/functions/alpha_scale.json +0 -27
- package/bundled/functions/analogous.json +0 -32
- package/bundled/functions/apca_contrast.json +0 -27
- package/bundled/functions/are_similar.json +0 -73
- package/bundled/functions/auto_text_color.json +0 -66
- package/bundled/functions/best_contrast.json +0 -28
- package/bundled/functions/chroma.json +0 -54
- package/bundled/functions/clamp_chroma.json +0 -66
- package/bundled/functions/clamp_lightness.json +0 -66
- package/bundled/functions/clamp_to_gamut.json +0 -23
- package/bundled/functions/complement.json +0 -24
- package/bundled/functions/contrast_ratio.json +0 -27
- package/bundled/functions/cooler.json +0 -52
- package/bundled/functions/darken.json +0 -28
- package/bundled/functions/delta_e_2000.json +0 -40
- package/bundled/functions/delta_e_76.json +0 -27
- package/bundled/functions/delta_e_ok.json +0 -27
- package/bundled/functions/desaturate.json +0 -28
- package/bundled/functions/distributed.json +0 -36
- package/bundled/functions/diverging.json +0 -36
- package/bundled/functions/grayscale.json +0 -24
- package/bundled/functions/harmonize.json +0 -65
- package/bundled/functions/hue.json +0 -54
- package/bundled/functions/hue_difference.json +0 -27
- package/bundled/functions/in_gamut.json +0 -27
- package/bundled/functions/interpolate.json +0 -66
- package/bundled/functions/invert.json +0 -23
- package/bundled/functions/is_cool.json +0 -23
- package/bundled/functions/is_dark.json +0 -27
- package/bundled/functions/is_light.json +0 -27
- package/bundled/functions/is_neutral.json +0 -65
- package/bundled/functions/is_warm.json +0 -23
- package/bundled/functions/lighten.json +0 -28
- package/bundled/functions/lightness.json +0 -61
- package/bundled/functions/luminance.json +0 -23
- package/bundled/functions/meets_contrast.json +0 -31
- package/bundled/functions/mix.json +0 -32
- package/bundled/functions/monochromatic.json +0 -28
- package/bundled/functions/muted.json +0 -59
- package/bundled/functions/neutral_variant.json +0 -59
- package/bundled/functions/relative_luminance.json +0 -61
- package/bundled/functions/rotate_hue.json +0 -28
- package/bundled/functions/saturate.json +0 -28
- package/bundled/functions/scale_chroma.json +0 -60
- package/bundled/functions/scale_lightness.json +0 -60
- package/bundled/functions/sepia.json +0 -59
- package/bundled/functions/set_chroma.json +0 -28
- package/bundled/functions/set_hue.json +0 -28
- package/bundled/functions/set_lightness.json +0 -28
- package/bundled/functions/shade_scale.json +0 -28
- package/bundled/functions/split_complement.json +0 -28
- package/bundled/functions/steps.json +0 -32
- package/bundled/functions/tetradic.json +0 -24
- package/bundled/functions/tint_scale.json +0 -36
- package/bundled/functions/to_gamut.json +0 -59
- package/bundled/functions/triadic.json +0 -24
- package/bundled/functions/vibrant.json +0 -59
- package/bundled/functions/warmer.json +0 -52
- package/bundled/functions/wcag_level.json +0 -60
- package/bundled/functions.json +0 -2624
- package/bundled/registry.json +0 -3833
- package/bundled/types/css-color.json +0 -151
- package/bundled/types/hex-color.json +0 -25
- package/bundled/types/hsl-color.json +0 -66
- package/bundled/types/hsv-color.json +0 -57
- package/bundled/types/hwb-color.json +0 -66
- package/bundled/types/lab-color.json +0 -57
- package/bundled/types/lch-color.json +0 -57
- package/bundled/types/okhsl-color.json +0 -57
- package/bundled/types/okhsv-color.json +0 -57
- package/bundled/types/oklab-color.json +0 -87
- package/bundled/types/oklch-color.json +0 -57
- package/bundled/types/p3-color.json +0 -57
- package/bundled/types/p3-linear-color.json +0 -57
- package/bundled/types/rgb-color.json +0 -73
- package/bundled/types/srgb-color.json +0 -77
- package/bundled/types/srgb-linear-color.json +0 -67
- package/bundled/types/xyz-d50-color.json +0 -57
- package/bundled/types/xyz-d65-color.json +0 -77
- package/bundled/types.json +0 -1207
package/dist/index.cjs.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","readFile","stat","readdir","mkdir","writeFile"],"mappings":";;;;;;AA0BA,eAAsB,yBAAA,CACpB,WACA,OAAA,EAC8B;AAE9B,EAAA,MAAM,cAAA,GAAiBA,SAAA,CAAK,SAAA,EAAW,aAAa,CAAA;AACpD,EAAA,MAAM,aAAA,GAAgB,MAAMC,iBAAA,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,MAA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,EAAA,MAAM,eAAA,CAAgB,UAAA,EAAY,OAAA,EAAS,MAAA,CAAO,aAAa,CAAA;AAC/D,EAAA,MAAM,qBAAA,CAAsB,YAAY,OAAO,CAAA;AAC/C,EAAA,MAAM,kBAAA,CAAmB,UAAA,EAAY,MAAA,CAAO,IAAA,EAAM,OAAO,IAAI,CAAA;AAE7D,EAAA,OAAA,CAAQ,IAAI,CAAA,kBAAA,EAAgB,MAAA,CAAO,IAAI,CAAA,IAAA,EAAO,UAAU,CAAA,CAAE,CAAA;AAC5D;AAKA,eAAsB,kBAAA,CAAmB,MAAA,GAAgC,EAAC,EAAkB;AAC1F,EAAA,MAAM,UAAA,GAAa,EAAE,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.cjs","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"]}
|
|
1
|
+
{"version":3,"sources":["../src/bundler/build-schema.ts","../src/bundler/utils.ts","../src/bundler/index.ts","../src/downloader/index.ts"],"names":["join","readFile","stat","readdir","mkdir","writeFile"],"mappings":";;;;;;AA0BA,eAAsB,wBAAA,CACpB,WACA,OAAA,EAC8B;AAE9B,EAAA,MAAM,cAAA,GAAiBA,SAAA,CAAK,SAAA,EAAW,aAAa,CAAA;AACpD,EAAA,MAAM,aAAA,GAAgB,MAAMC,iBAAA,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,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AAa,CAAA;AAC/D,EAAA,MAAM,qBAAA,CAAsB,YAAY,OAAO,CAAA;AAC/C,EAAA,MAAM,kBAAA,CAAmB,UAAA,EAAY,MAAA,CAAO,IAAA,EAAM,OAAO,IAAI,CAAA;AAE7D,EAAA,OAAA,CAAQ,IAAI,CAAA,kBAAA,EAAgB,MAAA,CAAO,IAAI,CAAA,IAAA,EAAO,UAAU,CAAA,CAAE,CAAA;AAC5D;AAKA,eAAsB,kBAAA,CAAmB,MAAA,GAAgC,EAAC,EAAkB;AAC1F,EAAA,MAAM,UAAA,GAAa,EAAE,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.cjs","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 build logic shared by build and runtime\n */\nexport async function buildSchemaFromDirectory(\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 { buildSchemaFromDirectory } from \"@/bundler/build-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 * Build a single schema from its directory\n */\nasync function buildSchema(schemaDir: string, schemaSlug: string): Promise<SchemaSpecification> {\n // Use shared build logic with baseUrl for build-time\n const bundled = await buildSchemaFromDirectory(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 * Build all color type schemas from a category directory\n */\nasync function buildTypeCategory(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(` Building ${slug}...`);\n\n try {\n const bundle = await buildSchema(schemaDir, slug);\n if (bundle.type === \"color\") {\n bundles.push(bundle as ColorSpecification);\n }\n } catch (error) {\n console.error(` ✗ Failed to build ${slug}:`, error);\n }\n }\n\n return bundles;\n}\n\n/**\n * Build all function schemas from a category directory\n */\nasync function buildFunctionCategory(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(` Building ${slug}...`);\n\n try {\n const bundle = await buildSchema(schemaDir, slug);\n if (bundle.type === \"function\") {\n bundles.push(bundle as FunctionSpecification);\n }\n } catch (error) {\n console.error(` ✗ Failed to build ${slug}:`, error);\n }\n }\n\n return bundles;\n}\n\n/**\n * Build all schemas from the schemas directory\n */\nexport async function buildAllSchemas(\n schemasDir: string,\n outputDir: string,\n options?: { cliArgs?: string[] },\n): Promise<BundledRegistry> {\n // Build types\n console.log(\"\\nBuilding type schemas...\");\n const typesDir = join(schemasDir, \"types\");\n const types = await buildTypeCategory(typesDir);\n console.log(`✓ Built ${types.length} type schemas`);\n\n // Build functions\n console.log(\"\\nBuilding function schemas...\");\n const functionsDir = join(schemasDir, \"functions\");\n const functions = await buildFunctionCategory(functionsDir);\n console.log(`✓ Built ${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/dist/index.d.cts
CHANGED
|
@@ -86,9 +86,9 @@ interface BundledRegistry {
|
|
|
86
86
|
*/
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
89
|
+
* Build all schemas from the schemas directory
|
|
90
90
|
*/
|
|
91
|
-
declare function
|
|
91
|
+
declare function buildAllSchemas(schemasDir: string, outputDir: string, options?: {
|
|
92
92
|
cliArgs?: string[];
|
|
93
93
|
}): Promise<BundledRegistry>;
|
|
94
94
|
|
|
@@ -158,4 +158,4 @@ declare function downloadSchema(schema: SchemaListItem, config?: SchemaConfig):
|
|
|
158
158
|
*/
|
|
159
159
|
declare function downloadAllSchemas(config?: Partial<SchemaConfig>): Promise<void>;
|
|
160
160
|
|
|
161
|
-
export { type BundledRegistry, type ColorSpecification, type Conversion, DEFAULT_CONFIG, type FunctionSpecification, type Initializer, type LatestVersion, type SchemaBundle, type SchemaConfig, type SchemaDetails, type SchemaFile, type SchemaListItem, type SchemaSpecification, type SchemaVersion, type ScriptBlock, type SpecProperty, type SpecSchema,
|
|
161
|
+
export { type BundledRegistry, type ColorSpecification, type Conversion, DEFAULT_CONFIG, type FunctionSpecification, type Initializer, type LatestVersion, type SchemaBundle, type SchemaConfig, type SchemaDetails, type SchemaFile, type SchemaListItem, type SchemaSpecification, type SchemaVersion, type ScriptBlock, type SpecProperty, type SpecSchema, buildAllSchemas, downloadAllSchemas, downloadSchema, fetchSchemaList, fetchSchemaVersions };
|
package/dist/index.d.ts
CHANGED
|
@@ -86,9 +86,9 @@ interface BundledRegistry {
|
|
|
86
86
|
*/
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
89
|
+
* Build all schemas from the schemas directory
|
|
90
90
|
*/
|
|
91
|
-
declare function
|
|
91
|
+
declare function buildAllSchemas(schemasDir: string, outputDir: string, options?: {
|
|
92
92
|
cliArgs?: string[];
|
|
93
93
|
}): Promise<BundledRegistry>;
|
|
94
94
|
|
|
@@ -158,4 +158,4 @@ declare function downloadSchema(schema: SchemaListItem, config?: SchemaConfig):
|
|
|
158
158
|
*/
|
|
159
159
|
declare function downloadAllSchemas(config?: Partial<SchemaConfig>): Promise<void>;
|
|
160
160
|
|
|
161
|
-
export { type BundledRegistry, type ColorSpecification, type Conversion, DEFAULT_CONFIG, type FunctionSpecification, type Initializer, type LatestVersion, type SchemaBundle, type SchemaConfig, type SchemaDetails, type SchemaFile, type SchemaListItem, type SchemaSpecification, type SchemaVersion, type ScriptBlock, type SpecProperty, type SpecSchema,
|
|
161
|
+
export { type BundledRegistry, type ColorSpecification, type Conversion, DEFAULT_CONFIG, type FunctionSpecification, type Initializer, type LatestVersion, type SchemaBundle, type SchemaConfig, type SchemaDetails, type SchemaFile, type SchemaListItem, type SchemaSpecification, type SchemaVersion, type ScriptBlock, type SpecProperty, type SpecSchema, buildAllSchemas, downloadAllSchemas, downloadSchema, fetchSchemaList, fetchSchemaVersions };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { mkdir, writeFile, readdir, stat, readFile } from 'fs/promises';
|
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
|
|
4
4
|
// src/bundler/index.ts
|
|
5
|
-
async function
|
|
5
|
+
async function buildSchemaFromDirectory(schemaDir, options) {
|
|
6
6
|
const schemaJsonPath = join(schemaDir, "schema.json");
|
|
7
7
|
const schemaContent = await readFile(schemaJsonPath, "utf-8");
|
|
8
8
|
const schema = JSON.parse(schemaContent);
|
|
@@ -94,56 +94,56 @@ async function getSubdirectories(dir) {
|
|
|
94
94
|
|
|
95
95
|
// src/bundler/index.ts
|
|
96
96
|
var DEFAULT_REGISTRY_URL = "https://schema.tokenscript.dev.gcp.tokens.studio";
|
|
97
|
-
async function
|
|
98
|
-
const bundled = await
|
|
97
|
+
async function buildSchema(schemaDir, schemaSlug) {
|
|
98
|
+
const bundled = await buildSchemaFromDirectory(schemaDir, {
|
|
99
99
|
baseUrl: DEFAULT_REGISTRY_URL
|
|
100
100
|
});
|
|
101
101
|
bundled.slug = schemaSlug;
|
|
102
102
|
return bundled;
|
|
103
103
|
}
|
|
104
|
-
async function
|
|
104
|
+
async function buildTypeCategory(categoryDir) {
|
|
105
105
|
const bundles = [];
|
|
106
106
|
const schemaSlugs = await getSubdirectories(categoryDir);
|
|
107
107
|
for (const slug of schemaSlugs) {
|
|
108
108
|
const schemaDir = join(categoryDir, slug);
|
|
109
|
-
console.log(`
|
|
109
|
+
console.log(` Building ${slug}...`);
|
|
110
110
|
try {
|
|
111
|
-
const bundle = await
|
|
111
|
+
const bundle = await buildSchema(schemaDir, slug);
|
|
112
112
|
if (bundle.type === "color") {
|
|
113
113
|
bundles.push(bundle);
|
|
114
114
|
}
|
|
115
115
|
} catch (error) {
|
|
116
|
-
console.error(` \u2717 Failed to
|
|
116
|
+
console.error(` \u2717 Failed to build ${slug}:`, error);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
return bundles;
|
|
120
120
|
}
|
|
121
|
-
async function
|
|
121
|
+
async function buildFunctionCategory(categoryDir) {
|
|
122
122
|
const bundles = [];
|
|
123
123
|
const schemaSlugs = await getSubdirectories(categoryDir);
|
|
124
124
|
for (const slug of schemaSlugs) {
|
|
125
125
|
const schemaDir = join(categoryDir, slug);
|
|
126
|
-
console.log(`
|
|
126
|
+
console.log(` Building ${slug}...`);
|
|
127
127
|
try {
|
|
128
|
-
const bundle = await
|
|
128
|
+
const bundle = await buildSchema(schemaDir, slug);
|
|
129
129
|
if (bundle.type === "function") {
|
|
130
130
|
bundles.push(bundle);
|
|
131
131
|
}
|
|
132
132
|
} catch (error) {
|
|
133
|
-
console.error(` \u2717 Failed to
|
|
133
|
+
console.error(` \u2717 Failed to build ${slug}:`, error);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
return bundles;
|
|
137
137
|
}
|
|
138
|
-
async function
|
|
139
|
-
console.log("\
|
|
138
|
+
async function buildAllSchemas(schemasDir, outputDir, options) {
|
|
139
|
+
console.log("\nBuilding type schemas...");
|
|
140
140
|
const typesDir = join(schemasDir, "types");
|
|
141
|
-
const types = await
|
|
142
|
-
console.log(`\u2713
|
|
143
|
-
console.log("\
|
|
141
|
+
const types = await buildTypeCategory(typesDir);
|
|
142
|
+
console.log(`\u2713 Built ${types.length} type schemas`);
|
|
143
|
+
console.log("\nBuilding function schemas...");
|
|
144
144
|
const functionsDir = join(schemasDir, "functions");
|
|
145
|
-
const functions = await
|
|
146
|
-
console.log(`\u2713
|
|
145
|
+
const functions = await buildFunctionCategory(functionsDir);
|
|
146
|
+
console.log(`\u2713 Built ${functions.length} function schemas`);
|
|
147
147
|
const baseCommand = "npx @tokens-studio/tokenscript-schemas bundle";
|
|
148
148
|
const generatedBy = options?.cliArgs?.length ? `${baseCommand} ${options.cliArgs.join(" ")}` : baseCommand;
|
|
149
149
|
const registry = {
|
|
@@ -324,6 +324,6 @@ async function downloadAllSchemas(config = {}) {
|
|
|
324
324
|
console.log("\n\u2713 All schemas downloaded successfully!");
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
-
export { DEFAULT_CONFIG,
|
|
327
|
+
export { DEFAULT_CONFIG, buildAllSchemas, downloadAllSchemas, downloadSchema, fetchSchemaList, fetchSchemaVersions };
|
|
328
328
|
//# sourceMappingURL=index.js.map
|
|
329
329
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bundler/bundle-schema.ts","../src/bundler/utils.ts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,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 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"]}
|
|
1
|
+
{"version":3,"sources":["../src/bundler/build-schema.ts","../src/bundler/utils.ts","../src/bundler/index.ts","../src/downloader/index.ts"],"names":["join","mkdir","writeFile"],"mappings":";;;;AA0BA,eAAsB,wBAAA,CACpB,WACA,OAAA,EAC8B;AAE9B,EAAA,MAAM,c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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 build logic shared by build and runtime\n */\nexport async function buildSchemaFromDirectory(\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 { buildSchemaFromDirectory } from \"@/bundler/build-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 * Build a single schema from its directory\n */\nasync function buildSchema(schemaDir: string, schemaSlug: string): Promise<SchemaSpecification> {\n // Use shared build logic with baseUrl for build-time\n const bundled = await buildSchemaFromDirectory(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 * Build all color type schemas from a category directory\n */\nasync function buildTypeCategory(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(` Building ${slug}...`);\n\n try {\n const bundle = await buildSchema(schemaDir, slug);\n if (bundle.type === \"color\") {\n bundles.push(bundle as ColorSpecification);\n }\n } catch (error) {\n console.error(` ✗ Failed to build ${slug}:`, error);\n }\n }\n\n return bundles;\n}\n\n/**\n * Build all function schemas from a category directory\n */\nasync function buildFunctionCategory(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(` Building ${slug}...`);\n\n try {\n const bundle = await buildSchema(schemaDir, slug);\n if (bundle.type === \"function\") {\n bundles.push(bundle as FunctionSpecification);\n }\n } catch (error) {\n console.error(` ✗ Failed to build ${slug}:`, error);\n }\n }\n\n return bundles;\n}\n\n/**\n * Build all schemas from the schemas directory\n */\nexport async function buildAllSchemas(\n schemasDir: string,\n outputDir: string,\n options?: { cliArgs?: string[] },\n): Promise<BundledRegistry> {\n // Build types\n console.log(\"\\nBuilding type schemas...\");\n const typesDir = join(schemasDir, \"types\");\n const types = await buildTypeCategory(typesDir);\n console.log(`✓ Built ${types.length} type schemas`);\n\n // Build functions\n console.log(\"\\nBuilding function schemas...\");\n const functionsDir = join(schemasDir, \"functions\");\n const functions = await buildFunctionCategory(functionsDir);\n console.log(`✓ Built ${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.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Schema registry for TokenScript with bundled schemas and validation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"files": [
|
|
24
24
|
"dist",
|
|
25
25
|
"src",
|
|
26
|
-
"
|
|
26
|
+
"result",
|
|
27
27
|
"README.md"
|
|
28
28
|
],
|
|
29
29
|
"sideEffects": false,
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"cli:presets": "tsx src/cli/index.ts",
|
|
51
51
|
"download": "tsx scripts/download-schemas.ts",
|
|
52
52
|
"update-versions": "tsx scripts/update-versions.ts",
|
|
53
|
-
"
|
|
53
|
+
"build-schemas": "tsx scripts/build-schemas.ts",
|
|
54
54
|
"push": "tsx scripts/push-to-registry.ts",
|
|
55
55
|
"demo:parity": "tsx scripts/generate-demo.ts",
|
|
56
56
|
"demo:advanced": "tsx scripts/generate-advanced-demo.ts",
|
|
@@ -22,9 +22,9 @@ export interface BundleOptions {
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Replace script file references with actual content
|
|
25
|
-
* This is the core
|
|
25
|
+
* This is the core build logic shared by build and runtime
|
|
26
26
|
*/
|
|
27
|
-
export async function
|
|
27
|
+
export async function buildSchemaFromDirectory(
|
|
28
28
|
schemaDir: string,
|
|
29
29
|
options?: BundleOptions,
|
|
30
30
|
): Promise<SchemaSpecification> {
|
package/src/bundler/index.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
6
6
|
import { join } from "node:path";
|
|
7
|
-
import {
|
|
7
|
+
import { buildSchemaFromDirectory } from "@/bundler/build-schema";
|
|
8
8
|
import type {
|
|
9
9
|
BundledRegistry,
|
|
10
10
|
ColorSpecification,
|
|
@@ -19,11 +19,11 @@ import { getSubdirectories } from "@/bundler/utils";
|
|
|
19
19
|
const DEFAULT_REGISTRY_URL = "https://schema.tokenscript.dev.gcp.tokens.studio";
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Build a single schema from its directory
|
|
23
23
|
*/
|
|
24
|
-
async function
|
|
25
|
-
// Use shared
|
|
26
|
-
const bundled = await
|
|
24
|
+
async function buildSchema(schemaDir: string, schemaSlug: string): Promise<SchemaSpecification> {
|
|
25
|
+
// Use shared build logic with baseUrl for build-time
|
|
26
|
+
const bundled = await buildSchemaFromDirectory(schemaDir, {
|
|
27
27
|
baseUrl: DEFAULT_REGISTRY_URL,
|
|
28
28
|
});
|
|
29
29
|
|
|
@@ -34,23 +34,23 @@ async function bundleSchema(schemaDir: string, schemaSlug: string): Promise<Sche
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* Build all color type schemas from a category directory
|
|
38
38
|
*/
|
|
39
|
-
async function
|
|
39
|
+
async function buildTypeCategory(categoryDir: string): Promise<ColorSpecification[]> {
|
|
40
40
|
const bundles: ColorSpecification[] = [];
|
|
41
41
|
const schemaSlugs = await getSubdirectories(categoryDir);
|
|
42
42
|
|
|
43
43
|
for (const slug of schemaSlugs) {
|
|
44
44
|
const schemaDir = join(categoryDir, slug);
|
|
45
|
-
console.log(`
|
|
45
|
+
console.log(` Building ${slug}...`);
|
|
46
46
|
|
|
47
47
|
try {
|
|
48
|
-
const bundle = await
|
|
48
|
+
const bundle = await buildSchema(schemaDir, slug);
|
|
49
49
|
if (bundle.type === "color") {
|
|
50
50
|
bundles.push(bundle as ColorSpecification);
|
|
51
51
|
}
|
|
52
52
|
} catch (error) {
|
|
53
|
-
console.error(` ✗ Failed to
|
|
53
|
+
console.error(` ✗ Failed to build ${slug}:`, error);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -58,23 +58,23 @@ async function bundleTypeCategory(categoryDir: string): Promise<ColorSpecificati
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* Build all function schemas from a category directory
|
|
62
62
|
*/
|
|
63
|
-
async function
|
|
63
|
+
async function buildFunctionCategory(categoryDir: string): Promise<FunctionSpecification[]> {
|
|
64
64
|
const bundles: FunctionSpecification[] = [];
|
|
65
65
|
const schemaSlugs = await getSubdirectories(categoryDir);
|
|
66
66
|
|
|
67
67
|
for (const slug of schemaSlugs) {
|
|
68
68
|
const schemaDir = join(categoryDir, slug);
|
|
69
|
-
console.log(`
|
|
69
|
+
console.log(` Building ${slug}...`);
|
|
70
70
|
|
|
71
71
|
try {
|
|
72
|
-
const bundle = await
|
|
72
|
+
const bundle = await buildSchema(schemaDir, slug);
|
|
73
73
|
if (bundle.type === "function") {
|
|
74
74
|
bundles.push(bundle as FunctionSpecification);
|
|
75
75
|
}
|
|
76
76
|
} catch (error) {
|
|
77
|
-
console.error(` ✗ Failed to
|
|
77
|
+
console.error(` ✗ Failed to build ${slug}:`, error);
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -82,24 +82,24 @@ async function bundleFunctionCategory(categoryDir: string): Promise<FunctionSpec
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
|
-
*
|
|
85
|
+
* Build all schemas from the schemas directory
|
|
86
86
|
*/
|
|
87
|
-
export async function
|
|
87
|
+
export async function buildAllSchemas(
|
|
88
88
|
schemasDir: string,
|
|
89
89
|
outputDir: string,
|
|
90
90
|
options?: { cliArgs?: string[] },
|
|
91
91
|
): Promise<BundledRegistry> {
|
|
92
|
-
//
|
|
93
|
-
console.log("\
|
|
92
|
+
// Build types
|
|
93
|
+
console.log("\nBuilding type schemas...");
|
|
94
94
|
const typesDir = join(schemasDir, "types");
|
|
95
|
-
const types = await
|
|
96
|
-
console.log(`✓
|
|
95
|
+
const types = await buildTypeCategory(typesDir);
|
|
96
|
+
console.log(`✓ Built ${types.length} type schemas`);
|
|
97
97
|
|
|
98
|
-
//
|
|
99
|
-
console.log("\
|
|
98
|
+
// Build functions
|
|
99
|
+
console.log("\nBuilding function schemas...");
|
|
100
100
|
const functionsDir = join(schemasDir, "functions");
|
|
101
|
-
const functions = await
|
|
102
|
-
console.log(`✓
|
|
101
|
+
const functions = await buildFunctionCategory(functionsDir);
|
|
102
|
+
console.log(`✓ Built ${functions.length} function schemas`);
|
|
103
103
|
|
|
104
104
|
// Create bundled registry
|
|
105
105
|
const baseCommand = "npx @tokens-studio/tokenscript-schemas bundle";
|