Skip to content

Commit b06dfe4

Browse files
authored
Merge pull request #3155 from perspective-dev/remove-docusaurus
Remove `docusaurus`
2 parents 0275fc5 + f517e9c commit b06dfe4

File tree

105 files changed

+7015
-15383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+7015
-15383
lines changed

docs/build.config.mjs

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2+
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3+
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4+
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5+
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6+
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7+
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
8+
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9+
// ┃ This file is part of the Perspective library, distributed under the terms ┃
10+
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11+
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12+
13+
import * as esbuild from "esbuild";
14+
import * as fs from "node:fs";
15+
import * as path from "node:path";
16+
import { createRequire } from "module";
17+
import { bundleAsync as bundleCssAsync, composeVisitors } from "lightningcss";
18+
import { fileURLToPath } from "node:url";
19+
20+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
21+
const DIST = path.join(__dirname, "dist");
22+
23+
function copyRecursive(src, dest) {
24+
if (!fs.existsSync(src)) return;
25+
const stat = fs.statSync(src);
26+
if (stat.isDirectory()) {
27+
fs.mkdirSync(dest, { recursive: true });
28+
for (const child of fs.readdirSync(src)) {
29+
copyRecursive(path.join(src, child), path.join(dest, child));
30+
}
31+
} else {
32+
fs.copyFileSync(src, dest);
33+
}
34+
}
35+
36+
// Inline url() asset references as data URIs.
37+
export function inlineUrlVisitor(fromFile) {
38+
const dir = path.dirname(fromFile);
39+
return composeVisitors([
40+
{
41+
Url(url) {
42+
const ext = path.extname(url.url).toLowerCase();
43+
if (![".svg", ".png", ".gif"].includes(ext)) {
44+
return;
45+
}
46+
47+
const resolved = path.resolve(dir, url.url);
48+
if (!fs.existsSync(resolved)) {
49+
throw new Error(`File not found ${url.url}`);
50+
// return;
51+
}
52+
53+
const content = fs.readFileSync(resolved);
54+
const mime =
55+
ext === ".svg"
56+
? "image/svg+xml"
57+
: ext === ".png"
58+
? "image/png"
59+
: "image/gif";
60+
61+
const new_content = content
62+
.toString("base64")
63+
.split("\n")
64+
.map((x) => x.trim())
65+
.join("");
66+
67+
return {
68+
url: `data:${mime};base64,${new_content}`,
69+
loc: url.loc,
70+
};
71+
},
72+
},
73+
]);
74+
}
75+
76+
export const resolveNPM = (url) => ({
77+
read(filePath) {
78+
if (filePath.startsWith("http")) {
79+
return `@import url("${filePath}");`;
80+
}
81+
82+
return fs.readFileSync(filePath, "utf8");
83+
},
84+
resolve(specifier, from) {
85+
if (specifier.startsWith("http")) {
86+
return { external: specifier };
87+
}
88+
89+
const _require = createRequire(url);
90+
91+
if (specifier.startsWith(".") || specifier.startsWith("/")) {
92+
return path.resolve(path.dirname(from), specifier);
93+
}
94+
95+
return _require.resolve(specifier);
96+
},
97+
});
98+
99+
async function build() {
100+
// Clean and create dist
101+
fs.mkdirSync(DIST, { recursive: true });
102+
103+
// Bundle CSS
104+
const { code: cssCode } = await bundleCssAsync({
105+
filename: path.join(__dirname, "./src/css/style.css"),
106+
minify: true,
107+
resolver: resolveNPM(import.meta.url),
108+
visitor: inlineUrlVisitor("./src/css/style.css"),
109+
});
110+
111+
fs.mkdirSync(path.join(DIST, "css"), { recursive: true });
112+
fs.writeFileSync(path.join(DIST, "style.css"), cssCode);
113+
114+
// Bundle JS entry points
115+
await esbuild.build({
116+
entryPoints: [
117+
path.join(__dirname, "src/index.ts"),
118+
path.join(__dirname, "src/examples.ts"),
119+
path.join(__dirname, "src/block.ts"),
120+
],
121+
bundle: true,
122+
splitting: true,
123+
format: "esm",
124+
outdir: DIST,
125+
minify: true,
126+
sourcemap: true,
127+
target: ["es2022"],
128+
define: {
129+
global: "window",
130+
},
131+
loader: {
132+
".wasm": "file",
133+
".arrow": "file",
134+
},
135+
});
136+
137+
// Copy HTML files
138+
for (const html of ["index.html", "examples.html", "block.html"]) {
139+
fs.copyFileSync(
140+
path.join(__dirname, "src", html),
141+
path.join(DIST, html),
142+
);
143+
}
144+
145+
// Copy static assets
146+
copyRecursive(path.join(__dirname, "static"), DIST);
147+
148+
// Generate blocks manifest
149+
const blocksDir = path.join(DIST, "blocks");
150+
if (fs.existsSync(blocksDir)) {
151+
const manifest = {};
152+
for (const example of fs.readdirSync(blocksDir)) {
153+
const exDir = path.join(blocksDir, example);
154+
if (!fs.statSync(exDir).isDirectory()) continue;
155+
manifest[example] = fs
156+
.readdirSync(exDir)
157+
.filter(
158+
(f) =>
159+
!f.startsWith(".") &&
160+
!f.endsWith(".png") &&
161+
!f.endsWith(".arrow"),
162+
);
163+
}
164+
fs.writeFileSync(
165+
path.join(blocksDir, "manifest.json"),
166+
JSON.stringify(manifest),
167+
);
168+
}
169+
170+
console.log("Build complete: dist/");
171+
}
172+
173+
build().catch((e) => {
174+
console.error(e);
175+
process.exit(1);
176+
});

