Skip to content

Commit c7144a8

Browse files
Merge pull request #127 from chainguard-dev/dev
Fix CDN imports, Safari nav, DOM timing, and dev build pipeline
2 parents 6d36fc8 + ad75db7 commit c7144a8

12 files changed

Lines changed: 1179 additions & 62 deletions

File tree

build-dev.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Dev build script — identical to the npm build:css:dev + build:js:dev scripts
3+
* but injects the current git commit hash as a banner comment in both outputs
4+
* so you can verify which bundle is loaded without checking filenames.
5+
*
6+
* Usage: node build-dev.mjs
7+
* CI: set GITHUB_SHA in environment; the first 7 chars are used automatically.
8+
*/
9+
10+
import { execSync } from "child_process";
11+
import { readFileSync, writeFileSync } from "fs";
12+
13+
const commit = process.env.GITHUB_SHA
14+
? process.env.GITHUB_SHA.slice(0, 7)
15+
: execSync("git rev-parse --short HEAD").toString().trim();
16+
17+
const banner = `/* build: ${commit} */`;
18+
19+
console.log(`Building dev bundle (commit: ${commit})…`);
20+
21+
// Lint (same as build:dev)
22+
execSync("npm run lint", { stdio: "inherit" });
23+
24+
// CSS
25+
execSync("npx postcss production/style.css -o dist/bundle.css --map", {
26+
stdio: "inherit",
27+
});
28+
const css = readFileSync("dist/bundle.css", "utf8");
29+
writeFileSync("dist/bundle.css", `${banner}\n${css}`);
30+
31+
// JS — esbuild handles the banner natively
32+
execSync(
33+
`npx esbuild production/theme.mjs --bundle --sourcemap --banner:js=${JSON.stringify(banner)} --outfile=dist/bundle.js`,
34+
{ stdio: "inherit" },
35+
);
36+
37+
console.log(`Done. Bundle tagged: ${commit}`);

eslint.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ export default defineConfig([
99
{ files: ["**/*.{js,mjs,cjs}"], languageOptions: { globals: globals.browser } },
1010
{ files: ["**/*.{js,mjs,cjs}"], plugins: { js }, extends: ["js/recommended"] },
1111

12-
// Node.js config files need Node globals (module, require, process, …)
12+
// Node.js config and generator scripts need Node globals (module, require, process, …)
1313
{
14-
files: ["*.config.js", "*.config.mjs", "*.config.cjs"],
14+
files: ["*.config.js", "*.config.mjs", "*.config.cjs", "generate_*.js", "build-*.mjs"],
1515
languageOptions: { globals: globals.node },
1616
},
1717

generate_language_file.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env node
2+
// Scans a folder of course HTML files and writes a sorted JSON array of all
3+
// Shiki language identifiers found in code blocks to production/data/languages.json.
4+
//
5+
// Usage: node generate_language_file.js <path-to-html-folder>
6+
//
7+
// Recognises both patterns Skilljar produces:
8+
// <pre class="language-terraform"><code data-lang="terraform">
9+
// <pre data-lang="terraform"><code>
10+
11+
const { readFileSync, writeFileSync, readdirSync, statSync } = require("fs");
12+
const { join, extname, resolve } = require("path");
13+
14+
const htmlFolder = process.argv[2];
15+
16+
if (!htmlFolder) {
17+
console.error("Usage: node generate_language_file.js <path-to-html-folder>");
18+
process.exit(1);
19+
}
20+
21+
function walkHtml(dir) {
22+
const files = [];
23+
for (const entry of readdirSync(dir)) {
24+
const full = join(dir, entry);
25+
if (statSync(full).isDirectory()) {
26+
files.push(...walkHtml(full));
27+
} else if (extname(entry) === ".html") {
28+
files.push(full);
29+
}
30+
}
31+
return files;
32+
}
33+
34+
const patterns = [
35+
/class="language-([^"\s]+)"/g,
36+
/data-lang="([^"]+)"/g,
37+
];
38+
39+
const languages = new Set();
40+
41+
for (const file of walkHtml(resolve(htmlFolder))) {
42+
const content = readFileSync(file, "utf-8");
43+
for (const re of patterns) {
44+
re.lastIndex = 0;
45+
let match;
46+
while ((match = re.exec(content)) !== null) {
47+
languages.add(match[1]);
48+
}
49+
}
50+
}
51+
52+
const sorted = [...languages].sort();
53+
const outputPath = join(__dirname, "production/data/languages.json");
54+
55+
writeFileSync(outputPath, JSON.stringify(sorted, null, 2) + "\n");
56+
57+
console.log(`Found ${sorted.length} language(s): ${sorted.join(", ") || "(none)"}`);
58+
console.log(`Written to ${outputPath}`);

0 commit comments

Comments
 (0)