-
Notifications
You must be signed in to change notification settings - Fork 14
/
prebuild.js
51 lines (41 loc) · 1.52 KB
/
prebuild.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
require('dotenv').config();
const fs = require('fs');
const path = require('path');
function copyIcon(src, dst) {
if (!src) {
console.warn(`Icon path for ${dst} is not defined in your environment variables`);
return;
}
console.log(`Replacing icon ${dst} by ${src}`);
if (!fs.existsSync(src)) {
console.warn(`Icon file ${src} does not exist.`);
return;
}
const destPath = path.join(__dirname, 'assets', dst);
try {
fs.copyFileSync(src, destPath);
fs.chmodSync(destPath, 0o644);
} catch(e) {
console.warn(`Failed to copy logo ${e}`);
}
}
function updatePackageJson() {
const placeholders = {
EXTENSION_NAME: process.env.EXTENSION_NAME || "devchat",
PUBLISHER: process.env.PUBLISHER || "merico",
ASSISTANT_NAME_EN: process.env.ASSISTANT_NAME_EN || "DevChat",
ASSISTANT_NAME_ZH: process.env.ASSISTANT_NAME_ZH || "DevChat"
}
console.log(`Updating package.json, env: ${JSON.stringify(placeholders)}`);
let packageJson = fs.readFileSync('package.json', 'utf8');
// Replace placeholders
Object.entries(placeholders).forEach(([key, value]) => {
const regex = new RegExp(`\\$\\{${key}\\}`, 'g');
packageJson = packageJson.replace(regex, value);
});
fs.writeFileSync('package.json', packageJson);
}
copyIcon(process.env.EXTENSION_ICON, 'devchat.png');
copyIcon(process.env.SIDEBAR_ICON, 'devchat_icon.svg');
copyIcon(process.env.DIFF_APPLY_ICON, 'devchat_apply.svg');
updatePackageJson();