Created
May 20, 2019 13:41
-
-
Save karakufire/17035943468d8cdf1c3c938695251978 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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