Browse Source

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.
xmkb
Peter Johanson 4 years ago committed by Pete Johanson
parent
commit
5e6634d2e5
  1. 6
      docs/docusaurus.config.js
  2. 19757
      docs/package-lock.json
  3. 10
      docs/package.json
  4. 1
      docs/src/.gitignore
  5. 1
      docs/src/data/.gitignore
  6. 6
      docs/src/docusaurus-tree-sitter-plugin/index.js
  7. 33
      docs/src/hardware-metadata-collection-plugin/index.js
  8. 29
      docs/src/hardware-schema-typescript-plugin/index.js
  9. 4
      docs/tsconfig.json

6
docs/docusaurus.config.js

@ -8,7 +8,11 @@ module.exports = { @@ -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,

19757
docs/package-lock.json generated

File diff suppressed because it is too large Load Diff

10
docs/package.json

@ -44,8 +44,16 @@ @@ -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

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

1
docs/src/data/.gitignore vendored

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

6
docs/src/docusaurus-tree-sitter-plugin/index.js

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

33
docs/src/hardware-metadata-collection-plugin/index.js

@ -0,0 +1,33 @@ @@ -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

@ -0,0 +1,29 @@ @@ -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

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