refactor: Add js-yaml dep, scrtipt gen tweaks.

*  Make the synthetic "base name" property double underscore prefixed,
  since internal, and to avoid future conflicts w/ YAML format add'ns.
* Switch to PS hash dictionaries for our metadata collections for saner
  data inspection/use.
This commit is contained in:
Peter Johanson 2021-10-16 02:42:38 +00:00 committed by Pete Johanson
parent e544d74948
commit 01d2102c23
6 changed files with 600 additions and 1445 deletions

1968
docs/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -20,14 +20,15 @@
"@fortawesome/fontawesome-svg-core": "^1.2.32", "@fortawesome/fontawesome-svg-core": "^1.2.32",
"@fortawesome/free-solid-svg-icons": "^5.15.3", "@fortawesome/free-solid-svg-icons": "^5.15.3",
"@fortawesome/react-fontawesome": "^0.1.14", "@fortawesome/react-fontawesome": "^0.1.14",
"@mdx-js/react": "^1.6.22",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"js-yaml": "^4.1.0",
"react": "^17.0.2", "react": "^17.0.2",
"react-async": "^10.0.1", "react-async": "^10.0.1",
"react-copy-to-clipboard": "^5.0.3", "react-copy-to-clipboard": "^5.0.3",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
"react-toastify": "^7.0.4", "react-toastify": "^7.0.4",
"web-tree-sitter": "^0.19.4", "web-tree-sitter": "^0.19.4"
"@mdx-js/react": "^1.6.22"
}, },
"browserslist": { "browserslist": {
"production": [ "production": [
@ -42,6 +43,11 @@
] ]
}, },
"devDependencies": { "devDependencies": {
"@docusaurus/module-type-aliases": "^2.0.0-beta.3",
"@tsconfig/docusaurus": "^1.0.2",
"@types/react": "^17.0.3",
"@types/react-helmet": "^6.1.0",
"@types/react-router-dom": "^5.1.7",
"eslint": "^7.32.0", "eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
"eslint-plugin-mdx": "^1.13.0", "eslint-plugin-mdx": "^1.13.0",
@ -53,11 +59,6 @@
"prettier": "2.3.1", "prettier": "2.3.1",
"string-replace-loader": "^3.0.3", "string-replace-loader": "^3.0.3",
"typescript": "^4.2.3", "typescript": "^4.2.3",
"webpack": "^5.46.0", "webpack": "^5.46.0"
"@docusaurus/module-type-aliases": "^2.0.0-beta.3",
"@tsconfig/docusaurus": "^1.0.2",
"@types/react": "^17.0.3",
"@types/react-helmet": "^6.1.0",
"@types/react-router-dom": "^5.1.7"
} }
} }

View file

