Skip to content

Instantly share code, notes, and snippets.

@karakufire
Created May 20, 2019 13:41
Show Gist options
  • Save karakufire/17035943468d8cdf1c3c938695251978 to your computer and use it in GitHub Desktop.
Save karakufire/17035943468d8cdf1c3c938695251978 to your computer and use it in GitHub Desktop.
const fs = require('fs');
`
# README
This program outputs line number and this contents to output file.
keys file formats as:
item.foo.name
block.bar.name
...
[EOF]
`;
if (process.argv.length < 5) {
console.error("use : node ./whereisline <lang file path> <keys file path> <output file path>");
return;
}
const [lpath, kpath, opath]
= [process.argv[2], process.argv[3], process.argv[4]];
let langs = fs.readFileSync(lpath, 'utf-8')
.split('\n')
.map(e => e.replace(/\r$/, ''));
let keys = fs.readFileSync(kpath, 'utf-8')
.split('\n')
.map(e => e.replace(/\r$/, ''));
let res = langs
.map((lang, index) => {
const c = keys.filter(key => lang.startsWith(key));
return c.length > 0 ? { line: index, entry: lang } : null;
})
.filter(l => l != null)
.map(l => `${("0000" + l.line).slice(-4)} : ${l.entry}`).join("\n");
fs.writeFileSync(opath, res);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment