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:
parent
b52835ffbf
commit
5e6634d2e5
9 changed files with 14827 additions and 6594 deletions
|
@ -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,
|
||||||
|
|
21331
docs/package-lock.json
generated
21331
docs/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -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
1
docs/src/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
hardware-metadata.d.ts
|
1
docs/src/data/.gitignore
vendored
Normal file
1
docs/src/data/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
hardware-metadata.json
|
|
@ -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) {
|
||||||
|
|
33
docs/src/hardware-metadata-collection-plugin/index.js
Normal file
33
docs/src/hardware-metadata-collection-plugin/index.js
Normal 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,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
29
docs/src/hardware-schema-typescript-plugin/index.js
Normal file
29
docs/src/hardware-schema-typescript-plugin/index.js
Normal 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
4
docs/tsconfig.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"extends": "@tsconfig/docusaurus/tsconfig.json",
|
||||||
|
"include": ["src/"]
|
||||||
|
}
|
Loading…
Reference in a new issue