Skip to content

Commit b82bbb5

Browse files
committed
feat: Generate setup scripts from metadata.
1 parent 683991a commit b82bbb5

File tree

8 files changed

+564
-392
lines changed

8 files changed

+564
-392
lines changed

docs/.prettierignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules
22
build
3-
.docusaurus
3+
.docusaurus
4+
*.mustache
5+
hardware-metadata.json

docs/docusaurus.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
path.resolve(__dirname, "src/docusaurus-tree-sitter-plugin"),
1313
path.resolve(__dirname, "src/hardware-metadata-collection-plugin"),
1414
path.resolve(__dirname, "src/hardware-schema-typescript-plugin"),
15+
path.resolve(__dirname, "src/setup-script-generation-plugin"),
1516
],
1617
themeConfig: {
1718
colorMode: {

docs/package-lock.json

+226-126
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"react-copy-to-clipboard": "^5.0.3",
2727
"react-dom": "^17.0.2",
2828
"react-toastify": "^7.0.4",
29-
"web-tree-sitter": "^0.19.4"
29+
"web-tree-sitter": "^0.19.4",
30+
"@mdx-js/react": "^1.6.22"
3031
},
3132
"browserslist": {
3233
"production": [
@@ -46,12 +47,14 @@
4647
"eslint-plugin-mdx": "^1.13.0",
4748
"eslint-plugin-react": "^7.23.2",
4849
"json-schema-to-typescript": "^10.1.3",
50+
"mustache": "^4.2.0",
4951
"null-loader": "^4.0.0",
5052
"prebuild-webpack-plugin": "^1.1.1",
5153
"prettier": "2.3.1",
5254
"string-replace-loader": "^3.0.3",
5355
"typescript": "^4.2.3",
54-
"@docusaurus/module-type-aliases": "^2.0.0-alpha.72",
56+
"webpack": "^5.46.0",
57+
"@docusaurus/module-type-aliases": "^2.0.0-beta.3",
5558
"@tsconfig/docusaurus": "^1.0.2",
5659
"@types/react": "^17.0.3",
5760
"@types/react-helmet": "^6.1.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2021 The ZMK Contributors
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
7+
var PrebuildPlugin = require("prebuild-webpack-plugin");
8+
const fs = require("fs");
9+
const glob = require("glob");
10+
const yaml = require("js-yaml");
11+
const Mustache = require("mustache");
12+
13+
function generateSetupScripts() {
14+
return glob("../app/boards/**/*.zmk.yml", (error, files) => {
15+
const aggregated = files.flatMap((f) =>
16+
yaml.safeLoadAll(fs.readFileSync(f, "utf8"))
17+
);
18+
19+
const data = aggregated.reduce(
20+
(agg, item) => {
21+
switch (item.type) {
22+
case "shield":
23+
item.compatible = true;
24+
item.split = item.siblings?.length > 1;
25+
agg.keyboards.push(item);
26+
break;
27+
case "board":
28+
if (!item.features?.includes("keys")) {
29+
agg.boards.push(item);
30+
}
31+
break;
32+
}
33+
return agg;
34+
},
35+
{ keyboards: [], boards: [] }
36+
);
37+
38+
for (let script_ext of ["sh", "ps1"]) {
39+
const templateBuffer = fs.readFileSync(
40+
`src/templates/setup.${script_ext}.mustache`,
41+
"utf8"
42+
);
43+
const script = Mustache.render(templateBuffer, data);
44+
fs.writeFileSync(`static/setup.${script_ext}`, script);
45+
}
46+
});
47+
}
48+
49+
module.exports = function () {
50+
return {
51+
name: "setup-script-generation-plugin",
52+
configureWebpack() {
53+
return {
54+
plugins: [
55+
new PrebuildPlugin({
56+
build: generateSetupScripts,
57+
}),
58+
],
59+
};
60+
},
61+
};
62+
};

0 commit comments

Comments
 (0)