-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
55 lines (48 loc) · 2.07 KB
/
Copy pathbuild.js
File metadata and controls
55 lines (48 loc) · 2.07 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
#!/usr/bin/env node
/**
* GeoSpot build script
* ---------------------
* The extension logic (popup.js, background.js, popup.html, shared images,
* and _locales translations) is identical across Chrome and Firefox once
* written against the promise-based `browser.*` namespace (see the small
* shim at the top of popup.js / background.js). Only manifest.json genuinely
* differs per browser (service_worker vs. scripts array, CSP,
* browser_specific_settings) and is hand-maintained in chrome/manifest.json
* and firefox/manifest.json.
*
* Edit files under ./shared, then run:
* node build.js
* to copy them into ./chrome and ./firefox. Do not edit the copies in
* chrome/ or firefox/ directly - they will be overwritten.
*/
const fs = require('fs');
const path = require('path');
const ROOT = __dirname;
const SHARED = path.join(ROOT, 'shared');
const TARGETS = ['chrome', 'firefox'];
const SHARED_FILES = ['popup.js', 'background.js', 'popup.html'];
function copyFile(src, dest) {
fs.mkdirSync(path.dirname(dest), { recursive: true });
fs.copyFileSync(src, dest);
console.log(` ${path.relative(ROOT, src)} -> ${path.relative(ROOT, dest)}`);
}
for (const target of TARGETS) {
console.log(`Syncing shared/ -> ${target}/`);
for (const file of SHARED_FILES) {
copyFile(path.join(SHARED, file), path.join(ROOT, target, file));
}
const sharedImagesDir = path.join(SHARED, 'images');
const targetImagesDir = path.join(ROOT, target, 'images');
for (const imgFile of fs.readdirSync(sharedImagesDir)) {
copyFile(path.join(sharedImagesDir, imgFile), path.join(targetImagesDir, imgFile));
}
const sharedLocalesDir = path.join(SHARED, '_locales');
const targetLocalesDir = path.join(ROOT, target, '_locales');
for (const locale of fs.readdirSync(sharedLocalesDir)) {
copyFile(
path.join(sharedLocalesDir, locale, 'messages.json'),
path.join(targetLocalesDir, locale, 'messages.json')
);
}
}
console.log('\nDone. manifest.json in chrome/ and firefox/ are hand-maintained and were not touched.');