Skip to content

Instantly share code, notes, and snippets.

@cannalee90
Last active January 30, 2019 01:37
Show Gist options
  • Select an option

  • Save cannalee90/e0f5554e79bf473f1bd253fb004783ec to your computer and use it in GitHub Desktop.

Select an option

Save cannalee90/e0f5554e79bf473f1bd253fb004783ec to your computer and use it in GitHub Desktop.
// $ node keyreplace.js MISSION:320010
const fs = require('fs');
const path = require('path');
const args = process.argv.slice(2);
const targetKey = args[0];
if (!targetKey) {
console.log('Please ADD Key for Data');
process.exit(1);
}
const from = 'C:/Users/kangho/PUBG/game-design-data/localization/mission';
const target = 'C:/Users/kangho/PUBG/Tsl_server/Source/src/Bro/BroApp2/src/app/_lib/Bro/translation/data';
const getFileList = (dir) => {
return fs.readdirSync(dir).reduce(function(list, file) {
const name = path.join(dir, file);
const isDir = fs.statSync(name).isDirectory();
return list.concat(isDir ? getFileList(name) : [name]);
}, []);
}
const fromfileList = getFileList(from);
const targetfileList = getFileList(target);
fromfileList.forEach((dataFilePath) => {
const tmp = dataFilePath.split('\\');
const filename = tmp[tmp.length -1];
const code = filename.split('_')[1]
const data = fs.readFileSync(dataFilePath, {encoding: 'utf8'});
const targetfilePath = targetfileList.filter((file) => {
return file.indexOf(code) !== -1;
})[0];
if (!targetfilePath) {
console.log(`There is not ${filename} in Broapp`);
return;
};
const target = fs.readFileSync(targetfilePath, { encoding: 'utf8' });
json = JSON.parse(data.trim());
targetJson = JSON.parse(target.trim());
console.log(`from ${dataFilePath} to ${targetfilePath}`);
console.log(`from ${targetJson[targetKey]} to ${json[targetKey]}`);
targetJson[targetKey] = json[targetKey];
fs.writeFileSync(targetfilePath, JSON.stringify(targetJson, null, 4), { encoding: 'utf8' });
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment