-
Notifications
You must be signed in to change notification settings - Fork 4
/
update-manifest-version.js
45 lines (34 loc) · 1.29 KB
/
update-manifest-version.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
import { readFileSync, writeFileSync } from 'fs';
const manPath = './manifest.json';
const pkgPath = './package.json';
const htmlPath = './src/index.html';
// Read and parse files
const pkgRaw = readFileSync(pkgPath, 'utf8');
const pkgData = JSON.parse(pkgRaw);
const manRaw = readFileSync(manPath, 'utf8');
const manData = JSON.parse(manRaw);
const htmlRaw = readFileSync(htmlPath, 'utf8');
// Defaults
pkgData.name = 'structured-start-tab';
pkgData.description = 'Structured Start Tab';
let pageTitle = 'Structured Start Tab';
const [version, type] = pkgData.version.split('-');
manData.version = version;
manData.version_name = version;
manData.name = pkgData.description;
// Add beta definitions
if (type === 'beta') { // beta version should end with -beta
// package details
pkgData.name += '-beta';
pkgData.description += ' (beta)';
// manifest details
manData.version_name += '-beta';
manData.version = `${manData.version}.1`;
manData.name += manData.name.endsWith(' (Beta)') ? '' : ' (Beta)';
pageTitle += ' (beta)';
}
// update title in the html
const htmlData = htmlRaw.replace(/<title>.*<\/title>/, `<title>${pageTitle}</title>`);
writeFileSync(manPath, JSON.stringify(manData, null, 2));
writeFileSync(pkgPath, JSON.stringify(pkgData, null, 2));
writeFileSync(htmlPath, htmlData);