improve export script, add todo.md

This commit is contained in:
alice pellerin
2026-05-03 10:49:41 -05:00
parent 596f3d5c12
commit c879cdb271
7 changed files with 62 additions and 44 deletions
+22 -13
View File
@@ -29,6 +29,11 @@ func camelCaseToSnakeCase(_ string: Substring) -> String {
return output
}
let cargoTOMLPath = URL(filePath: "Cargo.toml")
let cargoTOML = try String(contentsOf: cargoTOMLPath, encoding: .utf8)
let versionNumber = cargoTOML.matches(of: #/version = "(?'number'[\d\.]+)"/#).first!.output.number
let defaultConfigPath = URL(filePath: "src/config/default.rs")
let lines = try String(contentsOf: defaultConfigPath, encoding: .utf8)
@@ -38,31 +43,35 @@ let lines = try String(contentsOf: defaultConfigPath, encoding: .utf8)
precondition(lines.first!.contains("Mode::Normal"))
var output = """
{%- highlight toml -%}
#:schema https://simonomi.dev/hexapoda/config/schema-v\(versionNumber).json
"""
var mode: String?
for line in lines {
if let match = line.wholeMatch(of: #/.*Mode::(?'mode'\w*),.*/#) {
mode = match.output.mode.lowercased()
} else if line.contains("None") {
print("[\(mode!)]")
output += "[\(mode!)]\n"
} else if let match = line.wholeMatch(of: #/.*PartialAction::(?'partialAction'\w*).*/#) {
let partialAction = match.output.partialAction.lowercased()
print("[\(mode!).\(partialAction)]")
output += "[\(mode!).\(partialAction)]\n"
} else if let match = line.wholeMatch(of: #/.*\(keypress\("(?'keypress'.*?)"\), (?'action'.*?)\.into\(\)\).*/#) {
if match.output.keypress.contains(where: { !($0.isLetter || $0.isNumber) }) {
print(
"\"\(match.output.keypress)\"",
"=",
"\"\(camelCaseToSnakeCase(match.output.action))\""
)
output += "\"\(match.output.keypress)\" = \"\(camelCaseToSnakeCase(match.output.action))\"\n"
} else {
print(
match.output.keypress,
"=",
"\"\(camelCaseToSnakeCase(match.output.action))\""
)
output += "\(match.output.keypress) = \"\(camelCaseToSnakeCase(match.output.action))\"\n"
}
} else {
print()
output += "\n"
}
}
output += "{%- endhighlight -%}\n"
let outputPath = URL(filePath: "~/Documents/programming/websites/simonomi.dev/_includes/hexapoda/hexapoda v\(versionNumber).toml")
try Data(output.utf8).write(to: outputPath)
print("wrote config to \(outputPath.path(percentEncoded: false))")