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:
Peter Johanson 2021-03-29 00:59:15 +00:00 committed by Pete Johanson
parent b52835ffbf
commit 5e6634d2e5
9 changed files with 14827 additions and 6594 deletions

View File

@ -8,7 +8,11 @@ module.exports = {
favicon: "img/favicon.ico",
organizationName: "zmkfirmware", // Usually your GitHub org/user name.
projectName: "zmk", // Usually your repo name.
plugins: [path.resolve(__dirname, "src/docusaurus-tree-sitter-plugin")],
plugins: [
path.resolve(__dirname, "src/docusaurus-tree-sitter-plugin"),
path.resolve(__dirname, "src/hardware-metadata-collection-plugin"),
path.resolve(__dirname, "src/hardware-schema-typescript-plugin")
],
themeConfig: {
colorMode: {
respectPrefersColorScheme: true,

21331
docs/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -44,8 +44,16 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-mdx": "^1.13.0",
"eslint-plugin-react": "^7.23.2",
"json-schema-to-typescript": "^10.1.3",
"null-loader": "^4.0.0",
"prebuild-webpack-plugin": "^1.1.1",
"prettier": "2.3.1",
"string-replace-loader": "^3.0.3"
"string-replace-loader": "^3.0.3",
"typescript": "^4.2.3",
"@docusaurus/module-type-aliases": "^2.0.0-alpha.72",
"@tsconfig/docusaurus": "^1.0.2",
"@types/react": "^17.0.3",
"@types/react-helmet": "^6.1.0",
"@types/react-router-dom": "^5.1.7"
}
}

1
docs/src/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
hardware-metadata.d.ts

1
docs/src/data/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
hardware-metadata.json

View File

@ -1,3 +1,9 @@
/*
* Copyright (c) 2021 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
module.exports = function () {
return {
configureWebpack(config, isServer) {

View 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,
}),
],
};
},
};
};

View File

@ -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,
}),
],
};
},
};
};

4
docs/tsconfig.json Normal file
View File

@ -0,0 +1,4 @@
{
"extends": "@tsconfig/docusaurus/tsconfig.json",
"include": ["src/"]
}