generated from AminoffZ/bun-browser-extension-builder
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathupdate-version.ts
51 lines (43 loc) · 1.37 KB
/
update-version.ts
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
import { join } from 'path';
import { readFile, writeFile } from 'fs/promises';
import chalk from 'chalk';
async function updateManifestVersion() {
try {
const arg = process.argv[2];
const browser = arg && arg === 'firefox' ? 'firefox' : 'chrome';
const packageJsonPath = join(import.meta.dir, 'package.json');
const { version } = await import(packageJsonPath);
const manifestPath = join(import.meta.dir, 'public', 'manifest.json');
const manifestData = await readFile(manifestPath, 'utf-8');
const manifest = JSON.parse(manifestData);
manifest.version = version;
if (browser && browser === 'firefox') {
manifest.background = {
scripts: ['background.js'],
};
manifest.browser_specific_settings = {
gecko: {
id: 'github-repo-size@gmail.com',
strict_min_version: '42.0',
},
};
} else {
manifest.background = {
service_worker: 'background.js',
};
delete manifest.browser_specific_settings;
}
await writeFile(manifestPath, JSON.stringify(manifest, null, 2));
console.log(
chalk.green(
'Version updated successfully in manifest.json for ' +
browser +
' Browser!'
)
);
} catch (error) {
console.error(chalk.red('Error updating version: ' + error));
process.exit(1);
}
}
updateManifestVersion();