forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy.js
More file actions
64 lines (58 loc) · 1.87 KB
/
Copy pathcopy.js
File metadata and controls
64 lines (58 loc) · 1.87 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
const fs = require('fs-extra');
const globby = require('globby');
const {getDestDir} = require('./paths');
const reload = require('./reload');
const {createTask} = require('./task');
const srcDir = 'src';
const cwdPaths = [
'background/index.html',
'config/**/*.config',
'icons/**/*.*',
'ui/assets/**/*.*',
'ui/popup/compatibility.js',
'manifest.json',
];
const paths = cwdPaths.map((path) => `${srcDir}/${path}`);
function getCwdPath(/** @type {string} */srcPath) {
return srcPath.substring(srcDir.length + 1);
}
async function patchFirefoxManifest({debug}) {
const manifest = await fs.readJson(`${srcDir}/manifest.json`);
const patch = await fs.readJson(`${srcDir}/manifest-firefox.json`);
const patched = {...manifest, ...patch};
const firefoxDir = getDestDir({debug, firefox: true});
await fs.writeJson(`${firefoxDir}/manifest.json`, patched, {spaces: 4});
}
async function copyFile(path, {debug, firefox}) {
const cwdPath = getCwdPath(path);
const destDir = getDestDir({debug, firefox});
if (firefox && cwdPath === 'manifest.json') {
await patchFirefoxManifest({debug});
} else {
const src = `${srcDir}/${cwdPath}`;
const dest = `${destDir}/${cwdPath}`;
await fs.copy(src, dest);
}
}
async function copy({debug}) {
const files = await globby(paths);
for (const file of files) {
await copyFile(file, {debug, firefox: false});
await copyFile(file, {debug, firefox: true});
}
}
module.exports = createTask(
'copy',
copy,
).addWatcher(
paths,
async (changedFiles) => {
for (const file of changedFiles) {
if (await fs.exists(file)) {
await copyFile(file, {debug: true, firefox: false});
await copyFile(file, {debug: true, firefox: true});
}
}
reload({type: reload.FULL});
},
);