docs/build.js renamed to docs/build.mjs

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@
1010
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
1111
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
1212

13-
const puppeteer = require("puppeteer");
14-
const fs = require("fs");
15-
const cp = require("child_process");
16-
const path = require("node:path");
17-
const mkdirp = require("mkdirp");
18-
const EXAMPLES = require("./src/components/ExampleGallery/features.js").default;
13+
import puppeteer from "puppeteer";
14+
import * as fs from "node:fs";
15+
import * as cp from "node:child_process";
16+
import * as path from "node:path";
17+
import { fileURLToPath } from "node:url";
18+
19+
import EXAMPLES from "./src/data/features.js";
20+
21+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
22+
23+
// features.js uses CJS exports.default, import it dynamically
24+
// const EXAMPLES = (await import("./src/data/features.ts")).default;
1925

2026
const perspective = import(
2127
"@perspective-dev/client/dist/esm/perspective.node.js"
@@ -26,27 +32,7 @@ const DEFAULT_VIEWPORT = {
2632
height: 300,
2733
};
2834

29-
function shuffle(array) {
30-
let currentIndex = array.length,
31-
randomIndex;
32-
33-
// While there remain elements to shuffle.
34-
while (currentIndex != 0) {
35-
// Pick a remaining element.
36-
randomIndex = Math.floor(Math.random() * currentIndex);
37-
currentIndex--;
38-
39-
// And swap it with the current element.
40-
[array[currentIndex], array[randomIndex]] = [
41-
array[randomIndex],
42-
array[currentIndex],
43-
];
44-
}
45-
46-
return array;
47-
}
48-
49-
async function run_with_theme(page, is_dark = false) {
35+
async function run_with_theme(page, is_dark = false, order) {
5036
await page.goto("http://localhost:8080/");
5137
await page.setContent(template(is_dark));
5238
await page.setViewport(DEFAULT_VIEWPORT);
@@ -55,16 +41,16 @@ async function run_with_theme(page, is_dark = false) {
5541
await new Promise((resolve) => setTimeout(resolve, 10));
5642
}
5743
});
44+
5845
await page.evaluate(async function () {
5946
const viewer = document.querySelector("perspective-viewer");
6047
await viewer.flush();
6148
await viewer.toggleConfig();
6249
});
6350

64-
const files = [];
6551
for (const idx in EXAMPLES) {
6652
const { config, viewport } = EXAMPLES[idx];
67-
await await page.setViewport(viewport || DEFAULT_VIEWPORT);
53+
await page.setViewport(viewport || DEFAULT_VIEWPORT);
6854
const new_config = Object.assign(
6955
{
7056
plugin: "Datagrid",
@@ -93,18 +79,20 @@ async function run_with_theme(page, is_dark = false) {
9379
is_dark ? "_dark" : ""
9480
}.png`;
9581

96-
files.push(name);
9782
fs.writeFileSync(name, screenshot);
9883
cp.execSync(`convert ${name} -resize 200x150 ${name}`);
9984
}
10085

86+
const suffix = is_dark ? "_dark" : "";
87+
const montage_files = order.map(
88+
(idx) => `static/features/feature_${idx}${suffix}.png`,
89+
);
90+
10191
cp.execSync(
102-
`montage -mode concatenate -tile 5x ${shuffle(files).join(
92+
`montage -mode concatenate -background none -tile 5x ${montage_files.join(
10393
" ",
10494
)} static/features/montage${is_dark ? "_dark" : "_light"}.png`,
10595
);
106-
107-
// fs.writeFileSync("features/index.html", `<html><style>img{width:200px;height:150px;</style><body>${html.join("")}</body></html>`);
10896
}
10997

11098
async function run() {
@@ -116,6 +104,7 @@ async function run() {
116104
fs.mkdirSync(path.join(__dirname, "static/features"), {
117105
recursive: true,
118106
});
107+
119108
const x = await perspective;
120109
const server = new x.WebSocketServer({
121110
assets: [
@@ -124,16 +113,31 @@ async function run() {
124113
],
125114
});
126115

116+
const indices = Array.from({ length: EXAMPLES.length }, (_, i) => i);
117+
for (let i = indices.length - 1; i > 0; i--) {
118+
const j = Math.floor(Math.random() * (i + 1));
119+
[indices[i], indices[j]] = [indices[j], indices[i]];
120+
}
121+
127122
const browser = await puppeteer.launch({ headless: true });
128123
const page = await browser.newPage();
129-
await run_with_theme(page);
130-
await run_with_theme(page, true);
124+
await run_with_theme(page, false, indices);
125+
await run_with_theme(page, true, indices);
131126
await page.close();
132127
await browser.close();
133128
await server.close();
129+
130+
fs.writeFileSync(
131+
path.join(__dirname, "static/features/montage_map.json"),
132+
JSON.stringify({
133+
tile_width: 200,
134+
tile_height: 150,
135+
columns: 5,
136+
order: indices,
137+
}),
138+
);
134139
}
135140

136-
// TODO There is a typescript module annoyingly called `blocks`.
137141
if (!fs.existsSync("static/blocks")) {
138142
fs.mkdirSync("static/blocks");
139143
}

0 commit comments

Comments
 (0)