Skip to content

Commit 18697b0

Browse files
committed
Work on firefox build
1 parent f78682b commit 18697b0

File tree

4 files changed

+971
-23
lines changed

4 files changed

+971
-23
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@ node build.js
4646
## TODO List
4747

4848
### Custom API Additions
49-
50-
* [ ] Implement new custom APIs
51-
52-
* [ ] `GM_download`
53-
* [ ] `GM_confirm`
49+
* [ ] `GM_download`
50+
* [ ] `GM_addValueChangeListener`
51+
* [ ] `GM_getResourceURL `
5452
* [ ] Additional APIs as needed
5553

5654
### Editor
@@ -64,12 +62,13 @@ node build.js
6462
* [ ] Display execution world and run-at time in editor/dashboard
6563

6664
### UI
67-
* [ ] Add iframe preview with live refresh
65+
* [ ] Make it so you choose where the modifcation goes on pages with mutiple scripts running
66+
* [ ] Change highlight theme color
6867
* [ ] Fix editor optimizations
6968
* [ ] Can you make it so if you have mutiple scripts running at once on the same page the notifications will expand verticlly and not all overlap
7069

71-
### Communication & Helpers
72-
* [ ] Fix script loading other scripts against CORS
70+
### Helpers
71+
* [ ] Fix regrex
7372
---
7473

7574
## Acknowledgments

build.js

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,53 @@
11

22
import { build } from 'esbuild';
3-
import { rmSync, mkdirSync, cpSync } from 'fs';
3+
import { rmSync, mkdirSync, cpSync, readFileSync, writeFileSync, createWriteStream } from 'fs';
44
import { join } from 'path';
55
import process from 'process';
6+
import archiver from 'archiver';
67

7-
const outdir = 'build';
8+
const args = process.argv.slice(2);
9+
const browserFlag = args.find(arg => arg.startsWith('--browser='));
10+
const browser = browserFlag ? browserFlag.split('=')[1] : 'chrome';
11+
const isProduction = args.includes('--production');
12+
13+
const outdir = `build/${browser}`;
814

9-
// Clean the build directory
1015
rmSync(outdir, { recursive: true, force: true });
1116
mkdirSync(outdir, { recursive: true });
12-
13-
// Copy public files
1417
cpSync('src/assets', join(outdir, 'assets'), { recursive: true });
1518
cpSync('src/dashboard', join(outdir, 'dashboard'), { recursive: true });
16-
1719
cpSync('src/editor', join(outdir, 'editor'), { recursive: true });
1820
cpSync('src/offscreen', join(outdir, 'offscreen'), { recursive: true });
1921
cpSync('src/popup', join(outdir, 'popup'), { recursive: true });
2022
cpSync('src/GM', join(outdir, 'GM'), { recursive: true });
2123

22-
cpSync('src/manifest.json', join(outdir, 'manifest.json'));
23-
24-
// Copy feather-icons
25-
mkdirSync(join(outdir, 'vendor'));
26-
24+
let manifest = JSON.parse(readFileSync('src/manifest.json', 'utf8'));
2725

26+
if (browser === 'firefox') {
27+
manifest.applications = {
28+
gecko: {
29+
id: 'codetweak@example.com',
30+
},
31+
};
32+
manifest.permissions = manifest.permissions.filter(perm => perm !== 'offscreen');
33+
manifest.browser_specific_settings = {
34+
gecko: {
35+
data_collection_permissions: {
36+
unrestricted: true,
37+
// description: "This extension does not collect any personal data."
38+
},
39+
},
40+
};
41+
if (manifest.background && manifest.background.service_worker) {
42+
manifest.background.scripts = [manifest.background.service_worker];
43+
delete manifest.background.service_worker;
44+
delete manifest.background.type;
45+
}
46+
}
47+
writeFileSync(join(outdir, 'manifest.json'), JSON.stringify(manifest, null, 2));
2848

49+
mkdirSync(join(outdir, 'vendor'));
2950
cpSync('src/utils', join(outdir, 'utils'), { recursive: true });
30-
31-
// Build the extension
3251
build({
3352
entryPoints: [
3453
'src/background/background.js',
@@ -46,5 +65,28 @@ build({
4665
outdir: outdir,
4766
logLevel: 'info',
4867
platform: 'browser',
68+
define: {
69+
'process.env.BROWSER': JSON.stringify(browser),
70+
},
4971
external: [],
72+
}).then(() => {
73+
if (browser === 'firefox' && isProduction) {
74+
const archiveName = `codetweak-firefox.zip`;
75+
const output = createWriteStream(join('build', archiveName));
76+
const archive = archiver('zip', {
77+
zlib: { level: 9 }
78+
});
79+
80+
output.on('close', () => {
81+
console.log(`Successfully created ${archiveName}: ${archive.pointer()} total bytes`);
82+
});
83+
84+
archive.on('error', (err) => {
85+
throw err;
86+
});
87+
88+
archive.pipe(output);
89+
archive.directory(outdir, false);
90+
archive.finalize();
91+
}
5092
}).catch(() => process.exit(1));

0 commit comments

Comments
 (0)