diff options
author | Peter Johanson <peter@peterjohanson.com> | 2021-03-29 00:59:15 +0000 |
---|---|---|
committer | Pete Johanson <peter@peterjohanson.com> | 2021-09-11 00:50:36 -0400 |
commit | 5e6634d2e522289c5169b22a2a0d8b600a0e008d (patch) | |
tree | 8d4d314585a1ec02b9027233648cdcedf65199cf /docs/src/hardware-metadata-collection-plugin | |
parent | b52835ffbf1c47ab854d491dac9bb5ffbb15e80f (diff) |
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.
Diffstat (limited to 'docs/src/hardware-metadata-collection-plugin')
-rw-r--r-- | docs/src/hardware-metadata-collection-plugin/index.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/docs/src/hardware-metadata-collection-plugin/index.js b/docs/src/hardware-metadata-collection-plugin/index.js new file mode 100644 index 0000000..cbea805 --- /dev/null +++ b/docs/src/hardware-metadata-collection-plugin/index.js @@ -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, + }), + ], + }; + }, + }; +};
\ No newline at end of file |