Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Moshe Kolodny
committed
May 5, 2015
1 parent
e7e7ed9
commit fe499a1
Showing
9 changed files
with
540 additions
and
337 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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 @@ | ||
node_modules/ |
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,55 @@ | ||
#!/usr/bin/env node | ||
|
||
var nip = require('..'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var argv = require('minimist')(process.argv.slice(2)); | ||
|
||
var jsFile = argv.f || argv.file | ||
|
||
if (argv.h || argv.help) { | ||
console.log(fs.readFileSync(__dirname + '/usage.txt').toString()); | ||
return; | ||
} | ||
|
||
if (!argv._.length && !jsFile) { | ||
console.error('You muse specify a js-exec or a --js-file\nsee nip --help for more info'); | ||
return; | ||
} | ||
|
||
|
||
|
||
var callbackStr; | ||
if (jsFile) { | ||
callbackStr = fs.readFileSync(jsFile).toString(); | ||
} else { | ||
callbackStr = argv._.shift(); | ||
} | ||
|
||
var files = argv._; | ||
|
||
var callback; | ||
try { | ||
if (/^\s*return\b/.test(callbackStr)) { | ||
callback = Function('return function(line, index) {' + callbackStr + '}')(); | ||
} else if (/\s*function\b/.test(callbackStr)) { | ||
callback = Function('return ' + callbackStr)(); | ||
} else { | ||
callback = Function(callbackStr)(); | ||
} | ||
} catch (e) { | ||
console.error("coudn't build callback function", e); | ||
return; | ||
} | ||
|
||
files = files.map(function(file) { | ||
return (file === '-') ? nip.STDIN : file; | ||
}); | ||
|
||
console.log(files) | ||
|
||
nip({ | ||
files: files, | ||
callback: callback | ||
}); | ||
|
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,21 @@ | ||
Usage: nip [js-executor] {OPTIONS} [files, ...] | ||
|
||
The js-executor can either be a js function-like string like this: | ||
'return line.toUpperCase()' | ||
or can be a file which contains the js function-like string | ||
|
||
A js function-like string can be one of these three formats: | ||
'return line.toUpperCase()' | ||
'function(line, lineIndex) { return line.toUpperCase(); }' | ||
'var setup = 123; return function(line) { return line; }' | ||
If used like in the first example, the variables line and index | ||
are available. | ||
You can return a transformed line or false to omit the line | ||
|
||
You must supply either a js function-like string or a --file | ||
|
||
Standard Options: | ||
|
||
--file, -f The file that contains the js-executor | ||
|
||
--help, -h Show this message |
Oops, something went wrong.