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 | |
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')
-rw-r--r-- | docs/src/.gitignore | 1 | ||||
-rw-r--r-- | docs/src/data/.gitignore | 1 | ||||
-rw-r--r-- | docs/src/docusaurus-tree-sitter-plugin/index.js | 6 | ||||
-rw-r--r-- | docs/src/hardware-metadata-collection-plugin/index.js | 33 | ||||
-rw-r--r-- | docs/src/hardware-schema-typescript-plugin/index.js | 29 |
5 files changed, 70 insertions, 0 deletions
diff --git a/docs/src/.gitignore b/docs/src/.gitignore new file mode 100644 index 0000000..3a722c8 --- /dev/null +++ b/docs/src/.gitignore @@ -0,0 +1 @@ +hardware-metadata.d.ts diff --git a/docs/src/data/.gitignore b/docs/src/data/.gitignore new file mode 100644 index 0000000..201a309 --- /dev/null +++ b/docs/src/data/.gitignore @@ -0,0 +1 @@ +hardware-metadata.json diff --git a/docs/src/docusaurus-tree-sitter-plugin/index.js b/docs/src/docusaurus-tree-sitter-plugin/index.js index c8a9500..e782aea 100644 --- a/docs/src/docusaurus-tree-sitter-plugin/index.js +++ b/docs/src/docusaurus-tree-sitter-plugin/index.js @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2021 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + module.exports = function () { return { configureWebpack(config, isServer) { 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 diff --git a/docs/src/hardware-schema-typescript-plugin/index.js b/docs/src/hardware-schema-typescript-plugin/index.js new file mode 100644 index 0000000..2ccbf19 --- /dev/null +++ b/docs/src/hardware-schema-typescript-plugin/index.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +var PrebuildPlugin = require("prebuild-webpack-plugin"); +const fs = require("fs"); +const { compileFromFile } = require('json-schema-to-typescript'); + +async function generateHardwareMetadataTypescript() { + const ts = await compileFromFile("../schema/hardware-metadata.schema.json"); + fs.writeFileSync("src/hardware-metadata.d.ts", ts); +} + +module.exports = function () { + return { + name: "hardware-metadata-typescript-plugin", + configureWebpack() { + return { + plugins: [ + new PrebuildPlugin({ + build: generateHardwareMetadataTypescript, + }), + ], + }; + }, + }; +};
\ No newline at end of file |