Browse Source

Add stdin support

pull/2/head
Luke Childs 9 years ago
parent
commit
cfad8a12b2
  1. 4
      package.json
  2. 9
      src/cli.js

4
package.json

@ -50,6 +50,8 @@
"eslint-config-lukechilds": "^1.5.1" "eslint-config-lukechilds": "^1.5.1"
}, },
"dependencies": { "dependencies": {
"commander": "^2.9.0" "commander": "^2.9.0",
"fs-promise": "^0.5.0",
"get-stdin": "^5.0.1"
} }
} }

9
src/cli.js

@ -1,7 +1,8 @@
#!/usr/bin/env node #!/usr/bin/env node
import program from 'commander'; import program from 'commander';
import { readFileSync } from 'fs'; import { readFile } from 'fs-promise';
import getStdin from 'get-stdin';
import { version } from '../package.json'; import { version } from '../package.json';
import htconvert from './htconvert'; import htconvert from './htconvert';
@ -10,6 +11,6 @@ program
.option('-f, --file [.htaccess]', 'File containing .htaccess redirects') .option('-f, --file [.htaccess]', 'File containing .htaccess redirects')
.parse(process.argv); .parse(process.argv);
const htaccessRules = readFileSync(program.file, 'utf-8'); const readHtaccess = program.file ? readFile(program.file, 'utf-8') : getStdin();
const nginxRules = htconvert(htaccessRules);
console.log(nginxRules); readHtaccess.then(htconvert).then(console.log);

Loading…
Cancel
Save