forked from kofal.net/zmk
feat(docs): Add TS type gen, metadata JSON gen
* Generate TS types from new hardware metadata schema. * Aggregate all hw metadata YAML into one aggregate JSON file for consumption by others.
This commit is contained in:
committed by
Pete Johanson
parent
b52835ffbf
commit
5e6634d2e5
33
docs/src/hardware-metadata-collection-plugin/index.js
Normal file
33
docs/src/hardware-metadata-collection-plugin/index.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
var PrebuildPlugin = require("prebuild-webpack-plugin");
|
||||
const fs = require("fs");
|
||||
const yaml = require("js-yaml");
|
||||
const glob = require("glob");
|
||||
const { compile, compileFromFile } = require('json-schema-to-typescript');
|
||||
|
||||
function generateHardwareMetadataAggregate() {
|
||||
glob("../app/boards/**/*.zmk.yml", (error, files) => {
|
||||
const aggregated = files.flatMap(f => yaml.safeLoadAll(fs.readFileSync(f, "utf8")));
|
||||
fs.writeFileSync("src/data/hardware-metadata.json", JSON.stringify(aggregated));
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function () {
|
||||
return {
|
||||
name: "hardware-metadata-collection-plugin",
|
||||
configureWebpack() {
|
||||
return {
|
||||
plugins: [
|
||||
new PrebuildPlugin({
|
||||
build: generateHardwareMetadataAggregate,
|
||||
}),
|
||||
],
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user