Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion modules/graph-layers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.js"
},
"./graph-style-schema.json": "./dist/graph-style-schema.json",
"./graph-style-schema.cdn": {
"types": "./dist/graph-style-schema.cdn.d.ts",
"default": "./dist/graph-style-schema.cdn.js"
}
},
"files": [
"dist",
"src"
],
"scripts": {
"build": "tsc -b tsconfig.json && node ./scripts/generate-graphstyle-schema.mjs",
"build:schema": "node ./scripts/generate-graphstyle-schema.mjs",
"test": "vitest run",
"test-watch": "vitest"
},
Expand Down Expand Up @@ -56,7 +63,8 @@
},
"devDependencies": {
"ngraph.generators": "^20.1.0",
"zod": "^4.0.0"
"zod": "^4.0.0",
"zod-to-json-schema": "^3.22.5"
},
"peerDependencies": {
"zod": "^3.23.8 || ^4.0.0"
Expand Down
67 changes: 67 additions & 0 deletions modules/graph-layers/scripts/generate-graphstyle-schema.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// deck.gl-community
// SPDX-License-Identifier: MIT

import {mkdir, readFile, writeFile} from 'node:fs/promises';
import {dirname, join, relative} from 'node:path';
import {fileURLToPath, pathToFileURL} from 'node:url';

import {zodToJsonSchema} from 'zod-to-json-schema';

const __dirname = dirname(fileURLToPath(import.meta.url));
const packageRoot = join(__dirname, '..');
const distDir = join(packageRoot, 'dist');

async function loadGraphStylesheetModule() {
const schemaPath = join(distDir, 'style', 'graph-stylesheet.schema.js');
try {
const moduleUrl = pathToFileURL(schemaPath).href;
return await import(moduleUrl);
} catch (error) {
const relativePath = relative(packageRoot, schemaPath);
throw new Error(
`Failed to import compiled schema from "${relativePath}". Ensure TypeScript build succeeds before running this script.\n${
error instanceof Error ? error.message : error
}`
);
}
}

async function createSchemaArtifacts() {
const module = await loadGraphStylesheetModule();
const {GraphStylesheetSchema} = module;
if (!GraphStylesheetSchema) {
throw new Error('GraphStylesheetSchema export not found.');
}

const packageJson = JSON.parse(await readFile(join(packageRoot, 'package.json'), 'utf8'));
const packageName = packageJson.name;
const packageVersion = packageJson.version;
const cdnUrl = `https://cdn.jsdelivr.net/npm/${packageName}@${packageVersion}/dist/graph-style-schema.json`;

const schema = zodToJsonSchema(GraphStylesheetSchema, 'GraphStylesheet');
const {definitions, ...schemaBody} = schema;

const jsonSchema = {
$schema: 'https://json-schema.org/draft/2020-12/schema',
$id: cdnUrl,
title: 'Deck.gl Graph Stylesheet',
description:
'JSON schema describing the declarative stylesheet format supported by @deck.gl-community/graph-layers.',
...schemaBody,
...(definitions ? {definitions} : {})
};

await mkdir(distDir, {recursive: true});
await writeFile(join(distDir, 'graph-style-schema.json'), JSON.stringify(jsonSchema, null, 2));

const cdnModule = `export const GRAPH_STYLE_SCHEMA_CDN_URL = '${cdnUrl}';\nexport default GRAPH_STYLE_SCHEMA_CDN_URL;\n`;
const cdnTypes = `export declare const GRAPH_STYLE_SCHEMA_CDN_URL: string;\nexport default GRAPH_STYLE_SCHEMA_CDN_URL;\n`;

await writeFile(join(distDir, 'graph-style-schema.cdn.js'), cdnModule);
await writeFile(join(distDir, 'graph-style-schema.cdn.d.ts'), cdnTypes);
}

createSchemaArtifacts().catch((error) => {
console.error(error);
process.exitCode = 1;
});
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,7 @@ __metadata:
"@luma.gl/core": "npm:~9.2.0"
"@luma.gl/engine": "npm:~9.2.0"
"@luma.gl/shadertools": "npm:~9.2.0"
preact: "npm:^10.17.0"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -1467,6 +1468,7 @@ __metadata:
preact: "npm:^10.17.0"
raf: "npm:^3.4.1"
zod: "npm:^4.0.0"
zod-to-json-schema: "npm:^3.22.5"
peerDependencies:
zod: ^3.23.8 || ^4.0.0
languageName: unknown
Expand Down Expand Up @@ -22268,6 +22270,15 @@ __metadata:
languageName: node
linkType: hard

"zod-to-json-schema@npm:^3.22.5":
version: 3.24.6
resolution: "zod-to-json-schema@npm:3.24.6"
peerDependencies:
zod: ^3.24.1
checksum: 10c0/b907ab6d057100bd25a37e5545bf5f0efa5902cd84d3c3ec05c2e51541431a47bd9bf1e5e151a244273409b45f5986d55b26e5d207f98abc5200702f733eb368
languageName: node
linkType: hard

"zod@npm:^4.0.0":
version: 4.1.12
resolution: "zod@npm:4.1.12"
Expand Down