@micromag/cli 0.3.699 → 0.3.701

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.js +128 -132
  2. package/package.json +6 -6
package/lib/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var _regeneratorRuntime = require('@babel/runtime/helpers/regeneratorRuntime');
3
+ var _regenerator = require('@babel/runtime/helpers/regenerator');
4
4
  var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
5
5
  var fs = require('fs');
6
6
  var core = require('@micromag/core');
7
7
  var screensManager = require('@micromag/screens');
8
8
  var FieldsManager = require('@micromag/fields');
9
9
  var transforms = require('@micromag/transforms');
10
+ var _regeneratorValues = require('@babel/runtime/helpers/regeneratorValues');
10
11
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
11
12
  var path = require('path');
12
13
  var puppeteer = require('puppeteer');
@@ -141,37 +142,35 @@ var transformStory = function transformStory(story, format) {
141
142
  };
142
143
 
143
144
  var startServer = /*#__PURE__*/function () {
144
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(path) {
145
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(path) {
145
146
  var port,
146
147
  finalPort,
147
- _args = arguments;
148
- return _regeneratorRuntime().wrap(function _callee$(_context) {
149
- while (1) switch (_context.prev = _context.next) {
148
+ _args = arguments,
149
+ _t;
150
+ return _regenerator().w(function (_context) {
151
+ while (1) switch (_context.n) {
150
152
  case 0:
151
153
  port = _args.length > 1 && _args[1] !== undefined ? _args[1] : null;
152
- _context.t0 = port;
153
- if (_context.t0) {
154
- _context.next = 6;
154
+ _t = port;
155
+ if (_t) {
156
+ _context.n = 2;
155
157
  break;
156
158
  }
157
- _context.next = 5;
159
+ _context.n = 1;
158
160
  return getPort({
159
161
  port: getPort.makeRange(3050, 3100)
160
162
  });
161
- case 5:
162
- _context.t0 = _context.sent;
163
- case 6:
164
- finalPort = _context.t0;
165
- return _context.abrupt("return", new Promise(function (resolve) {
163
+ case 1:
164
+ _t = _context.v;
165
+ case 2:
166
+ finalPort = _t;
167
+ return _context.a(2, new Promise(function (resolve) {
166
168
  var app = express();
167
169
  app.use(express["static"](path));
168
170
  var server = app.listen(finalPort, function () {
169
171
  return resolve(server);
170
172
  });
171
173
  }));
172
- case 8:
173
- case "end":
174
- return _context.stop();
175
174
  }
176
175
  }, _callee);
177
176
  }));
@@ -201,7 +200,7 @@ var DEFAULT_VIEWPORT = {
201
200
  isMobile: true
202
201
  };
203
202
  var captureStory = /*#__PURE__*/function () {
204
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(story, location) {
203
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(story, location) {
205
204
  var settings,
206
205
  _settings$viewport,
207
206
  defaultViewport,
@@ -223,20 +222,21 @@ var captureStory = /*#__PURE__*/function () {
223
222
  count,
224
223
  _loop,
225
224
  index,
226
- _args2 = arguments;
227
- return _regeneratorRuntime().wrap(function _callee$(_context2) {
228
- while (1) switch (_context2.prev = _context2.next) {
225
+ _args2 = arguments,
226
+ _t2;
227
+ return _regenerator().w(function (_context2) {
228
+ while (1) switch (_context2.n) {
229
229
  case 0:
230
230
  settings = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
231
231
  _settings$viewport = settings.viewport, defaultViewport = _settings$viewport === void 0 ? DEFAULT_VIEWPORT : _settings$viewport, _settings$googleApiKe = settings.googleApiKey, googleApiKey = _settings$googleApiKe === void 0 ? null : _settings$googleApiKe, _settings$executableP = settings.executablePath, executablePath = _settings$executableP === void 0 ? null : _settings$executableP;
232
- _context2.next = 4;
232
+ _context2.n = 1;
233
233
  return startServer(path.join(process.cwd(), './node_modules/@micromag/viewer-build/build/'));
234
- case 4:
235
- server = _context2.sent;
234
+ case 1:
235
+ server = _context2.v;
236
236
  serverPort = server.address().port;
237
237
  width = defaultViewport.width, height = defaultViewport.height;
238
238
  _ref2 = story || {}, _ref2$components = _ref2.components, screens = _ref2$components === void 0 ? null : _ref2$components;
239
- _context2.next = 10;
239
+ _context2.n = 2;
240
240
  return puppeteer.launch(_objectSpread(_objectSpread({
241
241
  devtools: DEBUG
242
242
  }, executablePath !== null ? {
@@ -245,39 +245,39 @@ var captureStory = /*#__PURE__*/function () {
245
245
  defaultViewport: defaultViewport,
246
246
  args: ['--no-sandbox']
247
247
  }));
248
- case 10:
249
- browser = _context2.sent;
250
- _context2.next = 13;
248
+ case 2:
249
+ browser = _context2.v;
250
+ _context2.n = 3;
251
251
  return browser.pages();
252
- case 13:
253
- pages = _context2.sent;
252
+ case 3:
253
+ pages = _context2.v;
254
254
  hasPage = pages.length > 0;
255
255
  if (!hasPage) {
256
- _context2.next = 19;
256
+ _context2.n = 4;
257
257
  break;
258
258
  }
259
- _context2.t0 = pages[0];
260
- _context2.next = 22;
259
+ _t2 = pages[0];
260
+ _context2.n = 6;
261
261
  break;
262
- case 19:
263
- _context2.next = 21;
262
+ case 4:
263
+ _context2.n = 5;
264
264
  return browser.newPage();
265
- case 21:
266
- _context2.t0 = _context2.sent;
267
- case 22:
268
- page = _context2.t0;
269
- _context2.next = 25;
265
+ case 5:
266
+ _t2 = _context2.v;
267
+ case 6:
268
+ page = _t2;
269
+ _context2.n = 7;
270
270
  return page["goto"]("http://127.0.0.1:".concat(serverPort));
271
- case 25:
271
+ case 7:
272
272
  if (!(screens !== null)) {
273
- _context2.next = 34;
273
+ _context2.n = 10;
274
274
  break;
275
275
  }
276
276
  count = screens.length;
277
- _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
277
+ _loop = /*#__PURE__*/_regenerator().m(function _loop() {
278
278
  var screenNumber, screen, id, type, singleScreenStory, _screen$video, _screen$video2, _screen$video2$media, _screen$video2$media2, _screen$video2$media3, url, fileExtension, res, fileStream;
279
- return _regeneratorRuntime().wrap(function _loop$(_context) {
280
- while (1) switch (_context.prev = _context.next) {
279
+ return _regenerator().w(function (_context) {
280
+ while (1) switch (_context.n) {
281
281
  case 0:
282
282
  screenNumber = index + 1;
283
283
  screen = screens[index];
@@ -287,25 +287,25 @@ var captureStory = /*#__PURE__*/function () {
287
287
  });
288
288
  console.log("Screen ".concat(screenNumber, "/").concat(count, " (").concat(type, ")..."));
289
289
  if (!(type === 'video' || type === 'video-360')) {
290
- _context.next = 15;
290
+ _context.n = 2;
291
291
  break;
292
292
  }
293
293
  _screen$video = screen.video, _screen$video2 = _screen$video === void 0 ? {} : _screen$video, _screen$video2$media = _screen$video2.media, _screen$video2$media2 = _screen$video2$media === void 0 ? {} : _screen$video2$media, _screen$video2$media3 = _screen$video2$media2.url, url = _screen$video2$media3 === void 0 ? null : _screen$video2$media3;
294
294
  console.log("Downloading video from ".concat(url, "..."));
295
295
  fileExtension = url.split(/[#?]/)[0].split('.').pop().trim();
296
- _context.next = 11;
296
+ _context.n = 1;
297
297
  return nodeFetch(url);
298
- case 11:
299
- res = _context.sent;
298
+ case 1:
299
+ res = _context.v;
300
300
  fileStream = fsExtra.createWriteStream(getOutputPath(location, "".concat(screenNumber, ".").concat(fileExtension)));
301
- _context.next = 15;
301
+ _context.n = 2;
302
302
  return new Promise(function (resolve, reject) {
303
303
  res.body.pipe(fileStream);
304
304
  res.body.on('error', reject);
305
305
  fileStream.on('finish', resolve);
306
306
  });
307
- case 15:
308
- _context.next = 17;
307
+ case 2:
308
+ _context.n = 3;
309
309
  return page.evaluate(function (storyToRender, storyProps) {
310
310
  return renderStory(storyToRender, storyProps);
311
311
  }, singleScreenStory, {
@@ -317,49 +317,47 @@ var captureStory = /*#__PURE__*/function () {
317
317
  height: height,
318
318
  googleApiKey: googleApiKey
319
319
  });
320
- case 17:
321
- _context.prev = 17;
322
- _context.next = 20;
320
+ case 3:
321
+ _context.p = 3;
322
+ _context.n = 4;
323
323
  return page.waitForSelector('[data-screen-ready="true"]', {
324
324
  timeout: READY_WAIT_TIMEOUT
325
325
  });
326
- case 20:
327
- _context.next = 25;
326
+ case 4:
327
+ _context.n = 6;
328
328
  break;
329
- case 22:
330
- _context.prev = 22;
331
- _context.t0 = _context["catch"](17);
329
+ case 5:
330
+ _context.p = 5;
331
+ _context.v;
332
332
  console.log("Timeout reached: ".concat(id));
333
- case 25:
334
- _context.next = 27;
333
+ case 6:
334
+ _context.n = 7;
335
335
  return page.screenshot({
336
336
  path: getOutputPath(location, "".concat(screenNumber, ".png"))
337
337
  });
338
- case 27:
339
- case "end":
340
- return _context.stop();
338
+ case 7:
339
+ return _context.a(2);
341
340
  }
342
- }, _loop, null, [[17, 22]]);
341
+ }, _loop, null, [[3, 5]]);
343
342
  });
344
343
  index = 0;
345
- case 29:
344
+ case 8:
346
345
  if (!(index < count)) {
347
- _context2.next = 34;
346
+ _context2.n = 10;
348
347
  break;
349
348
  }
350
- return _context2.delegateYield(_loop(), "t1", 31);
351
- case 31:
349
+ return _context2.d(_regeneratorValues(_loop()), 9);
350
+ case 9:
352
351
  index += 1;
353
- _context2.next = 29;
352
+ _context2.n = 8;
354
353
  break;
355
- case 34:
356
- _context2.next = 36;
354
+ case 10:
355
+ _context2.n = 11;
357
356
  return browser.close();
358
- case 36:
357
+ case 11:
359
358
  server.close();
360
- case 37:
361
- case "end":
362
- return _context2.stop();
359
+ case 12:
360
+ return _context2.a(2);
363
361
  }
364
362
  }, _callee);
365
363
  }));
@@ -369,7 +367,7 @@ var captureStory = /*#__PURE__*/function () {
369
367
  }();
370
368
 
371
369
  var getStoryHtml = /*#__PURE__*/function () {
372
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(story) {
370
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(story) {
373
371
  var settings,
374
372
  _settings$googleApiKe,
375
373
  googleApiKey,
@@ -382,18 +380,19 @@ var getStoryHtml = /*#__PURE__*/function () {
382
380
  hasPage,
383
381
  page,
384
382
  pageContent,
385
- _args = arguments;
386
- return _regeneratorRuntime().wrap(function _callee$(_context) {
387
- while (1) switch (_context.prev = _context.next) {
383
+ _args = arguments,
384
+ _t;
385
+ return _regenerator().w(function (_context) {
386
+ while (1) switch (_context.n) {
388
387
  case 0:
389
388
  settings = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
390
389
  _settings$googleApiKe = settings.googleApiKey, googleApiKey = _settings$googleApiKe === void 0 ? null : _settings$googleApiKe, _settings$executableP = settings.executablePath, executablePath = _settings$executableP === void 0 ? null : _settings$executableP;
391
- _context.next = 4;
390
+ _context.n = 1;
392
391
  return startServer(path.join(process.cwd(), './node_modules/@micromag/viewer-build/build/'));
393
- case 4:
394
- server = _context.sent;
392
+ case 1:
393
+ server = _context.v;
395
394
  serverPort = server.address().port;
396
- _context.next = 8;
395
+ _context.n = 2;
397
396
  return puppeteer.launch(_objectSpread(_objectSpread({
398
397
  devtools: false
399
398
  }, executablePath !== null ? {
@@ -406,31 +405,31 @@ var getStoryHtml = /*#__PURE__*/function () {
406
405
  isMobile: true
407
406
  }
408
407
  }));
409
- case 8:
410
- browser = _context.sent;
411
- _context.next = 11;
408
+ case 2:
409
+ browser = _context.v;
410
+ _context.n = 3;
412
411
  return browser.pages();
413
- case 11:
414
- pages = _context.sent;
412
+ case 3:
413
+ pages = _context.v;
415
414
  hasPage = pages.length > 0;
416
415
  if (!hasPage) {
417
- _context.next = 17;
416
+ _context.n = 4;
418
417
  break;
419
418
  }
420
- _context.t0 = pages[0];
421
- _context.next = 20;
419
+ _t = pages[0];
420
+ _context.n = 6;
422
421
  break;
423
- case 17:
424
- _context.next = 19;
422
+ case 4:
423
+ _context.n = 5;
425
424
  return browser.newPage();
426
- case 19:
427
- _context.t0 = _context.sent;
428
- case 20:
429
- page = _context.t0;
430
- _context.next = 23;
425
+ case 5:
426
+ _t = _context.v;
427
+ case 6:
428
+ page = _t;
429
+ _context.n = 7;
431
430
  return page["goto"]("http://127.0.0.1:".concat(serverPort));
432
- case 23:
433
- _context.next = 25;
431
+ case 7:
432
+ _context.n = 8;
434
433
  return page.evaluate(function (storyToRender, storyProps) {
435
434
  return renderStory(storyToRender, storyProps);
436
435
  }, story, {
@@ -439,19 +438,16 @@ var getStoryHtml = /*#__PURE__*/function () {
439
438
  withoutMenu: true,
440
439
  googleApiKey: googleApiKey
441
440
  });
442
- case 25:
443
- _context.next = 27;
441
+ case 8:
442
+ _context.n = 9;
444
443
  return page.content();
445
- case 27:
446
- pageContent = _context.sent;
447
- _context.next = 30;
444
+ case 9:
445
+ pageContent = _context.v;
446
+ _context.n = 10;
448
447
  return browser.close();
449
- case 30:
448
+ case 10:
450
449
  server.close();
451
- return _context.abrupt("return", pageContent);
452
- case 32:
453
- case "end":
454
- return _context.stop();
450
+ return _context.a(2, pageContent);
455
451
  }
456
452
  }, _callee);
457
453
  }));
@@ -480,7 +476,7 @@ var storyParser = new core.StoryParser({
480
476
  screensManager: screensManager
481
477
  });
482
478
  var exportStoryToPath = /*#__PURE__*/function () {
483
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(story, format, output) {
479
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(story, format, output) {
484
480
  var settings,
485
481
  storyParsed,
486
482
  html,
@@ -490,43 +486,43 @@ var exportStoryToPath = /*#__PURE__*/function () {
490
486
  parsedDestination,
491
487
  newStory,
492
488
  fileDestination,
493
- _args = arguments;
494
- return _regeneratorRuntime().wrap(function _callee$(_context) {
495
- while (1) switch (_context.prev = _context.next) {
489
+ _args = arguments,
490
+ _t;
491
+ return _regenerator().w(function (_context) {
492
+ while (1) switch (_context.n) {
496
493
  case 0:
497
494
  settings = _args.length > 3 && _args[3] !== undefined ? _args[3] : {};
498
495
  storyParsed = storyParser.parse(story);
499
- _context.t0 = format;
500
- _context.next = _context.t0 === 'html' ? 5 : _context.t0 === 'html-ssr' ? 12 : _context.t0 === 'images' ? 16 : 18;
496
+ _t = format;
497
+ _context.n = _t === 'html' ? 1 : _t === 'html-ssr' ? 3 : _t === 'images' ? 4 : 5;
501
498
  break;
502
- case 5:
503
- _context.next = 7;
499
+ case 1:
500
+ _context.n = 2;
504
501
  return getStoryHtml(storyParsed, settings);
505
- case 7:
506
- html = _context.sent;
502
+ case 2:
503
+ html = _context.v;
507
504
  destination = getOutputPath(output, 'story.html');
508
505
  console.log('destination', destination);
509
506
  fs.writeFileSync(destination, html, 'utf-8');
510
- return _context.abrupt("break", 25);
511
- case 12:
507
+ return _context.a(3, 6);
508
+ case 3:
512
509
  _html = getStoryHtmlSSR(storyParsed, settings);
513
510
  _destination = getOutputPath(output, 'story-ssr.html');
514
511
  fs.writeFileSync(_destination, _html, 'utf-8');
515
- return _context.abrupt("break", 25);
516
- case 16:
512
+ return _context.a(3, 6);
513
+ case 4:
517
514
  captureStory(storyParsed, output, settings);
518
- return _context.abrupt("break", 25);
519
- case 18:
515
+ return _context.a(3, 6);
516
+ case 5:
520
517
  parsedDestination = getOutputPath(output, 'parsed.json');
521
518
  fs.writeFileSync(parsedDestination, JSON.stringify(storyParsed), 'utf-8');
522
519
  newStory = transformStory(storyParsed, format); // const mediaDestination = getOutputPath(output);
523
520
  fileDestination = getOutputPath(output, 'article.json');
524
521
  console.log(output, fileDestination);
525
522
  fs.writeFileSync(fileDestination, JSON.stringify(newStory), 'utf-8');
526
- return _context.abrupt("break", 25);
527
- case 25:
528
- case "end":
529
- return _context.stop();
523
+ return _context.a(3, 6);
524
+ case 6:
525
+ return _context.a(2);
530
526
  }
531
527
  }, _callee);
532
528
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/cli",
3
- "version": "0.3.699",
3
+ "version": "0.3.701",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -47,12 +47,12 @@
47
47
  "dependencies": {
48
48
  "@babel/runtime": "^7.13.10",
49
49
  "@micromag/core": "^0.3.679",
50
- "@micromag/elements": "^0.3.683",
50
+ "@micromag/elements": "^0.3.700",
51
51
  "@micromag/fields": "^0.3.699",
52
- "@micromag/screens": "^0.3.699",
52
+ "@micromag/screens": "^0.3.701",
53
53
  "@micromag/transforms": "^0.3.679",
54
- "@micromag/viewer": "^0.3.699",
55
- "@micromag/viewer-build": "^0.3.699",
54
+ "@micromag/viewer": "^0.3.701",
55
+ "@micromag/viewer-build": "^0.3.701",
56
56
  "change-case": "^5.4.4",
57
57
  "classnames": "^2.2.6",
58
58
  "commander": "^12.0.0",
@@ -70,5 +70,5 @@
70
70
  "access": "public",
71
71
  "registry": "https://registry.npmjs.org/"
72
72
  },
73
- "gitHead": "8d69620bde11630e19004ac76f6ed1454fc33516"
73
+ "gitHead": "c693ba9ccf9798d2b047c5a8b427453a1b7a09d6"
74
74
  }