11#!/usr/bin/env node
2+
3+ 'use strict' ;
4+
25var faucet = require ( '../' ) ;
36var minimist = require ( 'minimist' ) ;
47var defined = require ( 'defined' ) ;
@@ -9,65 +12,61 @@ var spawn = require('child_process').spawn;
912var fs = require ( 'fs' ) ;
1013var path = require ( 'path' ) ;
1114
15+ function jsFile ( x ) { return ( / \. j s $ / i) . test ( x ) ; }
16+
1217var argv = minimist ( process . argv . slice ( 2 ) ) ;
1318var tap = faucet ( {
14- width : defined ( argv . w , argv . width , process . stdout . isTTY
15- ? process . stdout . columns - 5
16- : 0
17- )
19+ width : defined ( argv . w , argv . width , process . stdout . isTTY
20+ ? process . stdout . columns - 5
21+ : 0 )
1822} ) ;
1923process . on ( 'exit' , function ( code ) {
20- if ( code === 0 && tap . exitCode !== 0 ) {
21- process . exit ( tap . exitCode ) ;
22- }
24+ if ( code === 0 && tap . exitCode !== 0 ) {
25+ process . exit ( tap . exitCode ) ;
26+ }
2327} ) ;
2428process . stdout . on ( 'error' , function ( ) { } ) ;
2529
2630if ( ! process . stdin . isTTY || argv . _ [ 0 ] === '-' ) {
27- process . stdin . pipe ( tap ) . pipe ( process . stdout ) ;
28- return ;
31+ process . stdin . pipe ( tap ) . pipe ( process . stdout ) ;
32+ return ;
2933}
3034
3135var files = argv . _ . reduce ( function ( acc , file ) {
32- if ( fs . statSync ( file ) . isDirectory ( ) ) {
33- return acc . concat ( fs . readdirSync ( file ) . map ( function ( x ) {
34- return path . join ( file , x ) ;
35- } ) . filter ( jsFile ) ) ;
36- }
37- else return acc . concat ( file ) ;
36+ if ( fs . statSync ( file ) . isDirectory ( ) ) {
37+ return acc . concat ( fs . readdirSync ( file ) . map ( function ( x ) {
38+ return path . join ( file , x ) ;
39+ } ) . filter ( jsFile ) ) ;
40+ }
41+ return acc . concat ( file ) ;
3842} , [ ] ) ;
3943
4044if ( files . length === 0 && fs . existsSync ( 'test' ) ) {
41- files . push . apply ( files , fs . readdirSync ( 'test' ) . map ( function ( x ) {
42- return path . join ( 'test' , x ) ;
43- } ) . filter ( jsFile ) ) ;
45+ files . push . apply ( files , fs . readdirSync ( 'test' ) . map ( function ( x ) {
46+ return path . join ( 'test' , x ) ;
47+ } ) . filter ( jsFile ) ) ;
4448}
4549if ( files . length === 0 && fs . existsSync ( 'tests' ) ) {
46- files . push . apply ( files , fs . readdirSync ( 'tests' ) . map ( function ( x ) {
47- return path . join ( 'tests' , x ) ;
48- } ) . filter ( jsFile ) ) ;
50+ files . push . apply ( files , fs . readdirSync ( 'tests' ) . map ( function ( x ) {
51+ return path . join ( 'tests' , x ) ;
52+ } ) . filter ( jsFile ) ) ;
4953}
5054
5155if ( files . length === 0 ) {
52- console . error ( 'usage: `faucet [FILES]` or `| faucet`\n' ) ;
53- console . error (
54- 'No test files or stdin provided and no files in test/ or tests/'
55- + ' directories found.'
56- ) ;
57- return process . exit ( 1 ) ;
56+ console . error ( 'usage: `faucet [FILES]` or `| faucet`\n' ) ;
57+ console . error ( 'No test files or stdin provided and no files in test/ or tests/ directories found.' ) ;
58+ process . exit ( 1 ) ;
5859}
5960
6061var tape = spawn ( tapeCmd , files ) ;
6162tape . stderr . pipe ( process . stderr ) ;
6263tape . stdout . pipe ( tap ) . pipe ( process . stdout ) ;
6364
6465var tapeCode ;
65- tape . on ( 'exit' , function ( code ) { tapeCode = code } ) ;
66+ tape . on ( 'exit' , function ( code ) { tapeCode = code ; } ) ;
6667process . on ( 'exit' , function ( code ) {
67- if ( code === 0 && tapeCode !== 0 ) {
68- console . error ( '# non-zero exit from the `tape` command' ) ;
69- process . exit ( tapeCode ) ;
70- }
68+ if ( code === 0 && tapeCode !== 0 ) {
69+ console . error ( '# non-zero exit from the `tape` command' ) ;
70+ process . exit ( tapeCode ) ;
71+ }
7172} ) ;
72-
73- function jsFile ( x ) { return / \. j s $ / i. test ( x ) }
0 commit comments