Skip to content

Commit

Permalink
generate a style from a custom theme .ts file [#261]
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon committed Sep 3, 2024
1 parent 60e7d48 commit 83bfb9b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
],
"scripts": {
"generate-styles": "tsx src/generate_styles.ts",
"generate-custom-style": "tsx src/generate_style.ts",
"build": "tsup && npm run generate-styles https://example.com/tiles.json",
"test": "tsx test/index.test.ts",
"tsc-watch": "tsc --noEmit --watch",
Expand Down
31 changes: 31 additions & 0 deletions styles/src/generate_style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// @ts-nocheck
declare const process: unknown;

import fs from "fs";
import path from "path";
import { writeFile } from "fs/promises";
import { layersWithCustomTheme } from "./index";

const args = process.argv.slice(2);
const tileJson = args[0];
const theme = await import(path.resolve(process.cwd(), args[1]));
const lang = args[2];
const output = args[3];

const style = {
version: 8,
sources: {
protomaps: {
type: "vector",
attribution:
'<a href="https://github.com/protomaps/basemaps">Protomaps</a> © <a href="https://openstreetmap.org">OpenStreetMap</a>',
url: tileJson,
},
},
layers: layersWithCustomTheme("protomaps", themeObj, lang),
sprite: "https://protomaps.github.io/basemaps-assets/sprites/v3/light",
glyphs:
"https://protomaps.github.io/basemaps-assets/fonts/{fontstack}/{range}.pbf",
};

await writeFile(output, JSON.stringify(style, null, 2));

0 comments on commit 83bfb9b

Please sign in to comment.