forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.js
More file actions
159 lines (146 loc) · 4.82 KB
/
Copy pathbuild.js
File metadata and controls
159 lines (146 loc) · 4.82 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// @ts-check
import bundleAPI from './bundle-api.js';
import bundleHTML from './bundle-html.js';
import bundleCSS from './bundle-css.js';
import bundleJS from './bundle-js.js';
import bundleLocales from './bundle-locales.js';
import bundleManifest from './bundle-manifest.js';
import bundleSignature from './bundle-signature.js';
import clean from './clean.js';
import copy from './copy.js';
import saveLog from './log.js';
import * as reload from './reload.js';
import codeStyle from './code-style.js';
import zip from './zip.js';
import {runTasks} from './task.js';
import {log, pathExistsSync} from './utils.js';
import process from 'node:process';
import {PLATFORM} from './platform.js';
const standardTask = [
clean,
bundleHTML,
bundleJS,
bundleCSS,
bundleLocales,
bundleManifest,
copy,
saveLog,
];
const buildTask = [
...standardTask,
codeStyle,
zip,
];
const signedBuildTask = [
...standardTask,
codeStyle,
bundleSignature,
zip,
];
async function build({platforms, debug, watch, log: logging, test, version}) {
log.ok('BUILD');
platforms = {
...platforms,
[PLATFORM.API]: false,
};
try {
await runTasks(debug ? standardTask : (version ? signedBuildTask : buildTask), {platforms, debug, watch, log: logging, test, version});
if (watch) {
standardTask.forEach((task) => task.watch(platforms));
reload.reload({type: reload.FULL});
log.ok('Watching...');
} else {
log.ok('MISSION PASSED! RESPECT +');
}
} catch (err) {
console.log(err);
log.error(`MISSION FAILED!`);
process.exit(13);
}
}
async function api(debug, watch) {
log.ok('API');
try {
const tasks = [bundleAPI];
if (!debug) {
tasks.push(codeStyle);
}
await runTasks(tasks, {platforms: {[PLATFORM.API]: true}, debug, watch, version: false, log: false, test: false});
if (watch) {
bundleAPI.watch();
log.ok('Watching...');
}
log.ok('MISSION PASSED! RESPECT +');
} catch (err) {
console.log(err);
log.error(`MISSION FAILED!`);
process.exit(13);
}
}
async function run({release, debug, platforms, watch, log, test, version}) {
const regular = Object.keys(platforms).some((platform) => platform !== PLATFORM.API && platforms[platform]);
if (release && regular) {
await build({platforms, version, debug: false, watch: false, log: null, test: false});
}
if (debug && regular) {
await build({platforms, version, debug, watch, log, test});
}
if (platforms[PLATFORM.API]) {
await api(debug, watch);
}
}
function getParams(args) {
const argMap = {
'--api': PLATFORM.API,
'--chrome': PLATFORM.CHROMIUM_MV2,
'--chrome-mv2': PLATFORM.CHROMIUM_MV2,
'--chrome-mv3': PLATFORM.CHROMIUM_MV3,
'--firefox': PLATFORM.FIREFOX_MV2,
'--firefox-mv2': PLATFORM.FIREFOX_MV2,
'--firefox-mv3': PLATFORM.FIREFOX_MV3,
'--thunderbird': PLATFORM.THUNDERBIRD,
};
const platforms = {
[PLATFORM.CHROMIUM_MV2]: false,
[PLATFORM.CHROMIUM_MV2_PLUS]: false,
[PLATFORM.CHROMIUM_MV3]: false,
[PLATFORM.FIREFOX_MV2]: false,
[PLATFORM.THUNDERBIRD]: false,
};
let allPlatforms = true;
for (const arg of args) {
if (argMap[arg]) {
platforms[argMap[arg]] = true;
allPlatforms = false;
}
}
if ((args.includes('--chrome') || args.includes('--chrome-mv2')) && args.includes('--plus')) {
platforms[PLATFORM.CHROMIUM_MV2] = false;
platforms[PLATFORM.CHROMIUM_MV2_PLUS] = true;
}
if (allPlatforms) {
Object.keys(platforms).forEach((platform) => platforms[platform] = true);
}
// TODO(Anton): remove me
if (platforms[PLATFORM.FIREFOX_MV3]) {
platforms[PLATFORM.FIREFOX_MV3] = false;
console.log('Firefox MV3 build is not supported yet');
}
if (!pathExistsSync('./src/plus/')) {
platforms[PLATFORM.CHROMIUM_MV2_PLUS] = false;
}
const versionArg = args.find((a) => a.startsWith('--version='));
const version = versionArg ? versionArg.substring('--version='.length) : null;
const release = args.includes('--release');
const debug = args.includes('--debug');
const watch = args.includes('--watch');
const logInfo = watch && args.includes('--log-info');
const logWarn = watch && args.includes('--log-warn');
const logAssert = watch && args.includes('--log-assert');
const log = logWarn ? 'warn' : (logInfo ? 'info' : (logAssert ? 'assert' : null));
const test = args.includes('--test');
return {release, debug, platforms, watch, log, test, version};
}
const args = process.argv.slice(2);
const params = getParams(args);
run(params);