@ -12,7 +12,7 @@ const glob = require("glob");
function generateHardwareMetadataAggregate() { function generateHardwareMetadataAggregate() {
glob("../app/boards/**/*.zmk.yml", (error, files) => { glob("../app/boards/**/*.zmk.yml", (error, files) => {
const aggregated = files.flatMap((f) => const aggregated = files.flatMap((f) =>
yaml.safeLoadAll(fs.readFileSync(f, "utf8")) yaml.loadAll(fs.readFileSync(f, "utf8"))
); );
fs.writeFileSync( fs.writeFileSync(
"src/data/hardware-metadata.json", "src/data/hardware-metadata.json",

View file

@ -14,8 +14,8 @@ const Mustache = require("mustache");
function generateSetupScripts() { function generateSetupScripts() {
return glob("../app/boards/**/*.zmk.yml", (error, files) => { return glob("../app/boards/**/*.zmk.yml", (error, files) => {
const aggregated = files.map((f) => ({ const aggregated = files.map((f) => ({
...yaml.safeLoadAll(fs.readFileSync(f, "utf8"))[0], ...yaml.load(fs.readFileSync(f, "utf8")),
base_dir: path.basename(path.dirname(f)), __base_dir: path.basename(path.dirname(f)),
})); }));
const data = aggregated.reduce( const data = aggregated.reduce(

View file

@ -91,44 +91,54 @@ Write-Host ""
Write-Host "Keyboard Shield Selection:" Write-Host "Keyboard Shield Selection:"
$prompt = "Pick a keyboard" $prompt = "Pick a keyboard"
$keyboards = [ordered]@{
{{#keyboards}}
"{{id}}" = @{
name = "{{{name}}}";
type = "{{type}}";
basedir = "{{__base_dir}}";
split = "{{split}}";
arch = "{{arch}}";
siblings = {{#siblings.0}}@(
{{#siblings}}
"{{.}}"
{{/siblings}}
){{/siblings.0}}{{^siblings.0}}( "{{id}}" ){{/siblings.0}};
}
{{/keyboards}}
}
# TODO: Add support for "Other" and linking to docs on adding custom shields in user config repos. # TODO: Add support for "Other" and linking to docs on adding custom shields in user config repos.
$options = {{#keyboards}}"{{name}}", {{/keyboards}} "" | Where-Object { $_ -ne "" }
$names = {{#keyboards}}"{{id}}", {{/keyboards}} "" | Where-Object { $_ -ne "" }
$types = {{#keyboards}}"{{type}}", {{/keyboards}} "" | Where-Object { $_ -ne "" }
$basedirs = {{#keyboards}}"{{base_dir}}", {{/keyboards}} "" | Where-Object { $_ -ne "" }
$splits = {{#keyboards}}"{{#split}}y{{/split}}{{^split}}n{{/split}}", {{/keyboards}} "" | Where-Object { $_ -ne "" }
$arches = {{#keyboards}}"{{arch}}", {{/keyboards}} "REMOVEME" | Where-Object { $_ -ne "REMOVEME" }
$basedirs = {{#keyboards}}"{{base_dir}}", {{/keyboards}} "" | Where-Object { $_ -ne "" }
$sibling_sets = {{#keyboards}}{{#siblings.0}}( {{#siblings}}"{{.}}",{{/siblings}} "" | Where-Object { $_ -ne "" } ){{/siblings.0}}{{^siblings.0}}( "{{id}}" ){{/siblings.0}}, {{/keyboards}} "REMOVEME" | Where-Object { $_ -ne "REMOVEME" }
$choice = Get-Choice-From-Options -Options $options -Prompt $prompt $choice = Get-Choice-From-Options -Options ($keyboards.values | % { $_['name'] }) -Prompt $prompt
$keyboard_title = $($options[$choice]) $keyboard = $($($keyboards.keys)[$choice])
$keyboard = $($names[$choice]) $keyboard_title = $keyboards[$keyboard].name
$basedir = $($basedirs[$choice]) $basedir = $keyboards[$keyboard].basedir
$keyboard_split = $($splits[$choice]) $keyboard_split = $keyboards[$keyboard].split
$keyboard_arch = $($arches[$choice]) $keyboard_arch = $keyboards[$keyboard].arch
$keyboard_siblings = $($sibling_sets[$choice]) $keyboard_siblings = $keyboards[$keyboard].siblings
$keyboard_type = $($types[$choice]) $keyboard_type = $keyboards[$keyboard].type
if ($keyboard_type -eq "shield") { if ($keyboard_type -eq "shield") {
$prompt = "Pick an MCU board" $prompt = "Pick an MCU board"
$options = {{#boards}}"{{{name}}}", {{/boards}} "" | Where-Object { $_ -ne "" } $boards = [ordered]@{
$boards = {{#boards}}"{{id}}", {{/boards}} "" | Where-Object { $_ -ne "" } {{#boards}}
{{id}} = "{{{name}}}";
{{/boards}}
}
Write-Host "$title" Write-Host "$title"
Write-Host "" Write-Host ""
Write-Host "MCU Board Selection:" Write-Host "MCU Board Selection:"
$choice = Get-Choice-From-Options -Options $options -Prompt $prompt $choice = Get-Choice-From-Options -Options $boards.values -Prompt $prompt
$shields = $keyboard_siblings $shields = $keyboard_siblings
$board = $($boards[$choice]) $board = $($($boards.keys)[$choice])
$boards = ( $board ) $boards = ( $board )
} else { } else {
$boards = ( $keyboard_siblings ) $boards = ( $keyboard_siblings )
$shields = @( ) $shields = @( )
} }
$copy_keymap = Read-Host "Copy in the stock keymap for customisation? [Yn]" $copy_keymap = Read-Host "Copy in the stock keymap for customisation? [Yn]"
if ($copy_keymap -eq "" -or $copy_keymap -eq "Y" -or $copy_keymap -eq "y") { if ($copy_keymap -eq "" -or $copy_keymap -eq "Y" -or $copy_keymap -eq "y") {

View file

@ -72,7 +72,7 @@ options=({{#keyboards}}"{{{name}}}" {{/keyboards}})
keyboards_id=({{#keyboards}}"{{id}}" {{/keyboards}}) keyboards_id=({{#keyboards}}"{{id}}" {{/keyboards}})
keyboards_type=({{#keyboards}}"{{type}}" {{/keyboards}}) keyboards_type=({{#keyboards}}"{{type}}" {{/keyboards}})
keyboards_arch=({{#keyboards}}"{{arch}}" {{/keyboards}}) keyboards_arch=({{#keyboards}}"{{arch}}" {{/keyboards}})
keyboards_basedir=({{#keyboards}}"{{base_dir}}" {{/keyboards}}) keyboards_basedir=({{#keyboards}}"{{__base_dir}}" {{/keyboards}})
keyboards_split=({{#keyboards}}"{{#split}}y{{/split}}{{^split}}n{{/split}}" {{/keyboards}}) keyboards_split=({{#keyboards}}"{{#split}}y{{/split}}{{^split}}n{{/split}}" {{/keyboards}})
keyboards_shield=({{#keyboards}}"{{#compatible}}y{{/compatible}}{{^compatible}}n{{/compatible}}" {{/keyboards}}) keyboards_shield=({{#keyboards}}"{{#compatible}}y{{/compatible}}{{^compatible}}n{{/compatible}}" {{/keyboards}})