forked from jamesshore/lets_code_javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.js
More file actions
157 lines (145 loc) · 3.89 KB
/
program.js
File metadata and controls
157 lines (145 loc) · 3.89 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* Jake JavaScript build tool
* Copyright 2112 Matthew Eernisse ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var parseargs = require('../lib/parseargs')
, Program
, optsReg
, preempts
, usage
, die;
optsReg = [
{ full: 'jakefile'
, abbr: 'f'
, preempts: false
, expectValue: true
}
, { full: 'quiet'
, abbr: 'q'
, preempts: false
, expectValue: false
}
, { full: 'directory'
, abbr: 'C'
, preempts: false
, expectValue: true
}
, { full: 'always-make'
, abbr: 'B'
, preempts: false
, expectValue: false
}
, { full: 'tasks'
, abbr: 'T'
, preempts: true
}
, { full: 'trace'
, abbr: 't'
, preempts: false
, expectValue: false
}
, { full: 'help'
, abbr: 'h'
, preempts: true
}
, { full: 'version'
, abbr: 'V'
, preempts: true
}
// Alias lowercase v
, { full: 'version'
, abbr: 'v'
, preempts: true
}
, { full: 'jakelibdir'
, abbr: 'J'
, preempts: false
, expectValue: true
}
];
preempts = {
version: function () {
die(jake.version);
}
, help: function () {
die(usage);
}
};
usage = ''
+ 'Jake JavaScript build tool\n'
+ '********************************************************************************\n'
+ 'If no flags are given, Jake looks for a Jakefile or Jakefile.js in the current directory.\n'
+ '********************************************************************************\n'
+ '{Usage}: jake [options ...] [env variables ...] target\n'
+ '\n'
+ '{Options}:\n'
+ ' -f, --jakefile FILE Use FILE as the Jakefile.\n'
+ ' -C, --directory DIRECTORY Change to DIRECTORY before running tasks.\n'
+ ' -q, --quiet Do not log messages to standard output.\n'
+ ' -B, --always-make Unconditionally make all targets.\n'
+ ' -T, --tasks Display the tasks (matching optional PATTERN) with descriptions, then exit.\n'
+ ' -J, --jakelibdir JAKELIBDIR Auto-import any .jake files in JAKELIBDIR. (default is \'jakelib\')\n'
+ ' -t, --trace Enable full backtrace.\n'
+ ' -h, --help Display this help message.\n'
+ ' -V/v, --version Display the Jake version.\n'
+ '';
Program = function () {
this.opts = {};
this.taskNames = null;
this.taskArgs = null;
this.envVars = null;
};
Program.prototype = new (function () {
this.handleErr = function (err) {
var msg;
jake.logger.error('jake aborted.');
if (this.opts.trace && err.stack) {
jake.logger.error(err.stack);
}
else {
if (err.stack) {
msg = err.stack.split('\n').slice(0, 2).join('\n');
jake.logger.error(msg);
jake.logger.error('(See full trace by running task with --trace)');
}
else {
jake.logger.error(err.message);
}
}
process.exit(jake.errorCode || 1);
};
this.parseArgs = function (args) {
var result = (new parseargs.Parser(optsReg)).parse(args);
this.opts = result.opts;
this.taskNames = result.taskNames;
this.envVars = result.envVars;
};
this.preemptiveOption = function () {
var opts = this.opts;
for (var p in opts) {
if (preempts[p]) {
preempts[p]();
return true;
}
}
return false;
};
})();
die = function (msg) {
console.log(msg);
process.exit();
};
module.exports.Program = Program;