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", favicon: "img/favicon.ico",
organizationName: "zmkfirmware", // Usually your GitHub org/user name. organizationName: "zmkfirmware", // Usually your GitHub org/user name.
projectName: "zmk", // Usually your repo 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: { themeConfig: {
colorMode: { colorMode: {
respectPrefersColorScheme: true, respectPrefersColorScheme: true,

21079
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-config-prettier": "^8.3.0",
"eslint-plugin-mdx": "^1.13.0", "eslint-plugin-mdx": "^1.13.0",
"eslint-plugin-react": "^7.23.2", "eslint-plugin-react": "^7.23.2",
"json-schema-to-typescript": "^10.1.3",
"null-loader": "^4.0.0", "null-loader": "^4.0.0",
"prebuild-webpack-plugin": "^1.1.1",
"prettier": "2.3.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 () { module.exports = function () {
return { return {
configureWebpack(config, isServer) { 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/"]
}