forked from Manoonchai/kiimo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.ts
117 lines (103 loc) · 3.46 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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 { generateChr_background } from "./generateChr_background"
import { generateChr_manifest } from "./generateChr_manifest"
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)
}
// Chr___OS
try {
const layoutName = response.input.split(".").slice(0, -1).join(".")
const dir = `output/${layoutName}/${jsonInput.os.windows.installerName.toLowerCase()}`
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
const outputManifest = dir+`/manifest.json`
await generateChr_manifest(jsonInput, outputManifest)
console.log(`Output : ${outputManifest}`)
const outputBackground = dir+`/background.js`
await generateChr_background(jsonInput, outputBackground)
console.log(`Output : ${outputBackground}`)
} catch (e) {
console.error(e)
process.exit(1)
}
})()