Browse Source
* 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
9 changed files with 22902 additions and 14669 deletions
File diff suppressed because it is too large
Load Diff
@ -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, |
||||||
|
}), |
||||||
|
], |
||||||
|
}; |
||||||
|
}, |
||||||
|
}; |
||||||
|
}; |
@ -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, |
||||||
|
}), |
||||||
|
], |
||||||
|
}; |
||||||
|
}, |
||||||
|
}; |
||||||
|
}; |
Loading…
Reference in new issue