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