Permalink
Browse files

add cli

  • Loading branch information...
zertosh committed May 15, 2016
1 parent afa2176 commit d9bc273146c757418de4440c36860f543d079837
Showing with 65 additions and 1 deletion.
  1. +1 −1 README.md
  2. +15 −0 cli.js
  3. +3 −0 package.json
  4. +46 −0 test/cli.js
View
@@ -20,7 +20,7 @@ Fast (and loose) selective `process.env` replacer using [js-tokens](https://gith
## Usage/Options
loose-envify has the exact same interface as [envify](https://github.com/hughsk/envify).
loose-envify has the exact same interface as [envify](https://github.com/hughsk/envify), including the CLI.
## Benchmark
View
15 cli.js
@@ -0,0 +1,15 @@
#!/usr/bin/env node
var looseEnvify = require('./');
var fs = require('fs');
if (process.argv[2]) {
fs.createReadStream(process.argv[2], {encoding: 'utf8'})
.pipe(looseEnvify(process.argv[2]))
.pipe(process.stdout);
} else {
process.stdin.resume()
process.stdin
.pipe(looseEnvify(__filename))
.pipe(process.stdout);
}
View
@@ -14,6 +14,9 @@
"homepage": "https://github.com/zertosh/loose-envify",
"license": "MIT",
"author": "Andres Suarez <zertosh@gmail.com>",
"bin": {
"loose-envify": "cli.js"
},
"repository": {
"type": "git",
"url": "git://github.com/zertosh/loose-envify.git"
View
@@ -0,0 +1,46 @@
'use strict';
var child_process = require('child_process');
var test = require('tap').test;
test('cli', function(t) {
t.plan(5);
var res = [];
var ps = child_process.spawn(
require.resolve('../cli.js'),
[require.resolve('./react/react-with-addons-with-node_env.js')]
);
var out = '';
var err = '';
ps.stdout.on('data', function(buf) { out += buf; });
ps.stderr.on('data', function(buf) { err += buf; });
ps.on('close', function() {
t.equal(err, '');
t.ok(out);
res.push(out);
if (res.length === 2) done();
});
var envifyps = child_process.spawn(
require.resolve('.bin/envify'),
[require.resolve('./react/react-with-addons-with-node_env.js')]
);
var envifyout = '';
var envifyerr = '';
envifyps.stdout.on('data', function(buf) { envifyout += buf; });
envifyps.stderr.on('data', function(buf) { envifyerr += buf; });
envifyps.on('close', function() {
t.equal(envifyerr, '');
t.ok(envifyout);
res.push(envifyout);
if (res.length === 2) done();
});
function done() {
t.same(res[0], res[1]);
}
});

0 comments on commit d9bc273

Please sign in to comment.