-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugged_ImportManual.js
41 lines (39 loc) · 1.69 KB
/
plugged_ImportManual.js
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
"use strict";
const cheerio = require("cheerio");
const glob = require("glob");
const path = require("path");
const fs = require("fs");
let settings = require("../setting.json");
let template = fs.readFileSync("../patch/template.htm").toString();
let translation_directory = "../language/" + settings.group + "/www/"
let manual_directory = "../GMS2-Robohelp-en/"
let export_directory = "../build/"
let json_global = fs.readFileSync("../language/" + settings.group + "/global.json").toString();
glob(export_directory + '**/*.htm', {}, (err, files) => {
if (err) {
console.log("错误:" + err)
} else {
for (let index = 0; index < files.length; index++) {
let filename = path.dirname(files[index]).split("/").splice(2).join("/") + "/" + path.basename(files[index], ".htm")
let normalizeName = path.normalize(files[index])
let $ = cheerio.load(fs.readFileSync(files[index]))
let json
if (fs.existsSync(normalizeName) && fs.existsSync(translation_directory + filename + ".json")) {
json = fs.readFileSync(translation_directory + filename + ".json").toString()
} else {
continue
}
// console.log(json)
let headDep = fs.readFileSync(normalizeName + ".head").toString()
let final = template.replace("{importHtml}", headDep)
.replace("{json}", json)
.replace("{global}", json_global)
$("head").prepend(final)
fs.writeFile(normalizeName, $.html(), (err) => {
if (err) {
console.log(err)
}
})
}
}
})