Skip to content

Commit 56667bd

Browse files
committed
🎉
0 parents  commit 56667bd

22 files changed

Lines changed: 3217 additions & 0 deletions

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# Editor config, for sharing IDE preferences ~ https://editorconfig.org/
3+
#
4+
5+
root = true
6+
7+
[*]
8+
charset = utf-8
9+
indent_style = tab
10+
indent_size = 2
11+
end_of_line = lf
12+
insert_final_newline = true
13+
14+
[*.{yml,md}]
15+
indent_style = space

.github/workflows/pages.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: pages
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
actions: read
17+
18+
environment:
19+
name: github-pages
20+
url: ${{ steps.deployment.outputs.page_url }}
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Setup Pages
26+
uses: actions/configure-pages@v5
27+
28+
- uses: actions/setup-node@v4
29+
with:
30+
cache: "npm"
31+
cache-dependency-path: "website/package-lock.json"
32+
33+
- run: npm ci
34+
working-directory: ./website
35+
36+
- name: Build website
37+
run: npx eleventy # --pathprefix=/maps.openlab.dev/
38+
working-directory: ./website
39+
env:
40+
NODE_ENV: production
41+
42+
- name: Upload pages artifact
43+
uses: actions/upload-pages-artifact@v3
44+
with:
45+
path: website/_site
46+
47+
- name: Deploy to GitHub Pages
48+
id: deployment
49+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#
2+
# Files to ignore from git source control
3+
#
4+
5+
.DS_Store
6+
*.env
7+
node_modules
8+
coverage
9+
dist
10+
tiles
11+
_site

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts-jod

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# maps.openlab.dev
2+
3+
This repository houses the [maps.openlab.dev](https://maps.openlab.dev) website
4+
along with a containerised cli that is responsible for fetching and storing the tiles.
5+
6+
<!-- ... -->

cli/config.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"targets": [
3+
{
4+
"name": "ncl.pmtiles",
5+
"bbox": [-2.072468, 54.730692, -1.112537, 55.248329]
6+
}
7+
],
8+
"s3": {
9+
"objectMetadata": {
10+
"x-amz-acl": "public-read"
11+
}
12+
}
13+
}

cli/config.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { getConfiguration, Structure } from "gruber";
2+
import pkg from "./package.json" with { type: "json" };
3+
4+
const config = getConfiguration();
5+
6+
const UNSET = "gruber://unset";
7+
8+
const struct = config.object({
9+
env: config.string({ variable: "NODE_ENV", fallback: "development" }),
10+
11+
meta: config.object({
12+
name: config.string({ variable: "APP_NAME", fallback: pkg.name }),
13+
version: config.string({ variable: "APP_VERSION", fallback: pkg.version }),
14+
}),
15+
16+
targets: config.array(
17+
config.object({
18+
name: Structure.string(),
19+
bbox: Structure.array(Structure.number()),
20+
}),
21+
),
22+
23+
protomaps: config.object({
24+
metadata: config.url({
25+
variable: "PROTOMAPS_METADATA_URL",
26+
fallback: "https://build-metadata.protomaps.dev/builds.json",
27+
}),
28+
builds: config.url({
29+
variable: "PROTOMAPS_BUILDS_URL",
30+
fallback: "https://build.protomaps.com",
31+
}),
32+
}),
33+
34+
s3: config.object({
35+
prefix: config.string({ variable: "S3_PREFIX", fallback: "" }),
36+
accessKey: config.string({ variable: "S3_ACCESS_KEY", fallback: UNSET }),
37+
secretKey: config.string({ variable: "S3_SECRET_KEY", fallback: UNSET }),
38+
bucketName: config.string({ variable: "S3_BUCKET_NAME", fallback: UNSET }),
39+
endpoint: config.url({ variable: "S3_ENDPOINT", fallback: UNSET }),
40+
objectMetadata: Structure.any(),
41+
}),
42+
});
43+
44+
export async function loadConfiguration(path: string | URL) {
45+
const value = await config.load(path, struct);
46+
if (value.env === "production") {
47+
if (value.s3.accessKey === UNSET) throw new Error("s3.accessKey not set");
48+
if (value.s3.secretKey === UNSET) throw new Error("s3.secretKey not set");
49+
if (value.s3.bucketName === UNSET) throw new Error("s3.bucketName not set");
50+
if (value.s3.endpoint.toString() === UNSET) {
51+
throw new Error("s3.endpoint not set");
52+
}
53+
}
54+
for (const target of value.targets) {
55+
if (target.bbox.length !== 4) throw new Error("bbox must have 4 elements");
56+
}
57+
return value;
58+
}
59+
60+
export function outputConfiguration() {
61+
console.log(config.getUsage(struct, appConfig));
62+
}
63+
64+
export const appConfig = await loadConfiguration(
65+
new URL("./config.json", import.meta.url),
66+
);

cli/lib.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import cp from "node:child_process";
2+
import { promisify } from "node:util";
3+
4+
export const exec = promisify(cp.exec);

cli/main.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env node --experimental-strip-types --env-file=.env
2+
3+
// import "gruber/polyfill.js"; TODO: waiting on gruber fix
4+
import "urlpattern-polyfill";
5+
6+
import process from "node:process";
7+
import yargs from "yargs";
8+
import { hideBin } from "yargs/helpers";
9+
10+
import { outputConfiguration } from "./config.ts";
11+
import { runTool } from "./run.ts";
12+
13+
const cli = yargs()
14+
.demandCommand(1, "A command is required")
15+
.recommendCommands()
16+
.help();
17+
18+
cli.command(
19+
"config",
20+
"Output config and usage",
21+
(yargs) => yargs,
22+
() => outputConfiguration(),
23+
);
24+
25+
cli.command(
26+
"run",
27+
"Run the tool",
28+
(yargs) => yargs.option("dryRun", { type: "boolean", default: false }),
29+
(args) => runTool(args),
30+
);
31+
32+
cli.parse(hideBin(process.argv));

cli/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@openlab/protomaps-cli",
3+
"version": "0.0.0",
4+
"type": "module",
5+
"scripts": {
6+
"dev": "node --experimental-strip-types --env-file=.env main.ts",
7+
"debug": "node --experimental-strip-types --env-file=.env --inspect-wait main.ts",
8+
"build": "tsc"
9+
},
10+
"dependencies": {
11+
"gruber": "^0.9.0-beta.1",
12+
"minio": "^8.0.5",
13+
"yargs": "^18.0.0"
14+
},
15+
"devDependencies": {
16+
"@types/yargs": "^17.0.33"
17+
}
18+
}

0 commit comments

Comments
 (0)