@makano/rew 1.1.8 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/coffeescript/browser.js +144 -139
- package/lib/coffeescript/cake.js +132 -133
- package/lib/coffeescript/coffeescript.js +437 -381
- package/lib/coffeescript/command.js +806 -724
- package/lib/coffeescript/grammar.js +1908 -2474
- package/lib/coffeescript/helpers.js +509 -473
- package/lib/coffeescript/index.js +228 -215
- package/lib/coffeescript/lexer.js +2282 -1909
- package/lib/coffeescript/nodes.js +9782 -9202
- package/lib/coffeescript/optparse.js +255 -227
- package/lib/coffeescript/parser.js +20305 -1265
- package/lib/coffeescript/register.js +107 -87
- package/lib/coffeescript/repl.js +307 -284
- package/lib/coffeescript/rewriter.js +1389 -1079
- package/lib/coffeescript/scope.js +176 -172
- package/lib/coffeescript/sourcemap.js +242 -227
- package/lib/rew/cli/cli.js +243 -202
- package/lib/rew/cli/log.js +31 -32
- package/lib/rew/cli/run.js +10 -12
- package/lib/rew/cli/utils.js +248 -176
- package/lib/rew/const/config_path.js +2 -3
- package/lib/rew/const/default.js +38 -35
- package/lib/rew/const/files.js +9 -9
- package/lib/rew/const/opt.js +8 -8
- package/lib/rew/css/theme.css +2 -2
- package/lib/rew/functions/core.js +55 -57
- package/lib/rew/functions/curl.js +23 -0
- package/lib/rew/functions/emitter.js +52 -55
- package/lib/rew/functions/exec.js +25 -21
- package/lib/rew/functions/export.js +18 -20
- package/lib/rew/functions/fs.js +55 -54
- package/lib/rew/functions/future.js +29 -21
- package/lib/rew/functions/id.js +8 -9
- package/lib/rew/functions/import.js +116 -110
- package/lib/rew/functions/map.js +13 -16
- package/lib/rew/functions/match.js +35 -26
- package/lib/rew/functions/path.js +8 -8
- package/lib/rew/functions/require.js +32 -33
- package/lib/rew/functions/sleep.js +2 -2
- package/lib/rew/functions/stdout.js +20 -20
- package/lib/rew/functions/types.js +96 -95
- package/lib/rew/html/ui.html +12 -13
- package/lib/rew/html/ui.js +205 -168
- package/lib/rew/main.js +14 -14
- package/lib/rew/misc/findAppInfo.js +14 -14
- package/lib/rew/misc/findAppPath.js +16 -16
- package/lib/rew/misc/seededid.js +9 -11
- package/lib/rew/models/enum.js +12 -12
- package/lib/rew/models/struct.js +30 -32
- package/lib/rew/modules/compiler.js +228 -177
- package/lib/rew/modules/context.js +33 -21
- package/lib/rew/modules/fs.js +10 -10
- package/lib/rew/modules/runtime.js +17 -21
- package/lib/rew/modules/yaml.js +27 -30
- package/lib/rew/pkgs/conf.js +80 -80
- package/lib/rew/pkgs/data.js +12 -7
- package/lib/rew/pkgs/date.js +27 -28
- package/lib/rew/pkgs/env.js +6 -8
- package/lib/rew/pkgs/modules/data/bintree.js +52 -52
- package/lib/rew/pkgs/modules/data/doublylinked.js +85 -85
- package/lib/rew/pkgs/modules/data/linkedList.js +73 -73
- package/lib/rew/pkgs/modules/data/queue.js +19 -20
- package/lib/rew/pkgs/modules/data/stack.js +19 -19
- package/lib/rew/pkgs/modules/threads/worker.js +36 -26
- package/lib/rew/pkgs/modules/ui/classes.js +182 -178
- package/lib/rew/pkgs/pkgs.js +9 -10
- package/lib/rew/pkgs/rune.js +391 -345
- package/lib/rew/pkgs/threads.js +57 -53
- package/lib/rew/pkgs/ui.js +148 -136
- package/package.json +1 -1
@@ -1,143 +1,213 @@
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
2
|
-
(function() {
|
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
|
-
|
2
|
+
(function () {
|
3
|
+
// The `coffee` utility. Handles command-line compilation of CoffeeScript
|
4
|
+
// into various forms: saved into `.js` files or printed to stdout
|
5
|
+
// or recompiled every time the source is saved,
|
6
|
+
// printed as a token stream or as the syntax tree, or launch an
|
7
|
+
// interactive REPL.
|
8
|
+
|
9
|
+
// External dependencies.
|
10
|
+
var BANNER,
|
11
|
+
CoffeeScript,
|
12
|
+
EventEmitter,
|
13
|
+
SWITCHES,
|
14
|
+
buildCSOptionParser,
|
15
|
+
compileJoin,
|
16
|
+
compileOptions,
|
17
|
+
compilePath,
|
18
|
+
compileScript,
|
19
|
+
compileStdio,
|
20
|
+
exec,
|
21
|
+
findDirectoryIndex,
|
22
|
+
forkNode,
|
23
|
+
fs,
|
24
|
+
helpers,
|
25
|
+
hidden,
|
26
|
+
joinTimeout,
|
27
|
+
makePrelude,
|
28
|
+
mkdirp,
|
29
|
+
notSources,
|
30
|
+
optionParser,
|
31
|
+
optparse,
|
32
|
+
opts,
|
33
|
+
outputPath,
|
34
|
+
parseOptions,
|
35
|
+
path,
|
36
|
+
printLine,
|
37
|
+
printTokens,
|
38
|
+
printWarn,
|
39
|
+
removeSource,
|
40
|
+
removeSourceDir,
|
41
|
+
silentUnlink,
|
42
|
+
sourceCode,
|
43
|
+
sources,
|
44
|
+
spawn,
|
45
|
+
timeLog,
|
46
|
+
usage,
|
47
|
+
useWinPathSep,
|
48
|
+
version,
|
49
|
+
wait,
|
50
|
+
watch,
|
51
|
+
watchDir,
|
52
|
+
watchedDirs,
|
53
|
+
writeJs,
|
54
|
+
indexOf = [].indexOf;
|
55
|
+
|
56
|
+
fs = require('fs');
|
57
|
+
|
58
|
+
path = require('path');
|
59
|
+
|
60
|
+
helpers = require('./helpers');
|
61
|
+
|
62
|
+
optparse = require('./optparse');
|
63
|
+
|
64
|
+
CoffeeScript = require('./');
|
65
|
+
|
66
|
+
({ spawn, exec } = require('child_process'));
|
67
|
+
|
68
|
+
({ EventEmitter } = require('events'));
|
69
|
+
|
70
|
+
useWinPathSep = path.sep === '\\';
|
71
|
+
|
72
|
+
// Allow CoffeeScript to emit Node.js events.
|
73
|
+
helpers.extend(CoffeeScript, new EventEmitter());
|
74
|
+
|
75
|
+
printLine = function (line) {
|
76
|
+
return process.stdout.write(line + '\n');
|
77
|
+
};
|
78
|
+
|
79
|
+
printWarn = function (line) {
|
80
|
+
return process.stderr.write(line + '\n');
|
81
|
+
};
|
82
|
+
|
83
|
+
hidden = function (file) {
|
84
|
+
return /^\.|~$/.test(file);
|
85
|
+
};
|
86
|
+
|
87
|
+
// The help banner that is printed in conjunction with `-h`/`--help`.
|
88
|
+
BANNER = `Usage: coffee [options] path/to/script.coffee [args]
|
46
89
|
|
47
90
|
If called without options, \`coffee\` will run your script.`;
|
48
91
|
|
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
|
-
|
92
|
+
// The list of all the valid option flags that `coffee` knows how to handle.
|
93
|
+
SWITCHES = [
|
94
|
+
['--ast', 'generate an abstract syntax tree of nodes'],
|
95
|
+
['-b', '--bare', 'compile without a top-level function wrapper'],
|
96
|
+
['-c', '--compile', 'compile to JavaScript and save as .js files'],
|
97
|
+
['-e', '--eval', 'pass a string from the command line as input'],
|
98
|
+
['-h', '--help', 'display this help message'],
|
99
|
+
['-i', '--interactive', 'run an interactive CoffeeScript REPL'],
|
100
|
+
['-j', '--join [FILE]', 'concatenate the source CoffeeScript before compiling'],
|
101
|
+
['-l', '--literate', 'treat stdio as literate style coffeescript'],
|
102
|
+
['-m', '--map', 'generate source map and save as .js.map files'],
|
103
|
+
['-M', '--inline-map', 'generate source map and include it directly in output'],
|
104
|
+
['-n', '--nodes', 'print out the parse tree that the parser produces'],
|
105
|
+
['--nodejs [ARGS]', 'pass options directly to the "node" binary'],
|
106
|
+
['--no-header', 'suppress the "Generated by" header'],
|
107
|
+
['-o', '--output [PATH]', 'set the output path or path/filename for compiled JavaScript'],
|
108
|
+
['-p', '--print', 'print out the compiled JavaScript'],
|
109
|
+
['-r', '--require [MODULE*]', 'require the given module before eval or REPL'],
|
110
|
+
['-s', '--stdio', 'listen for and compile scripts over stdio'],
|
111
|
+
['-t', '--transpile', 'pipe generated JavaScript through Babel'],
|
112
|
+
['--tokens', 'print out the tokens that the lexer/rewriter produce'],
|
113
|
+
['-v', '--version', 'display the version number'],
|
114
|
+
['-w', '--watch', 'watch scripts for changes and rerun commands'],
|
115
|
+
];
|
116
|
+
|
117
|
+
// Top-level objects shared by all the functions.
|
118
|
+
opts = {};
|
119
|
+
|
120
|
+
sources = [];
|
121
|
+
|
122
|
+
sourceCode = [];
|
123
|
+
|
124
|
+
notSources = {};
|
125
|
+
|
126
|
+
watchedDirs = {};
|
127
|
+
|
128
|
+
optionParser = null;
|
129
|
+
|
130
|
+
exports.buildCSOptionParser = buildCSOptionParser = function () {
|
131
|
+
return new optparse.OptionParser(SWITCHES, BANNER);
|
132
|
+
};
|
133
|
+
|
134
|
+
// Run `coffee` by parsing passed options and determining what action to take.
|
135
|
+
// Many flags cause us to divert before compiling anything. Flags passed after
|
136
|
+
// `--` will be passed verbatim to your script as arguments in `process.argv`
|
137
|
+
exports.run = function () {
|
138
|
+
var err, i, len, literals, outputBasename, ref, replCliOpts, results, source;
|
139
|
+
optionParser = buildCSOptionParser();
|
140
|
+
try {
|
141
|
+
parseOptions();
|
142
|
+
} catch (error) {
|
143
|
+
err = error;
|
144
|
+
console.error(`option parsing error: ${err.message}`);
|
145
|
+
process.exit(1);
|
146
|
+
}
|
147
|
+
if (!opts.doubleDashed && opts.arguments[1] === '--') {
|
148
|
+
printWarn(`coffee was invoked with '--' as the second positional argument, which is
|
84
149
|
now deprecated. To pass '--' as an argument to a script to run, put an
|
85
150
|
additional '--' before the path to your script.
|
86
151
|
|
87
152
|
'--' will be removed from the argument list.`);
|
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
|
-
|
153
|
+
printWarn(`The positional arguments were: ${JSON.stringify(opts.arguments)}`);
|
154
|
+
opts.arguments = [opts.arguments[0]].concat(opts.arguments.slice(2));
|
155
|
+
}
|
156
|
+
// Make the REPL *CLI* use the global context so as to (a) be consistent with the
|
157
|
+
// `node` REPL CLI and, therefore, (b) make packages that modify native prototypes
|
158
|
+
// (such as 'colors' and 'sugar') work as expected.
|
159
|
+
replCliOpts = {
|
160
|
+
useGlobal: true,
|
161
|
+
};
|
162
|
+
if (opts.require) {
|
163
|
+
opts.prelude = makePrelude(opts.require);
|
164
|
+
}
|
165
|
+
replCliOpts.prelude = opts.prelude;
|
166
|
+
replCliOpts.transpile = opts.transpile;
|
167
|
+
if (opts.nodejs) {
|
168
|
+
return forkNode();
|
169
|
+
}
|
170
|
+
if (opts.help) {
|
171
|
+
return usage();
|
172
|
+
}
|
173
|
+
if (opts.version) {
|
174
|
+
return version();
|
175
|
+
}
|
176
|
+
if (opts.interactive) {
|
177
|
+
return require('./repl').start(replCliOpts);
|
178
|
+
}
|
179
|
+
if (opts.stdio) {
|
180
|
+
return compileStdio();
|
181
|
+
}
|
182
|
+
if (opts.eval) {
|
183
|
+
return compileScript(null, opts.arguments[0]);
|
184
|
+
}
|
185
|
+
if (!opts.arguments.length) {
|
186
|
+
return require('./repl').start(replCliOpts);
|
187
|
+
}
|
188
|
+
literals = opts.run ? opts.arguments.splice(1) : [];
|
189
|
+
process.argv = process.argv.slice(0, 2).concat(literals);
|
190
|
+
process.argv[0] = 'coffee';
|
191
|
+
if (opts.output) {
|
192
|
+
outputBasename = path.basename(opts.output);
|
193
|
+
if (
|
194
|
+
indexOf.call(outputBasename, '.') >= 0 &&
|
195
|
+
outputBasename !== '.' &&
|
196
|
+
outputBasename !== '..' &&
|
197
|
+
!helpers.ends(opts.output, path.sep)
|
198
|
+
) {
|
199
|
+
// An output filename was specified, e.g. `/dist/scripts.js`.
|
200
|
+
opts.outputFilename = outputBasename;
|
201
|
+
opts.outputPath = path.resolve(path.dirname(opts.output));
|
202
|
+
} else {
|
203
|
+
// An output path was specified, e.g. `/dist`.
|
204
|
+
opts.outputFilename = null;
|
205
|
+
opts.outputPath = path.resolve(opts.output);
|
206
|
+
}
|
207
|
+
}
|
208
|
+
if (opts.join) {
|
209
|
+
opts.join = path.resolve(opts.join);
|
210
|
+
console.error(`
|
141
211
|
The --join option is deprecated and will be removed in a future version.
|
142
212
|
|
143
213
|
If for some reason it's necessary to share local variables between files,
|
@@ -149,602 +219,614 @@ with...
|
|
149
219
|
|
150
220
|
$ cat a.coffee b.coffee c.coffee | coffee --compile --stdio > bundle.js
|
151
221
|
`);
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
222
|
+
}
|
223
|
+
ref = opts.arguments;
|
224
|
+
results = [];
|
225
|
+
for (i = 0, len = ref.length; i < len; i++) {
|
226
|
+
source = ref[i];
|
227
|
+
source = path.resolve(source);
|
228
|
+
results.push(compilePath(source, true, source));
|
229
|
+
}
|
230
|
+
return results;
|
231
|
+
};
|
232
|
+
|
233
|
+
makePrelude = function (requires) {
|
234
|
+
return requires
|
235
|
+
.map(function (module) {
|
236
|
+
var full, match, name;
|
237
|
+
if ((match = module.match(/^(.*)=(.*)$/))) {
|
238
|
+
[full, name, module] = match;
|
239
|
+
}
|
240
|
+
name || (name = helpers.baseFileName(module, true, useWinPathSep));
|
241
|
+
return `global['${name}'] = require('${module}')`;
|
242
|
+
})
|
243
|
+
.join(';');
|
244
|
+
};
|
245
|
+
|
246
|
+
// Compile a path, which could be a script or a directory. If a directory
|
247
|
+
// is passed, recursively compile all '.coffee', '.litcoffee', and '.coffee.md'
|
248
|
+
// extension source files in it and all subdirectories.
|
249
|
+
compilePath = function (source, topLevel, base) {
|
250
|
+
var code, err, file, files, i, len, results, stats;
|
251
|
+
if (indexOf.call(sources, source) >= 0 || watchedDirs[source] || (!topLevel && (notSources[source] || hidden(source)))) {
|
252
|
+
return;
|
253
|
+
}
|
254
|
+
try {
|
255
|
+
stats = fs.statSync(source);
|
256
|
+
} catch (error) {
|
257
|
+
err = error;
|
258
|
+
if (err.code === 'ENOENT') {
|
259
|
+
console.error(`File not found: ${source}`);
|
260
|
+
process.exit(1);
|
261
|
+
}
|
262
|
+
throw err;
|
263
|
+
}
|
264
|
+
if (stats.isDirectory()) {
|
265
|
+
if (path.basename(source) === 'node_modules') {
|
266
|
+
notSources[source] = true;
|
267
|
+
return;
|
268
|
+
}
|
269
|
+
if (opts.run) {
|
270
|
+
compilePath(findDirectoryIndex(source), topLevel, base);
|
271
|
+
return;
|
272
|
+
}
|
273
|
+
if (opts.watch) {
|
274
|
+
watchDir(source, base);
|
275
|
+
}
|
276
|
+
try {
|
277
|
+
files = fs.readdirSync(source);
|
278
|
+
} catch (error) {
|
279
|
+
err = error;
|
280
|
+
if (err.code === 'ENOENT') {
|
281
|
+
return;
|
282
|
+
} else {
|
283
|
+
throw err;
|
284
|
+
}
|
285
|
+
}
|
286
|
+
results = [];
|
287
|
+
for (i = 0, len = files.length; i < len; i++) {
|
288
|
+
file = files[i];
|
289
|
+
results.push(compilePath(path.join(source, file), false, base));
|
290
|
+
}
|
291
|
+
return results;
|
292
|
+
} else if (topLevel || helpers.isCoffee(source)) {
|
293
|
+
sources.push(source);
|
294
|
+
sourceCode.push(null);
|
295
|
+
delete notSources[source];
|
296
|
+
if (opts.watch) {
|
297
|
+
watch(source, base);
|
298
|
+
}
|
299
|
+
try {
|
300
|
+
code = fs.readFileSync(source);
|
301
|
+
} catch (error) {
|
302
|
+
err = error;
|
303
|
+
if (err.code === 'ENOENT') {
|
304
|
+
return;
|
305
|
+
} else {
|
306
|
+
throw err;
|
307
|
+
}
|
308
|
+
}
|
309
|
+
return compileScript(source, code.toString(), base);
|
310
|
+
} else {
|
311
|
+
return (notSources[source] = true);
|
312
|
+
}
|
313
|
+
};
|
314
|
+
|
315
|
+
findDirectoryIndex = function (source) {
|
316
|
+
var err, ext, i, index, len, ref;
|
317
|
+
ref = CoffeeScript.FILE_EXTENSIONS;
|
318
|
+
for (i = 0, len = ref.length; i < len; i++) {
|
319
|
+
ext = ref[i];
|
320
|
+
index = path.join(source, `index${ext}`);
|
321
|
+
try {
|
322
|
+
if (fs.statSync(index).isFile()) {
|
323
|
+
return index;
|
324
|
+
}
|
325
|
+
} catch (error) {
|
326
|
+
err = error;
|
327
|
+
if (err.code !== 'ENOENT') {
|
328
|
+
throw err;
|
329
|
+
}
|
330
|
+
}
|
331
|
+
}
|
332
|
+
console.error(`Missing index.coffee or index.litcoffee in ${source}`);
|
333
|
+
return process.exit(1);
|
334
|
+
};
|
335
|
+
|
336
|
+
// Compile a single source script, containing the given code, according to the
|
337
|
+
// requested options. If evaluating the script directly, set `__filename`,
|
338
|
+
// `__dirname` and `module.filename` to be correct relative to the script's path.
|
339
|
+
compileScript = function (file, input, base = null) {
|
340
|
+
var compiled, err, message, options, saveTo, task;
|
341
|
+
options = compileOptions(file, base);
|
342
|
+
try {
|
343
|
+
task = { file, input, options };
|
344
|
+
CoffeeScript.emit('compile', task);
|
345
|
+
if (opts.tokens) {
|
346
|
+
return printTokens(CoffeeScript.tokens(task.input, task.options));
|
347
|
+
} else if (opts.nodes) {
|
348
|
+
return printLine(CoffeeScript.nodes(task.input, task.options).toString().trim());
|
349
|
+
} else if (opts.ast) {
|
350
|
+
compiled = CoffeeScript.compile(task.input, task.options);
|
351
|
+
return printLine(JSON.stringify(compiled, null, 2));
|
352
|
+
} else if (opts.run) {
|
353
|
+
CoffeeScript.register();
|
354
|
+
if (opts.prelude) {
|
355
|
+
CoffeeScript.eval(opts.prelude, task.options);
|
356
|
+
}
|
357
|
+
return CoffeeScript.run(task.input, task.options);
|
358
|
+
} else if (opts.join && task.file !== opts.join) {
|
359
|
+
if (helpers.isLiterate(file)) {
|
360
|
+
task.input = helpers.invertLiterate(task.input);
|
361
|
+
}
|
362
|
+
sourceCode[sources.indexOf(task.file)] = task.input;
|
363
|
+
return compileJoin();
|
364
|
+
} else {
|
365
|
+
compiled = CoffeeScript.compile(task.input, task.options);
|
366
|
+
task.output = compiled;
|
367
|
+
if (opts.map) {
|
368
|
+
task.output = compiled.js;
|
369
|
+
task.sourceMap = compiled.v3SourceMap;
|
370
|
+
}
|
371
|
+
CoffeeScript.emit('success', task);
|
372
|
+
if (opts.print) {
|
373
|
+
return printLine(task.output.trim());
|
374
|
+
} else if (opts.compile || opts.map) {
|
375
|
+
saveTo = opts.outputFilename && sources.length === 1 ? path.join(opts.outputPath, opts.outputFilename) : options.jsPath;
|
376
|
+
return writeJs(base, task.file, task.output, saveTo, task.sourceMap);
|
377
|
+
}
|
378
|
+
}
|
379
|
+
} catch (error) {
|
380
|
+
err = error;
|
381
|
+
CoffeeScript.emit('failure', err, task);
|
382
|
+
if (CoffeeScript.listeners('failure').length) {
|
383
|
+
return;
|
384
|
+
}
|
385
|
+
message = (err != null ? err.stack : void 0) || `${err}`;
|
386
|
+
if (opts.watch) {
|
387
|
+
return printLine(message + '\x07');
|
388
|
+
} else {
|
389
|
+
printWarn(message);
|
390
|
+
return process.exit(1);
|
391
|
+
}
|
392
|
+
}
|
393
|
+
};
|
394
|
+
|
395
|
+
// Attach the appropriate listeners to compile scripts incoming over **stdin**,
|
396
|
+
// and write them back to **stdout**.
|
397
|
+
compileStdio = function () {
|
398
|
+
var buffers, stdin;
|
399
|
+
if (opts.map) {
|
400
|
+
console.error('--stdio and --map cannot be used together');
|
401
|
+
process.exit(1);
|
402
|
+
}
|
403
|
+
buffers = [];
|
404
|
+
stdin = process.openStdin();
|
405
|
+
stdin.on('data', function (buffer) {
|
406
|
+
if (buffer) {
|
407
|
+
return buffers.push(buffer);
|
408
|
+
}
|
409
|
+
});
|
410
|
+
return stdin.on('end', function () {
|
411
|
+
return compileScript(null, Buffer.concat(buffers).toString());
|
412
|
+
});
|
413
|
+
};
|
414
|
+
|
415
|
+
// If all of the source files are done being read, concatenate and compile
|
416
|
+
// them together.
|
417
|
+
joinTimeout = null;
|
418
|
+
|
419
|
+
compileJoin = function () {
|
420
|
+
if (!opts.join) {
|
421
|
+
return;
|
422
|
+
}
|
423
|
+
if (
|
424
|
+
!sourceCode.some(function (code) {
|
425
|
+
return code === null;
|
426
|
+
})
|
427
|
+
) {
|
428
|
+
clearTimeout(joinTimeout);
|
429
|
+
return (joinTimeout = wait(100, function () {
|
430
|
+
return compileScript(opts.join, sourceCode.join('\n'), opts.join);
|
431
|
+
}));
|
432
|
+
}
|
433
|
+
};
|
434
|
+
|
435
|
+
// Watch a source CoffeeScript file using `fs.watch`, recompiling it every
|
436
|
+
// time the file is updated. May be used in combination with other options,
|
437
|
+
// such as `--print`.
|
438
|
+
watch = function (source, base) {
|
439
|
+
var compile, compileTimeout, err, prevStats, rewatch, startWatcher, watchErr, watcher;
|
440
|
+
watcher = null;
|
441
|
+
prevStats = null;
|
442
|
+
compileTimeout = null;
|
443
|
+
watchErr = function (err) {
|
444
|
+
if (err.code !== 'ENOENT') {
|
445
|
+
throw err;
|
446
|
+
}
|
447
|
+
if (indexOf.call(sources, source) < 0) {
|
448
|
+
return;
|
449
|
+
}
|
450
|
+
try {
|
451
|
+
rewatch();
|
452
|
+
return compile();
|
453
|
+
} catch (error) {
|
454
|
+
removeSource(source, base);
|
455
|
+
return compileJoin();
|
456
|
+
}
|
457
|
+
};
|
458
|
+
compile = function () {
|
459
|
+
clearTimeout(compileTimeout);
|
460
|
+
return (compileTimeout = wait(25, function () {
|
461
|
+
return fs.stat(source, function (err, stats) {
|
462
|
+
if (err) {
|
463
|
+
return watchErr(err);
|
464
|
+
}
|
465
|
+
if (prevStats && stats.size === prevStats.size && stats.mtime.getTime() === prevStats.mtime.getTime()) {
|
466
|
+
return rewatch();
|
467
|
+
}
|
468
|
+
prevStats = stats;
|
469
|
+
return fs.readFile(source, function (err, code) {
|
470
|
+
if (err) {
|
471
|
+
return watchErr(err);
|
472
|
+
}
|
473
|
+
compileScript(source, code.toString(), base);
|
474
|
+
return rewatch();
|
475
|
+
});
|
476
|
+
});
|
477
|
+
}));
|
478
|
+
};
|
479
|
+
startWatcher = function () {
|
480
|
+
return (watcher = fs
|
481
|
+
.watch(source)
|
482
|
+
.on('change', compile)
|
483
|
+
.on('error', function (err) {
|
484
|
+
if (err.code !== 'EPERM') {
|
485
|
+
throw err;
|
486
|
+
}
|
487
|
+
return removeSource(source, base);
|
488
|
+
}));
|
489
|
+
};
|
490
|
+
rewatch = function () {
|
491
|
+
if (watcher != null) {
|
492
|
+
watcher.close();
|
493
|
+
}
|
494
|
+
return startWatcher();
|
495
|
+
};
|
496
|
+
try {
|
497
|
+
return startWatcher();
|
498
|
+
} catch (error) {
|
499
|
+
err = error;
|
500
|
+
return watchErr(err);
|
501
|
+
}
|
502
|
+
};
|
503
|
+
|
504
|
+
// Watch a directory of files for new additions.
|
505
|
+
watchDir = function (source, base) {
|
506
|
+
var err, readdirTimeout, startWatcher, stopWatcher, watcher;
|
507
|
+
watcher = null;
|
508
|
+
readdirTimeout = null;
|
509
|
+
startWatcher = function () {
|
510
|
+
return (watcher = fs
|
511
|
+
.watch(source)
|
512
|
+
.on('error', function (err) {
|
513
|
+
if (err.code !== 'EPERM') {
|
514
|
+
throw err;
|
515
|
+
}
|
516
|
+
return stopWatcher();
|
517
|
+
})
|
518
|
+
.on('change', function () {
|
519
|
+
clearTimeout(readdirTimeout);
|
520
|
+
return (readdirTimeout = wait(25, function () {
|
521
|
+
var err, file, files, i, len, results;
|
522
|
+
try {
|
523
|
+
files = fs.readdirSync(source);
|
524
|
+
} catch (error) {
|
525
|
+
err = error;
|
526
|
+
if (err.code !== 'ENOENT') {
|
527
|
+
throw err;
|
528
|
+
}
|
529
|
+
return stopWatcher();
|
530
|
+
}
|
531
|
+
results = [];
|
532
|
+
for (i = 0, len = files.length; i < len; i++) {
|
533
|
+
file = files[i];
|
534
|
+
results.push(compilePath(path.join(source, file), false, base));
|
535
|
+
}
|
536
|
+
return results;
|
537
|
+
}));
|
538
|
+
}));
|
539
|
+
};
|
540
|
+
stopWatcher = function () {
|
541
|
+
watcher.close();
|
542
|
+
return removeSourceDir(source, base);
|
543
|
+
};
|
544
|
+
watchedDirs[source] = true;
|
545
|
+
try {
|
546
|
+
return startWatcher();
|
547
|
+
} catch (error) {
|
548
|
+
err = error;
|
549
|
+
if (err.code !== 'ENOENT') {
|
550
|
+
throw err;
|
551
|
+
}
|
552
|
+
}
|
553
|
+
};
|
554
|
+
|
555
|
+
removeSourceDir = function (source, base) {
|
556
|
+
var file, i, len, sourcesChanged;
|
557
|
+
delete watchedDirs[source];
|
558
|
+
sourcesChanged = false;
|
559
|
+
for (i = 0, len = sources.length; i < len; i++) {
|
560
|
+
file = sources[i];
|
561
|
+
if (!(source === path.dirname(file))) {
|
562
|
+
continue;
|
563
|
+
}
|
564
|
+
removeSource(file, base);
|
565
|
+
sourcesChanged = true;
|
566
|
+
}
|
567
|
+
if (sourcesChanged) {
|
568
|
+
return compileJoin();
|
569
|
+
}
|
570
|
+
};
|
571
|
+
|
572
|
+
// Remove a file from our source list, and source code cache. Optionally remove
|
573
|
+
// the compiled JS version as well.
|
574
|
+
removeSource = function (source, base) {
|
575
|
+
var index;
|
576
|
+
index = sources.indexOf(source);
|
577
|
+
sources.splice(index, 1);
|
578
|
+
sourceCode.splice(index, 1);
|
579
|
+
if (!opts.join) {
|
580
|
+
silentUnlink(outputPath(source, base));
|
581
|
+
silentUnlink(outputPath(source, base, '.js.map'));
|
582
|
+
return timeLog(`removed ${source}`);
|
583
|
+
}
|
584
|
+
};
|
585
|
+
|
586
|
+
silentUnlink = function (path) {
|
587
|
+
var err, ref;
|
588
|
+
try {
|
589
|
+
return fs.unlinkSync(path);
|
590
|
+
} catch (error) {
|
591
|
+
err = error;
|
592
|
+
if ((ref = err.code) !== 'ENOENT' && ref !== 'EPERM') {
|
593
|
+
throw err;
|
594
|
+
}
|
595
|
+
}
|
596
|
+
};
|
597
|
+
|
598
|
+
// Get the corresponding output JavaScript path for a source file.
|
599
|
+
outputPath = function (source, base, extension = '.js') {
|
600
|
+
var basename, dir, srcDir;
|
601
|
+
basename = helpers.baseFileName(source, true, useWinPathSep);
|
602
|
+
srcDir = path.dirname(source);
|
603
|
+
dir = !opts.outputPath ? srcDir : source === base ? opts.outputPath : path.join(opts.outputPath, path.relative(base, srcDir));
|
604
|
+
return path.join(dir, basename + extension);
|
605
|
+
};
|
606
|
+
|
607
|
+
// Recursively mkdir, like `mkdir -p`.
|
608
|
+
mkdirp = function (dir, fn) {
|
609
|
+
var mkdirs, mode;
|
610
|
+
mode = 0o777 & ~process.umask();
|
611
|
+
return (mkdirs = function (p, fn) {
|
612
|
+
return fs.exists(p, function (exists) {
|
613
|
+
if (exists) {
|
614
|
+
return fn();
|
615
|
+
} else {
|
616
|
+
return mkdirs(path.dirname(p), function () {
|
617
|
+
return fs.mkdir(p, mode, function (err) {
|
618
|
+
if (err) {
|
619
|
+
return fn(err);
|
620
|
+
}
|
621
|
+
return fn();
|
622
|
+
});
|
623
|
+
});
|
624
|
+
}
|
625
|
+
});
|
626
|
+
})(dir, fn);
|
627
|
+
};
|
628
|
+
|
629
|
+
// Write out a JavaScript source file with the compiled code. By default, files
|
630
|
+
// are written out in `cwd` as `.js` files with the same name, but the output
|
631
|
+
// directory can be customized with `--output`.
|
632
|
+
|
633
|
+
// If `generatedSourceMap` is provided, this will write a `.js.map` file into the
|
634
|
+
// same directory as the `.js` file.
|
635
|
+
writeJs = function (base, sourcePath, js, jsPath, generatedSourceMap = null) {
|
636
|
+
var compile, jsDir, sourceMapPath;
|
637
|
+
sourceMapPath = `${jsPath}.map`;
|
638
|
+
jsDir = path.dirname(jsPath);
|
639
|
+
compile = function () {
|
640
|
+
if (opts.compile) {
|
641
|
+
if (js.length <= 0) {
|
642
|
+
js = ' ';
|
643
|
+
}
|
644
|
+
if (generatedSourceMap) {
|
645
|
+
js = `${js}\n//# sourceMappingURL=${helpers.baseFileName(sourceMapPath, false, useWinPathSep)}\n`;
|
646
|
+
}
|
647
|
+
fs.writeFile(jsPath, js, function (err) {
|
648
|
+
if (err) {
|
649
|
+
printLine(err.message);
|
650
|
+
return process.exit(1);
|
651
|
+
} else if (opts.compile && opts.watch) {
|
652
|
+
return timeLog(`compiled ${sourcePath}`);
|
653
|
+
}
|
654
|
+
});
|
655
|
+
}
|
656
|
+
if (generatedSourceMap) {
|
657
|
+
return fs.writeFile(sourceMapPath, generatedSourceMap, function (err) {
|
658
|
+
if (err) {
|
659
|
+
printLine(`Could not write source map: ${err.message}`);
|
660
|
+
return process.exit(1);
|
661
|
+
}
|
662
|
+
});
|
663
|
+
}
|
664
|
+
};
|
665
|
+
return fs.exists(jsDir, function (itExists) {
|
666
|
+
if (itExists) {
|
667
|
+
return compile();
|
668
|
+
} else {
|
669
|
+
return mkdirp(jsDir, compile);
|
670
|
+
}
|
671
|
+
});
|
672
|
+
};
|
673
|
+
|
674
|
+
// Convenience for cleaner setTimeouts.
|
675
|
+
wait = function (milliseconds, func) {
|
676
|
+
return setTimeout(func, milliseconds);
|
677
|
+
};
|
678
|
+
|
679
|
+
// When watching scripts, it's useful to log changes with the timestamp.
|
680
|
+
timeLog = function (message) {
|
681
|
+
return console.log(`${new Date().toLocaleTimeString()} - ${message}`);
|
682
|
+
};
|
683
|
+
|
684
|
+
// Pretty-print a stream of tokens, sans location data.
|
685
|
+
printTokens = function (tokens) {
|
686
|
+
var strings, tag, token, value;
|
687
|
+
strings = (function () {
|
688
|
+
var i, len, results;
|
689
|
+
results = [];
|
690
|
+
for (i = 0, len = tokens.length; i < len; i++) {
|
691
|
+
token = tokens[i];
|
692
|
+
tag = token[0];
|
693
|
+
value = token[1].toString().replace(/\n/, '\\n');
|
694
|
+
results.push(`[${tag} ${value}]`);
|
695
|
+
}
|
696
|
+
return results;
|
697
|
+
})();
|
698
|
+
return printLine(strings.join(' '));
|
699
|
+
};
|
700
|
+
|
701
|
+
// Use the [OptionParser module](optparse.html) to extract all options from
|
702
|
+
// `process.argv` that are specified in `SWITCHES`.
|
703
|
+
parseOptions = function () {
|
704
|
+
var o;
|
705
|
+
o = opts = optionParser.parse(process.argv.slice(2));
|
706
|
+
o.compile || (o.compile = !!o.output);
|
707
|
+
o.run = !(o.compile || o.print || o.map);
|
708
|
+
return (o.print = !!(o.print || o.eval || (o.stdio && o.compile)));
|
709
|
+
};
|
710
|
+
|
711
|
+
// The compile-time options to pass to the CoffeeScript compiler.
|
712
|
+
compileOptions = function (filename, base) {
|
713
|
+
var answer, cwd, jsDir, jsPath;
|
714
|
+
if (opts.transpile) {
|
715
|
+
try {
|
716
|
+
// The user has requested that the CoffeeScript compiler also transpile
|
717
|
+
// via Babel. We don’t include Babel as a dependency because we want to
|
718
|
+
// avoid dependencies in general, and most users probably won’t be relying
|
719
|
+
// on us to transpile for them; we assume most users will probably either
|
720
|
+
// run CoffeeScript’s output without transpilation (modern Node or evergreen
|
721
|
+
// browsers) or use a proper build chain like Gulp or Webpack.
|
722
|
+
require('@babel/core');
|
723
|
+
} catch (error) {
|
724
|
+
try {
|
725
|
+
require('babel-core');
|
726
|
+
} catch (error) {
|
727
|
+
// Give appropriate instructions depending on whether `coffee` was run
|
728
|
+
// locally or globally.
|
729
|
+
if (require.resolve('.').indexOf(process.cwd()) === 0) {
|
730
|
+
console.error(`To use --transpile, you must have @babel/core installed:
|
651
731
|
npm install --save-dev @babel/core
|
652
732
|
And you must save options to configure Babel in one of the places it looks to find its options.
|
653
733
|
See https://coffeescript.org/#transpilation`);
|
654
|
-
|
655
|
-
|
734
|
+
} else {
|
735
|
+
console.error(`To use --transpile with globally-installed CoffeeScript, you must have @babel/core installed globally:
|
656
736
|
npm install --global @babel/core
|
657
737
|
And you must save options to configure Babel in one of the places it looks to find its options, relative to the file being compiled or to the current folder.
|
658
738
|
See https://coffeescript.org/#transpilation`);
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
739
|
+
}
|
740
|
+
process.exit(1);
|
741
|
+
}
|
742
|
+
}
|
743
|
+
if (typeof opts.transpile !== 'object') {
|
744
|
+
opts.transpile = {};
|
745
|
+
}
|
746
|
+
// Pass a reference to Babel into the compiler, so that the transpile option
|
747
|
+
// is available for the CLI. We need to do this so that tools like Webpack
|
748
|
+
// can `require('coffeescript')` and build correctly, without trying to
|
749
|
+
// require Babel.
|
750
|
+
opts.transpile.transpile = CoffeeScript.transpile;
|
751
|
+
// Babel searches for its options (a `.babelrc` file, a `.babelrc.js` file,
|
752
|
+
// a `package.json` file with a `babel` key, etc.) relative to the path
|
753
|
+
// given to it in its `filename` option. Make sure we have a path to pass
|
754
|
+
// along.
|
755
|
+
if (!opts.transpile.filename) {
|
756
|
+
opts.transpile.filename = filename || path.resolve(base || process.cwd(), '<anonymous>');
|
757
|
+
}
|
758
|
+
} else {
|
759
|
+
opts.transpile = false;
|
760
|
+
}
|
761
|
+
answer = {
|
762
|
+
filename: filename,
|
763
|
+
literate: opts.literate || helpers.isLiterate(filename),
|
764
|
+
bare: opts.bare,
|
765
|
+
header: opts.compile && !opts['no-header'],
|
766
|
+
transpile: opts.transpile,
|
767
|
+
sourceMap: opts.map,
|
768
|
+
inlineMap: opts['inline-map'],
|
769
|
+
ast: opts.ast,
|
770
|
+
};
|
771
|
+
if (filename) {
|
772
|
+
if (base) {
|
773
|
+
cwd = process.cwd();
|
774
|
+
jsPath = outputPath(filename, base);
|
775
|
+
jsDir = path.dirname(jsPath);
|
776
|
+
answer = helpers.merge(answer, {
|
777
|
+
jsPath,
|
778
|
+
sourceRoot: path.relative(jsDir, cwd) + path.sep,
|
779
|
+
sourceFiles: [path.relative(cwd, filename)],
|
780
|
+
generatedFile: helpers.baseFileName(jsPath, false, useWinPathSep),
|
781
|
+
});
|
782
|
+
} else {
|
783
|
+
answer = helpers.merge(answer, {
|
784
|
+
sourceRoot: '',
|
785
|
+
sourceFiles: [helpers.baseFileName(filename, false, useWinPathSep)],
|
786
|
+
generatedFile: helpers.baseFileName(filename, true, useWinPathSep) + '.js',
|
787
|
+
});
|
788
|
+
}
|
789
|
+
}
|
790
|
+
return answer;
|
791
|
+
};
|
792
|
+
|
793
|
+
// Start up a new Node.js instance with the arguments in `--nodejs` passed to
|
794
|
+
// the `node` binary, preserving the other options.
|
795
|
+
forkNode = function () {
|
796
|
+
var args, i, len, nodeArgs, p, ref, signal;
|
797
|
+
nodeArgs = opts.nodejs.split(/\s+/);
|
798
|
+
args = process.argv.slice(1);
|
799
|
+
args.splice(args.indexOf('--nodejs'), 2);
|
800
|
+
p = spawn(process.execPath, nodeArgs.concat(args), {
|
801
|
+
cwd: process.cwd(),
|
802
|
+
env: process.env,
|
803
|
+
stdio: [0, 1, 2],
|
804
|
+
});
|
805
|
+
ref = ['SIGINT', 'SIGTERM'];
|
806
|
+
for (i = 0, len = ref.length; i < len; i++) {
|
807
|
+
signal = ref[i];
|
808
|
+
process.on(
|
809
|
+
signal,
|
810
|
+
(function (signal) {
|
811
|
+
return function () {
|
812
|
+
return p.kill(signal);
|
813
|
+
};
|
814
|
+
})(signal),
|
815
|
+
);
|
816
|
+
}
|
817
|
+
return p.on('exit', function (code) {
|
818
|
+
return process.exit(code);
|
819
|
+
});
|
820
|
+
};
|
821
|
+
|
822
|
+
// Print the `--help` usage message and exit. Deprecated switches are not
|
823
|
+
// shown.
|
824
|
+
usage = function () {
|
825
|
+
return printLine(optionParser.help());
|
826
|
+
};
|
827
|
+
|
828
|
+
// Print the `--version` message and exit.
|
829
|
+
version = function () {
|
830
|
+
return printLine(`CoffeeScript version ${CoffeeScript.VERSION}`);
|
831
|
+
};
|
750
832
|
}).call(this);
|