summaryrefslogtreecommitdiff
path: root/docs/src/hardware-metadata-collection-plugin/index.js
blob: 89f057a83a7b27d9151665678fbbe58868ab52b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * 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");

function generateHardwareMetadataAggregate() {
  glob("../app/boards/**/*.zmk.yml", (error, files) => {
    const aggregated = files.flatMap((f) =>
      yaml.loadAll(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,
          }),
        ],
      };
    },
  };
};