/
swake
executable file
·79 lines (71 loc) · 1.84 KB
/
swake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
var argv = process.argv.slice( 2 ),
arg,
args = [],
lib_path = __dirname + '/../lib/',
logly = require( 'logly' ),
options = {},
path = require( 'path' ),
program = path.basename( __filename ),
swake = require( lib_path + 'swake.js' );
logly.name( program );
var usage = [
"usage",
" " + program + " ( -e SWAKETASKFILE | SWAKETASK ) [OPTIONS] [ARG]*",
""
].join( '\n' ),
help = [
usage,
"options:",
" --debug Debug mode",
" -e Executes SWAKETASKFILE using provided ARGs",
" -h, --help Displays this information",
" --swake-path SWAKE_PATH Specifies SWAKE_PATH to use",
""
].join( '\n' );
if ( argv.length == 0 ) {
logly.stdout( help );
process.exit( 0 );
}
while ( arg = argv.shift() ) {
if ( arg === program ) continue;
if ( arg[ 0 ] !== '-' ) {
args.push( arg );
} else {
arg = arg.match( /--?(.+)/ )[ 1 ];
switch ( arg ) {
case 'debug':
logly.mode( 'debug' );
break;
case 'e':
options.swakeTaskFile = argv.shift();
if ( ! options.swakeTaskFile ) {
logly.stdout( usage );
process.exit( 0 );
}
options.executionMode = true;
break
case 'help':
case 'h':
logly.stdout( help );
process.exit( 0 );
break;
case 'swake-path':
options.swakePath = argv.shift();
if ( ! options.swakePath ) {
logly.stdout( usage );
process.exit( 0 );
}
break;
}
}
}
if ( options.executionMode ) {
swake.executeSwakeFile( options.swakeTaskFile, args, options );
} else {
if ( args.length < 1 ) {
logly.stdout( usage );
process.exit( 0 );
}
swake.swake( args.shift(), args, options );
}