-
-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathrelease-extension.ts
93 lines (83 loc) · 3.22 KB
/
release-extension.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import * as fs from 'node:fs'
import * as path from 'node:path'
import * as p from '@clack/prompts'
import color from 'picocolors'
import semver from 'semver'
import manifest from '../packages/chrome-extension/manifest.json'
import pkg from '../packages/chrome-extension/package.json'
import firefoxManifest from '../packages/firefox-extension/manifest.json'
import firefoxPkg from '../packages/firefox-extension/package.json'
const __dirname = path.dirname(new URL(import.meta.url).pathname)
const curVersion = pkg.version
function applyIcons(manifest: Record<any, any>, suffix = '') {
[16, 48, 128].forEach((size) => {
manifest.icons[size] = `icons/${size}${suffix}.png`
})
}
async function getNewVersion() {
const project = await p.group({
version: () =>
p.text({
message: `Please provide a version (current: ${curVersion}):`,
validate: (value) => {
if (!value) {
return 'Version is required.'
}
if (!semver.valid(value)) {
return `Invalid version: ${value}`
}
if (semver.lt(value, curVersion)) {
return `New version (${value}) cannot be lower than current version (${curVersion}).`
}
},
}),
confirm: ({ results }) => {
return p.confirm({
message: `Are you sure to release version ${results.version}?`,
})
},
}, {
onCancel: () => {
p.cancel('Release cancelled.')
process.exit(0)
},
})
return project.confirm ? project.version : ''
}
async function release() {
p.intro(`${color.bgCyan(color.black(' Start to release chrome and firefox extension...'))}`)
getNewVersion().then(async (newVersion) => {
if (newVersion) {
console.log(`\n${color.bgGreen(color.black(` Bump version ${newVersion}...`))}`)
const isBeta = newVersion.includes('beta')
pkg.version = newVersion
firefoxPkg.version = newVersion
if (isBeta) {
const [, baseVersion, betaVersion] = /(.*)-beta\.(\w+)/.exec(newVersion)!
manifest.version = `${baseVersion}.${betaVersion}`
manifest.version_name = `${baseVersion} beta ${betaVersion}`
applyIcons(manifest, '-beta')
firefoxManifest.version = `${baseVersion}.${betaVersion}`
firefoxManifest.version_name = `${baseVersion} beta ${betaVersion}`
applyIcons(firefoxManifest, '-beta')
}
else {
manifest.version = newVersion
manifest.version_name = newVersion
applyIcons(manifest)
firefoxManifest.version = newVersion
firefoxManifest.version_name = newVersion
applyIcons(firefoxManifest)
}
fs.writeFileSync(path.resolve(__dirname, '../packages/chrome-extension/package.json'), JSON.stringify(pkg, null, 2))
fs.writeFileSync(path.resolve(__dirname, '../packages/firefox-extension/package.json'), JSON.stringify(firefoxPkg, null, 2))
fs.writeFileSync(path.resolve(__dirname, '../packages/chrome-extension/manifest.json'), JSON.stringify(manifest, null, 2))
fs.writeFileSync(path.resolve(__dirname, '../packages/firefox-extension/manifest.json'), JSON.stringify(firefoxManifest, null, 2))
}
else {
p.cancel(color.red('Release cancelled.'))
process.exit(0)
}
})
}
release()