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.

Revisions

  1. cannalee90 revised this gist Jan 23, 2019. 1 changed file with 9 additions and 4 deletions.
    13 changes: 9 additions & 4 deletions keyreaplce.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    // $ node keyreplace.js MISSION:320010

    const fs = require('fs');
    const path = require('path');

    @@ -29,8 +31,8 @@ fromfileList.forEach((dataFilePath) => {
    const filename = tmp[tmp.length -1];
    const code = filename.split('_')[1]

    let data = fs.readFileSync(dataFilePath, {encoding: 'utf8'});
    let targetfilePath = targetfileList.filter((file) => {
    const data = fs.readFileSync(dataFilePath, {encoding: 'utf8'});
    const targetfilePath = targetfileList.filter((file) => {
    return file.indexOf(code) !== -1;
    })[0];

    @@ -39,12 +41,15 @@ fromfileList.forEach((dataFilePath) => {
    return;
    };

    let target = fs.readFileSync(targetfilePath, { encoding: 'utf8' });
    const target = fs.readFileSync(targetfilePath, { encoding: 'utf8' });

    json = JSON.parse(data.trim());

    targetJson = JSON.parse(target.trim());
    targetJson[targetKey] = json[targetKey];

    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' });
    })
  2. cannalee90 created this gist Jan 23, 2019.
    50 changes: 50 additions & 0 deletions keyreaplce.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    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]

    let data = fs.readFileSync(dataFilePath, {encoding: 'utf8'});
    let targetfilePath = targetfileList.filter((file) => {
    return file.indexOf(code) !== -1;
    })[0];

    if (!targetfilePath) {
    console.log(`There is not ${filename} in Broapp`);
    return;
    };

    let target = fs.readFileSync(targetfilePath, { encoding: 'utf8' });

    json = JSON.parse(data.trim());

    targetJson = JSON.parse(target.trim());
    targetJson[targetKey] = json[targetKey];

    fs.writeFileSync(targetfilePath, JSON.stringify(targetJson, null, 4), { encoding: 'utf8' });
    })