-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools(foreach): replace relative to absolute paths in build output (#…
…2109) this allows running "foreach" from the IDE and have problems discovered globally.
- Loading branch information
1 parent
bc40494
commit 7001f77
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env node | ||
// converts relative file paths at the beginning of each input line to absolute file paths | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const rl = require('readline'); | ||
|
||
const REMOVE_COLORS = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; | ||
|
||
const dir = process.argv[2]; | ||
if (!dir) { | ||
throw new Error(`usage: path-prefix DIR`); | ||
} | ||
|
||
const reldir = path.relative(process.cwd(), dir); | ||
|
||
const ifc = rl.createInterface(process.stdin); | ||
ifc.on('line', line => { | ||
line = line.toString(); | ||
const [ relative, ...rest ] = line.split(':'); | ||
const rel = relative.replace(REMOVE_COLORS, ''); | ||
const absolute = path.join(dir, rel); | ||
if (relative && fs.existsSync(absolute)) { | ||
process.stdout.write(path.join(reldir, rel) + ':' + rest.join(':') + '\n'); | ||
} else { | ||
process.stdout.write(line + '\n'); | ||
} | ||
}); | ||
|
||
process.stdin.resume(); | ||
|
||
function exists(p) { | ||
try { | ||
fs.readFileSync(p); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} |