-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.js
50 lines (41 loc) · 1.41 KB
/
build.js
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
import 'dotenv/config'
import { build } from 'esbuild';
import { copyFile, mkdir, rm } from 'node:fs/promises';
const { API_KEY, SECRET_KEY } = process.env;
if (!API_KEY || !SECRET_KEY) {
console.error('ERROR: Please export your Last.fm API credentials:');
console.log(' export API_KEY=xxx');
console.log(' export SECRET_KEY=xxx\n');
process.exit(1);
}
await rm('./dist', { recursive: true, force: true });
await rm('./bandcamp-scrobbler.xpi', { force: true });
await rm('./bandcamp-scrobbler.zip', { force: true });
await build({
entryPoints: [
'src/background.js',
'src/popup.jsx',
],
bundle: true,
outdir: 'dist',
define: {
'process.env.API_KEY': JSON.stringify(process.env.API_KEY || ''),
'process.env.SECRET_KEY': JSON.stringify(process.env.SECRET_KEY || ''),
},
jsxFactory: 'h',
});
const { MODE, BROWSER } = process.env;
const manifest = MODE === 'dev' ? `manifest.${BROWSER}.dev.json`: `manifest.${BROWSER}.json`;
const resources = MODE === 'dev' ? 'resources.dev' : 'resources';
const files = [
['popup.html', 'popup.html'],
['popup.css', 'popup.css'],
[manifest, 'manifest.json'],
[`${resources}/icon16.png`, 'resources/icon16.png'],
[`${resources}/icon48.png`, 'resources/icon48.png'],
[`${resources}/icon128.png`, 'resources/icon128.png'],
];
await mkdir('./dist/resources');
for (const [src, dest] of files) {
await copyFile(`./static/${src}`, `./dist/${dest}`);
}