-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Generate setup scripts from metadata.
- Loading branch information
1 parent
8895d5a
commit da0d184
Showing
8 changed files
with
568 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules | ||
build | ||
.docusaurus | ||
.docusaurus | ||
*.mustache | ||
hardware-metadata.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* TODO: COPYRIGHT AND LICENSE HEADER */ | ||
|
||
var PrebuildPlugin = require("prebuild-webpack-plugin"); | ||
const fs = require("fs"); | ||
const glob = require("glob"); | ||
const yaml = require("js-yaml"); | ||
const Mustache = require("mustache"); | ||
|
||
function generateSetupScripts() { | ||
return glob("../app/boards/**/*.zmk.yml", (error, files) => { | ||
const aggregated = files.flatMap((f) => | ||
yaml.safeLoadAll(fs.readFileSync(f, "utf8")) | ||
); | ||
|
||
const data = aggregated.reduce( | ||
(agg, item) => { | ||
switch (item.type) { | ||
case "shield": | ||
item.compatible = true; | ||
item.split = item.siblings?.length > 1; | ||
agg.keyboards.push(item); | ||
break; | ||
case "board": | ||
if (!item.features?.includes("keys")) { | ||
agg.boards.push(item); | ||
} | ||
break; | ||
} | ||
return agg; | ||
}, | ||
{ keyboards: [], boards: [] } | ||
); | ||
|
||
const templateBuffer = fs.readFileSync( | ||
"src/templates/setup.sh.mustache", | ||
"utf8" | ||
); | ||
const script = Mustache.render(templateBuffer, data); | ||
fs.writeFileSync("static/setup.sh", script); | ||
const powershellTemplateBuffer = fs.readFileSync( | ||
"src/templates/setup.ps1.mustache", | ||
"utf8" | ||
); | ||
const psScript = Mustache.render(powershellTemplateBuffer, data); | ||
return fs.writeFileSync("static/setup.ps1", psScript); | ||
}); | ||
} | ||
|
||
module.exports = function () { | ||
return { | ||
name: "setup-script-generation-plugin", | ||
configureWebpack() { | ||
return { | ||
plugins: [ | ||
new PrebuildPlugin({ | ||
build: generateSetupScripts, | ||
}), | ||
], | ||
}; | ||
}, | ||
}; | ||
}; |
Oops, something went wrong.