-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.ts
97 lines (84 loc) · 2.69 KB
/
cli.ts
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import prompts from "prompts"
import fs from "fs"
import path from "path"
import { generateKeylayout } from "./generateKeylayout"
import { generateKlc } from "./generateKlc"
import { generateXkb } from "./generateXkb"
import { generateKcm } from "./generateKcm"
import { fixUnicode } from "./utils"
// eslint-disable-next-line @typescript-eslint/no-var-requires
prompts.override(require("yargs").argv)
const filenames = fs.readdirSync("input")
const choices = filenames.map((filename) => ({
title: filename,
value: filename,
}))
; (async () => {
const response = await prompts({
type: "select",
name: "input",
message: "Pick input JSON file",
choices,
})
const jsonInput = JSON.parse(
fs.readFileSync(path.join(process.cwd(), "input", response.input), "utf8")
)
// Keylayout
try {
const keylayoutXml = await generateKeylayout(jsonInput)
const layoutName = response.input.split(".").slice(0, -1).join(".")
const dir = `output/${layoutName}`
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
const outputFilename = `output/${layoutName}/${layoutName}.keylayout`
fs.writeFileSync(outputFilename, keylayoutXml)
fixUnicode(outputFilename)
console.log(`Output : ${outputFilename}`)
} catch (e) {
console.error(e)
process.exit(1)
}
// Klc
try {
const layoutName = response.input.split(".").slice(0, -1).join(".")
const dir = `output/${layoutName}`
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
const outputFilename = `output/${layoutName}/`+jsonInput.os.windows.installerName+`.klc`
await generateKlc(jsonInput, outputFilename)
console.log(`Output : ${outputFilename}`)
} catch (e) {
console.error(e)
process.exit(1)
}
// Xkb
try {
const layoutName = response.input.split(".").slice(0, -1).join(".")
const dir = `output/${layoutName}`
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
const outputFilename = `output/${layoutName}/${layoutName}_xkb`
await generateXkb(jsonInput, outputFilename)
console.log(`Output : ${outputFilename}`)
} catch (e) {
console.error(e)
process.exit(1)
}
// Kmc
try {
const layoutName = response.input.split(".").slice(0, -1).join(".")
const dir = `output/${layoutName}`
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
const outputFilename = `output/${layoutName}/${layoutName}.kcm`
await generateKcm(jsonInput, outputFilename)
console.log(`Output : ${outputFilename}`)
} catch (e) {
console.error(e)
process.exit(1)
}
})()