-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathbundle-html.js
More file actions
122 lines (115 loc) · 4.01 KB
/
Copy pathbundle-html.js
File metadata and controls
122 lines (115 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// @ts-check
import {getDestDir} from './paths.js';
import {PLATFORM} from './platform.js';
import * as reload from './reload.js';
import {createTask} from './task.js';
import {writeFile} from './utils.js';
/** @typedef {import('./types.d.ts').HTMLEntry} HTMLEntry */
function html(platform, title, hasLoader, hasStyleSheet, compatibility) {
return [
'<!DOCTYPE html>',
'<html>',
' <head>',
' <meta charset="utf-8" />',
` <title>${title}</title>`,
hasStyleSheet ? [
' <meta name="theme-color" content="#0B2228" />',
' <meta name="viewport" content="width=device-width, initial-scale=1" />',
' <link rel="stylesheet" type="text/css" href="style.css" />',
' <link',
' rel="shortcut icon"',
' href="../assets/images/darkreader-icon-256x256.png"',
' />',
] : null,
' <script src="index.js" defer></script>',
(compatibility && platform === PLATFORM.CHROMIUM_MV2) ? ' <script src="compatibility.js" defer></script>' : null,
' </head>',
'',
hasLoader ? [
' <body>',
' <div class="loader">',
' <label class="loader__message">Loading, please wait</label>',
' </div>',
' </body>',
] : [
' <body></body>',
],
'</html>',
'',
].filter((s) => s !== null).flat().join('\r\n');
}
/** @type {HTMLEntry[]} */
const htmlEntries = [
{
title: 'Dark Reader background',
path: 'background/index.html',
hasLoader: false,
hasStyleSheet: false,
hasCompatibilityCheck: false,
reloadType: reload.FULL,
platforms: [PLATFORM.CHROMIUM_MV2, PLATFORM.CHROMIUM_MV2_PLUS, PLATFORM.FIREFOX_MV2, PLATFORM.THUNDERBIRD],
},
{
title: 'Dark Reader settings',
path: 'ui/popup/index.html',
hasLoader: true,
hasStyleSheet: true,
hasCompatibilityCheck: true,
reloadType: reload.UI,
},
{
title: 'Dark Reader settings',
path: 'ui/options/index.html',
hasLoader: false,
hasStyleSheet: true,
hasCompatibilityCheck: false,
reloadType: reload.UI,
},
{
title: 'Dark Reader developer tools',
path: 'ui/devtools/index.html',
hasLoader: false,
hasStyleSheet: true,
hasCompatibilityCheck: false,
reloadType: reload.UI,
},
{
title: 'Dark Reader CSS editor',
path: 'ui/stylesheet-editor/index.html',
hasLoader: false,
hasStyleSheet: true,
hasCompatibilityCheck: false,
reloadType: reload.UI,
},
];
async function writeEntry({path, title, hasLoader, hasStyleSheet, hasCompatibilityCheck}, {debug, platform}) {
const destDir = getDestDir({debug, platform});
const d = `${destDir}/${path}`;
await writeFile(d, html(platform, title, hasLoader, hasStyleSheet, hasCompatibilityCheck));
}
/**
* @param {HTMLEntry[]} htmlEntries
* @returns {ReturnType<typeof createTask>}
*/
export function createBundleHTMLTask(htmlEntries) {
const bundleHTML = async ({platforms, debug}) => {
const promises = [];
const enabledPlatforms = Object.values(PLATFORM).filter((platform) => platform !== PLATFORM.API && platforms[platform]);
for (const entry of htmlEntries) {
if (entry.platforms && !entry.platforms.some((platform) => platforms[platform])) {
continue;
}
for (const platform of enabledPlatforms) {
if (entry.platforms === undefined || entry.platforms.includes(platform)) {
promises.push(writeEntry(entry, {debug, platform}));
}
}
}
await Promise.all(promises);
};
return createTask(
'bundle-html',
bundleHTML,
);
}
export default createBundleHTMLTask(htmlEntries);