1 | 'use strict';
|
2 |
|
3 | var main = function () {
|
4 | var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee8() {
|
5 | var _this = this;
|
6 |
|
7 | var collect = function () {
|
8 | var _ref5 = _asyncToGenerator(regeneratorRuntime.mark(function _callee5(include, exclude) {
|
9 | var collection, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, pattern, files;
|
10 |
|
11 | return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
12 | while (1) {
|
13 | switch (_context5.prev = _context5.next) {
|
14 | case 0:
|
15 | collection = [];
|
16 | _iteratorNormalCompletion = true;
|
17 | _didIteratorError = false;
|
18 | _iteratorError = undefined;
|
19 | _context5.prev = 4;
|
20 | _iterator = include[Symbol.iterator]();
|
21 |
|
22 | case 6:
|
23 | if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
|
24 | _context5.next = 15;
|
25 | break;
|
26 | }
|
27 |
|
28 | pattern = _step.value;
|
29 | _context5.next = 10;
|
30 | return (0, _file.find)(opts.src + '/' + pattern, { nodir: true, ignore: exclude, cwd: pkg.root });
|
31 |
|
32 | case 10:
|
33 | files = _context5.sent;
|
34 |
|
35 | collection = [].concat(_toConsumableArray(collection), _toConsumableArray(files));
|
36 |
|
37 | case 12:
|
38 | _iteratorNormalCompletion = true;
|
39 | _context5.next = 6;
|
40 | break;
|
41 |
|
42 | case 15:
|
43 | _context5.next = 21;
|
44 | break;
|
45 |
|
46 | case 17:
|
47 | _context5.prev = 17;
|
48 | _context5.t0 = _context5['catch'](4);
|
49 | _didIteratorError = true;
|
50 | _iteratorError = _context5.t0;
|
51 |
|
52 | case 21:
|
53 | _context5.prev = 21;
|
54 | _context5.prev = 22;
|
55 |
|
56 | if (!_iteratorNormalCompletion && _iterator.return) {
|
57 | _iterator.return();
|
58 | }
|
59 |
|
60 | case 24:
|
61 | _context5.prev = 24;
|
62 |
|
63 | if (!_didIteratorError) {
|
64 | _context5.next = 27;
|
65 | break;
|
66 | }
|
67 |
|
68 | throw _iteratorError;
|
69 |
|
70 | case 27:
|
71 | return _context5.finish(24);
|
72 |
|
73 | case 28:
|
74 | return _context5.finish(21);
|
75 |
|
76 | case 29:
|
77 | return _context5.abrupt('return', collection);
|
78 |
|
79 | case 30:
|
80 | case 'end':
|
81 | return _context5.stop();
|
82 | }
|
83 | }
|
84 | }, _callee5, this, [[4, 17, 21, 29], [22,, 24, 28]]);
|
85 | }));
|
86 |
|
87 | return function collect(_x5, _x6) {
|
88 | return _ref5.apply(this, arguments);
|
89 | };
|
90 | }();
|
91 |
|
92 | var execute = function () {
|
93 | var _ref6 = _asyncToGenerator(regeneratorRuntime.mark(function _callee6(type, pipeline) {
|
94 | for (var _len = arguments.length, input = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
95 | input[_key - 2] = arguments[_key];
|
96 | }
|
97 |
|
98 | var result;
|
99 | return regeneratorRuntime.wrap(function _callee6$(_context6) {
|
100 | while (1) {
|
101 | switch (_context6.prev = _context6.next) {
|
102 | case 0:
|
103 | _context6.next = 2;
|
104 | return all(pipeline.apply(undefined, input));
|
105 |
|
106 | case 2:
|
107 | result = _context6.sent;
|
108 | _context6.next = 5;
|
109 | return status.apply(undefined, [type].concat(_toConsumableArray(result)));
|
110 |
|
111 | case 5:
|
112 | return _context6.abrupt('return', result);
|
113 |
|
114 | case 6:
|
115 | case 'end':
|
116 | return _context6.stop();
|
117 | }
|
118 | }
|
119 | }, _callee6, this);
|
120 | }));
|
121 |
|
122 | return function execute(_x7, _x8, _x9) {
|
123 | return _ref6.apply(this, arguments);
|
124 | };
|
125 | }();
|
126 |
|
127 | var status = function () {
|
128 | var _ref7 = _asyncToGenerator(regeneratorRuntime.mark(function _callee7(type) {
|
129 | var _this2 = this;
|
130 |
|
131 | for (var _len2 = arguments.length, results = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
132 | results[_key2 - 1] = arguments[_key2];
|
133 | }
|
134 |
|
135 | var _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _loop, _iterator2, _step2;
|
136 |
|
137 | return regeneratorRuntime.wrap(function _callee7$(_context8) {
|
138 | while (1) {
|
139 | switch (_context8.prev = _context8.next) {
|
140 | case 0:
|
141 | _iteratorNormalCompletion2 = true;
|
142 | _didIteratorError2 = false;
|
143 | _iteratorError2 = undefined;
|
144 | _context8.prev = 3;
|
145 | _loop = regeneratorRuntime.mark(function _loop() {
|
146 | var result, _ref8, input, messages, files, error;
|
147 |
|
148 | return regeneratorRuntime.wrap(function _loop$(_context7) {
|
149 | while (1) {
|
150 | switch (_context7.prev = _context7.next) {
|
151 | case 0:
|
152 | result = _step2.value;
|
153 | _context7.next = 3;
|
154 | return result;
|
155 |
|
156 | case 3:
|
157 | _ref8 = _context7.sent;
|
158 | input = _ref8.input;
|
159 | messages = _ref8.messages;
|
160 | files = _ref8.files;
|
161 | error = _ref8.error;
|
162 |
|
163 |
|
164 | if (messages) {
|
165 | [].concat(_toConsumableArray(messages)).forEach(function (message) {
|
166 | console.warn((0, _ansicolors.yellow)('\n' + type + ' – ' + input + ': ' + message));
|
167 | });
|
168 | }
|
169 |
|
170 | if (error) {
|
171 | console.error('\n' + type + ' – ' + (0, _ansicolors.red)(error.message) + '\n' + (error.codeFrame || error.stack) + '\n');
|
172 | } else {
|
173 | console.log(type + ' – ' + input + ' -> ' + files);
|
174 | }
|
175 |
|
176 | case 10:
|
177 | case 'end':
|
178 | return _context7.stop();
|
179 | }
|
180 | }
|
181 | }, _loop, _this2);
|
182 | });
|
183 | _iterator2 = results[Symbol.iterator]();
|
184 |
|
185 | case 6:
|
186 | if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) {
|
187 | _context8.next = 11;
|
188 | break;
|
189 | }
|
190 |
|
191 | return _context8.delegateYield(_loop(), 't0', 8);
|
192 |
|
193 | case 8:
|
194 | _iteratorNormalCompletion2 = true;
|
195 | _context8.next = 6;
|
196 | break;
|
197 |
|
198 | case 11:
|
199 | _context8.next = 17;
|
200 | break;
|
201 |
|
202 | case 13:
|
203 | _context8.prev = 13;
|
204 | _context8.t1 = _context8['catch'](3);
|
205 | _didIteratorError2 = true;
|
206 | _iteratorError2 = _context8.t1;
|
207 |
|
208 | case 17:
|
209 | _context8.prev = 17;
|
210 | _context8.prev = 18;
|
211 |
|
212 | if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
213 | _iterator2.return();
|
214 | }
|
215 |
|
216 | case 20:
|
217 | _context8.prev = 20;
|
218 |
|
219 | if (!_didIteratorError2) {
|
220 | _context8.next = 23;
|
221 | break;
|
222 | }
|
223 |
|
224 | throw _iteratorError2;
|
225 |
|
226 | case 23:
|
227 | return _context8.finish(20);
|
228 |
|
229 | case 24:
|
230 | return _context8.finish(17);
|
231 |
|
232 | case 25:
|
233 | case 'end':
|
234 | return _context8.stop();
|
235 | }
|
236 | }
|
237 | }, _callee7, this, [[3, 13, 17, 25], [18,, 20, 24]]);
|
238 | }));
|
239 |
|
240 | return function status(_x10, _x11) {
|
241 | return _ref7.apply(this, arguments);
|
242 | };
|
243 | }();
|
244 |
|
245 | var pkg, opts, console, pipeline, build, interactive;
|
246 | return regeneratorRuntime.wrap(function _callee8$(_context9) {
|
247 | while (1) {
|
248 | switch (_context9.prev = _context9.next) {
|
249 | case 0:
|
250 | interactive = function interactive(include, exclude) {
|
251 | var watcher = (0, _chokidar.watch)(include.reduce(function (files, pattern) {
|
252 | return files.concat(opts.src + '/' + pattern);
|
253 | }, []), { ignored: exclude, cwd: pkg.root, ignoreInitial: true });
|
254 |
|
255 | return watcher;
|
256 | };
|
257 |
|
258 | _context9.next = 3;
|
259 | return (0, _pkg.read)(process.cwd());
|
260 |
|
261 | case 3:
|
262 | pkg = _context9.sent;
|
263 | _context9.next = 6;
|
264 | return (0, _opts2.default)(pkg, process.argv);
|
265 |
|
266 | case 6:
|
267 | opts = _context9.sent;
|
268 | console = (0, _stdio2.default)({ debug: !!process.env.DEBUG, format: opts.log });
|
269 |
|
270 |
|
271 | console.debug('Options:');
|
272 | keys(opts).forEach(function (name) {
|
273 | return console.debug('- ' + name + ': ' + JSON.stringify(opts[name]));
|
274 | });
|
275 |
|
276 | pipeline = { js: (0, _pipeline2.default)(pkg, opts, (0, _javascript2.default)(pkg, opts)),
|
277 | css: (0, _pipeline2.default)(pkg, opts, (0, _css2.default)(pkg, opts))
|
278 | };
|
279 |
|
280 |
|
281 | if (opts.copy) {
|
282 | pipeline['copy-files'] = (0, _pipeline2.default)(pkg, opts, (0, _copyFiles2.default)(pkg, opts));
|
283 | }
|
284 |
|
285 | _context9.next = 14;
|
286 | return (0, _performance.timed)(keys(pipeline).reduce(function () {
|
287 | var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee(result, type) {
|
288 | var input;
|
289 | return regeneratorRuntime.wrap(function _callee$(_context) {
|
290 | while (1) {
|
291 | switch (_context.prev = _context.next) {
|
292 | case 0:
|
293 | _context.next = 2;
|
294 | return result;
|
295 |
|
296 | case 2:
|
297 | result = _context.sent;
|
298 | _context.next = 5;
|
299 | return collect(opts.include[type], opts.exclude[type]);
|
300 |
|
301 | case 5:
|
302 | input = _context.sent;
|
303 | _context.next = 8;
|
304 | return execute.apply(undefined, [type, pipeline[type]].concat(_toConsumableArray(input)));
|
305 |
|
306 | case 8:
|
307 | result[type] = _context.sent;
|
308 | return _context.abrupt('return', result);
|
309 |
|
310 | case 10:
|
311 | case 'end':
|
312 | return _context.stop();
|
313 | }
|
314 | }
|
315 | }, _callee, _this);
|
316 | }));
|
317 |
|
318 | return function (_x, _x2) {
|
319 | return _ref2.apply(this, arguments);
|
320 | };
|
321 | }(), {}));
|
322 |
|
323 | case 14:
|
324 | build = _context9.sent;
|
325 |
|
326 |
|
327 | console.debug('Build took ' + build.duration.ms + ' ms');
|
328 |
|
329 | if (!opts.interactive) {
|
330 | _context9.next = 21;
|
331 | break;
|
332 | }
|
333 |
|
334 | keys(pipeline).forEach(function (type) {
|
335 | console.debug('Watching ' + type + ' pipeline:');
|
336 | console.debug('- included: ' + opts.include[type]);
|
337 | console.debug('- excluded: ' + opts.exclude[type]);
|
338 | interactive(opts.include[type], opts.exclude[type]).on('add', function () {
|
339 | var _ref3 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(file) {
|
340 | return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
341 | while (1) {
|
342 | switch (_context2.prev = _context2.next) {
|
343 | case 0:
|
344 | _context2.next = 2;
|
345 | return execute(type, pipeline[type], file);
|
346 |
|
347 | case 2:
|
348 | return _context2.abrupt('return', _context2.sent);
|
349 |
|
350 | case 3:
|
351 | case 'end':
|
352 | return _context2.stop();
|
353 | }
|
354 | }
|
355 | }, _callee2, _this);
|
356 | }));
|
357 |
|
358 | return function (_x3) {
|
359 | return _ref3.apply(this, arguments);
|
360 | };
|
361 | }()).on('change', function () {
|
362 | var _ref4 = _asyncToGenerator(regeneratorRuntime.mark(function _callee3(file) {
|
363 | return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
364 | while (1) {
|
365 | switch (_context3.prev = _context3.next) {
|
366 | case 0:
|
367 | _context3.next = 2;
|
368 | return execute(type, pipeline[type], file);
|
369 |
|
370 | case 2:
|
371 | return _context3.abrupt('return', _context3.sent);
|
372 |
|
373 | case 3:
|
374 | case 'end':
|
375 | return _context3.stop();
|
376 | }
|
377 | }
|
378 | }, _callee3, _this);
|
379 | }));
|
380 |
|
381 | return function (_x4) {
|
382 | return _ref4.apply(this, arguments);
|
383 | };
|
384 | }());
|
385 | });
|
386 | console.info('Watching source files for changes...');
|
387 | _context9.next = 23;
|
388 | break;
|
389 |
|
390 | case 21:
|
391 | if (!opts.optimize) {
|
392 | _context9.next = 23;
|
393 | break;
|
394 | }
|
395 |
|
396 | return _context9.delegateYield(regeneratorRuntime.mark(function _callee4() {
|
397 | var extension, winslash, filename, contents, _filename, _contents;
|
398 |
|
399 | return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
400 | while (1) {
|
401 | switch (_context4.prev = _context4.next) {
|
402 | case 0:
|
403 | console.debug('Writing optimised-modules.json');
|
404 | extension = /^([^\.]+).*$/;
|
405 | winslash = /\\/g;
|
406 | _context4.next = 5;
|
407 | return (0, _file.put)(pkg.resolve('optimised-modules.json'), JSON.stringify(new Set(keys(build.result).reduce(function (files, type) {
|
408 | var pipe = build.result[type];
|
409 | return pipe.reduce(function (files, result) {
|
410 | if (result.files) {
|
411 | return [].concat(_toConsumableArray(files), _toConsumableArray(result.files.map(function (file) {
|
412 | var name = file.replace(extension, '$1').replace(winslash, '/');
|
413 | return pkg.name + '/' + name;
|
414 | })));
|
415 | } else {
|
416 | return files;
|
417 | }
|
418 | }, files);
|
419 | }, [])), null, 2));
|
420 |
|
421 | case 5:
|
422 | if (!build.result.css.length) {
|
423 | _context4.next = 13;
|
424 | break;
|
425 | }
|
426 |
|
427 | console.debug('Writing ' + opts.out + '.css');
|
428 | filename = pkg.resolve(opts.out + '.css');
|
429 | _context4.next = 10;
|
430 | return (0, _css4.default)(pkg, opts)(build.result.css);
|
431 |
|
432 | case 10:
|
433 | contents = _context4.sent;
|
434 | _context4.next = 13;
|
435 | return (0, _file.put)(filename, contents);
|
436 |
|
437 | case 13:
|
438 | if (!build.result.js.length) {
|
439 | _context4.next = 21;
|
440 | break;
|
441 | }
|
442 |
|
443 | console.debug('Writing ' + opts.out + '.js');
|
444 | _filename = pkg.resolve(opts.out + '.js');
|
445 | _context4.next = 18;
|
446 | return (0, _javascript4.default)(pkg, opts)(build.result.js);
|
447 |
|
448 | case 18:
|
449 | _contents = _context4.sent;
|
450 | _context4.next = 21;
|
451 | return (0, _file.put)(_filename, _contents);
|
452 |
|
453 | case 21:
|
454 | case 'end':
|
455 | return _context4.stop();
|
456 | }
|
457 | }
|
458 | }, _callee4, _this);
|
459 | })(), 't0', 23);
|
460 |
|
461 | case 23:
|
462 | case 'end':
|
463 | return _context9.stop();
|
464 | }
|
465 | }
|
466 | }, _callee8, this);
|
467 | }));
|
468 |
|
469 | return function main() {
|
470 | return _ref.apply(this, arguments);
|
471 | };
|
472 | }();
|
473 |
|
474 | var _pkg = require('./util/pkg');
|
475 |
|
476 | var _file = require('./util/file');
|
477 |
|
478 | var _stdio = require('./util/stdio');
|
479 |
|
480 | var _stdio2 = _interopRequireDefault(_stdio);
|
481 |
|
482 | var _javascript = require('./builder/javascript');
|
483 |
|
484 | var _javascript2 = _interopRequireDefault(_javascript);
|
485 |
|
486 | var _css = require('./builder/css');
|
487 |
|
488 | var _css2 = _interopRequireDefault(_css);
|
489 |
|
490 | var _copyFiles = require('./builder/copy-files');
|
491 |
|
492 | var _copyFiles2 = _interopRequireDefault(_copyFiles);
|
493 |
|
494 | var _pipeline = require('./pipeline');
|
495 |
|
496 | var _pipeline2 = _interopRequireDefault(_pipeline);
|
497 |
|
498 | var _javascript3 = require('./postbuild/javascript');
|
499 |
|
500 | var _javascript4 = _interopRequireDefault(_javascript3);
|
501 |
|
502 | var _css3 = require('./postbuild/css');
|
503 |
|
504 | var _css4 = _interopRequireDefault(_css3);
|
505 |
|
506 | var _ansicolors = require('ansicolors');
|
507 |
|
508 | var _chokidar = require('chokidar');
|
509 |
|
510 | var _performance = require('./util/performance');
|
511 |
|
512 | require('./util/cli');
|
513 |
|
514 | var _opts = require('./cli/opts');
|
515 |
|
516 | var _opts2 = _interopRequireDefault(_opts);
|
517 |
|
518 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
519 |
|
520 | 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); } }
|
521 |
|
522 | 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) { return step("next", value); }, function (err) { return step("throw", err); }); } } return step("next"); }); }; }
|
523 |
|
524 | var keys = Object.keys;
|
525 | var all = Promise.all.bind(Promise);
|
526 |
|
527 | main();
|
528 |
|
\ | No newline at end of file |