From 5e6634d2e522289c5169b22a2a0d8b600a0e008d Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 29 Mar 2021 00:59:15 +0000 Subject: 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. --- .../src/hardware-schema-typescript-plugin/index.js | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 docs/src/hardware-schema-typescript-plugin/index.js (limited to 'docs/src/hardware-schema-typescript-plugin') 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 -- cgit v1.2.3