@micromag/cli 0.3.427 → 0.3.430
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.
- package/bin/export.js +106 -42
- package/lib/index.js +113 -54
- package/package.json +9 -9
package/bin/export.js
CHANGED
|
@@ -7,8 +7,8 @@ var fs = require('fs');
|
|
|
7
7
|
var core = require('@micromag/core');
|
|
8
8
|
var screensManager = require('@micromag/screens');
|
|
9
9
|
var FieldsManager = require('@micromag/fields');
|
|
10
|
-
var changeCase = require('change-case');
|
|
11
10
|
var transforms = require('@micromag/transforms');
|
|
11
|
+
var tslib = require('tslib');
|
|
12
12
|
var path = require('path');
|
|
13
13
|
var puppeteer = require('puppeteer');
|
|
14
14
|
var nodeFetch = require('node-fetch');
|
|
@@ -18,26 +18,89 @@ var React = require('react');
|
|
|
18
18
|
var ReactDOMServer = require('react-dom/server');
|
|
19
19
|
var Viewer = require('@micromag/viewer');
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const readJSON = file => fsExtra.readJsonSync(file);
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var
|
|
35
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Lower case as a function.
|
|
28
|
+
*/
|
|
29
|
+
function lowerCase(str) {
|
|
30
|
+
return str.toLowerCase();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
|
|
34
|
+
var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
|
|
35
|
+
// Remove all non-word characters.
|
|
36
|
+
var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
|
|
37
|
+
/**
|
|
38
|
+
* Normalize the string into something other libraries can manipulate easier.
|
|
39
|
+
*/
|
|
40
|
+
function noCase(input, options) {
|
|
41
|
+
if (options === void 0) {
|
|
42
|
+
options = {};
|
|
43
|
+
}
|
|
44
|
+
var _a = options.splitRegexp,
|
|
45
|
+
splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a,
|
|
46
|
+
_b = options.stripRegexp,
|
|
47
|
+
stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b,
|
|
48
|
+
_c = options.transform,
|
|
49
|
+
transform = _c === void 0 ? lowerCase : _c,
|
|
50
|
+
_d = options.delimiter,
|
|
51
|
+
delimiter = _d === void 0 ? " " : _d;
|
|
52
|
+
var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
|
|
53
|
+
var start = 0;
|
|
54
|
+
var end = result.length;
|
|
55
|
+
// Trim the delimiter from around the output string.
|
|
56
|
+
while (result.charAt(start) === "\0") start++;
|
|
57
|
+
while (result.charAt(end - 1) === "\0") end--;
|
|
58
|
+
// Transform each token independently.
|
|
59
|
+
return result.slice(start, end).split("\0").map(transform).join(delimiter);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Replace `re` in the input string with the replacement value.
|
|
63
|
+
*/
|
|
64
|
+
function replace(input, re, value) {
|
|
65
|
+
if (re instanceof RegExp) return input.replace(re, value);
|
|
66
|
+
return re.reduce(function (input, re) {
|
|
67
|
+
return input.replace(re, value);
|
|
68
|
+
}, input);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function pascalCaseTransform(input, index) {
|
|
72
|
+
var firstChar = input.charAt(0);
|
|
73
|
+
var lowerChars = input.substr(1).toLowerCase();
|
|
74
|
+
if (index > 0 && firstChar >= "0" && firstChar <= "9") {
|
|
75
|
+
return "_" + firstChar + lowerChars;
|
|
76
|
+
}
|
|
77
|
+
return "" + firstChar.toUpperCase() + lowerChars;
|
|
78
|
+
}
|
|
79
|
+
function pascalCase(input, options) {
|
|
80
|
+
if (options === void 0) {
|
|
81
|
+
options = {};
|
|
82
|
+
}
|
|
83
|
+
return noCase(input, tslib.__assign({
|
|
84
|
+
delimiter: "",
|
|
85
|
+
transform: pascalCaseTransform
|
|
86
|
+
}, options));
|
|
87
|
+
}
|
|
36
88
|
|
|
37
|
-
|
|
89
|
+
function camelCaseTransform(input, index) {
|
|
90
|
+
if (index === 0) return input.toLowerCase();
|
|
91
|
+
return pascalCaseTransform(input, index);
|
|
92
|
+
}
|
|
93
|
+
function camelCase(input, options) {
|
|
94
|
+
if (options === void 0) {
|
|
95
|
+
options = {};
|
|
96
|
+
}
|
|
97
|
+
return pascalCase(input, tslib.__assign({
|
|
98
|
+
transform: camelCaseTransform
|
|
99
|
+
}, options));
|
|
100
|
+
}
|
|
38
101
|
|
|
39
102
|
const transformStory = (story, format) => {
|
|
40
|
-
const transformKey =
|
|
103
|
+
const transformKey = camelCase(format);
|
|
41
104
|
const baseStory = transforms.transformer(story, transformKey, story);
|
|
42
105
|
const {
|
|
43
106
|
components = []
|
|
@@ -48,7 +111,7 @@ const transformStory = (story, format) => {
|
|
|
48
111
|
} = screen;
|
|
49
112
|
const {
|
|
50
113
|
transforms = {}
|
|
51
|
-
} =
|
|
114
|
+
} = screensManager.getDefinition(type);
|
|
52
115
|
const transform = transforms[transformKey] || null;
|
|
53
116
|
if (transform !== null) {
|
|
54
117
|
return transform(newStory, screen, story);
|
|
@@ -59,29 +122,30 @@ const transformStory = (story, format) => {
|
|
|
59
122
|
};
|
|
60
123
|
|
|
61
124
|
const startServer = async (path, port = null) => {
|
|
62
|
-
const finalPort = port || (await
|
|
63
|
-
port:
|
|
125
|
+
const finalPort = port || (await getPort({
|
|
126
|
+
port: getPort.makeRange(3050, 3100)
|
|
64
127
|
}));
|
|
65
128
|
return new Promise(resolve => {
|
|
66
|
-
const app =
|
|
67
|
-
app.use(
|
|
129
|
+
const app = express();
|
|
130
|
+
app.use(express.static(path));
|
|
68
131
|
const server = app.listen(finalPort, () => resolve(server));
|
|
69
132
|
});
|
|
70
133
|
};
|
|
71
134
|
|
|
72
135
|
const getOutputPath = (output, filename) => {
|
|
73
136
|
if (output !== null) {
|
|
74
|
-
const fileExt =
|
|
75
|
-
const outputExt =
|
|
137
|
+
const fileExt = path.extname(filename);
|
|
138
|
+
const outputExt = path.extname(output);
|
|
76
139
|
if (fileExt && outputExt === '') {
|
|
77
|
-
return
|
|
140
|
+
return path.join(output, filename);
|
|
78
141
|
}
|
|
79
142
|
return output;
|
|
80
143
|
}
|
|
81
|
-
return
|
|
144
|
+
return path.join(process.cwd(), `./${filename}`);
|
|
82
145
|
};
|
|
83
146
|
|
|
84
147
|
/* eslint-disable no-await-in-loop */
|
|
148
|
+
/* globals renderStory: true */
|
|
85
149
|
const DEBUG = false;
|
|
86
150
|
const READY_WAIT_TIMEOUT = 20000; // ms
|
|
87
151
|
const DEFAULT_VIEWPORT = {
|
|
@@ -96,7 +160,7 @@ const captureStory = async (story, location, settings = {}) => {
|
|
|
96
160
|
googleApiKey = null,
|
|
97
161
|
executablePath = null
|
|
98
162
|
} = settings;
|
|
99
|
-
const server = await startServer(
|
|
163
|
+
const server = await startServer(path.join(process.cwd(), './node_modules/@micromag/viewer-build/build/'));
|
|
100
164
|
const serverPort = server.address().port;
|
|
101
165
|
const {
|
|
102
166
|
width,
|
|
@@ -105,7 +169,7 @@ const captureStory = async (story, location, settings = {}) => {
|
|
|
105
169
|
const {
|
|
106
170
|
components: screens = null
|
|
107
171
|
} = story || {};
|
|
108
|
-
const browser = await
|
|
172
|
+
const browser = await puppeteer.launch({
|
|
109
173
|
devtools: DEBUG,
|
|
110
174
|
...(executablePath !== null ? {
|
|
111
175
|
executablePath
|
|
@@ -143,8 +207,8 @@ const captureStory = async (story, location, settings = {}) => {
|
|
|
143
207
|
} = screen;
|
|
144
208
|
console.log(`Downloading video from ${url}...`);
|
|
145
209
|
const fileExtension = url.split(/[#?]/)[0].split('.').pop().trim();
|
|
146
|
-
const res = await
|
|
147
|
-
const fileStream =
|
|
210
|
+
const res = await nodeFetch(url);
|
|
211
|
+
const fileStream = fsExtra.createWriteStream(getOutputPath(location, `${screenNumber}.${fileExtension}`));
|
|
148
212
|
await new Promise((resolve, reject) => {
|
|
149
213
|
res.body.pipe(fileStream);
|
|
150
214
|
res.body.on('error', reject);
|
|
@@ -186,9 +250,9 @@ const getStoryHtml = async (story, settings = {}) => {
|
|
|
186
250
|
googleApiKey = null,
|
|
187
251
|
executablePath = null
|
|
188
252
|
} = settings;
|
|
189
|
-
const server = await startServer(
|
|
253
|
+
const server = await startServer(path.join(process.cwd(), './node_modules/@micromag/viewer-build/build/'));
|
|
190
254
|
const serverPort = server.address().port;
|
|
191
|
-
const browser = await
|
|
255
|
+
const browser = await puppeteer.launch({
|
|
192
256
|
devtools: false,
|
|
193
257
|
...(executablePath !== null ? {
|
|
194
258
|
executablePath
|
|
@@ -220,7 +284,7 @@ const getStoryHtmlSSR = (story, settings = {}) => {
|
|
|
220
284
|
const {
|
|
221
285
|
googleApiKey = null
|
|
222
286
|
} = settings;
|
|
223
|
-
const element = /*#__PURE__*/
|
|
287
|
+
const element = /*#__PURE__*/React.createElement(Viewer, {
|
|
224
288
|
story,
|
|
225
289
|
renderContext: 'static',
|
|
226
290
|
withoutRouter: true,
|
|
@@ -228,12 +292,12 @@ const getStoryHtmlSSR = (story, settings = {}) => {
|
|
|
228
292
|
googleApiKey,
|
|
229
293
|
memoryRouter: true
|
|
230
294
|
});
|
|
231
|
-
return
|
|
295
|
+
return ReactDOMServer.renderToStaticMarkup(element);
|
|
232
296
|
};
|
|
233
297
|
|
|
234
298
|
const storyParser = new core.StoryParser({
|
|
235
|
-
fieldsManager:
|
|
236
|
-
screensManager:
|
|
299
|
+
fieldsManager: FieldsManager,
|
|
300
|
+
screensManager: screensManager
|
|
237
301
|
});
|
|
238
302
|
const exportStoryToPath = async (story, format, output, settings = {}) => {
|
|
239
303
|
const storyParsed = storyParser.parse(story);
|
|
@@ -243,14 +307,14 @@ const exportStoryToPath = async (story, format, output, settings = {}) => {
|
|
|
243
307
|
const html = await getStoryHtml(storyParsed, settings);
|
|
244
308
|
const destination = getOutputPath(output, 'story.html');
|
|
245
309
|
console.log('destination', destination);
|
|
246
|
-
|
|
310
|
+
fs.writeFileSync(destination, html, 'utf-8');
|
|
247
311
|
break;
|
|
248
312
|
}
|
|
249
313
|
case 'html-ssr':
|
|
250
314
|
{
|
|
251
315
|
const html = getStoryHtmlSSR(storyParsed, settings);
|
|
252
316
|
const destination = getOutputPath(output, 'story-ssr.html');
|
|
253
|
-
|
|
317
|
+
fs.writeFileSync(destination, html, 'utf-8');
|
|
254
318
|
break;
|
|
255
319
|
}
|
|
256
320
|
case 'images':
|
|
@@ -261,12 +325,12 @@ const exportStoryToPath = async (story, format, output, settings = {}) => {
|
|
|
261
325
|
default:
|
|
262
326
|
{
|
|
263
327
|
const parsedDestination = getOutputPath(output, 'parsed.json');
|
|
264
|
-
|
|
328
|
+
fs.writeFileSync(parsedDestination, JSON.stringify(storyParsed), 'utf-8');
|
|
265
329
|
const newStory = transformStory(storyParsed, format);
|
|
266
330
|
// const mediaDestination = getOutputPath(output);
|
|
267
331
|
const fileDestination = getOutputPath(output, 'article.json');
|
|
268
332
|
console.log(output, fileDestination);
|
|
269
|
-
|
|
333
|
+
fs.writeFileSync(fileDestination, JSON.stringify(newStory), 'utf-8');
|
|
270
334
|
break;
|
|
271
335
|
}
|
|
272
336
|
}
|
|
@@ -274,7 +338,7 @@ const exportStoryToPath = async (story, format, output, settings = {}) => {
|
|
|
274
338
|
|
|
275
339
|
const startProgram = (stdin = null) => {
|
|
276
340
|
let storyArgument = null;
|
|
277
|
-
|
|
341
|
+
program.arguments('<path>').description({
|
|
278
342
|
path: 'Path to story JSON file'
|
|
279
343
|
}).requiredOption('-f, --format <format>', 'Format of the export').option('-o, --output <output>', 'Output path').option('-s, --settings <settings>', 'Settings').action((jsonPath = null) => {
|
|
280
344
|
storyArgument = jsonPath === '-' ? JSON.parse(stdin) : readJSON(jsonPath);
|
|
@@ -283,7 +347,7 @@ const startProgram = (stdin = null) => {
|
|
|
283
347
|
format,
|
|
284
348
|
output = null,
|
|
285
349
|
settings: jsonSettings = null
|
|
286
|
-
} =
|
|
350
|
+
} = program.opts();
|
|
287
351
|
const settings = jsonSettings !== null ? JSON.parse(jsonSettings) : {};
|
|
288
352
|
exportStoryToPath(storyArgument, format, output, settings);
|
|
289
353
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var _regeneratorRuntime = require('@babel/runtime/helpers/regeneratorRuntime');
|
|
6
4
|
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
7
5
|
var fs = require('fs');
|
|
8
6
|
var core = require('@micromag/core');
|
|
9
7
|
var screensManager = require('@micromag/screens');
|
|
10
8
|
var FieldsManager = require('@micromag/fields');
|
|
11
|
-
var changeCase = require('change-case');
|
|
12
9
|
var transforms = require('@micromag/transforms');
|
|
10
|
+
var tslib = require('tslib');
|
|
13
11
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
14
12
|
var path = require('path');
|
|
15
13
|
var puppeteer = require('puppeteer');
|
|
@@ -21,32 +19,93 @@ var React = require('react');
|
|
|
21
19
|
var ReactDOMServer = require('react-dom/server');
|
|
22
20
|
var Viewer = require('@micromag/viewer');
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Lower case as a function.
|
|
27
|
+
*/
|
|
28
|
+
function lowerCase(str) {
|
|
29
|
+
return str.toLowerCase();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
|
|
33
|
+
var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
|
|
34
|
+
// Remove all non-word characters.
|
|
35
|
+
var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
|
|
36
|
+
/**
|
|
37
|
+
* Normalize the string into something other libraries can manipulate easier.
|
|
38
|
+
*/
|
|
39
|
+
function noCase(input, options) {
|
|
40
|
+
if (options === void 0) {
|
|
41
|
+
options = {};
|
|
42
|
+
}
|
|
43
|
+
var _a = options.splitRegexp,
|
|
44
|
+
splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a,
|
|
45
|
+
_b = options.stripRegexp,
|
|
46
|
+
stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b,
|
|
47
|
+
_c = options.transform,
|
|
48
|
+
transform = _c === void 0 ? lowerCase : _c,
|
|
49
|
+
_d = options.delimiter,
|
|
50
|
+
delimiter = _d === void 0 ? " " : _d;
|
|
51
|
+
var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
|
|
52
|
+
var start = 0;
|
|
53
|
+
var end = result.length;
|
|
54
|
+
// Trim the delimiter from around the output string.
|
|
55
|
+
while (result.charAt(start) === "\0") start++;
|
|
56
|
+
while (result.charAt(end - 1) === "\0") end--;
|
|
57
|
+
// Transform each token independently.
|
|
58
|
+
return result.slice(start, end).split("\0").map(transform).join(delimiter);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Replace `re` in the input string with the replacement value.
|
|
62
|
+
*/
|
|
63
|
+
function replace(input, re, value) {
|
|
64
|
+
if (re instanceof RegExp) return input.replace(re, value);
|
|
65
|
+
return re.reduce(function (input, re) {
|
|
66
|
+
return input.replace(re, value);
|
|
67
|
+
}, input);
|
|
68
|
+
}
|
|
25
69
|
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
70
|
+
function pascalCaseTransform(input, index) {
|
|
71
|
+
var firstChar = input.charAt(0);
|
|
72
|
+
var lowerChars = input.substr(1).toLowerCase();
|
|
73
|
+
if (index > 0 && firstChar >= "0" && firstChar <= "9") {
|
|
74
|
+
return "_" + firstChar + lowerChars;
|
|
75
|
+
}
|
|
76
|
+
return "" + firstChar.toUpperCase() + lowerChars;
|
|
77
|
+
}
|
|
78
|
+
function pascalCase(input, options) {
|
|
79
|
+
if (options === void 0) {
|
|
80
|
+
options = {};
|
|
81
|
+
}
|
|
82
|
+
return noCase(input, tslib.__assign({
|
|
83
|
+
delimiter: "",
|
|
84
|
+
transform: pascalCaseTransform
|
|
85
|
+
}, options));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function camelCaseTransform(input, index) {
|
|
89
|
+
if (index === 0) return input.toLowerCase();
|
|
90
|
+
return pascalCaseTransform(input, index);
|
|
91
|
+
}
|
|
92
|
+
function camelCase(input, options) {
|
|
93
|
+
if (options === void 0) {
|
|
94
|
+
options = {};
|
|
95
|
+
}
|
|
96
|
+
return pascalCase(input, tslib.__assign({
|
|
97
|
+
transform: camelCaseTransform
|
|
98
|
+
}, options));
|
|
99
|
+
}
|
|
41
100
|
|
|
42
101
|
var transformStory = function transformStory(story, format) {
|
|
43
|
-
var transformKey =
|
|
102
|
+
var transformKey = camelCase(format);
|
|
44
103
|
var baseStory = transforms.transformer(story, transformKey, story);
|
|
45
104
|
var _story$components = story.components,
|
|
46
105
|
components = _story$components === void 0 ? [] : _story$components;
|
|
47
106
|
var componentsStory = components.reduce(function (newStory, screen) {
|
|
48
107
|
var type = screen.type;
|
|
49
|
-
var _screensManager$getDe =
|
|
108
|
+
var _screensManager$getDe = screensManager.getDefinition(type),
|
|
50
109
|
_screensManager$getDe2 = _screensManager$getDe.transforms,
|
|
51
110
|
transforms = _screensManager$getDe2 === void 0 ? {} : _screensManager$getDe2;
|
|
52
111
|
var transform = transforms[transformKey] || null;
|
|
@@ -59,11 +118,11 @@ var transformStory = function transformStory(story, format) {
|
|
|
59
118
|
};
|
|
60
119
|
|
|
61
120
|
var startServer = /*#__PURE__*/function () {
|
|
62
|
-
var _ref =
|
|
121
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(path) {
|
|
63
122
|
var port,
|
|
64
123
|
finalPort,
|
|
65
124
|
_args = arguments;
|
|
66
|
-
return
|
|
125
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
67
126
|
while (1) switch (_context.prev = _context.next) {
|
|
68
127
|
case 0:
|
|
69
128
|
port = _args.length > 1 && _args[1] !== undefined ? _args[1] : null;
|
|
@@ -73,16 +132,16 @@ var startServer = /*#__PURE__*/function () {
|
|
|
73
132
|
break;
|
|
74
133
|
}
|
|
75
134
|
_context.next = 5;
|
|
76
|
-
return
|
|
77
|
-
port:
|
|
135
|
+
return getPort({
|
|
136
|
+
port: getPort.makeRange(3050, 3100)
|
|
78
137
|
});
|
|
79
138
|
case 5:
|
|
80
139
|
_context.t0 = _context.sent;
|
|
81
140
|
case 6:
|
|
82
141
|
finalPort = _context.t0;
|
|
83
142
|
return _context.abrupt("return", new Promise(function (resolve) {
|
|
84
|
-
var app =
|
|
85
|
-
app.use(
|
|
143
|
+
var app = express();
|
|
144
|
+
app.use(express["static"](path));
|
|
86
145
|
var server = app.listen(finalPort, function () {
|
|
87
146
|
return resolve(server);
|
|
88
147
|
});
|
|
@@ -100,14 +159,14 @@ var startServer = /*#__PURE__*/function () {
|
|
|
100
159
|
|
|
101
160
|
var getOutputPath = function getOutputPath(output, filename) {
|
|
102
161
|
if (output !== null) {
|
|
103
|
-
var fileExt =
|
|
104
|
-
var outputExt =
|
|
162
|
+
var fileExt = path.extname(filename);
|
|
163
|
+
var outputExt = path.extname(output);
|
|
105
164
|
if (fileExt && outputExt === '') {
|
|
106
|
-
return
|
|
165
|
+
return path.join(output, filename);
|
|
107
166
|
}
|
|
108
167
|
return output;
|
|
109
168
|
}
|
|
110
|
-
return
|
|
169
|
+
return path.join(process.cwd(), "./".concat(filename));
|
|
111
170
|
};
|
|
112
171
|
|
|
113
172
|
var DEBUG = false;
|
|
@@ -119,7 +178,7 @@ var DEFAULT_VIEWPORT = {
|
|
|
119
178
|
isMobile: true
|
|
120
179
|
};
|
|
121
180
|
var captureStory = /*#__PURE__*/function () {
|
|
122
|
-
var _ref =
|
|
181
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(story, location) {
|
|
123
182
|
var settings,
|
|
124
183
|
_settings$viewport,
|
|
125
184
|
defaultViewport,
|
|
@@ -142,20 +201,20 @@ var captureStory = /*#__PURE__*/function () {
|
|
|
142
201
|
_loop,
|
|
143
202
|
index,
|
|
144
203
|
_args2 = arguments;
|
|
145
|
-
return
|
|
204
|
+
return _regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
146
205
|
while (1) switch (_context2.prev = _context2.next) {
|
|
147
206
|
case 0:
|
|
148
207
|
settings = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
|
|
149
208
|
_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;
|
|
150
209
|
_context2.next = 4;
|
|
151
|
-
return startServer(
|
|
210
|
+
return startServer(path.join(process.cwd(), './node_modules/@micromag/viewer-build/build/'));
|
|
152
211
|
case 4:
|
|
153
212
|
server = _context2.sent;
|
|
154
213
|
serverPort = server.address().port;
|
|
155
214
|
width = defaultViewport.width, height = defaultViewport.height;
|
|
156
215
|
_ref2 = story || {}, _ref2$components = _ref2.components, screens = _ref2$components === void 0 ? null : _ref2$components;
|
|
157
216
|
_context2.next = 10;
|
|
158
|
-
return
|
|
217
|
+
return puppeteer.launch(_objectSpread(_objectSpread({
|
|
159
218
|
devtools: DEBUG
|
|
160
219
|
}, executablePath !== null ? {
|
|
161
220
|
executablePath: executablePath
|
|
@@ -192,15 +251,15 @@ var captureStory = /*#__PURE__*/function () {
|
|
|
192
251
|
break;
|
|
193
252
|
}
|
|
194
253
|
count = screens.length;
|
|
195
|
-
_loop = /*#__PURE__*/
|
|
254
|
+
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
196
255
|
var screenNumber, screen, id, type, singleScreenStory, _screen$video, _screen$video2, _screen$video2$media, _screen$video2$media2, _screen$video2$media3, url, fileExtension, res, fileStream;
|
|
197
|
-
return
|
|
256
|
+
return _regeneratorRuntime().wrap(function _loop$(_context) {
|
|
198
257
|
while (1) switch (_context.prev = _context.next) {
|
|
199
258
|
case 0:
|
|
200
259
|
screenNumber = index + 1;
|
|
201
260
|
screen = screens[index];
|
|
202
261
|
id = screen.id, type = screen.type;
|
|
203
|
-
singleScreenStory =
|
|
262
|
+
singleScreenStory = _objectSpread(_objectSpread({}, story), {}, {
|
|
204
263
|
components: screens.slice(index, index + 1)
|
|
205
264
|
});
|
|
206
265
|
console.log("Screen ".concat(screenNumber, "/").concat(count, " (").concat(type, ")..."));
|
|
@@ -212,10 +271,10 @@ var captureStory = /*#__PURE__*/function () {
|
|
|
212
271
|
console.log("Downloading video from ".concat(url, "..."));
|
|
213
272
|
fileExtension = url.split(/[#?]/)[0].split('.').pop().trim();
|
|
214
273
|
_context.next = 11;
|
|
215
|
-
return
|
|
274
|
+
return nodeFetch(url);
|
|
216
275
|
case 11:
|
|
217
276
|
res = _context.sent;
|
|
218
|
-
fileStream =
|
|
277
|
+
fileStream = fsExtra.createWriteStream(getOutputPath(location, "".concat(screenNumber, ".").concat(fileExtension)));
|
|
219
278
|
_context.next = 15;
|
|
220
279
|
return new Promise(function (resolve, reject) {
|
|
221
280
|
res.body.pipe(fileStream);
|
|
@@ -287,7 +346,7 @@ var captureStory = /*#__PURE__*/function () {
|
|
|
287
346
|
}();
|
|
288
347
|
|
|
289
348
|
var getStoryHtml = /*#__PURE__*/function () {
|
|
290
|
-
var _ref =
|
|
349
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(story) {
|
|
291
350
|
var settings,
|
|
292
351
|
_settings$googleApiKe,
|
|
293
352
|
googleApiKey,
|
|
@@ -301,18 +360,18 @@ var getStoryHtml = /*#__PURE__*/function () {
|
|
|
301
360
|
page,
|
|
302
361
|
pageContent,
|
|
303
362
|
_args = arguments;
|
|
304
|
-
return
|
|
363
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
305
364
|
while (1) switch (_context.prev = _context.next) {
|
|
306
365
|
case 0:
|
|
307
366
|
settings = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
|
|
308
367
|
_settings$googleApiKe = settings.googleApiKey, googleApiKey = _settings$googleApiKe === void 0 ? null : _settings$googleApiKe, _settings$executableP = settings.executablePath, executablePath = _settings$executableP === void 0 ? null : _settings$executableP;
|
|
309
368
|
_context.next = 4;
|
|
310
|
-
return startServer(
|
|
369
|
+
return startServer(path.join(process.cwd(), './node_modules/@micromag/viewer-build/build/'));
|
|
311
370
|
case 4:
|
|
312
371
|
server = _context.sent;
|
|
313
372
|
serverPort = server.address().port;
|
|
314
373
|
_context.next = 8;
|
|
315
|
-
return
|
|
374
|
+
return puppeteer.launch(_objectSpread(_objectSpread({
|
|
316
375
|
devtools: false
|
|
317
376
|
}, executablePath !== null ? {
|
|
318
377
|
executablePath: executablePath
|
|
@@ -382,7 +441,7 @@ var getStoryHtmlSSR = function getStoryHtmlSSR(story) {
|
|
|
382
441
|
var settings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
383
442
|
var _settings$googleApiKe = settings.googleApiKey,
|
|
384
443
|
googleApiKey = _settings$googleApiKe === void 0 ? null : _settings$googleApiKe;
|
|
385
|
-
var element = /*#__PURE__*/
|
|
444
|
+
var element = /*#__PURE__*/React.createElement(Viewer, {
|
|
386
445
|
story: story,
|
|
387
446
|
renderContext: 'static',
|
|
388
447
|
withoutRouter: true,
|
|
@@ -390,15 +449,15 @@ var getStoryHtmlSSR = function getStoryHtmlSSR(story) {
|
|
|
390
449
|
googleApiKey: googleApiKey,
|
|
391
450
|
memoryRouter: true
|
|
392
451
|
});
|
|
393
|
-
return
|
|
452
|
+
return ReactDOMServer.renderToStaticMarkup(element);
|
|
394
453
|
};
|
|
395
454
|
|
|
396
455
|
var storyParser = new core.StoryParser({
|
|
397
|
-
fieldsManager:
|
|
398
|
-
screensManager:
|
|
456
|
+
fieldsManager: FieldsManager,
|
|
457
|
+
screensManager: screensManager
|
|
399
458
|
});
|
|
400
459
|
var exportStoryToPath = /*#__PURE__*/function () {
|
|
401
|
-
var _ref =
|
|
460
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(story, format, output) {
|
|
402
461
|
var settings,
|
|
403
462
|
storyParsed,
|
|
404
463
|
html,
|
|
@@ -409,7 +468,7 @@ var exportStoryToPath = /*#__PURE__*/function () {
|
|
|
409
468
|
newStory,
|
|
410
469
|
fileDestination,
|
|
411
470
|
_args = arguments;
|
|
412
|
-
return
|
|
471
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
413
472
|
while (1) switch (_context.prev = _context.next) {
|
|
414
473
|
case 0:
|
|
415
474
|
settings = _args.length > 3 && _args[3] !== undefined ? _args[3] : {};
|
|
@@ -424,23 +483,23 @@ var exportStoryToPath = /*#__PURE__*/function () {
|
|
|
424
483
|
html = _context.sent;
|
|
425
484
|
destination = getOutputPath(output, 'story.html');
|
|
426
485
|
console.log('destination', destination);
|
|
427
|
-
|
|
486
|
+
fs.writeFileSync(destination, html, 'utf-8');
|
|
428
487
|
return _context.abrupt("break", 25);
|
|
429
488
|
case 12:
|
|
430
489
|
_html = getStoryHtmlSSR(storyParsed, settings);
|
|
431
490
|
_destination = getOutputPath(output, 'story-ssr.html');
|
|
432
|
-
|
|
491
|
+
fs.writeFileSync(_destination, _html, 'utf-8');
|
|
433
492
|
return _context.abrupt("break", 25);
|
|
434
493
|
case 16:
|
|
435
494
|
captureStory(storyParsed, output, settings);
|
|
436
495
|
return _context.abrupt("break", 25);
|
|
437
496
|
case 18:
|
|
438
497
|
parsedDestination = getOutputPath(output, 'parsed.json');
|
|
439
|
-
|
|
498
|
+
fs.writeFileSync(parsedDestination, JSON.stringify(storyParsed), 'utf-8');
|
|
440
499
|
newStory = transformStory(storyParsed, format); // const mediaDestination = getOutputPath(output);
|
|
441
500
|
fileDestination = getOutputPath(output, 'article.json');
|
|
442
501
|
console.log(output, fileDestination);
|
|
443
|
-
|
|
502
|
+
fs.writeFileSync(fileDestination, JSON.stringify(newStory), 'utf-8');
|
|
444
503
|
return _context.abrupt("break", 25);
|
|
445
504
|
case 25:
|
|
446
505
|
case "end":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.430",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@babel/runtime": "^7.13.10",
|
|
48
|
-
"@micromag/core": "^0.3.
|
|
49
|
-
"@micromag/elements": "^0.3.
|
|
50
|
-
"@micromag/fields": "^0.3.
|
|
51
|
-
"@micromag/screens": "^0.3.
|
|
52
|
-
"@micromag/transforms": "^0.3.
|
|
53
|
-
"@micromag/viewer": "^0.3.
|
|
54
|
-
"@micromag/viewer-build": "^0.3.
|
|
48
|
+
"@micromag/core": "^0.3.430",
|
|
49
|
+
"@micromag/elements": "^0.3.430",
|
|
50
|
+
"@micromag/fields": "^0.3.430",
|
|
51
|
+
"@micromag/screens": "^0.3.430",
|
|
52
|
+
"@micromag/transforms": "^0.3.430",
|
|
53
|
+
"@micromag/viewer": "^0.3.430",
|
|
54
|
+
"@micromag/viewer-build": "^0.3.430",
|
|
55
55
|
"change-case": "^4.1.2",
|
|
56
56
|
"classnames": "^2.2.6",
|
|
57
57
|
"commander": "^8.3.0",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"access": "public",
|
|
70
70
|
"registry": "https://registry.npmjs.org/"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "da790d76dba9d8e308d9f9c4e51d93a4a0e012a9"
|
|
73
73
|
}
|