-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
55 lines (46 loc) · 1.46 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
51
52
53
54
55
const fs = require("fs");
const path = require("path");
const platforms = {
chrome: {
source: "config/chrome",
dist: "dist/chrome/",
},
firefox: {
source: "config/firefox",
dist: "dist/firefox/",
},
};
function build(platform) {
const config = platforms[platform];
if (!config) {
console.error(`Invalid platform: ${platform}`);
process.exit(1);
}
// create dist folder if it doesn't exist
if (!fs.existsSync(config.dist)) {
fs.mkdirSync(config.dist, { recursive: true });
}
// copy manifest and platform-specific files
const platformFolder = path.resolve(config.source);
fs.cpSync(platformFolder, config.dist, {
recursive: true
});
// copy src folder
const srcFolder = path.resolve("src");
const targetSrcFolder = path.join(config.dist, "src");
fs.cpSync(srcFolder, targetSrcFolder, { recursive: true });
// copy assets/icons folder
const iconsFolder = path.resolve("assets/icons");
const targetIconsFolder = path.join(config.dist, "assets/icons");
fs.mkdirSync(path.dirname(targetIconsFolder), { recursive: true });
fs.cpSync(iconsFolder, targetIconsFolder, { recursive: true });
console.log(`Build for ${platform} completed in dist/`);
}
// run build based on command-line argument
const platform = process.argv[2];
if (!platform) {
console.error("Usage: node build.js <platform>");
console.error(`Available platforms: ${Object.keys(platforms).join(", ")}`);
process.exit(1);
}
build(platform);