diff options
author | Peter Johanson <peter@peterjohanson.com> | 2021-10-16 02:42:38 +0000 |
---|---|---|
committer | Pete Johanson <peter@peterjohanson.com> | 2021-10-16 21:50:58 -0400 |
commit | 01d2102c2326b86b0f87bb008c2a3eb3871e3963 (patch) | |
tree | de18f50d8534b7eb78f0d07ac11c4c4df6a2a129 /docs/src | |
parent | e544d74948097864a9e0d846694ea16e5a443f22 (diff) |
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.
Diffstat (limited to 'docs/src')
-rw-r--r-- | docs/src/hardware-metadata-collection-plugin/index.js | 2 | ||||
-rw-r--r-- | docs/src/setup-script-generation-plugin/index.js | 4 | ||||
-rw-r--r-- | docs/src/templates/setup.ps1.mustache | 54 | ||||
-rw-r--r-- | docs/src/templates/setup.sh.mustache | 2 |
4 files changed, 36 insertions, 26 deletions
diff --git a/docs/src/hardware-metadata-collection-plugin/index.js b/docs/src/hardware-metadata-collection-plugin/index.js index 5f5660b..89f057a 100644 --- a/docs/src/hardware-metadata-collection-plugin/index.js +++ b/docs/src/hardware-metadata-collection-plugin/index.js @@ -12,7 +12,7 @@ const glob = require("glob"); function generateHardwareMetadataAggregate() { glob("../app/boards/**/*.zmk.yml", (error, files) => { const aggregated = files.flatMap((f) => - yaml.safeLoadAll(fs.readFileSync(f, "utf8")) + yaml.loadAll(fs.readFileSync(f, "utf8")) ); fs.writeFileSync( "src/data/hardware-metadata.json", diff --git a/docs/src/setup-script-generation-plugin/index.js b/docs/src/setup-script-generation-plugin/index.js index 0d768d7..908ac65 100644 --- a/docs/src/setup-script-generation-plugin/index.js +++ b/docs/src/setup-script-generation-plugin/index.js @@ -14,8 +14,8 @@ const Mustache = require("mustache"); function generateSetupScripts() { return glob("../app/boards/**/*.zmk.yml", (error, files) => { const aggregated = files.map((f) => ({ - ...yaml.safeLoadAll(fs.readFileSync(f, "utf8"))[0], - base_dir: path.basename(path.dirname(f)), + ...yaml.load(fs.readFileSync(f, "utf8")), + __base_dir: path.basename(path.dirname(f)), })); const data = aggregated.reduce( diff --git a/docs/src/templates/setup.ps1.mustache b/docs/src/templates/setup.ps1.mustache index d4b92ff..4af4d79 100644 --- a/docs/src/templates/setup.ps1.mustache +++ b/docs/src/templates/setup.ps1.mustache @@ -91,44 +91,54 @@ Write-Host "" Write-Host "Keyboard Shield Selection:" $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. -$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 -$keyboard_title = $($options[$choice]) -$keyboard = $($names[$choice]) -$basedir = $($basedirs[$choice]) -$keyboard_split = $($splits[$choice]) -$keyboard_arch = $($arches[$choice]) -$keyboard_siblings = $($sibling_sets[$choice]) -$keyboard_type = $($types[$choice]) + +$choice = Get-Choice-From-Options -Options ($keyboards.values | % { $_['name'] }) -Prompt $prompt +$keyboard = $($($keyboards.keys)[$choice]) +$keyboard_title = $keyboards[$keyboard].name +$basedir = $keyboards[$keyboard].basedir +$keyboard_split = $keyboards[$keyboard].split +$keyboard_arch = $keyboards[$keyboard].arch +$keyboard_siblings = $keyboards[$keyboard].siblings +$keyboard_type = $keyboards[$keyboard].type if ($keyboard_type -eq "shield") { $prompt = "Pick an MCU board" - $options = {{#boards}}"{{{name}}}", {{/boards}} "" | Where-Object { $_ -ne "" } - $boards = {{#boards}}"{{id}}", {{/boards}} "" | Where-Object { $_ -ne "" } + $boards = [ordered]@{ + {{#boards}} + {{id}} = "{{{name}}}"; + {{/boards}} + } Write-Host "$title" Write-Host "" 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 - $board = $($boards[$choice]) + $board = $($($boards.keys)[$choice]) $boards = ( $board ) } else { $boards = ( $keyboard_siblings ) $shields = @( ) } - $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") { diff --git a/docs/src/templates/setup.sh.mustache b/docs/src/templates/setup.sh.mustache index 03df993..54405fa 100644 --- a/docs/src/templates/setup.sh.mustache +++ b/docs/src/templates/setup.sh.mustache @@ -72,7 +72,7 @@ options=({{#keyboards}}"{{{name}}}" {{/keyboards}}) keyboards_id=({{#keyboards}}"{{id}}" {{/keyboards}}) keyboards_type=({{#keyboards}}"{{type}}" {{/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_shield=({{#keyboards}}"{{#compatible}}y{{/compatible}}{{^compatible}}n{{/compatible}}" {{/keyboards}}) |