You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
804 B
30 lines
804 B
const message = require("../public/h5_assets/messages/zh_CN/common.json");
|
|
const fs = require('fs')
|
|
let keys = [];
|
|
|
|
function toHump(name) {
|
|
return name.replace(/_(\w)/g, function (all, letter) {
|
|
return letter.toUpperCase();
|
|
});
|
|
}
|
|
|
|
function parse(obj, preFix = "", preKey = "") {
|
|
Object.keys(obj).forEach(key => {
|
|
if (typeof obj[key] == 'string') {
|
|
keys.push(` ${ preFix }${ preFix === "" ? "" : '$' }${ toHump(key) } = "${ preKey }${ preKey === "" ? "" : '.' }${ key }",`);
|
|
} else {
|
|
parse(obj[key], `${ preFix }${ preFix === "" ? "" : '$' }${ toHump(key) }`, `${ preKey }${ preKey === "" ? "" : '.' }${ key }`)
|
|
}
|
|
});
|
|
}
|
|
|
|
keys.push("export enum KEYS {");
|
|
|
|
parse(message);
|
|
|
|
keys.push("}");
|
|
|
|
fs.writeFile('./lib/keys.ts', keys.join('\n'), (e) => {
|
|
console.info(e);
|
|
});
|