1 | 'use strict';
|
2 |
|
3 | var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
4 |
|
5 | var main = function () {
|
6 | var _ref = _asyncToGenerator( regeneratorRuntime.mark(function _callee6() {
|
7 | var _this = this;
|
8 |
|
9 | var collect = function () {
|
10 | var _ref4 = _asyncToGenerator( regeneratorRuntime.mark(function _callee3(include, exclude) {
|
11 | var collection, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, pattern, files;
|
12 |
|
13 | return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
14 | while (1) {
|
15 | switch (_context3.prev = _context3.next) {
|
16 | case 0:
|
17 | collection = [];
|
18 | _iteratorNormalCompletion = true;
|
19 | _didIteratorError = false;
|
20 | _iteratorError = undefined;
|
21 | _context3.prev = 4;
|
22 | _iterator = include[Symbol.iterator]();
|
23 |
|
24 | case 6:
|
25 | if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
|
26 | _context3.next = 15;
|
27 | break;
|
28 | }
|
29 |
|
30 | pattern = _step.value;
|
31 | _context3.next = 10;
|
32 | return (0, _file.find)(`${opts.src}/${pattern}`, { nodir: true, ignore: exclude, cwd: pkg.root });
|
33 |
|
34 | case 10:
|
35 | files = _context3.sent;
|
36 |
|
37 | collection = [].concat(_toConsumableArray(collection), _toConsumableArray(files));
|
38 |
|
39 | case 12:
|
40 | _iteratorNormalCompletion = true;
|
41 | _context3.next = 6;
|
42 | break;
|
43 |
|
44 | case 15:
|
45 | _context3.next = 21;
|
46 | break;
|
47 |
|
48 | case 17:
|
49 | _context3.prev = 17;
|
50 | _context3.t0 = _context3['catch'](4);
|
51 | _didIteratorError = true;
|
52 | _iteratorError = _context3.t0;
|
53 |
|
54 | case 21:
|
55 | _context3.prev = 21;
|
56 | _context3.prev = 22;
|
57 |
|
58 | if (!_iteratorNormalCompletion && _iterator.return) {
|
59 | _iterator.return();
|
60 | }
|
61 |
|
62 | case 24:
|
63 | _context3.prev = 24;
|
64 |
|
65 | if (!_didIteratorError) {
|
66 | _context3.next = 27;
|
67 | break;
|
68 | }
|
69 |
|
70 | throw _iteratorError;
|
71 |
|
72 | case 27:
|
73 | return _context3.finish(24);
|
74 |
|
75 | case 28:
|
76 | return _context3.finish(21);
|
77 |
|
78 | case 29:
|
79 | return _context3.abrupt('return', collection);
|
80 |
|
81 | case 30:
|
82 | case 'end':
|
83 | return _context3.stop();
|
84 | }
|
85 | }
|
86 | }, _callee3, this, [[4, 17, 21, 29], [22,, 24, 28]]);
|
87 | }));
|
88 |
|
89 | return function collect(_x4, _x5) {
|
90 | return _ref4.apply(this, arguments);
|
91 | };
|
92 | }();
|
93 |
|
94 | var execute = function () {
|
95 | var _ref5 = _asyncToGenerator( regeneratorRuntime.mark(function _callee4(type, pipeline) {
|
96 | for (var _len = arguments.length, input = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
97 | input[_key - 2] = arguments[_key];
|
98 | }
|
99 |
|
100 | var result;
|
101 | return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
102 | while (1) {
|
103 | switch (_context4.prev = _context4.next) {
|
104 | case 0:
|
105 | _context4.next = 2;
|
106 | return all(pipeline.apply(undefined, _toConsumableArray(input)));
|
107 |
|
108 | case 2:
|
109 | result = _context4.sent;
|
110 | return _context4.abrupt('return', result);
|
111 |
|
112 | case 4:
|
113 | case 'end':
|
114 | return _context4.stop();
|
115 | }
|
116 | }
|
117 | }, _callee4, this);
|
118 | }));
|
119 |
|
120 | return function execute(_x6, _x7) {
|
121 | return _ref5.apply(this, arguments);
|
122 | };
|
123 | }();
|
124 |
|
125 | var status = function () {
|
126 | var _ref6 = _asyncToGenerator( regeneratorRuntime.mark(function _callee5(type) {
|
127 | var _this2 = this;
|
128 |
|
129 | for (var _len2 = arguments.length, results = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
130 | results[_key2 - 1] = arguments[_key2];
|
131 | }
|
132 |
|
133 | var _loop, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, result;
|
134 |
|
135 | return regeneratorRuntime.wrap(function _callee5$(_context6) {
|
136 | while (1) {
|
137 | switch (_context6.prev = _context6.next) {
|
138 | case 0:
|
139 | _loop = regeneratorRuntime.mark(function _loop(result) {
|
140 | var _ref7, input, messages, files, error;
|
141 |
|
142 | return regeneratorRuntime.wrap(function _loop$(_context5) {
|
143 | while (1) {
|
144 | switch (_context5.prev = _context5.next) {
|
145 | case 0:
|
146 | _context5.next = 2;
|
147 | return result;
|
148 |
|
149 | case 2:
|
150 | _ref7 = _context5.sent;
|
151 | input = _ref7.input;
|
152 | messages = _ref7.messages;
|
153 | files = _ref7.files;
|
154 | error = _ref7.error;
|
155 |
|
156 |
|
157 | if (messages) {
|
158 | [].concat(_toConsumableArray(messages)).forEach(function (message) {
|
159 | console.warn((0, _ansicolors.yellow)(`${type} – ${input}: ${message}`));
|
160 | });
|
161 | }
|
162 |
|
163 | if (error) {
|
164 | console.error((0, _ansicolors.red)(`${type} – ${error.message}\n${error.codeFrame || error.stack}`));
|
165 | } else {
|
166 | console.log(`${type} – ${input} -> ${files}`);
|
167 | }
|
168 |
|
169 | case 9:
|
170 | case 'end':
|
171 | return _context5.stop();
|
172 | }
|
173 | }
|
174 | }, _loop, _this2);
|
175 | });
|
176 | _iteratorNormalCompletion2 = true;
|
177 | _didIteratorError2 = false;
|
178 | _iteratorError2 = undefined;
|
179 | _context6.prev = 4;
|
180 | _iterator2 = results[Symbol.iterator]();
|
181 |
|
182 | case 6:
|
183 | if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) {
|
184 | _context6.next = 12;
|
185 | break;
|
186 | }
|
187 |
|
188 | result = _step2.value;
|
189 | return _context6.delegateYield(_loop(result), 't0', 9);
|
190 |
|
191 | case 9:
|
192 | _iteratorNormalCompletion2 = true;
|
193 | _context6.next = 6;
|
194 | break;
|
195 |
|
196 | case 12:
|
197 | _context6.next = 18;
|
198 | break;
|
199 |
|
200 | case 14:
|
201 | _context6.prev = 14;
|
202 | _context6.t1 = _context6['catch'](4);
|
203 | _didIteratorError2 = true;
|
204 | _iteratorError2 = _context6.t1;
|
205 |
|
206 | case 18:
|
207 | _context6.prev = 18;
|
208 | _context6.prev = 19;
|
209 |
|
210 | if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
211 | _iterator2.return();
|
212 | }
|
213 |
|
214 | case 21:
|
215 | _context6.prev = 21;
|
216 |
|
217 | if (!_didIteratorError2) {
|
218 | _context6.next = 24;
|
219 | break;
|
220 | }
|
221 |
|
222 | throw _iteratorError2;
|
223 |
|
224 | case 24:
|
225 | return _context6.finish(21);
|
226 |
|
227 | case 25:
|
228 | return _context6.finish(18);
|
229 |
|
230 | case 26:
|
231 | case 'end':
|
232 | return _context6.stop();
|
233 | }
|
234 | }
|
235 | }, _callee5, this, [[4, 14, 18, 26], [19,, 21, 25]]);
|
236 | }));
|
237 |
|
238 | return function status(_x8) {
|
239 | return _ref6.apply(this, arguments);
|
240 | };
|
241 | }();
|
242 |
|
243 | var pkg, opts, console, pipeline, build, extension, winslash, filename, contents, _filename, _contents, interactive;
|
244 |
|
245 | return regeneratorRuntime.wrap(function _callee6$(_context7) {
|
246 | while (1) {
|
247 | switch (_context7.prev = _context7.next) {
|
248 | case 0:
|
249 | interactive = function interactive(include, exclude) {
|
250 | var watcher = (0, _chokidar.watch)(include.reduce(function (files, pattern) {
|
251 | return files.concat(`${opts.src}/${pattern}`);
|
252 | }, []), { ignored: exclude, cwd: pkg.root, ignoreInitial: true });
|
253 |
|
254 | return watcher;
|
255 | };
|
256 |
|
257 | _context7.next = 3;
|
258 | return (0, _pkg.read)(process.cwd());
|
259 |
|
260 | case 3:
|
261 | pkg = _context7.sent;
|
262 | _context7.next = 6;
|
263 | return (0, _opts2.default)(pkg, process.argv);
|
264 |
|
265 | case 6:
|
266 | opts = _context7.sent;
|
267 | console = (0, _stdio2.default)({ debug: !!process.env.DEBUG, format: opts.log });
|
268 | _context7.next = 10;
|
269 | return babelrcWarning(pkg, console);
|
270 |
|
271 | case 10:
|
272 | opts.babelrc = _context7.sent;
|
273 |
|
274 |
|
275 | console.debug('Options:');
|
276 | keys(opts).forEach(function (name) {
|
277 | return console.debug(`- ${name}: ${JSON.stringify(opts[name])}`);
|
278 | });
|
279 |
|
280 | if (process.env.NODE_ENV === undefined) {
|
281 | process.env.NODE_ENV = opts.production ? 'production' : 'development';
|
282 | }
|
283 |
|
284 | pipeline = void 0;
|
285 |
|
286 |
|
287 | try {
|
288 | pipeline = { js: (0, _pipeline2.default)(pkg, opts, (0, _javascript2.default)(pkg, opts)),
|
289 | css: (0, _pipeline2.default)(pkg, opts, (0, _css2.default)(pkg, opts))
|
290 | };
|
291 |
|
292 | if (opts.copy) {
|
293 | pipeline['copy-files'] = (0, _pipeline2.default)(pkg, opts, (0, _copyFiles2.default)(pkg, opts));
|
294 | }
|
295 | } catch (e) {
|
296 | console.error((0, _ansicolors.red)(`Failed to start compiler: ${e.message}`));
|
297 | process.exit(1);
|
298 | }
|
299 |
|
300 | _context7.next = 18;
|
301 | return (0, _performance.timed)(keys(pipeline).reduce(function () {
|
302 | var _ref2 = _asyncToGenerator( regeneratorRuntime.mark(function _callee(result, type) {
|
303 | var input;
|
304 | return regeneratorRuntime.wrap(function _callee$(_context) {
|
305 | while (1) {
|
306 | switch (_context.prev = _context.next) {
|
307 | case 0:
|
308 | _context.next = 2;
|
309 | return result;
|
310 |
|
311 | case 2:
|
312 | result = _context.sent;
|
313 | _context.next = 5;
|
314 | return collect(opts.include[type], opts.exclude[type]);
|
315 |
|
316 | case 5:
|
317 | input = _context.sent;
|
318 | _context.next = 8;
|
319 | return execute.apply(undefined, [type, pipeline[type]].concat(_toConsumableArray(input)));
|
320 |
|
321 | case 8:
|
322 | result[type] = _context.sent;
|
323 |
|
324 | result[type].errors = result[type].filter(function (result) {
|
325 | return result.error;
|
326 | });
|
327 |
|
328 | if (!(!opts.interactive || process.stdout.isTTY)) {
|
329 | _context.next = 13;
|
330 | break;
|
331 | }
|
332 |
|
333 | _context.next = 13;
|
334 | return status.apply(undefined, [type].concat(_toConsumableArray(result[type])));
|
335 |
|
336 | case 13:
|
337 | return _context.abrupt('return', result);
|
338 |
|
339 | case 14:
|
340 | case 'end':
|
341 | return _context.stop();
|
342 | }
|
343 | }
|
344 | }, _callee, _this);
|
345 | }));
|
346 |
|
347 | return function (_x, _x2) {
|
348 | return _ref2.apply(this, arguments);
|
349 | };
|
350 | }(), {}));
|
351 |
|
352 | case 18:
|
353 | build = _context7.sent;
|
354 |
|
355 |
|
356 | console.debug(`Build took ${build.duration.ms} ms`);
|
357 |
|
358 | if (!opts.interactive) {
|
359 | _context7.next = 25;
|
360 | break;
|
361 | }
|
362 |
|
363 | keys(pipeline).forEach(function (type) {
|
364 | var build = function () {
|
365 | var _ref3 = _asyncToGenerator( regeneratorRuntime.mark(function _callee2(file) {
|
366 | var result;
|
367 | return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
368 | while (1) {
|
369 | switch (_context2.prev = _context2.next) {
|
370 | case 0:
|
371 | _context2.next = 2;
|
372 | return execute(type, pipeline[type], file);
|
373 |
|
374 | case 2:
|
375 | result = _context2.sent;
|
376 | _context2.next = 5;
|
377 | return status.apply(undefined, [type].concat(_toConsumableArray(result)));
|
378 |
|
379 | case 5:
|
380 | case 'end':
|
381 | return _context2.stop();
|
382 | }
|
383 | }
|
384 | }, _callee2, this);
|
385 | }));
|
386 |
|
387 | return function build(_x3) {
|
388 | return _ref3.apply(this, arguments);
|
389 | };
|
390 | }();
|
391 |
|
392 | console.debug(`Watching ${type} pipeline:`);
|
393 | console.debug(`- included: ${opts.include[type]}`);
|
394 | console.debug(`- excluded: ${opts.exclude[type]}`);
|
395 | interactive(opts.include[type], opts.exclude[type]).on('add', build).on('change', build);
|
396 | });
|
397 | console.info('Watching source files for changes...');
|
398 | _context7.next = 52;
|
399 | break;
|
400 |
|
401 | case 25:
|
402 | if (!keys(build.result).some(function (type) {
|
403 | return build.result[type].errors.length;
|
404 | })) {
|
405 | _context7.next = 30;
|
406 | break;
|
407 | }
|
408 |
|
409 | console.info('\nBuild failed to due unrecoverable errors.');
|
410 | process.exit(1);
|
411 | _context7.next = 52;
|
412 | break;
|
413 |
|
414 | case 30:
|
415 | if (!opts.optimize) {
|
416 | _context7.next = 52;
|
417 | break;
|
418 | }
|
419 |
|
420 | console.debug('Writing optimised-modules.json');
|
421 | extension = /^([^\.]+).*$/;
|
422 | winslash = /\\/g;
|
423 | _context7.next = 36;
|
424 | return (0, _file.put)(pkg.resolve('optimised-modules.json'), JSON.stringify(new Set(keys(build.result).reduce(function (files, type) {
|
425 | var pipe = build.result[type];
|
426 | return pipe.reduce(function (files, result) {
|
427 | if (result.files) {
|
428 | return [].concat(_toConsumableArray(files), _toConsumableArray(result.files.map(function (file) {
|
429 | var name = file.replace(extension, '$1').replace(winslash, '/');
|
430 | return `${pkg.name}/${name}`;
|
431 | })));
|
432 | } else {
|
433 | return files;
|
434 | }
|
435 | }, files);
|
436 | }, [])), null, 2));
|
437 |
|
438 | case 36:
|
439 | if (!build.result.css.length) {
|
440 | _context7.next = 44;
|
441 | break;
|
442 | }
|
443 |
|
444 | console.debug(`Writing ${opts.out}.css`);
|
445 | filename = pkg.resolve(`${opts.out}.css`);
|
446 | _context7.next = 41;
|
447 | return (0, _css4.default)(pkg, opts)(build.result.css);
|
448 |
|
449 | case 41:
|
450 | contents = _context7.sent;
|
451 | _context7.next = 44;
|
452 | return (0, _file.put)(filename, contents);
|
453 |
|
454 | case 44:
|
455 | if (!build.result.js.length) {
|
456 | _context7.next = 52;
|
457 | break;
|
458 | }
|
459 |
|
460 | console.debug(`Writing ${opts.out}.js`);
|
461 | _filename = pkg.resolve(`${opts.out}.js`);
|
462 | _context7.next = 49;
|
463 | return (0, _javascript4.default)(pkg, opts)(build.result.js);
|
464 |
|
465 | case 49:
|
466 | _contents = _context7.sent;
|
467 | _context7.next = 52;
|
468 | return (0, _file.put)(_filename, _contents);
|
469 |
|
470 | case 52:
|
471 | case 'end':
|
472 | return _context7.stop();
|
473 | }
|
474 | }
|
475 | }, _callee6, this);
|
476 | }));
|
477 |
|
478 | return function main() {
|
479 | return _ref.apply(this, arguments);
|
480 | };
|
481 | }();
|
482 |
|
483 | var babelrcWarning = function () {
|
484 | var _ref8 = _asyncToGenerator( regeneratorRuntime.mark(function _callee7(pkg, console) {
|
485 | var babelrc, _messages;
|
486 |
|
487 | return regeneratorRuntime.wrap(function _callee7$(_context8) {
|
488 | while (1) {
|
489 | switch (_context8.prev = _context8.next) {
|
490 | case 0:
|
491 | babelrc = void 0;
|
492 | _context8.prev = 1;
|
493 | _context8.t0 = JSON;
|
494 | _context8.next = 5;
|
495 | return (0, _file.slurp)(pkg.resolve('.babelrc'), 'utf8');
|
496 |
|
497 | case 5:
|
498 | _context8.t1 = _context8.sent;
|
499 | babelrc = _context8.t0.parse.call(_context8.t0, _context8.t1);
|
500 | _context8.next = 12;
|
501 | break;
|
502 |
|
503 | case 9:
|
504 | _context8.prev = 9;
|
505 | _context8.t2 = _context8['catch'](1);
|
506 |
|
507 | babelrc = pkg.babel;
|
508 |
|
509 | case 12:
|
510 |
|
511 | if (babelrc) {
|
512 | _messages = [];
|
513 | (babelrc.presets || []).forEach(function (preset) {
|
514 | var _concat = [].concat(preset),
|
515 | _concat2 = _slicedToArray(_concat, 1),
|
516 | name = _concat2[0];
|
517 |
|
518 | if (name === 'es2015' || name === 'es2016') {
|
519 | _messages.push(`${name} support is always enabled`);
|
520 | } else if (name === 'es2017') {
|
521 | _messages.push('To enable es2017 support, use: --flags es2017');
|
522 | } else if (name === 'react') {
|
523 | _messages.push('To enable react support, use: --flags react');
|
524 | } else {
|
525 | _messages.push(`Unsupported preset: ${name}`);
|
526 | }
|
527 | });(babelrc.plugins || []).forEach(function (plugin) {
|
528 | var _concat3 = [].concat(plugin),
|
529 | _concat4 = _slicedToArray(_concat3, 1),
|
530 | name = _concat4[0];
|
531 |
|
532 | if (/^transform-es2015-modules-(umd|amd|ecmascript|commonjs|systemjs)$/.test(name)) {
|
533 | var format = name.slice('transform-es2015-modules-'.length);
|
534 | _messages.push(`To enable ${format} modules, use: --flags modules:${format}`);
|
535 | } else {
|
536 | _messages.push(`Unsupported plugin: ${name}`);
|
537 | }
|
538 | });
|
539 |
|
540 | if (babelrc.env) {
|
541 | _messages.push(`babel.env: NODE_ENV is respected by ez-build`);
|
542 | }
|
543 |
|
544 | console.warn((0, _ansicolors.red)('WARNING: ez-build is discontinuing support for .babelrc'), (0, _ansicolors.yellow)(`
|
545 |
|
546 | Currently ez-build still loads .babelrc files, but this support is
|
547 | going away before v1.0.0. Please make sure to migrate any relevant
|
548 | configuration to use flags instead.
|
549 |
|
550 | Not sure how to migrate? Please open an issue:
|
551 |
|
552 | https://github.com/zambezi/ez-build/issues/new
|
553 | ${_messages.length ? `
|
554 | Comments on the detected babel configuration:
|
555 |
|
556 | - ${_messages.join('\n- ')}
|
557 | ` : ''}
|
558 | `));
|
559 | }
|
560 |
|
561 | return _context8.abrupt('return', !!babelrc);
|
562 |
|
563 | case 14:
|
564 | case 'end':
|
565 | return _context8.stop();
|
566 | }
|
567 | }
|
568 | }, _callee7, this, [[1, 9]]);
|
569 | }));
|
570 |
|
571 | return function babelrcWarning(_x9, _x10) {
|
572 | return _ref8.apply(this, arguments);
|
573 | };
|
574 | }();
|
575 |
|
576 | var _pkg = require('./util/pkg');
|
577 |
|
578 | var _file = require('./util/file');
|
579 |
|
580 | var _stdio = require('./util/stdio');
|
581 |
|
582 | var _stdio2 = _interopRequireDefault(_stdio);
|
583 |
|
584 | var _javascript = require('./builder/javascript');
|
585 |
|
586 | var _javascript2 = _interopRequireDefault(_javascript);
|
587 |
|
588 | var _css = require('./builder/css');
|
589 |
|
590 | var _css2 = _interopRequireDefault(_css);
|
591 |
|
592 | var _copyFiles = require('./builder/copy-files');
|
593 |
|
594 | var _copyFiles2 = _interopRequireDefault(_copyFiles);
|
595 |
|
596 | var _pipeline = require('./pipeline');
|
597 |
|
598 | var _pipeline2 = _interopRequireDefault(_pipeline);
|
599 |
|
600 | var _javascript3 = require('./postbuild/javascript');
|
601 |
|
602 | var _javascript4 = _interopRequireDefault(_javascript3);
|
603 |
|
604 | var _css3 = require('./postbuild/css');
|
605 |
|
606 | var _css4 = _interopRequireDefault(_css3);
|
607 |
|
608 | var _ansicolors = require('ansicolors');
|
609 |
|
610 | var _chokidar = require('chokidar');
|
611 |
|
612 | var _performance = require('./util/performance');
|
613 |
|
614 | require('./util/cli');
|
615 |
|
616 | var _opts = require('./cli/opts');
|
617 |
|
618 | var _opts2 = _interopRequireDefault(_opts);
|
619 |
|
620 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
621 |
|
622 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
623 |
|
624 | function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
|
625 |
|
626 | var keys = Object.keys;
|
627 | var all = Promise.all.bind(Promise);
|
628 |
|
629 | main();
|
630 |
|
\ | No newline at end of file |