1 | "use strict";
|
2 | var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
3 | if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
4 | if (ar || !(i in from)) {
|
5 | if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
6 | ar[i] = from[i];
|
7 | }
|
8 | }
|
9 | return to.concat(ar || Array.prototype.slice.call(from));
|
10 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | exports.setEntries = exports.replaceEntries = exports.getTemplates = exports.extractParts = exports.isLocal = void 0;
|
13 | function isLocal(path) {
|
14 | if (path) {
|
15 | if (path.startsWith(':')) {
|
16 | return false;
|
17 | }
|
18 | else if (path.startsWith('http:')) {
|
19 | return false;
|
20 | }
|
21 | else if (path.startsWith('https:')) {
|
22 | return false;
|
23 | }
|
24 | else if (path.startsWith('data:')) {
|
25 | return false;
|
26 | }
|
27 | return true;
|
28 | }
|
29 | return false;
|
30 | }
|
31 | exports.isLocal = isLocal;
|
32 | function extractParts(content) {
|
33 | var sheets = content('link[href][rel=stylesheet]')
|
34 | .filter(function (_, e) { return isLocal(e.attribs.href); })
|
35 | .remove()
|
36 | .toArray();
|
37 | var scripts = content('script[src]')
|
38 | .filter(function (_, e) { return isLocal(e.attribs.src); })
|
39 | .remove()
|
40 | .toArray();
|
41 | var files = [];
|
42 | for (var _i = 0, sheets_1 = sheets; _i < sheets_1.length; _i++) {
|
43 | var sheet = sheets_1[_i];
|
44 | files.push(sheet.attribs.href);
|
45 | }
|
46 | for (var _a = 0, scripts_1 = scripts; _a < scripts_1.length; _a++) {
|
47 | var script = scripts_1[_a];
|
48 | files.push(script.attribs.src);
|
49 | }
|
50 | return files;
|
51 | }
|
52 | exports.extractParts = extractParts;
|
53 | function getTemplates(entry) {
|
54 | var templates = [];
|
55 | if (typeof entry === 'string') {
|
56 | if (entry.endsWith('.html')) {
|
57 | templates.push(entry);
|
58 | }
|
59 | }
|
60 | else if (Array.isArray(entry)) {
|
61 | templates.push.apply(templates, entry.filter(function (e) { return e.endsWith('.html'); }));
|
62 | }
|
63 | else if (typeof entry !== 'function') {
|
64 | Object.keys(entry).forEach(function (key) {
|
65 | var value = entry[key];
|
66 | templates.push.apply(templates, getTemplates(value));
|
67 | });
|
68 | }
|
69 | return templates;
|
70 | }
|
71 | exports.getTemplates = getTemplates;
|
72 | function replaceEntries(existingEntries, oldEntry, newEntries) {
|
73 | for (var i = 0; i < existingEntries.length; i++) {
|
74 | if (existingEntries[i] === oldEntry) {
|
75 | existingEntries.splice.apply(existingEntries, __spreadArray([i, 1], newEntries, false));
|
76 | break;
|
77 | }
|
78 | }
|
79 | }
|
80 | exports.replaceEntries = replaceEntries;
|
81 | function setEntries(config, template, entries) {
|
82 | if (typeof config.entry === 'string') {
|
83 | config.entry = entries;
|
84 | }
|
85 | else if (Array.isArray(config.entry)) {
|
86 | replaceEntries(config.entry, template, entries);
|
87 | }
|
88 | else if (typeof config.entry !== 'function') {
|
89 | Object.keys(config.entry).forEach(function (key) {
|
90 | var value = config.entry[key];
|
91 | if (value === template) {
|
92 | config.entry[key] = entries;
|
93 | }
|
94 | else if (Array.isArray(value)) {
|
95 | replaceEntries(value, template, entries);
|
96 | }
|
97 | });
|
98 | }
|
99 | }
|
100 | exports.setEntries = setEntries;
|
101 |
|
\ | No newline at end of file |