-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateAssetResource.js
50 lines (44 loc) · 1.38 KB
/
generateAssetResource.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
42
43
44
45
46
47
48
49
50
console.log("Generating...")
var fs = require('fs');
var Hjson = require('hjson');
genStringResource = () => {
try {
const data = fs.readFileSync('./app/i18n/locales/vi.js', 'utf8')
const json = Hjson.parse(data.replace("export default", "").replace(";", ""))
const stringName = Object.keys(json)
fs.writeFileSync("./app/assets/strings.js", `import i18 from '@i18';
const strings = {
${stringName.map(string => {
path = `
${string}: i18.t("${string}")`
return path
})}
}
export default strings
`);
console.log(`============== Linked ${stringName.length} string ==============`)
} catch (err) {
console.error(err)
}
}
function genImageResource() {
fs.readdir("./app/assets/images/", function (err, fileName) {
if (err) {
console.log(err);
return;
}
fs.writeFileSync("./app/assets/imagesAsset.js",
`const images = {
${fileName.map(iconNane => {
path = `
${iconNane.replace('.png', "")}: require("./images/${iconNane}")`
return path
})}
}
export default images`
, { encoding: 'utf8', flag: 'w' })
console.log(`============== Linked ${fileName.length} images ==============`)
});
}
genImageResource()
genStringResource()