vis-dev-utils 4.0.44 → 5.0.0
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/babel-preset/index.cjs +102 -0
- package/babel-preset/index.cjs.map +1 -0
- package/babel-preset/{index.js → index.mjs} +58 -31
- package/babel-preset/index.mjs.map +1 -0
- package/bin/ci-utils.js +35 -41
- package/bin/ci-utils.js.map +1 -1
- package/bin/generate-examples-index.js +779 -1265
- package/bin/generate-examples-index.js.map +1 -1
- package/bin/test-e2e-interop.js +431 -3492
- package/bin/test-e2e-interop.js.map +1 -1
- package/declarations/babel-preset/index.d.ts +23 -0
- package/declarations/babel-preset/index.d.ts.map +1 -0
- package/declarations/ci-utils/index.d.ts +2 -0
- package/declarations/ci-utils/index.d.ts.map +1 -0
- package/declarations/generate-examples-index/cli.d.ts +44 -0
- package/declarations/generate-examples-index/cli.d.ts.map +1 -0
- package/declarations/generate-examples-index/content-builder/builder.d.ts +53 -0
- package/declarations/generate-examples-index/content-builder/builder.d.ts.map +1 -0
- package/declarations/generate-examples-index/content-builder/common.d.ts +47 -0
- package/declarations/generate-examples-index/content-builder/common.d.ts.map +1 -0
- package/declarations/generate-examples-index/content-builder/format.d.ts +5 -0
- package/declarations/generate-examples-index/content-builder/format.d.ts.map +1 -0
- package/declarations/generate-examples-index/content-builder/html/index.d.ts +3 -0
- package/declarations/generate-examples-index/content-builder/html/index.d.ts.map +1 -0
- package/declarations/generate-examples-index/content-builder/index.d.ts +6 -0
- package/declarations/generate-examples-index/content-builder/index.d.ts.map +1 -0
- package/declarations/generate-examples-index/content-builder/md/index.d.ts +3 -0
- package/declarations/generate-examples-index/content-builder/md/index.d.ts.map +1 -0
- package/declarations/generate-examples-index/content-builder/playground/codepen.d.ts +6 -0
- package/declarations/generate-examples-index/content-builder/playground/codepen.d.ts.map +1 -0
- package/declarations/generate-examples-index/content-builder/playground/data.d.ts +8 -0
- package/declarations/generate-examples-index/content-builder/playground/data.d.ts.map +1 -0
- package/declarations/generate-examples-index/content-builder/playground/index.d.ts +4 -0
- package/declarations/generate-examples-index/content-builder/playground/index.d.ts.map +1 -0
- package/declarations/generate-examples-index/content-builder/playground/jsfiddle.d.ts +6 -0
- package/declarations/generate-examples-index/content-builder/playground/jsfiddle.d.ts.map +1 -0
- package/declarations/generate-examples-index/content-builder/screenshots/index.d.ts +26 -0
- package/declarations/generate-examples-index/content-builder/screenshots/index.d.ts.map +1 -0
- package/declarations/generate-examples-index/index.d.ts +2 -0
- package/declarations/generate-examples-index/index.d.ts.map +1 -0
- package/declarations/generate-examples-index/paths.d.ts +16 -0
- package/declarations/generate-examples-index/paths.d.ts.map +1 -0
- package/declarations/generate-examples-index/types.d.ts +61 -0
- package/declarations/generate-examples-index/types.d.ts.map +1 -0
- package/declarations/module/constants.d.ts +2 -0
- package/declarations/module/constants.d.ts.map +1 -0
- package/declarations/{generate-rollup-configuration → module/generate-rollup-configuration}/index.d.ts +4 -3
- package/declarations/module/generate-rollup-configuration/index.d.ts.map +1 -0
- package/declarations/{header.d.ts → module/header.d.ts} +1 -3
- package/declarations/module/header.d.ts.map +1 -0
- package/declarations/module/index.d.ts.map +1 -0
- package/declarations/module/inspect-npm-pack.d.ts +8 -0
- package/declarations/module/inspect-npm-pack.d.ts.map +1 -0
- package/declarations/module/util.d.ts.map +1 -0
- package/declarations/test-e2e-interop/cli.d.ts +18 -0
- package/declarations/test-e2e-interop/cli.d.ts.map +1 -0
- package/declarations/test-e2e-interop/index.d.ts +2 -0
- package/declarations/test-e2e-interop/index.d.ts.map +1 -0
- package/declarations/test-e2e-interop/test.d.ts +23 -0
- package/declarations/test-e2e-interop/test.d.ts.map +1 -0
- package/declarations/test-e2e-interop/util.d.ts +49 -0
- package/declarations/test-e2e-interop/util.d.ts.map +1 -0
- package/dist/vis-dev-utils.cjs +871 -0
- package/dist/vis-dev-utils.cjs.map +1 -0
- package/dist/vis-dev-utils.mjs +864 -0
- package/dist/vis-dev-utils.mjs.map +1 -0
- package/package.json +81 -59
- package/babel-register/index.js +0 -110
- package/babel-register/index.js.map +0 -1
- package/declarations/constants.d.ts +0 -2
- package/declarations/constants.d.ts.map +0 -1
- package/declarations/generate-rollup-configuration/index.d.ts.map +0 -1
- package/declarations/header.d.ts.map +0 -1
- package/declarations/index.d.ts.map +0 -1
- package/declarations/inspect-npm-pack.d.ts +0 -8
- package/declarations/inspect-npm-pack.d.ts.map +0 -1
- package/declarations/util.d.ts.map +0 -1
- package/dist/vis-dev-utils.cjs.js +0 -777
- package/dist/vis-dev-utils.cjs.js.map +0 -1
- package/dist/vis-dev-utils.esm.js +0 -771
- package/dist/vis-dev-utils.esm.js.map +0 -1
- package/lib/header.d.ts +0 -38
- package/lib/header.d.ts.map +0 -1
- package/lib/header.js +0 -85
- package/lib/header.js.map +0 -1
- package/lib/inspect-npm-pack.d.ts +0 -8
- package/lib/inspect-npm-pack.d.ts.map +0 -1
- package/lib/inspect-npm-pack.js +0 -74
- package/lib/inspect-npm-pack.js.map +0 -1
- /package/declarations/{index.d.ts → module/index.d.ts} +0 -0
- /package/declarations/{util.d.ts → module/util.d.ts} +0 -0
- /package/eslint-shareable-config/{index.js → index.cjs} +0 -0
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Development utilities for the Vis family projects.
|
|
8
8
|
*
|
|
9
|
-
* @version
|
|
10
|
-
* @date
|
|
9
|
+
* @version 5.0.0
|
|
10
|
+
* @date 2025-07-12T17:03:14.214Z
|
|
11
11
|
*
|
|
12
12
|
* @copyright (c) 2011-2017 Almende B.V, http://almende.com
|
|
13
13
|
* @copyright (c) 2017-2019 visjs contributors, https://github.com/visjs
|
|
@@ -26,893 +26,554 @@
|
|
|
26
26
|
* vis.js may be distributed under either license.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
import * as cheerio from 'cheerio';
|
|
30
|
+
import fs from 'node:fs';
|
|
31
|
+
import util, { promisify } from 'node:util';
|
|
32
|
+
import yargs from 'yargs';
|
|
33
|
+
import { relative, resolve, dirname, basename, sep, posix, join } from 'node:path';
|
|
34
|
+
import puppeteer from 'puppeteer';
|
|
35
|
+
import prettier from 'prettier';
|
|
36
|
+
import { Jimp } from 'jimp';
|
|
37
|
+
import { hideBin } from 'yargs/helpers';
|
|
38
|
+
import { createHash } from 'node:crypto';
|
|
30
39
|
|
|
31
|
-
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
32
|
-
var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
|
|
33
|
-
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
34
|
-
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
35
|
-
var _Number$isNaN = require('@babel/runtime-corejs3/core-js-stable/number/is-nan');
|
|
36
|
-
var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
|
|
37
|
-
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
38
|
-
var _Promise = require('@babel/runtime-corejs3/core-js-stable/promise');
|
|
39
|
-
var _endsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/ends-with');
|
|
40
|
-
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
41
|
-
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
42
|
-
var _sortInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/sort');
|
|
43
|
-
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
44
|
-
var $ = require('cheerio');
|
|
45
|
-
var fs = require('node:fs');
|
|
46
|
-
var util = require('node:util');
|
|
47
|
-
var yargs = require('yargs');
|
|
48
|
-
var node_path = require('node:path');
|
|
49
|
-
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
50
|
-
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
51
|
-
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
52
|
-
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
53
|
-
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
54
|
-
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
55
|
-
var _Array$from = require('@babel/runtime-corejs3/core-js-stable/array/from');
|
|
56
|
-
var _Symbol = require('@babel/runtime-corejs3/core-js-stable/symbol');
|
|
57
|
-
var _getIteratorMethod = require('@babel/runtime-corejs3/core-js/get-iterator-method');
|
|
58
|
-
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
59
|
-
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
60
|
-
var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
61
|
-
var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
|
|
62
|
-
var _flatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat');
|
|
63
|
-
var _everyInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/every');
|
|
64
|
-
var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
|
|
65
|
-
var _fillInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/fill');
|
|
66
|
-
var _padStartInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/pad-start');
|
|
67
|
-
var _reverseInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reverse');
|
|
68
|
-
var _spliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/splice');
|
|
69
|
-
var _flatMapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat-map');
|
|
70
|
-
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
71
|
-
var puppeteer = require('puppeteer');
|
|
72
|
-
var _typeof = require('@babel/runtime-corejs3/helpers/typeof');
|
|
73
|
-
var _Date$now = require('@babel/runtime-corejs3/core-js-stable/date/now');
|
|
74
|
-
var prettier = require('prettier');
|
|
75
|
-
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
76
|
-
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
77
|
-
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
78
|
-
var Jimp = require('jimp');
|
|
79
|
-
var _repeatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/repeat');
|
|
80
|
-
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
81
|
-
var node_crypto = require('node:crypto');
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @param value
|
|
85
|
-
*/
|
|
86
40
|
function isExample(value) {
|
|
87
|
-
return
|
|
41
|
+
return typeof value === "object" && value !== null && typeof value.path === "string";
|
|
88
42
|
}
|
|
89
|
-
/**
|
|
90
|
-
*
|
|
91
|
-
*/
|
|
92
43
|
function measureStartStopMs() {
|
|
93
|
-
|
|
94
|
-
return
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
start: start,
|
|
98
|
-
stop: stop
|
|
99
|
-
};
|
|
44
|
+
const start = Date.now();
|
|
45
|
+
return () => {
|
|
46
|
+
const stop = Date.now();
|
|
47
|
+
return { start, stop };
|
|
100
48
|
};
|
|
101
49
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
count: 0,
|
|
110
|
-
result: "fulfilled",
|
|
111
|
-
start: -1,
|
|
112
|
-
stop: -1
|
|
113
|
-
};
|
|
114
|
-
return (_reports$reduce = _reduceInstanceProperty(reports).call(reports, function (acc, val) {
|
|
115
|
-
var _acc$count, _val$count, _context, _acc$result, _acc$start, _acc$stop;
|
|
50
|
+
function reduceReports(reports, fallback = {
|
|
51
|
+
count: 0,
|
|
52
|
+
result: "fulfilled",
|
|
53
|
+
start: -1,
|
|
54
|
+
stop: -1
|
|
55
|
+
}) {
|
|
56
|
+
return reports.reduce((acc, val) => {
|
|
116
57
|
return {
|
|
117
|
-
count: (
|
|
118
|
-
result:
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
start: Math.min(
|
|
122
|
-
stop: Math.max(
|
|
58
|
+
count: (acc?.count ?? 0) + (val?.count ?? 0),
|
|
59
|
+
result: [acc?.result ?? "fulfilled", val.result].every(
|
|
60
|
+
(result) => result === "fulfilled"
|
|
61
|
+
) ? "fulfilled" : "rejected",
|
|
62
|
+
start: Math.min(acc?.start ?? Number.POSITIVE_INFINITY, val.start),
|
|
63
|
+
stop: Math.max(acc?.stop ?? Number.NEGATIVE_INFINITY, val.stop)
|
|
123
64
|
};
|
|
124
|
-
}, null)
|
|
65
|
+
}, null) ?? fallback;
|
|
125
66
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
* @param root0.start
|
|
129
|
-
* @param root0.stop
|
|
130
|
-
*/
|
|
131
|
-
function formatStartStopMs(_ref) {
|
|
132
|
-
var start = _ref.start,
|
|
133
|
-
stop = _ref.stop;
|
|
134
|
-
return "".concat((Math.round((stop - start) / 100) / 10).toFixed(1), "s");
|
|
67
|
+
function formatStartStopMs({ start, stop }) {
|
|
68
|
+
return `${(Math.round((stop - start) / 100) / 10).toFixed(1)}s`;
|
|
135
69
|
}
|
|
136
70
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
};
|
|
142
|
-
var formatHTML = function formatHTML(html) {
|
|
143
|
-
return prettier.format(html || "", {
|
|
144
|
-
filepath: "index.html"
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
var formatJS = function formatJS(js) {
|
|
148
|
-
return prettier.format(js || "", {
|
|
149
|
-
filepath: "script.js"
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
|
-
var formatMD = function formatMD(md) {
|
|
153
|
-
return prettier.format(md || "", {
|
|
154
|
-
filepath: "README.md"
|
|
155
|
-
});
|
|
156
|
-
};
|
|
71
|
+
const formatCSS = (css) => prettier.format(css || "", { filepath: "style.css" });
|
|
72
|
+
const formatHTML = (html) => prettier.format(html || "", { filepath: "index.html" });
|
|
73
|
+
const formatJS = (js) => prettier.format(js || "", { filepath: "script.js" });
|
|
74
|
+
const formatMD = (md) => prettier.format(md || "", { filepath: "README.md" });
|
|
157
75
|
|
|
158
|
-
var
|
|
76
|
+
var codepen_template_default = '<html>\n <head>\n <meta charset="utf-8" />\n <title>CodePen</title>\n </head>\n <body>\n <form\n id="form"\n action="https://codepen.io/pen/define"\n method="post"\n target="_self"\n >\n <input type="hidden" name="data" />\n <button id="open" alt="JSFiddle" title="JSFiddle">Open CodePen</button>\n </form>\n\n <script type="text/javascript">\n document.getElementById("open").click();\n <\/script>\n </body>\n</html>\n';
|
|
159
77
|
|
|
160
|
-
/**
|
|
161
|
-
* @param example
|
|
162
|
-
*/
|
|
163
78
|
function generateCodePenPage(example) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
79
|
+
const data = example.playground;
|
|
80
|
+
const title = example.titles.join(" | ");
|
|
81
|
+
const page = cheerio.load(codepen_template_default);
|
|
167
82
|
page("title").text(title);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
83
|
+
const form = page("#form");
|
|
84
|
+
form.find('input[name="data"]').attr(
|
|
85
|
+
"value",
|
|
86
|
+
JSON.stringify({
|
|
87
|
+
css: data.code.css,
|
|
88
|
+
css_external: data.resources.css.join(";"),
|
|
89
|
+
html: data.code.html,
|
|
90
|
+
js: data.code.js,
|
|
91
|
+
js_external: data.resources.js.join(";"),
|
|
92
|
+
title: example.titles.join(" | ")
|
|
93
|
+
})
|
|
94
|
+
);
|
|
177
95
|
return page.html();
|
|
178
96
|
}
|
|
179
97
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
value = _ref4[1];
|
|
196
|
-
return [_sliceInstanceProperty(name).call(name, 2), "".concat(value)];
|
|
197
|
-
})).call(_context, function (_ref5) {
|
|
198
|
-
var _context4;
|
|
199
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
200
|
-
name = _ref6[0],
|
|
201
|
-
value = _ref6[1];
|
|
202
|
-
return _concatInstanceProperty(_context4 = "window.addEventListener(\"".concat(name, "\", () => { ")).call(_context4, value, " });");
|
|
203
|
-
}).join("\n");
|
|
204
|
-
var js = formatJS(_mapInstanceProperty(_context5 = _mapInstanceProperty(_context6 = example$("script")).call(_context6, function (_i, elem) {
|
|
205
|
-
return elem.children[0];
|
|
206
|
-
}).get()).call(_context5, function (elem) {
|
|
207
|
-
return elem.data;
|
|
208
|
-
}).join("") + "\n\n;" + eventListeners);
|
|
209
|
-
// Cascading Style Sheets
|
|
210
|
-
var css = formatCSS(_mapInstanceProperty(_context7 = _mapInstanceProperty(_context8 = example$("style")).call(_context8, function (_i, elem) {
|
|
211
|
-
return elem.children[0];
|
|
212
|
-
}).get()).call(_context7, function (elem) {
|
|
213
|
-
return elem.data;
|
|
214
|
-
}).join(""));
|
|
215
|
-
// Hypertext Markup Language
|
|
216
|
-
var $html = $.load(example$("body").html() || "");
|
|
98
|
+
async function generatePlaygroundData(baseURL, example$, examplePath) {
|
|
99
|
+
const firstBodyChild = example$("body").get(0);
|
|
100
|
+
if (firstBodyChild == null) {
|
|
101
|
+
throw new Error("Example body has no children.");
|
|
102
|
+
}
|
|
103
|
+
const eventListeners = Object.entries(firstBodyChild.attribs).filter(([name]) => /^on/.test(name)).map(([name, value]) => [name.slice(2), `${value}`]).map(
|
|
104
|
+
([name, value]) => `window.addEventListener("${name}", () => { ${value} });`
|
|
105
|
+
).join("\n");
|
|
106
|
+
const js = formatJS(
|
|
107
|
+
example$("script").map((_i, elem) => elem.children[0]).get().map((elem) => elem.data).join("") + "\n\n;" + eventListeners
|
|
108
|
+
);
|
|
109
|
+
const css = formatCSS(
|
|
110
|
+
example$("style").map((_i, elem) => elem.children[0]).get().map((elem) => elem.data).join("")
|
|
111
|
+
);
|
|
112
|
+
const $html = cheerio.load(example$("body").html() || "");
|
|
217
113
|
$html("script").remove();
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
var fixPath = function fixPath(rawPath) {
|
|
221
|
-
return /^https?:\/\//.test(rawPath) ?
|
|
114
|
+
const html = formatHTML($html("body").html());
|
|
115
|
+
const fixPath = (rawPath) => /^https?:\/\//.test(rawPath) ? (
|
|
222
116
|
// World wide web absolute.
|
|
223
|
-
rawPath
|
|
117
|
+
rawPath
|
|
118
|
+
) : /^\//.test(rawPath) ? (
|
|
224
119
|
// Domain absolute.
|
|
225
|
-
baseURL +
|
|
120
|
+
baseURL + rawPath.slice(1)
|
|
121
|
+
) : (
|
|
226
122
|
//Relative.
|
|
227
|
-
baseURL +
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
js:
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return $.load(elem)("script").attr("href");
|
|
237
|
-
}).get()).call(_context13, function (href) {
|
|
238
|
-
return typeof href === "string";
|
|
239
|
-
})).call(_context12, fixPath)
|
|
123
|
+
baseURL + relative(process.cwd(), resolve(dirname(examplePath), rawPath))
|
|
124
|
+
);
|
|
125
|
+
const resources = {
|
|
126
|
+
js: example$("script").map(
|
|
127
|
+
(_i, elem) => cheerio.load(elem)("script").attr("src")
|
|
128
|
+
).get().filter((src) => typeof src === "string").map(fixPath),
|
|
129
|
+
css: example$("link[rel='stylesheet']").map(
|
|
130
|
+
(_i, elem) => cheerio.load(elem)("script").attr("href")
|
|
131
|
+
).get().filter((href) => typeof href === "string").map(fixPath)
|
|
240
132
|
};
|
|
241
133
|
return {
|
|
242
134
|
code: {
|
|
243
|
-
css: css,
|
|
244
|
-
html: html,
|
|
245
|
-
js: js
|
|
135
|
+
css: await css,
|
|
136
|
+
html: await html,
|
|
137
|
+
js: await js
|
|
246
138
|
},
|
|
247
|
-
resources
|
|
139
|
+
resources
|
|
248
140
|
};
|
|
249
141
|
}
|
|
250
142
|
|
|
251
|
-
var
|
|
143
|
+
var jsfiddle_template_default = '<html>\n <head>\n <meta charset="utf-8" />\n <title>JSFiddle</title>\n </head>\n <body>\n <form\n id="form"\n action="https://jsfiddle.net/api/post/library/pure/"\n method="post"\n target="_self"\n >\n <input type="hidden" name="css" />\n <input type="hidden" name="html" />\n <input type="hidden" name="js" />\n <input type="hidden" name="resources" />\n <input type="hidden" name="title" />\n <input type="hidden" name="wrap" />\n <button id="open" alt="JSFiddle" title="JSFiddle">Open JSFiddle</button>\n </form>\n\n <script type="text/javascript">\n document.getElementById("open").click();\n <\/script>\n </body>\n</html>\n';
|
|
252
144
|
|
|
253
|
-
/**
|
|
254
|
-
* @param example
|
|
255
|
-
*/
|
|
256
145
|
function generateJSFiddlePage(example) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
var page = $.load(template);
|
|
146
|
+
const data = example.playground;
|
|
147
|
+
const title = example.titles.join(" | ");
|
|
148
|
+
const resources = [...data.resources.css, ...data.resources.js].join(",");
|
|
149
|
+
const page = cheerio.load(jsfiddle_template_default);
|
|
262
150
|
page("title").text(title);
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
// Don't run JS before the DOM is ready.
|
|
271
|
-
_findInstanceProperty(form).call(form, 'input[name="wrap"]').attr("value", "b");
|
|
151
|
+
const form = page("#form");
|
|
152
|
+
form.find('input[name="css"]').attr("value", data.code.css);
|
|
153
|
+
form.find('input[name="html"]').attr("value", data.code.html);
|
|
154
|
+
form.find('input[name="js"]').attr("value", data.code.js);
|
|
155
|
+
form.find('input[name="resources"]').attr("value", resources);
|
|
156
|
+
form.find('input[name="title"]').attr("value", title);
|
|
157
|
+
form.find('input[name="wrap"]').attr("value", "b");
|
|
272
158
|
return page.html();
|
|
273
159
|
}
|
|
274
160
|
|
|
275
|
-
var
|
|
161
|
+
var screenshot_script_js_default = "/* global window: false */\n\n/**\n * Simulates confirmation usind window.confirm and window.alert otherwise the\n * screenshot generator would just hang forever.\n */\nwindow.realAlert = window.alert;\nwindow.alert = function () {};\nwindow.confirm = function () {\n return true;\n};\n\n/**\n * Wait for the page to report it's ready to take a screenshot.\n */\nwindow.readyToTakeAScreenshot = new Promise(function (resolve) {\n window.takeScreenshot = resolve;\n});\n";
|
|
276
162
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
function
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
*
|
|
287
|
-
* @param screenshot - The binary data of the screenshot.
|
|
288
|
-
* @returns True for valid and false for invalid.
|
|
289
|
-
*/
|
|
290
|
-
function isScreenshotValid(_x) {
|
|
291
|
-
return _isScreenshotValid.apply(this, arguments);
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Capture an element on the example's page and save the screenshot to the
|
|
295
|
-
* disk as a PNG file.
|
|
296
|
-
*
|
|
297
|
-
* @param browser - Puppeteer's browser instance.
|
|
298
|
-
* @param config - See the type's docs for detail.
|
|
299
|
-
* @returns Whether or not the screenshot passed validation check.
|
|
300
|
-
*/
|
|
301
|
-
function _isScreenshotValid() {
|
|
302
|
-
_isScreenshotValid = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(screenshot) {
|
|
303
|
-
var image, firstPixel, x, y;
|
|
304
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
305
|
-
while (1) switch (_context.prev = _context.next) {
|
|
306
|
-
case 0:
|
|
307
|
-
_context.next = 2;
|
|
308
|
-
return Jimp.read(screenshot);
|
|
309
|
-
case 2:
|
|
310
|
-
image = _context.sent;
|
|
311
|
-
firstPixel = image.getPixelColor(0, 0);
|
|
312
|
-
x = 0;
|
|
313
|
-
case 5:
|
|
314
|
-
if (!(x < image.getWidth())) {
|
|
315
|
-
_context.next = 16;
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
y = 0;
|
|
319
|
-
case 7:
|
|
320
|
-
if (!(y < image.getHeight())) {
|
|
321
|
-
_context.next = 13;
|
|
322
|
-
break;
|
|
323
|
-
}
|
|
324
|
-
if (!(firstPixel !== image.getPixelColor(x, y))) {
|
|
325
|
-
_context.next = 10;
|
|
326
|
-
break;
|
|
327
|
-
}
|
|
328
|
-
return _context.abrupt("return", true);
|
|
329
|
-
case 10:
|
|
330
|
-
++y;
|
|
331
|
-
_context.next = 7;
|
|
332
|
-
break;
|
|
333
|
-
case 13:
|
|
334
|
-
++x;
|
|
335
|
-
_context.next = 5;
|
|
336
|
-
break;
|
|
337
|
-
case 16:
|
|
338
|
-
return _context.abrupt("return", false);
|
|
339
|
-
case 17:
|
|
340
|
-
case "end":
|
|
341
|
-
return _context.stop();
|
|
163
|
+
const unlink = promisify(fs.unlink);
|
|
164
|
+
const writeFile$1 = promisify(fs.writeFile);
|
|
165
|
+
async function isScreenshotValid(screenshot) {
|
|
166
|
+
const image = await Jimp.read(screenshot);
|
|
167
|
+
const firstPixel = image.getPixelColor(0, 0);
|
|
168
|
+
for (let x = 0; x < image.width; ++x) {
|
|
169
|
+
for (let y = 0; y < image.height; ++y) {
|
|
170
|
+
if (firstPixel !== image.getPixelColor(x, y)) {
|
|
171
|
+
return true;
|
|
342
172
|
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
return
|
|
346
|
-
}
|
|
347
|
-
function generateScreenshot(_x2, _x3) {
|
|
348
|
-
return _generateScreenshot.apply(this, arguments);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return false;
|
|
349
176
|
}
|
|
350
|
-
function
|
|
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
|
-
case 39:
|
|
438
|
-
screenshot = _context4.sent;
|
|
439
|
-
if (!(screenshot == null)) {
|
|
440
|
-
_context4.next = 44;
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
throw new Error("Failed to take screenshot of \u201C".concat(example.paths.page, "\u201D"));
|
|
444
|
-
case 44:
|
|
445
|
-
if (!(typeof screenshot === "string")) {
|
|
446
|
-
_context4.next = 46;
|
|
447
|
-
break;
|
|
448
|
-
}
|
|
449
|
-
throw new Error("Failed to get the binary data of the screenshot of \u201C".concat(example.paths.page, "\u201D"));
|
|
450
|
-
case 46:
|
|
451
|
-
_context4.next = 48;
|
|
452
|
-
return writeFile$1(example.paths.screenshot.local, screenshot);
|
|
453
|
-
case 48:
|
|
454
|
-
return _context4.abrupt("return", isScreenshotValid(screenshot));
|
|
455
|
-
case 51:
|
|
456
|
-
_context4.prev = 51;
|
|
457
|
-
_context4.t0 = _context4["catch"](2);
|
|
458
|
-
console.error(_context4.t0);
|
|
459
|
-
return _context4.abrupt("return", false);
|
|
460
|
-
case 55:
|
|
461
|
-
_context4.prev = 55;
|
|
462
|
-
_iterator = _createForOfIteratorHelper$3(_reverseInstanceProperty(_context3 = _spliceInstanceProperty(cleanup).call(cleanup, 0)).call(_context3));
|
|
463
|
-
_context4.prev = 57;
|
|
464
|
-
_iterator.s();
|
|
465
|
-
case 59:
|
|
466
|
-
if ((_step = _iterator.n()).done) {
|
|
467
|
-
_context4.next = 71;
|
|
468
|
-
break;
|
|
469
|
-
}
|
|
470
|
-
callback = _step.value;
|
|
471
|
-
_context4.prev = 61;
|
|
472
|
-
_context4.next = 64;
|
|
473
|
-
return callback();
|
|
474
|
-
case 64:
|
|
475
|
-
_context4.next = 69;
|
|
476
|
-
break;
|
|
477
|
-
case 66:
|
|
478
|
-
_context4.prev = 66;
|
|
479
|
-
_context4.t1 = _context4["catch"](61);
|
|
480
|
-
console.error(_context4.t1);
|
|
481
|
-
case 69:
|
|
482
|
-
_context4.next = 59;
|
|
483
|
-
break;
|
|
484
|
-
case 71:
|
|
485
|
-
_context4.next = 76;
|
|
486
|
-
break;
|
|
487
|
-
case 73:
|
|
488
|
-
_context4.prev = 73;
|
|
489
|
-
_context4.t2 = _context4["catch"](57);
|
|
490
|
-
_iterator.e(_context4.t2);
|
|
491
|
-
case 76:
|
|
492
|
-
_context4.prev = 76;
|
|
493
|
-
_iterator.f();
|
|
494
|
-
return _context4.finish(76);
|
|
495
|
-
case 79:
|
|
496
|
-
return _context4.finish(55);
|
|
497
|
-
case 80:
|
|
498
|
-
case "end":
|
|
499
|
-
return _context4.stop();
|
|
177
|
+
async function generateScreenshot(browser, config) {
|
|
178
|
+
const { debug, example, height, screenshotScript, width } = config;
|
|
179
|
+
const cleanup = [];
|
|
180
|
+
try {
|
|
181
|
+
const tmpPath = resolve(
|
|
182
|
+
dirname(example.paths.page.local),
|
|
183
|
+
".tmp.example.screenshot." + basename(example.paths.page.local)
|
|
184
|
+
);
|
|
185
|
+
const screenshotPage = cheerio.load(example.html);
|
|
186
|
+
screenshotPage("head").prepend(
|
|
187
|
+
cheerio.load([])("<script>").attr("type", "text/javascript").text(`window.DEBUG = ${true};`),
|
|
188
|
+
cheerio.load([])("<script>").attr("type", "text/javascript").text(screenshot_script_js_default),
|
|
189
|
+
cheerio.load([])("<script>").attr("type", "text/javascript").text(screenshotScript),
|
|
190
|
+
cheerio.load([])("<style>").attr("type", "text/css").text(
|
|
191
|
+
[
|
|
192
|
+
`${example.selector} {`,
|
|
193
|
+
" border: none !important;",
|
|
194
|
+
"",
|
|
195
|
+
` min-width: ${width}px !important;`,
|
|
196
|
+
` min-height: ${height}px !important;`,
|
|
197
|
+
` width: ${width}px !important;`,
|
|
198
|
+
` height: ${height}px !important;`,
|
|
199
|
+
` max-width: ${width}px !important;`,
|
|
200
|
+
` max-height: ${height}px !important;`,
|
|
201
|
+
"}"
|
|
202
|
+
].join("\n")
|
|
203
|
+
)
|
|
204
|
+
);
|
|
205
|
+
await writeFile$1(tmpPath, await formatHTML(screenshotPage.html()));
|
|
206
|
+
if (!debug) {
|
|
207
|
+
cleanup.push(() => unlink(tmpPath));
|
|
208
|
+
}
|
|
209
|
+
const context = await browser.createBrowserContext();
|
|
210
|
+
if (!debug) {
|
|
211
|
+
cleanup.push(() => context.close());
|
|
212
|
+
}
|
|
213
|
+
const page = await context.newPage();
|
|
214
|
+
if (!debug) {
|
|
215
|
+
cleanup.push(() => page.close());
|
|
216
|
+
}
|
|
217
|
+
await page.setViewport({ width: width + 50, height: height + 50 });
|
|
218
|
+
await page.goto("file://" + tmpPath.split(sep).join(posix.sep));
|
|
219
|
+
await page.waitForSelector(example.selector, {
|
|
220
|
+
visible: true,
|
|
221
|
+
timeout: example.timeout * 1e3
|
|
222
|
+
});
|
|
223
|
+
const { delay } = example;
|
|
224
|
+
if (delay === "call") {
|
|
225
|
+
await page.evaluate(
|
|
226
|
+
"function fn() { return window.readyToTakeAScreenshot; }"
|
|
227
|
+
);
|
|
228
|
+
} else {
|
|
229
|
+
await new Promise(
|
|
230
|
+
(resolve2) => void setTimeout(resolve2, delay * 1e3)
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
const $element = await page.$(example.selector);
|
|
234
|
+
if ($element == null) {
|
|
235
|
+
throw new Error(
|
|
236
|
+
`Element "${example.selector}" not found in ${example.path}.`
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
await $element.evaluate((element) => {
|
|
240
|
+
element.scrollIntoView();
|
|
241
|
+
});
|
|
242
|
+
const screenshot = await $element.screenshot({
|
|
243
|
+
encoding: "binary"
|
|
244
|
+
});
|
|
245
|
+
if (screenshot == null) {
|
|
246
|
+
throw new Error(`Failed to take screenshot of \u201C${example.paths.page}\u201D`);
|
|
247
|
+
} else if (typeof screenshot === "string") {
|
|
248
|
+
throw new Error(
|
|
249
|
+
`Failed to get the binary data of the screenshot of \u201C${example.paths.page}\u201D`
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
await writeFile$1(example.paths.screenshot.local, screenshot);
|
|
253
|
+
return isScreenshotValid(Buffer.from(screenshot));
|
|
254
|
+
} catch (error) {
|
|
255
|
+
console.error(error);
|
|
256
|
+
return false;
|
|
257
|
+
} finally {
|
|
258
|
+
for (const callback of cleanup.splice(0).reverse()) {
|
|
259
|
+
try {
|
|
260
|
+
await callback();
|
|
261
|
+
} catch (error) {
|
|
262
|
+
console.error(error);
|
|
500
263
|
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
return _generateScreenshot.apply(this, arguments);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
504
266
|
}
|
|
505
267
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var _context22, _context23; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context22 = ownKeys$1(Object(t), !0)).call(_context22, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context23 = ownKeys$1(Object(t))).call(_context23, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
511
|
-
var collator = new Intl.Collator("US");
|
|
512
|
-
var writeFile = util.promisify(fs.writeFile);
|
|
513
|
-
var ContentBuilder = /*#__PURE__*/function () {
|
|
514
|
-
function ContentBuilder(_config) {
|
|
515
|
-
_classCallCheck(this, ContentBuilder);
|
|
268
|
+
const collator = new Intl.Collator("US");
|
|
269
|
+
const writeFile = promisify(fs.writeFile);
|
|
270
|
+
class ContentBuilder {
|
|
271
|
+
constructor(_config) {
|
|
516
272
|
this._config = _config;
|
|
517
273
|
}
|
|
518
|
-
/**
|
|
519
|
-
* Build the files and write them to the disk.
|
|
520
|
-
*
|
|
521
|
-
* @param emit
|
|
522
|
-
* @param emit.
|
|
523
|
-
* @param emit.
|
|
524
|
-
* @
|
|
525
|
-
* @returns A report with check results and the number of written files.
|
|
274
|
+
/**
|
|
275
|
+
* Build the files and write them to the disk.
|
|
276
|
+
* @param emit - Which types of files to emit.
|
|
277
|
+
* @param emit.index
|
|
278
|
+
* @param emit.playgrounds
|
|
279
|
+
* @param emit.screenshots
|
|
280
|
+
* @returns A report with check results and the number of written files.
|
|
526
281
|
*/
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
282
|
+
build(emit = {}) {
|
|
283
|
+
const allExamples = this._processGroup(this._config.examples);
|
|
284
|
+
const okay = [];
|
|
285
|
+
const fail = [];
|
|
286
|
+
console.info(
|
|
287
|
+
`Going to generate ${[
|
|
288
|
+
emit.index ? ["index files"] : [],
|
|
289
|
+
emit.playgrounds ? ["playground openers"] : [],
|
|
290
|
+
emit.screenshots ? ["screenshots"] : []
|
|
291
|
+
].flat().join(", ")} for ${allExamples.length} examples.`
|
|
292
|
+
);
|
|
293
|
+
process.stdout.write("\n");
|
|
294
|
+
const index = emit.index ? (
|
|
540
295
|
// Generate indexes.
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
}, _callee);
|
|
562
|
-
}));
|
|
563
|
-
return function (_x) {
|
|
564
|
-
return _ref3.apply(this, arguments);
|
|
565
|
-
};
|
|
566
|
-
}()));
|
|
567
|
-
case 3:
|
|
568
|
-
results = _context5.sent;
|
|
569
|
-
return _context5.abrupt("return", [_objectSpread$1(_objectSpread$1({}, getStartStopMs()), {}, {
|
|
570
|
-
count: results.length,
|
|
571
|
-
result: _everyInstanceProperty(results).call(results, function (_ref4) {
|
|
572
|
-
var status = _ref4.status;
|
|
573
|
-
return status === "fulfilled";
|
|
574
|
-
}) ? "fulfilled" : "rejected"
|
|
575
|
-
})]);
|
|
576
|
-
case 5:
|
|
577
|
-
case "end":
|
|
578
|
-
return _context5.stop();
|
|
296
|
+
(async () => {
|
|
297
|
+
const getStartStopMs = measureStartStopMs();
|
|
298
|
+
const contentParts = await this._config.renderer.render(
|
|
299
|
+
this._config.examples,
|
|
300
|
+
this._config.output,
|
|
301
|
+
this._config.title,
|
|
302
|
+
collator
|
|
303
|
+
);
|
|
304
|
+
const results = await Promise.allSettled(
|
|
305
|
+
contentParts.map(
|
|
306
|
+
async ({ content, filename }) => writeFile(join(this._config.output, filename), content)
|
|
307
|
+
)
|
|
308
|
+
);
|
|
309
|
+
return [
|
|
310
|
+
{
|
|
311
|
+
...getStartStopMs(),
|
|
312
|
+
count: results.length,
|
|
313
|
+
result: results.every(
|
|
314
|
+
({ status }) => status === "fulfilled"
|
|
315
|
+
) ? "fulfilled" : "rejected"
|
|
579
316
|
}
|
|
580
|
-
|
|
581
|
-
})
|
|
317
|
+
];
|
|
318
|
+
})()
|
|
319
|
+
) : (
|
|
582
320
|
// Skip indexes.
|
|
583
|
-
|
|
584
|
-
|
|
321
|
+
Promise.resolve([])
|
|
322
|
+
);
|
|
323
|
+
const playgrounds = emit.playgrounds ? (
|
|
585
324
|
// Generate playground pages.
|
|
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
|
-
count: results.length,
|
|
615
|
-
example: example,
|
|
616
|
-
result: _everyInstanceProperty(results).call(results, function (_ref8) {
|
|
617
|
-
var status = _ref8.status;
|
|
618
|
-
return status === "fulfilled";
|
|
619
|
-
}) ? "fulfilled" : "rejected"
|
|
620
|
-
}));
|
|
621
|
-
case 5:
|
|
622
|
-
case "end":
|
|
623
|
-
return _context7.stop();
|
|
624
|
-
}
|
|
625
|
-
}, _callee3);
|
|
626
|
-
}));
|
|
627
|
-
return function (_x2) {
|
|
628
|
-
return _ref6.apply(this, arguments);
|
|
629
|
-
};
|
|
630
|
-
}()));
|
|
631
|
-
case 2:
|
|
632
|
-
return _context8.abrupt("return", _context8.sent);
|
|
633
|
-
case 3:
|
|
634
|
-
case "end":
|
|
635
|
-
return _context8.stop();
|
|
636
|
-
}
|
|
637
|
-
}, _callee4);
|
|
638
|
-
}))() :
|
|
325
|
+
(async () => await Promise.all(
|
|
326
|
+
allExamples.map(async (example) => {
|
|
327
|
+
const getStartStopMs = measureStartStopMs();
|
|
328
|
+
const results = await Promise.allSettled(
|
|
329
|
+
[
|
|
330
|
+
{
|
|
331
|
+
html: generateJSFiddlePage(example),
|
|
332
|
+
path: example.paths.jsfiddle.local
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
html: generateCodePenPage(example),
|
|
336
|
+
path: example.paths.codepen.local
|
|
337
|
+
}
|
|
338
|
+
].map(
|
|
339
|
+
async ({ html, path }) => writeFile(path, await formatHTML(html))
|
|
340
|
+
)
|
|
341
|
+
);
|
|
342
|
+
return {
|
|
343
|
+
...getStartStopMs(),
|
|
344
|
+
count: results.length,
|
|
345
|
+
example,
|
|
346
|
+
result: results.every(
|
|
347
|
+
({ status }) => status === "fulfilled"
|
|
348
|
+
) ? "fulfilled" : "rejected"
|
|
349
|
+
};
|
|
350
|
+
})
|
|
351
|
+
))()
|
|
352
|
+
) : (
|
|
639
353
|
// Skip playground pages.
|
|
640
|
-
|
|
641
|
-
|
|
354
|
+
Promise.resolve([])
|
|
355
|
+
);
|
|
356
|
+
const screenshots = emit.screenshots ? (
|
|
642
357
|
// Generate screenshots.
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
} else {
|
|
671
|
-
cleanup.push(function () {
|
|
672
|
-
return browser.close();
|
|
358
|
+
(async () => {
|
|
359
|
+
const cleanup = [];
|
|
360
|
+
try {
|
|
361
|
+
const debug = /^1|y|yes|true$/i.test(process.env.DEBUG ?? "");
|
|
362
|
+
const browser = await puppeteer.launch({
|
|
363
|
+
headless: !debug,
|
|
364
|
+
slowMo: debug ? 100 : void 0
|
|
365
|
+
});
|
|
366
|
+
if (debug) {
|
|
367
|
+
cleanup.push(async () => browser.disconnect());
|
|
368
|
+
} else {
|
|
369
|
+
cleanup.push(() => browser.close());
|
|
370
|
+
}
|
|
371
|
+
const todo = allExamples.slice();
|
|
372
|
+
const total = todo.length;
|
|
373
|
+
const reports = [];
|
|
374
|
+
await Promise.allSettled(
|
|
375
|
+
new Array(this._config.parallel).fill(null).map(async () => {
|
|
376
|
+
let example;
|
|
377
|
+
while (example = todo.pop()) {
|
|
378
|
+
const getStartStopMs = measureStartStopMs();
|
|
379
|
+
const valid = await generateScreenshot(browser, {
|
|
380
|
+
debug,
|
|
381
|
+
example,
|
|
382
|
+
height: this._config.renderer.screenshot.height,
|
|
383
|
+
screenshotScript: this._config.screenshotScript,
|
|
384
|
+
width: this._config.renderer.screenshot.width
|
|
673
385
|
});
|
|
386
|
+
const report = {
|
|
387
|
+
...getStartStopMs(),
|
|
388
|
+
count: 1,
|
|
389
|
+
example,
|
|
390
|
+
result: valid ? "fulfilled" : "rejected"
|
|
391
|
+
};
|
|
392
|
+
reports.push(report);
|
|
393
|
+
if (valid) {
|
|
394
|
+
okay.push(example.path);
|
|
395
|
+
} else {
|
|
396
|
+
fail.push(example.path);
|
|
397
|
+
}
|
|
398
|
+
const percentage = (Math.floor(reports.length / total * 100) + "%").padStart(4, " ");
|
|
399
|
+
const validText = valid ? "okay" : "fail";
|
|
400
|
+
const msText = formatStartStopMs(report);
|
|
401
|
+
console.info(
|
|
402
|
+
`${percentage} ${validText} ${msText} - ${example.path}`
|
|
403
|
+
);
|
|
674
404
|
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
while (1) switch (_context16.prev = _context16.next) {
|
|
686
|
-
case 0:
|
|
687
|
-
if (!(example = todo.pop())) {
|
|
688
|
-
_context16.next = 14;
|
|
689
|
-
break;
|
|
690
|
-
}
|
|
691
|
-
getStartStopMs = measureStartStopMs();
|
|
692
|
-
_context16.next = 4;
|
|
693
|
-
return generateScreenshot(browser, {
|
|
694
|
-
debug: debug,
|
|
695
|
-
example: example,
|
|
696
|
-
height: _this._config.renderer.screenshot.height,
|
|
697
|
-
screenshotScript: _this._config.screenshotScript,
|
|
698
|
-
width: _this._config.renderer.screenshot.width
|
|
699
|
-
});
|
|
700
|
-
case 4:
|
|
701
|
-
valid = _context16.sent;
|
|
702
|
-
report = _objectSpread$1(_objectSpread$1({}, getStartStopMs()), {}, {
|
|
703
|
-
count: 1,
|
|
704
|
-
example: example,
|
|
705
|
-
result: valid ? "fulfilled" : "rejected"
|
|
706
|
-
});
|
|
707
|
-
reports.push(report);
|
|
708
|
-
if (valid) {
|
|
709
|
-
okay.push(example.path);
|
|
710
|
-
} else {
|
|
711
|
-
fail.push(example.path);
|
|
712
|
-
}
|
|
713
|
-
percentage = _padStartInstanceProperty(_context12 = Math.floor(reports.length / total * 100) + "%").call(_context12, 4, " ");
|
|
714
|
-
validText = valid ? "okay" : "fail";
|
|
715
|
-
msText = formatStartStopMs(report);
|
|
716
|
-
console.info(_concatInstanceProperty(_context13 = _concatInstanceProperty(_context14 = _concatInstanceProperty(_context15 = "".concat(percentage, " ")).call(_context15, validText, " ")).call(_context14, msText, " - ")).call(_context13, example.path));
|
|
717
|
-
_context16.next = 0;
|
|
718
|
-
break;
|
|
719
|
-
case 14:
|
|
720
|
-
case "end":
|
|
721
|
-
return _context16.stop();
|
|
722
|
-
}
|
|
723
|
-
}, _callee6);
|
|
724
|
-
}))));
|
|
725
|
-
case 12:
|
|
726
|
-
return _context18.abrupt("return", reports);
|
|
727
|
-
case 13:
|
|
728
|
-
_context18.prev = 13;
|
|
729
|
-
_iterator = _createForOfIteratorHelper$2(_reverseInstanceProperty(_context17 = _spliceInstanceProperty(cleanup).call(cleanup, 0)).call(_context17));
|
|
730
|
-
_context18.prev = 15;
|
|
731
|
-
_iterator.s();
|
|
732
|
-
case 17:
|
|
733
|
-
if ((_step = _iterator.n()).done) {
|
|
734
|
-
_context18.next = 29;
|
|
735
|
-
break;
|
|
736
|
-
}
|
|
737
|
-
callback = _step.value;
|
|
738
|
-
_context18.prev = 19;
|
|
739
|
-
_context18.next = 22;
|
|
740
|
-
return callback();
|
|
741
|
-
case 22:
|
|
742
|
-
_context18.next = 27;
|
|
743
|
-
break;
|
|
744
|
-
case 24:
|
|
745
|
-
_context18.prev = 24;
|
|
746
|
-
_context18.t0 = _context18["catch"](19);
|
|
747
|
-
console.error(_context18.t0);
|
|
748
|
-
case 27:
|
|
749
|
-
_context18.next = 17;
|
|
750
|
-
break;
|
|
751
|
-
case 29:
|
|
752
|
-
_context18.next = 34;
|
|
753
|
-
break;
|
|
754
|
-
case 31:
|
|
755
|
-
_context18.prev = 31;
|
|
756
|
-
_context18.t1 = _context18["catch"](15);
|
|
757
|
-
_iterator.e(_context18.t1);
|
|
758
|
-
case 34:
|
|
759
|
-
_context18.prev = 34;
|
|
760
|
-
_iterator.f();
|
|
761
|
-
return _context18.finish(34);
|
|
762
|
-
case 37:
|
|
763
|
-
return _context18.finish(13);
|
|
764
|
-
case 38:
|
|
765
|
-
case "end":
|
|
766
|
-
return _context18.stop();
|
|
405
|
+
})
|
|
406
|
+
);
|
|
407
|
+
return reports;
|
|
408
|
+
} finally {
|
|
409
|
+
for (const callback of cleanup.splice(0).reverse()) {
|
|
410
|
+
try {
|
|
411
|
+
await callback();
|
|
412
|
+
} catch (error) {
|
|
413
|
+
console.error(error);
|
|
414
|
+
}
|
|
767
415
|
}
|
|
768
|
-
}
|
|
769
|
-
})
|
|
416
|
+
}
|
|
417
|
+
})()
|
|
418
|
+
) : (
|
|
770
419
|
// Skip screenshots.
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
return index;
|
|
779
|
-
case 2:
|
|
780
|
-
_context19.next = 4;
|
|
781
|
-
return playgrounds;
|
|
782
|
-
case 4:
|
|
783
|
-
_context19.next = 6;
|
|
784
|
-
return screenshots;
|
|
785
|
-
case 6:
|
|
786
|
-
total = okay.length + fail.length;
|
|
787
|
-
return _context19.abrupt("return", {
|
|
788
|
-
fail: fail.length,
|
|
789
|
-
failPaths: fail,
|
|
790
|
-
okay: okay.length,
|
|
791
|
-
okayPaths: okay,
|
|
792
|
-
percentage: total === 0 ? 100 : 100 * okay.length / total,
|
|
793
|
-
total: total
|
|
794
|
-
});
|
|
795
|
-
case 8:
|
|
796
|
-
case "end":
|
|
797
|
-
return _context19.stop();
|
|
798
|
-
}
|
|
799
|
-
}, _callee8);
|
|
800
|
-
}))();
|
|
420
|
+
Promise.resolve([])
|
|
421
|
+
);
|
|
422
|
+
const checks = (async () => {
|
|
423
|
+
await index;
|
|
424
|
+
await playgrounds;
|
|
425
|
+
await screenshots;
|
|
426
|
+
const total = okay.length + fail.length;
|
|
801
427
|
return {
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
428
|
+
fail: fail.length,
|
|
429
|
+
failPaths: fail,
|
|
430
|
+
okay: okay.length,
|
|
431
|
+
okayPaths: okay,
|
|
432
|
+
percentage: total === 0 ? 100 : 100 * okay.length / total,
|
|
433
|
+
total
|
|
806
434
|
};
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
}]);
|
|
824
|
-
return ContentBuilder;
|
|
825
|
-
}();
|
|
435
|
+
})();
|
|
436
|
+
return { checks, index, playgrounds, screenshots };
|
|
437
|
+
}
|
|
438
|
+
_processGroup(examples) {
|
|
439
|
+
return Object.keys(examples).sort(collator.compare).flatMap((key) => {
|
|
440
|
+
const example = examples[key];
|
|
441
|
+
if (isExample(example)) {
|
|
442
|
+
return [example];
|
|
443
|
+
} else {
|
|
444
|
+
return this._processGroup(example);
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
}
|
|
826
449
|
|
|
827
|
-
var
|
|
450
|
+
var index_template_default$1 = '<html>\n <head>\n <meta charset="utf-8" />\n <title>Examples</title>\n\n <meta http-equiv="X-UA-Compatible" content="IE=edge" />\n <meta name="viewport" content="width=device-width, initial-scale=1" />\n\n <link rel="stylesheet" type="text/css" href="examples.css" />\n </head>\n <body></body>\n</html>\n';
|
|
828
451
|
|
|
829
|
-
var
|
|
452
|
+
var index_template_default = `.examples-root {
|
|
453
|
+
margin: 50px auto 200px;
|
|
454
|
+
min-width: calc(200px + 2em);
|
|
455
|
+
width: calc(100vw - 200px);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
.examples-root a {
|
|
459
|
+
color: #2b7ce9;
|
|
460
|
+
}
|
|
461
|
+
.examples-root a:visited {
|
|
462
|
+
color: #46417a;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
.examples-root .example-link {
|
|
466
|
+
margin: 1em;
|
|
467
|
+
position: relative;
|
|
468
|
+
width: 200px;
|
|
469
|
+
|
|
470
|
+
display: inline-block;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
.examples-root .example-link .example-image {
|
|
474
|
+
display: block;
|
|
475
|
+
height: 200px;
|
|
476
|
+
margin-top: 1ex;
|
|
477
|
+
position: relative;
|
|
478
|
+
width: 200px;
|
|
479
|
+
}
|
|
480
|
+
.examples-root .example-link .example-image > img {
|
|
481
|
+
position: absolute;
|
|
482
|
+
top: 0px;
|
|
483
|
+
left: 0px;
|
|
484
|
+
width: 200px;
|
|
485
|
+
height: 200px;
|
|
486
|
+
|
|
487
|
+
background: #2b7ce9;
|
|
488
|
+
border: 1px solid #2b7ce9;
|
|
489
|
+
color: #ffffff;
|
|
490
|
+
|
|
491
|
+
transition:
|
|
492
|
+
transform 0.5s ease 0s,
|
|
493
|
+
z-index 0.5s linear 0s;
|
|
494
|
+
z-index: 1;
|
|
495
|
+
}
|
|
496
|
+
.examples-root .example-link:hover .example-image > img {
|
|
497
|
+
transform: translate(0px, 95px) scale(2, 2);
|
|
498
|
+
z-index: 100;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
.examples-root .example-header > *:last-child {
|
|
502
|
+
margin-left: 0.5em;
|
|
503
|
+
}
|
|
504
|
+
.examples-root .icon {
|
|
505
|
+
height: 1.5em;
|
|
506
|
+
margin-bottom: -0.25em;
|
|
507
|
+
width: 1.5em;
|
|
508
|
+
|
|
509
|
+
background: none;
|
|
510
|
+
border: none;
|
|
511
|
+
cursor: pointer;
|
|
512
|
+
display: inline-block;
|
|
513
|
+
}
|
|
514
|
+
.examples-root .icon.jsfiddle {
|
|
515
|
+
background-size: contain;
|
|
516
|
+
background-image: url("data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%232b7ce9' d='M16.45,17.5C17.45,17.5 18.3,17.15 19,16.5C19.67,15.8 20,15 20,14C20,13.05 19.66,12.22 18.96,11.53C18.26,10.84 17.41,10.5 16.41,10.5C15.47,10.5 14.64,10.83 13.92,11.5L9.14,15.56C8.7,16 8.17,16.22 7.55,16.22C6.92,16.22 6.39,16 5.95,15.56C5.5,15.13 5.3,14.61 5.3,14C5.3,13.42 5.5,12.91 5.95,12.47C6.39,12.03 6.92,11.81 7.55,11.81C8.14,11.81 8.69,12.03 9.19,12.47L9.94,13.13L10.92,12.23L10.08,11.53C9.39,10.84 8.55,10.5 7.55,10.5C6.58,10.5 5.74,10.84 5.04,11.53C4.34,12.22 4,13.05 4,14C4,15 4.34,15.8 5.04,16.5C5.74,17.15 6.59,17.5 7.59,17.5C8.53,17.5 9.36,17.16 10.08,16.5L14.86,12.42C15.27,12 15.8,11.81 16.45,11.81C17.08,11.81 17.61,12.03 18.05,12.47C18.5,12.91 18.7,13.42 18.7,14C18.7,14.61 18.5,15.13 18.05,15.56C17.61,16 17.08,16.22 16.45,16.22C15.89,16.22 15.34,16 14.81,15.5L14.06,14.86L13.08,15.75L13.92,16.45C14.61,17.14 15.45,17.5 16.45,17.5M19.36,10.03C20.64,10.13 21.73,10.65 22.64,11.6C23.55,12.55 24,13.69 24,15C24,16.38 23.5,17.55 22.5,18.54C21.54,19.5 20.36,20 19,20H6C4.34,20 2.93,19.43 1.76,18.26C0.59,17.09 0,15.67 0,14C0,12.55 0.5,11.23 1.57,10.05C2.62,8.88 3.88,8.22 5.34,8.06C6,6.84 6.92,5.86 8.11,5.11C9.3,4.36 10.59,4 12,4C13.69,4 15.26,4.58 16.71,5.77C18.16,6.95 19.05,8.38 19.36,10.03Z' /%3E%3C/svg%3E");
|
|
517
|
+
}
|
|
518
|
+
.examples-root .icon.codepen {
|
|
519
|
+
background-size: contain;
|
|
520
|
+
background-image: url("data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%232b7ce9' d='M15.09,12L12,14.08V14.09L8.91,12L12,9.92V9.92L15.09,12M12,2C11.84,2 11.68,2.06 11.53,2.15L2.5,8.11C2.27,8.22 2.09,8.43 2,8.67V14.92C2,15.33 2,15.33 2.15,15.53L11.53,21.86C11.67,21.96 11.84,22 12,22C12.16,22 12.33,21.95 12.47,21.85L21.85,15.5C22,15.33 22,15.33 22,14.92V8.67C21.91,8.42 21.73,8.22 21.5,8.1L12.47,2.15C12.32,2.05 12.16,2 12,2M16.58,13L19.59,15.04L12.83,19.6V15.53L16.58,13M19.69,8.9L16.58,11L12.83,8.47V4.38L19.69,8.9M20.33,10.47V13.53L18.07,12L20.33,10.47M7.42,13L11.17,15.54V19.6L4.41,15.04L7.42,13M4.31,8.9L11.17,4.39V8.5L7.42,11L4.31,8.9M3.67,10.5L5.93,12L3.67,13.54V10.5Z' /%3E%3C/svg%3E");
|
|
521
|
+
}
|
|
522
|
+
`;
|
|
830
523
|
|
|
831
|
-
function _createForOfIteratorHelper$1(o, allowArrayLike) { var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"]; if (!it) { if (_Array$isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
832
|
-
function _unsupportedIterableToArray$1(o, minLen) { var _context3; if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(o, minLen); var n = _sliceInstanceProperty(_context3 = Object.prototype.toString.call(o)).call(_context3, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen); }
|
|
833
|
-
function _arrayLikeToArray$1(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
834
|
-
/**
|
|
835
|
-
* @param example
|
|
836
|
-
*/
|
|
837
524
|
function generateJSFiddle(example) {
|
|
838
|
-
return
|
|
525
|
+
return cheerio.load([])("<a>").addClass("icon jsfiddle").attr("href", example.paths.jsfiddle.web).attr("title", "JSFiddle");
|
|
839
526
|
}
|
|
840
|
-
/**
|
|
841
|
-
* @param example
|
|
842
|
-
*/
|
|
843
527
|
function generateCodePen(example) {
|
|
844
|
-
return
|
|
528
|
+
return cheerio.load([])("<a>").addClass("icon codepen").attr("href", example.paths.codepen.web).attr("title", "CodePen");
|
|
845
529
|
}
|
|
846
|
-
/**
|
|
847
|
-
* @param examples
|
|
848
|
-
* @param title
|
|
849
|
-
* @param level
|
|
850
|
-
* @param collator
|
|
851
|
-
*/
|
|
852
530
|
function processGroup$1(examples, title, level, collator) {
|
|
853
|
-
|
|
854
|
-
var heading = $.load([])("<h".concat(Math.max(1, Math.min(6, level)), ">"));
|
|
531
|
+
const heading = cheerio.load([])(`<h${Math.max(1, Math.min(6, level))}>`);
|
|
855
532
|
heading.text(title);
|
|
856
|
-
|
|
857
|
-
|
|
533
|
+
const list = cheerio.load([])("<div>");
|
|
534
|
+
const section = cheerio.load([])("<div>");
|
|
858
535
|
section.append(heading, list);
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
var key = _step.value;
|
|
864
|
-
var example = examples[key];
|
|
865
|
-
if (isExample(example)) {
|
|
866
|
-
var header = $.load([])("<div>").addClass("example-header").append(
|
|
536
|
+
for (const key of Object.keys(examples).sort(collator.compare)) {
|
|
537
|
+
const example = examples[key];
|
|
538
|
+
if (isExample(example)) {
|
|
539
|
+
const header = cheerio.load([])("<div>").addClass("example-header").append(
|
|
867
540
|
// Playgrounds
|
|
868
|
-
generateJSFiddle(example),
|
|
541
|
+
generateJSFiddle(example),
|
|
542
|
+
generateCodePen(example),
|
|
869
543
|
// Title
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
544
|
+
cheerio.load([])("<a>").attr("href", example.paths.page.web).text(key)
|
|
545
|
+
);
|
|
546
|
+
const image = cheerio.load([])("<a>").addClass("example-image").attr("href", example.paths.page.web).append(
|
|
547
|
+
cheerio.load([])("<img>").attr("src", example.paths.screenshot.web).attr("alt", key)
|
|
548
|
+
);
|
|
549
|
+
const item = cheerio.load([])("<span>").addClass("example-link").append(header, image);
|
|
550
|
+
list.append(item);
|
|
551
|
+
} else {
|
|
552
|
+
section.append(processGroup$1(example, key, level + 1, collator));
|
|
877
553
|
}
|
|
878
|
-
} catch (err) {
|
|
879
|
-
_iterator.e(err);
|
|
880
|
-
} finally {
|
|
881
|
-
_iterator.f();
|
|
882
554
|
}
|
|
883
555
|
return section;
|
|
884
556
|
}
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
var root = $.load([])("<div>");
|
|
557
|
+
const htmlRenderer = {
|
|
558
|
+
async render(examples, _output, title, collator) {
|
|
559
|
+
const filename = "index.html";
|
|
560
|
+
const root = cheerio.load([])("<div>");
|
|
890
561
|
root.addClass("examples-root");
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
try {
|
|
894
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
895
|
-
var key = _step2.value;
|
|
896
|
-
root.append(processGroup$1(examples[key], key, 1, collator));
|
|
897
|
-
}
|
|
898
|
-
} catch (err) {
|
|
899
|
-
_iterator2.e(err);
|
|
900
|
-
} finally {
|
|
901
|
-
_iterator2.f();
|
|
562
|
+
for (const key of Object.keys(examples).sort(collator.compare)) {
|
|
563
|
+
root.append(processGroup$1(examples[key], key, 1, collator));
|
|
902
564
|
}
|
|
903
|
-
|
|
565
|
+
const page = cheerio.load(index_template_default$1);
|
|
904
566
|
page("title").text(title);
|
|
905
567
|
page("body").append(root);
|
|
906
|
-
|
|
907
|
-
return [
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
}];
|
|
568
|
+
const content = await formatHTML(page.html());
|
|
569
|
+
return [
|
|
570
|
+
{ content, filename, title },
|
|
571
|
+
{
|
|
572
|
+
content: index_template_default,
|
|
573
|
+
filename: "examples.css",
|
|
574
|
+
title: "examples.css"
|
|
575
|
+
}
|
|
576
|
+
];
|
|
916
577
|
},
|
|
917
578
|
screenshot: {
|
|
918
579
|
width: 400,
|
|
@@ -920,109 +581,83 @@ var htmlRenderer = {
|
|
|
920
581
|
}
|
|
921
582
|
};
|
|
922
583
|
|
|
923
|
-
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
924
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context14, _context15; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context14 = ownKeys(Object(t), !0)).call(_context14, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context15 = ownKeys(Object(t))).call(_context15, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
925
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"]; if (!it) { if (_Array$isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
926
|
-
function _unsupportedIterableToArray(o, minLen) { var _context13; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty(_context13 = Object.prototype.toString.call(o)).call(_context13, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
927
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
928
|
-
/**
|
|
929
|
-
* @param lines
|
|
930
|
-
*/
|
|
931
584
|
function linesToContent(lines) {
|
|
932
585
|
return formatMD(lines.join("\n"));
|
|
933
586
|
}
|
|
934
|
-
/**
|
|
935
|
-
* @param title
|
|
936
|
-
* @param src
|
|
937
|
-
* @param href
|
|
938
|
-
*/
|
|
939
587
|
function image(title, src, href) {
|
|
940
|
-
|
|
941
|
-
return href == null ? _concatInstanceProperty(_context = ").call(_context, src, ")") : link(href, _concatInstanceProperty(_context2 = ").call(_context2, src, ")"));
|
|
588
|
+
return href == null ? `` : link(href, ``);
|
|
942
589
|
}
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
* @param text
|
|
946
|
-
*/
|
|
947
|
-
function link(href) {
|
|
948
|
-
var _context3;
|
|
949
|
-
var text = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : href;
|
|
950
|
-
return _concatInstanceProperty(_context3 = "[".concat(text, "](")).call(_context3, href, ")");
|
|
590
|
+
function link(href, text = href) {
|
|
591
|
+
return `[${text}](${href})`;
|
|
951
592
|
}
|
|
952
|
-
/**
|
|
953
|
-
* @param level
|
|
954
|
-
* @param text
|
|
955
|
-
*/
|
|
956
593
|
function header(level, text) {
|
|
957
|
-
|
|
958
|
-
return _concatInstanceProperty(_context4 = "".concat(_repeatInstanceProperty(_context5 = "#").call(_context5, level), " ")).call(_context4, text);
|
|
594
|
+
return `${"#".repeat(level)} ${text}`;
|
|
959
595
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
596
|
+
async function processGroup(examples, output, title, collator) {
|
|
597
|
+
const items = [];
|
|
598
|
+
const sections = [];
|
|
599
|
+
const filenamePart = title.replace(/[^a-zA-Z0-9]/g, "-").toLowerCase();
|
|
600
|
+
for (const key of Object.keys(examples).sort(collator.compare)) {
|
|
601
|
+
const example = examples[key];
|
|
602
|
+
if (isExample(example)) {
|
|
603
|
+
items.push(
|
|
604
|
+
header(2, key),
|
|
605
|
+
"",
|
|
606
|
+
image(
|
|
607
|
+
key,
|
|
608
|
+
"./" + relative(output, example.paths.screenshot.local),
|
|
609
|
+
example.paths.page.web
|
|
610
|
+
),
|
|
611
|
+
"",
|
|
612
|
+
[
|
|
613
|
+
link(example.paths.page.web, "Open"),
|
|
614
|
+
link(example.paths.jsfiddle.web, "JSFiddle"),
|
|
615
|
+
link(example.paths.codepen.web, "CodePen")
|
|
616
|
+
].join(" | "),
|
|
617
|
+
""
|
|
618
|
+
);
|
|
619
|
+
} else {
|
|
620
|
+
sections.push(
|
|
621
|
+
...(await processGroup(example, output, key, collator)).map(
|
|
622
|
+
(contentPart) => ({
|
|
623
|
+
...contentPart,
|
|
985
624
|
filename: filenamePart + "." + contentPart.filename
|
|
986
|
-
})
|
|
987
|
-
|
|
988
|
-
|
|
625
|
+
})
|
|
626
|
+
)
|
|
627
|
+
);
|
|
989
628
|
}
|
|
990
|
-
} catch (err) {
|
|
991
|
-
_iterator.e(err);
|
|
992
|
-
} finally {
|
|
993
|
-
_iterator.f();
|
|
994
629
|
}
|
|
995
|
-
return
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
630
|
+
return [
|
|
631
|
+
{
|
|
632
|
+
content: await linesToContent([header(1, title), "", ...items]),
|
|
633
|
+
filename: filenamePart + ".md",
|
|
634
|
+
title
|
|
635
|
+
},
|
|
636
|
+
...sections
|
|
637
|
+
];
|
|
1000
638
|
}
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
1009
|
-
var key = _step2.value;
|
|
1010
|
-
sections.push.apply(sections, _toConsumableArray(processGroup(examples[key], output, key, collator)));
|
|
1011
|
-
}
|
|
1012
|
-
} catch (err) {
|
|
1013
|
-
_iterator2.e(err);
|
|
1014
|
-
} finally {
|
|
1015
|
-
_iterator2.f();
|
|
639
|
+
const mdRenderer = {
|
|
640
|
+
async render(examples, output, _title, collator) {
|
|
641
|
+
const sections = [];
|
|
642
|
+
for (const key of Object.keys(examples).sort(collator.compare)) {
|
|
643
|
+
sections.push(
|
|
644
|
+
...await processGroup(examples[key], output, key, collator)
|
|
645
|
+
);
|
|
1016
646
|
}
|
|
1017
|
-
return
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
647
|
+
return [
|
|
648
|
+
{
|
|
649
|
+
content: await linesToContent([
|
|
650
|
+
header(1, "Examples"),
|
|
651
|
+
"",
|
|
652
|
+
...sections.map(
|
|
653
|
+
({ filename, title }) => "- " + link("./" + filename, title)
|
|
654
|
+
)
|
|
655
|
+
]),
|
|
656
|
+
filename: "README.md",
|
|
657
|
+
title: "Examples"
|
|
658
|
+
},
|
|
659
|
+
...sections
|
|
660
|
+
];
|
|
1026
661
|
},
|
|
1027
662
|
screenshot: {
|
|
1028
663
|
width: 740,
|
|
@@ -1030,7 +665,7 @@ var mdRenderer = {
|
|
|
1030
665
|
}
|
|
1031
666
|
};
|
|
1032
667
|
|
|
1033
|
-
|
|
668
|
+
const y = yargs(hideBin(process.argv)).strict(true).usage("generate-example-index [options]").hide("version").config().help().option("assets-local-directory", {
|
|
1034
669
|
default: "./examples/thumbnails",
|
|
1035
670
|
describe: "The directory where assets will be written to.",
|
|
1036
671
|
type: "string"
|
|
@@ -1102,137 +737,106 @@ var y = yargs.strict(true).usage("generate-example-index [options]").hide("versi
|
|
|
1102
737
|
describe: "Attempt to verify that the examples were generated correctly. The value is a percentage of checks that have to pass for the run to be considered success.",
|
|
1103
738
|
type: "number"
|
|
1104
739
|
});
|
|
1105
|
-
/**
|
|
1106
|
-
*
|
|
1107
|
-
*/
|
|
1108
740
|
function parseArguments() {
|
|
1109
|
-
return y.parserConfiguration({
|
|
1110
|
-
"camel-case-expansion": false
|
|
1111
|
-
}).parseSync();
|
|
741
|
+
return y.parserConfiguration({ "camel-case-expansion": false }).parseSync();
|
|
1112
742
|
}
|
|
1113
743
|
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
function joinURLs() {
|
|
1118
|
-
for (var _len = arguments.length, urls = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1119
|
-
urls[_key] = arguments[_key];
|
|
1120
|
-
}
|
|
1121
|
-
return _mapInstanceProperty(urls).call(urls, function (url) {
|
|
1122
|
-
return (
|
|
744
|
+
function joinURLs(...urls) {
|
|
745
|
+
return urls.map(
|
|
746
|
+
(url) => (
|
|
1123
747
|
// Strip the parts of leading and trailing slashes if they have them.
|
|
1124
748
|
url.replace(/^\/?(.*?)\/?$/, "$1")
|
|
1125
|
-
)
|
|
1126
|
-
|
|
749
|
+
)
|
|
750
|
+
).join("/");
|
|
1127
751
|
}
|
|
1128
|
-
/**
|
|
1129
|
-
* @param baseURL
|
|
1130
|
-
* @param url
|
|
1131
|
-
*/
|
|
1132
752
|
function fixAbsoluteInputURL(baseURL, url) {
|
|
1133
|
-
return
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
753
|
+
return url.startsWith("/") ? (
|
|
754
|
+
// Relative to the base URL. Base URL starts and URL ends with a slash.
|
|
755
|
+
baseURL + url.slice(1)
|
|
756
|
+
) : (
|
|
757
|
+
// Relative to some other point or absolute already.
|
|
758
|
+
url
|
|
759
|
+
);
|
|
1138
760
|
}
|
|
1139
|
-
/**
|
|
1140
|
-
* @param config
|
|
1141
|
-
* @param exampleAbsolutePath
|
|
1142
|
-
*/
|
|
1143
761
|
function generatePaths(config, exampleAbsolutePath) {
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
// is the same on all computers.
|
|
1147
|
-
var hash = node_crypto.createHash("sha256").update(exampleRelativePath).digest("hex");
|
|
762
|
+
const exampleRelativePath = relative(config.page.local, exampleAbsolutePath);
|
|
763
|
+
const hash = createHash("sha256").update(exampleRelativePath).digest("hex");
|
|
1148
764
|
return {
|
|
1149
|
-
codepen: generateLocalWebPair(
|
|
1150
|
-
|
|
765
|
+
codepen: generateLocalWebPair(
|
|
766
|
+
config.codepen.local,
|
|
767
|
+
config.codepen.web,
|
|
768
|
+
hash,
|
|
769
|
+
"codepen",
|
|
770
|
+
"html"
|
|
771
|
+
),
|
|
772
|
+
jsfiddle: generateLocalWebPair(
|
|
773
|
+
config.jsfiddle.local,
|
|
774
|
+
config.jsfiddle.web,
|
|
775
|
+
hash,
|
|
776
|
+
"jsfiddle",
|
|
777
|
+
"html"
|
|
778
|
+
),
|
|
1151
779
|
page: {
|
|
1152
780
|
local: exampleAbsolutePath,
|
|
1153
781
|
web: joinURLs(config.page.web, exampleRelativePath)
|
|
1154
782
|
},
|
|
1155
|
-
screenshot: generateLocalWebPair(
|
|
783
|
+
screenshot: generateLocalWebPair(
|
|
784
|
+
config.screenshot.local,
|
|
785
|
+
config.screenshot.web,
|
|
786
|
+
hash,
|
|
787
|
+
"screenshot",
|
|
788
|
+
"png"
|
|
789
|
+
)
|
|
1156
790
|
};
|
|
1157
791
|
}
|
|
1158
|
-
/**
|
|
1159
|
-
* @param localRoot
|
|
1160
|
-
* @param webRoot
|
|
1161
|
-
* @param hash
|
|
1162
|
-
* @param prefix
|
|
1163
|
-
* @param extension
|
|
1164
|
-
*/
|
|
1165
792
|
function generateLocalWebPair(localRoot, webRoot, hash, prefix, extension) {
|
|
1166
|
-
|
|
1167
|
-
var filename = _concatInstanceProperty(_context = _concatInstanceProperty(_context2 = "".concat(prefix, ".")).call(_context2, hash, ".")).call(_context, extension);
|
|
793
|
+
const filename = `${prefix}.${hash}.${extension}`;
|
|
1168
794
|
return {
|
|
1169
|
-
local:
|
|
795
|
+
local: resolve(localRoot, filename),
|
|
1170
796
|
web: joinURLs(webRoot, filename)
|
|
1171
797
|
};
|
|
1172
798
|
}
|
|
1173
799
|
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
// Log the parsed configuration for debugging purposes.
|
|
1177
|
-
console.info("Configuration: ", _JSON$stringify(argv, null, 2));
|
|
800
|
+
const argv = parseArguments();
|
|
801
|
+
console.info("Configuration: ", JSON.stringify(argv, null, 2));
|
|
1178
802
|
process.stdout.write("\n");
|
|
1179
|
-
// Pageres uses quite a lot of listeners when invoked multiple times in
|
|
1180
|
-
// parallel. This ensures there are no warnings about it.
|
|
1181
803
|
process.setMaxListeners(40);
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
var readFile = util.promisify(fs.readFile);
|
|
1186
|
-
/**
|
|
1187
|
-
* Extract and coerce a value from meta tag.
|
|
1188
|
-
*
|
|
1189
|
-
* @param page - The page to be queried.
|
|
1190
|
-
* @param name - The name of the meta tag.
|
|
1191
|
-
* @param fallback - The value to be used if the meta tag is not present.
|
|
1192
|
-
* @returns The value “smartly” coerced or the fallback if conversion isn't
|
|
1193
|
-
* possible or the value is not present in the page.
|
|
1194
|
-
*/
|
|
804
|
+
const screenshotScriptPath = typeof argv["screenshot-script"] === "string" ? resolve(argv["screenshot-script"]) : void 0;
|
|
805
|
+
const mkdir = util.promisify(fs.mkdir);
|
|
806
|
+
const readFile = util.promisify(fs.readFile);
|
|
1195
807
|
function getMeta(page, name, fallback) {
|
|
1196
|
-
|
|
808
|
+
const content = page(`meta[name="${name}"]`).attr("content");
|
|
1197
809
|
if (content == null) {
|
|
1198
|
-
// No meta of this name exists in the page, use the fallback.
|
|
1199
810
|
return fallback;
|
|
1200
|
-
} else if (!
|
|
1201
|
-
// Number.
|
|
811
|
+
} else if (!Number.isNaN(+content)) {
|
|
1202
812
|
return +content;
|
|
1203
813
|
} else if (typeof content === "string") {
|
|
1204
|
-
// String.
|
|
1205
814
|
return content;
|
|
1206
815
|
} else {
|
|
1207
|
-
// Something doesn't match, use the fallback.
|
|
1208
816
|
return fallback;
|
|
1209
817
|
}
|
|
1210
818
|
}
|
|
1211
|
-
/**
|
|
1212
|
-
* Test if the example conforms to the conventions.
|
|
1213
|
-
*
|
|
1214
|
-
* @param path - The path to the example (used for identification in logs).
|
|
1215
|
-
* @param page - The HTML to be linted.
|
|
1216
|
-
* @returns True if everything's okay, false otherwise.
|
|
1217
|
-
*/
|
|
1218
819
|
function lintExample(path, page) {
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
var msgs = ["".concat(path, ":")];
|
|
820
|
+
let valid = true;
|
|
821
|
+
const msgs = [`${path}:`];
|
|
1222
822
|
if (page("#title").length !== 1) {
|
|
1223
823
|
msgs.push("Missing #title element in the body.");
|
|
1224
824
|
valid = false;
|
|
1225
825
|
}
|
|
1226
826
|
if (page("#title > *").length < 2) {
|
|
1227
|
-
msgs.push(
|
|
827
|
+
msgs.push(
|
|
828
|
+
"There have to be at least two headings (group and example name)."
|
|
829
|
+
);
|
|
1228
830
|
valid = false;
|
|
1229
831
|
}
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
return $.load([])(elem).text();
|
|
1233
|
-
}).get().join(" | ")).call(_context2);
|
|
832
|
+
const headTitle = page("head > title").text().trim();
|
|
833
|
+
const bodyTitle = page("#title > *").map((_i, elem) => cheerio.load([])(elem).text()).get().join(" | ").trim();
|
|
1234
834
|
if (headTitle !== bodyTitle) {
|
|
1235
|
-
msgs.push(
|
|
835
|
+
msgs.push(
|
|
836
|
+
"The title in the head doesn't match the title in the body.",
|
|
837
|
+
` head: ${headTitle}`,
|
|
838
|
+
` body: ${bodyTitle}`
|
|
839
|
+
);
|
|
1236
840
|
valid = false;
|
|
1237
841
|
}
|
|
1238
842
|
if (msgs.length > 1) {
|
|
@@ -1240,284 +844,194 @@ function lintExample(path, page) {
|
|
|
1240
844
|
}
|
|
1241
845
|
return valid;
|
|
1242
846
|
}
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
}
|
|
1338
|
-
skipped.push(pagePath);
|
|
1339
|
-
return _context10.abrupt("return");
|
|
1340
|
-
case 10:
|
|
1341
|
-
// Lint if requested.
|
|
1342
|
-
if (argv.lint) {
|
|
1343
|
-
lintExample(pagePath, $page);
|
|
1344
|
-
}
|
|
1345
|
-
// Body titles.
|
|
1346
|
-
titles = _mapInstanceProperty(_context7 = $page("#title > *").get()).call(_context7, function (elem) {
|
|
1347
|
-
var _context8;
|
|
1348
|
-
return _trimInstanceProperty(_context8 = $page(elem).text()).call(_context8);
|
|
1349
|
-
}); // Head title fallback.
|
|
1350
|
-
if (titles.length < 2) {
|
|
1351
|
-
titles = _mapInstanceProperty(_context9 = $page("head > title").text().split("|")).call(_context9, function (title) {
|
|
1352
|
-
return _trimInstanceProperty(title).call(title);
|
|
1353
|
-
});
|
|
1354
|
-
}
|
|
1355
|
-
// File path fallback.
|
|
1356
|
-
if (titles.length < 2) {
|
|
1357
|
-
titles = pagePath.split("/");
|
|
1358
|
-
}
|
|
1359
|
-
// Just ignore it.
|
|
1360
|
-
if (!(titles.length < 2)) {
|
|
1361
|
-
_context10.next = 17;
|
|
1362
|
-
break;
|
|
1363
|
-
}
|
|
1364
|
-
console.error("Title resolution failed. Skipping.");
|
|
1365
|
-
return _context10.abrupt("return");
|
|
1366
|
-
case 17:
|
|
1367
|
-
// Put this example into the structure while creating any missing groups in the process.
|
|
1368
|
-
_reduceInstanceProperty(titles).call(titles, function (acc, title, i, arr) {
|
|
1369
|
-
while (acc[title] != null && acc[title].path != null) {
|
|
1370
|
-
console.error("The following group already exists: ", titles);
|
|
1371
|
-
title += "!";
|
|
1372
|
-
}
|
|
1373
|
-
if (i === arr.length - 1) {
|
|
1374
|
-
if (acc[title] != null) {
|
|
1375
|
-
console.error("The following example has the same name as an already existing group: ", titles);
|
|
1376
|
-
return null;
|
|
1377
|
-
} else {
|
|
1378
|
-
var example = {
|
|
1379
|
-
$: $page,
|
|
1380
|
-
delay: pageDelay,
|
|
1381
|
-
html: html,
|
|
1382
|
-
path: pagePath,
|
|
1383
|
-
paths: generatePaths(pathsConfig, pagePath),
|
|
1384
|
-
playground: generatePlaygroundData(baseURL, $page, pagePath),
|
|
1385
|
-
selector: pageSelector,
|
|
1386
|
-
timeout: pageTimeout,
|
|
1387
|
-
titles: titles
|
|
1388
|
-
};
|
|
1389
|
-
acc[title] = example;
|
|
1390
|
-
++stats.examples;
|
|
1391
|
-
}
|
|
1392
|
-
} else {
|
|
1393
|
-
return acc[title] = acc[title] || {};
|
|
1394
|
-
}
|
|
1395
|
-
}, examples);
|
|
1396
|
-
case 18:
|
|
1397
|
-
case "end":
|
|
1398
|
-
return _context10.stop();
|
|
1399
|
-
}
|
|
1400
|
-
}, _callee2);
|
|
1401
|
-
}));
|
|
1402
|
-
return function (_x2) {
|
|
1403
|
-
return _ref3.apply(this, arguments);
|
|
1404
|
-
};
|
|
1405
|
-
}());
|
|
1406
|
-
_context24.next = 24;
|
|
1407
|
-
return _context24.t0.all.call(_context24.t0, _context24.t3);
|
|
1408
|
-
case 24:
|
|
1409
|
-
if (skipped.length) {
|
|
1410
|
-
process.stdout.write("\n");
|
|
1411
|
-
console.info(_concatInstanceProperty(_context11 = ["The following files don't look like examples (there is nothing to take a screenshot of):"]).call(_context11, _toConsumableArray(_sortInstanceProperty(skipped).call(skipped))).join("\n "));
|
|
1412
|
-
}
|
|
1413
|
-
if (!(stats.examples === 0)) {
|
|
1414
|
-
_context24.next = 29;
|
|
1415
|
-
break;
|
|
1416
|
-
}
|
|
1417
|
-
console.info("No usable example files were found.");
|
|
1418
|
-
_context24.next = 69;
|
|
1419
|
-
break;
|
|
1420
|
-
case 29:
|
|
1421
|
-
if (!(argv.index || argv.playgrounds || argv.screenshots)) {
|
|
1422
|
-
_context24.next = 69;
|
|
1423
|
-
break;
|
|
1424
|
-
}
|
|
1425
|
-
process.stdout.write("\n");
|
|
1426
|
-
if (!(screenshotScriptPath != null)) {
|
|
1427
|
-
_context24.next = 40;
|
|
1428
|
-
break;
|
|
1429
|
-
}
|
|
1430
|
-
_context24.next = 34;
|
|
1431
|
-
return readFile(screenshotScriptPath, "utf-8");
|
|
1432
|
-
case 34:
|
|
1433
|
-
_context24.t5 = _context24.sent;
|
|
1434
|
-
if (_context24.t5) {
|
|
1435
|
-
_context24.next = 37;
|
|
1436
|
-
break;
|
|
1437
|
-
}
|
|
1438
|
-
_context24.t5 = "";
|
|
1439
|
-
case 37:
|
|
1440
|
-
_context24.t4 = _context24.t5;
|
|
1441
|
-
_context24.next = 41;
|
|
1442
|
-
break;
|
|
1443
|
-
case 40:
|
|
1444
|
-
_context24.t4 = "";
|
|
1445
|
-
case 41:
|
|
1446
|
-
screenshotScript = _context24.t4;
|
|
1447
|
-
builtData = new ContentBuilder({
|
|
1448
|
-
examples: examples,
|
|
1449
|
-
output: node_path.resolve(argv["output-directory"]),
|
|
1450
|
-
parallel: argv.parallel,
|
|
1451
|
-
renderer: argv.format === "md" ? mdRenderer : htmlRenderer,
|
|
1452
|
-
screenshotScript: screenshotScript,
|
|
1453
|
-
title: argv.title
|
|
1454
|
-
}).build({
|
|
1455
|
-
index: argv.index,
|
|
1456
|
-
playgrounds: argv.playgrounds,
|
|
1457
|
-
screenshots: argv.screenshots
|
|
1458
|
-
}); // Create and write the page.
|
|
1459
|
-
if (!argv.index) {
|
|
1460
|
-
_context24.next = 50;
|
|
1461
|
-
break;
|
|
1462
|
-
}
|
|
1463
|
-
_context24.t6 = reduceReports;
|
|
1464
|
-
_context24.next = 47;
|
|
1465
|
-
return builtData.index;
|
|
1466
|
-
case 47:
|
|
1467
|
-
_context24.t7 = _context24.sent;
|
|
1468
|
-
cummulativeReport = (0, _context24.t6)(_context24.t7);
|
|
1469
|
-
console.info(_concatInstanceProperty(_context12 = _concatInstanceProperty(_context13 = "Index with ".concat(stats.examples, " examples written (")).call(_context13, cummulativeReport.count, " files in ")).call(_context12, formatStartStopMs(cummulativeReport), ")."));
|
|
1470
|
-
case 50:
|
|
1471
|
-
if (!argv.index) {
|
|
1472
|
-
_context24.next = 57;
|
|
1473
|
-
break;
|
|
1474
|
-
}
|
|
1475
|
-
_context24.t8 = reduceReports;
|
|
1476
|
-
_context24.next = 54;
|
|
1477
|
-
return builtData.playgrounds;
|
|
1478
|
-
case 54:
|
|
1479
|
-
_context24.t9 = _context24.sent;
|
|
1480
|
-
_cummulativeReport = (0, _context24.t8)(_context24.t9);
|
|
1481
|
-
console.info(_concatInstanceProperty(_context14 = _concatInstanceProperty(_context15 = "Playground opener files for ".concat(stats.examples, " examples written (")).call(_context15, _cummulativeReport.count, " files in ")).call(_context14, formatStartStopMs(_cummulativeReport), ")."));
|
|
1482
|
-
case 57:
|
|
1483
|
-
if (!argv.screenshots) {
|
|
1484
|
-
_context24.next = 64;
|
|
1485
|
-
break;
|
|
847
|
+
(async () => {
|
|
848
|
+
let code = 0;
|
|
849
|
+
if (!argv.index && !argv.screenshots && !argv.lint) {
|
|
850
|
+
yargs.parse("--help");
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
await Promise.all(
|
|
854
|
+
[
|
|
855
|
+
argv["assets-local-directory"],
|
|
856
|
+
argv["examples-local-directory"],
|
|
857
|
+
argv["output-directory"],
|
|
858
|
+
argv["pages-local-directory"]
|
|
859
|
+
].map(async (path) => {
|
|
860
|
+
await mkdir(path, { recursive: true });
|
|
861
|
+
})
|
|
862
|
+
);
|
|
863
|
+
const baseURL = argv["base-url"];
|
|
864
|
+
if (!baseURL.endsWith("/")) {
|
|
865
|
+
throw new Error("Base URL (`base-url`) has to end with a slash (`/`).");
|
|
866
|
+
}
|
|
867
|
+
const pathsConfig = {
|
|
868
|
+
codepen: {
|
|
869
|
+
local: argv["pages-local-directory"],
|
|
870
|
+
web: fixAbsoluteInputURL(baseURL, argv["pages-web-directory"])
|
|
871
|
+
},
|
|
872
|
+
jsfiddle: {
|
|
873
|
+
local: argv["pages-local-directory"],
|
|
874
|
+
web: fixAbsoluteInputURL(baseURL, argv["pages-web-directory"])
|
|
875
|
+
},
|
|
876
|
+
page: {
|
|
877
|
+
local: argv["examples-local-directory"],
|
|
878
|
+
web: fixAbsoluteInputURL(baseURL, argv["examples-web-directory"])
|
|
879
|
+
},
|
|
880
|
+
screenshot: {
|
|
881
|
+
local: argv["assets-local-directory"],
|
|
882
|
+
web: fixAbsoluteInputURL(baseURL, argv["assets-web-directory"])
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
const examples = {};
|
|
886
|
+
const selector = "#" + argv["container-id"];
|
|
887
|
+
const stats = { examples: 0 };
|
|
888
|
+
const skipped = [];
|
|
889
|
+
await Promise.all(
|
|
890
|
+
(await (await import('globby')).globby(join(pathsConfig.page.local, "**/*.html"))).map(async (pagePath) => {
|
|
891
|
+
const html = await readFile(pagePath, "utf-8");
|
|
892
|
+
const $page = cheerio.load(html);
|
|
893
|
+
const pageDelay = getMeta(
|
|
894
|
+
$page,
|
|
895
|
+
"example-screenshot-delay",
|
|
896
|
+
6
|
|
897
|
+
);
|
|
898
|
+
const pageTimeout = getMeta(
|
|
899
|
+
$page,
|
|
900
|
+
"example-screenshot-timeout",
|
|
901
|
+
60
|
|
902
|
+
);
|
|
903
|
+
const pageSelector = getMeta(
|
|
904
|
+
$page,
|
|
905
|
+
"example-screenshot-selector",
|
|
906
|
+
selector
|
|
907
|
+
);
|
|
908
|
+
if ($page(pageSelector).length === 0) {
|
|
909
|
+
skipped.push(pagePath);
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
if (argv.lint) {
|
|
913
|
+
lintExample(pagePath, $page);
|
|
914
|
+
}
|
|
915
|
+
let titles = $page("#title > *").get().map((elem) => $page(elem).text().trim());
|
|
916
|
+
if (titles.length < 2) {
|
|
917
|
+
titles = $page("head > title").text().split("|").map((title) => title.trim());
|
|
918
|
+
}
|
|
919
|
+
if (titles.length < 2) {
|
|
920
|
+
titles = pagePath.split("/");
|
|
921
|
+
}
|
|
922
|
+
if (titles.length < 2) {
|
|
923
|
+
console.error("Title resolution failed. Skipping.");
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
const example = {
|
|
927
|
+
$: $page,
|
|
928
|
+
delay: pageDelay,
|
|
929
|
+
html,
|
|
930
|
+
path: pagePath,
|
|
931
|
+
paths: generatePaths(pathsConfig, pagePath),
|
|
932
|
+
playground: await generatePlaygroundData(baseURL, $page, pagePath),
|
|
933
|
+
selector: pageSelector,
|
|
934
|
+
timeout: pageTimeout,
|
|
935
|
+
titles
|
|
936
|
+
};
|
|
937
|
+
titles.reduce((acc, title, i, arr) => {
|
|
938
|
+
while (acc[title] != null && acc[title].path != null) {
|
|
939
|
+
console.error("The following group already exists: ", titles);
|
|
940
|
+
title += "!";
|
|
1486
941
|
}
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
case 64:
|
|
1495
|
-
_context24.next = 66;
|
|
1496
|
-
return builtData.checks;
|
|
1497
|
-
case 66:
|
|
1498
|
-
checks = _context24.sent;
|
|
1499
|
-
process.stdout.write("\n");
|
|
1500
|
-
if (checks.fail === 0) {
|
|
1501
|
-
console.info(_concatInstanceProperty(_context18 = "Verification: ".concat(checks.okay, " passed (")).call(_context18, Math.round(checks.percentage), " %) passed."));
|
|
1502
|
-
} else {
|
|
1503
|
-
if (checks.percentage >= argv.verify) {
|
|
1504
|
-
console.info(_concatInstanceProperty(_context19 = _concatInstanceProperty(_context20 = "Verification: ".concat(checks.okay, " passed (")).call(_context20, Math.round(checks.percentage), " %), ")).call(_context19, checks.fail, " failed.\n") + "This is within the threshold set by --verify.");
|
|
942
|
+
if (i === arr.length - 1) {
|
|
943
|
+
if (acc[title] != null) {
|
|
944
|
+
console.error(
|
|
945
|
+
"The following example has the same name as an already existing group: ",
|
|
946
|
+
titles
|
|
947
|
+
);
|
|
948
|
+
return null;
|
|
1505
949
|
} else {
|
|
1506
|
-
|
|
1507
|
-
|
|
950
|
+
acc[title] = example;
|
|
951
|
+
++stats.examples;
|
|
1508
952
|
}
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
});
|
|
953
|
+
} else {
|
|
954
|
+
return acc[title] = acc[title] || {};
|
|
1512
955
|
}
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
956
|
+
}, examples);
|
|
957
|
+
})
|
|
958
|
+
);
|
|
959
|
+
if (skipped.length) {
|
|
960
|
+
process.stdout.write("\n");
|
|
961
|
+
console.info(
|
|
962
|
+
[
|
|
963
|
+
"The following files don't look like examples (there is nothing to take a screenshot of):",
|
|
964
|
+
...skipped.sort()
|
|
965
|
+
].join("\n ")
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
if (stats.examples === 0) {
|
|
969
|
+
console.info("No usable example files were found.");
|
|
970
|
+
} else if (argv.index || argv.playgrounds || argv.screenshots) {
|
|
971
|
+
process.stdout.write("\n");
|
|
972
|
+
const screenshotScript = screenshotScriptPath != null ? await readFile(screenshotScriptPath, "utf-8") || "" : "";
|
|
973
|
+
const builtData = new ContentBuilder({
|
|
974
|
+
examples,
|
|
975
|
+
output: resolve(argv["output-directory"]),
|
|
976
|
+
parallel: argv.parallel,
|
|
977
|
+
renderer: argv.format === "md" ? mdRenderer : htmlRenderer,
|
|
978
|
+
screenshotScript,
|
|
979
|
+
title: argv.title
|
|
980
|
+
}).build({
|
|
981
|
+
index: argv.index,
|
|
982
|
+
playgrounds: argv.playgrounds,
|
|
983
|
+
screenshots: argv.screenshots
|
|
984
|
+
});
|
|
985
|
+
if (argv.index) {
|
|
986
|
+
const cummulativeReport = reduceReports(await builtData.index);
|
|
987
|
+
console.info(
|
|
988
|
+
`Index with ${stats.examples} examples written (${cummulativeReport.count} files in ${formatStartStopMs(cummulativeReport)}).`
|
|
989
|
+
);
|
|
990
|
+
}
|
|
991
|
+
if (argv.index) {
|
|
992
|
+
const cummulativeReport = reduceReports(await builtData.playgrounds);
|
|
993
|
+
console.info(
|
|
994
|
+
`Playground opener files for ${stats.examples} examples written (${cummulativeReport.count} files in ${formatStartStopMs(cummulativeReport)}).`
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
if (argv.screenshots) {
|
|
998
|
+
const cummulativeReport = reduceReports(await builtData.screenshots);
|
|
999
|
+
console.info(
|
|
1000
|
+
`Screenshot files for ${stats.examples} written (${cummulativeReport.count} files in ${formatStartStopMs(cummulativeReport)}).`
|
|
1001
|
+
);
|
|
1518
1002
|
}
|
|
1519
|
-
|
|
1520
|
-
|
|
1003
|
+
const checks = await builtData.checks;
|
|
1004
|
+
process.stdout.write("\n");
|
|
1005
|
+
if (checks.fail === 0) {
|
|
1006
|
+
console.info(
|
|
1007
|
+
`Verification: ${checks.okay} passed (${Math.round(
|
|
1008
|
+
checks.percentage
|
|
1009
|
+
)} %) passed.`
|
|
1010
|
+
);
|
|
1011
|
+
} else {
|
|
1012
|
+
if (checks.percentage >= argv.verify) {
|
|
1013
|
+
console.info(
|
|
1014
|
+
`Verification: ${checks.okay} passed (${Math.round(
|
|
1015
|
+
checks.percentage
|
|
1016
|
+
)} %), ${checks.fail} failed.
|
|
1017
|
+
This is within the threshold set by --verify.`
|
|
1018
|
+
);
|
|
1019
|
+
} else {
|
|
1020
|
+
console.error(
|
|
1021
|
+
`Verification: Only ${checks.okay} passed (${Math.round(
|
|
1022
|
+
checks.percentage
|
|
1023
|
+
)} %), ${checks.fail} failed.
|
|
1024
|
+
This is not within the threshold set by --verify. Exiting with an error.`
|
|
1025
|
+
);
|
|
1026
|
+
code = 3;
|
|
1027
|
+
}
|
|
1028
|
+
checks.failPaths.forEach((path) => {
|
|
1029
|
+
console.error(path);
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
process.exitCode = code;
|
|
1034
|
+
})().catch((error) => {
|
|
1521
1035
|
process.exitCode = 1;
|
|
1522
1036
|
console.error(error);
|
|
1523
1037
|
});
|