forked from zincplusplus/habit-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-release.mjs
57 lines (45 loc) · 1.91 KB
/
make-release.mjs
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
import {readFileSync, writeFileSync} from 'fs'
import fs from 'fs-extra'
import {exec} from 'child_process'
const targetVersion = process.argv[2]
const targetVersionPattern = /^[0-9]+\.[0-9]+\.[0-9]+$/
if (!targetVersionPattern.test(targetVersion)) {
console.log(
`${process.argv[2]} is not a valid version number. I was expecting something like 1.0.0`,
)
process.exit()
}
// read minAppVersion from manifest.json and bump version to target version
let manifest = JSON.parse(readFileSync('manifest.json', 'utf8'))
const {minAppVersion} = manifest
manifest.version = targetVersion
writeFileSync('manifest.json', JSON.stringify(manifest, null, '\t'))
console.log(`bumped manifest.json to version ${targetVersion}`)
// update versions.json with target version and minAppVersion from manifest.json
let versions = JSON.parse(readFileSync('versions.json', 'utf8'))
versions[targetVersion] = minAppVersion
writeFileSync('versions.json', JSON.stringify(versions, null, '\t'))
console.log(`bumped versions.json to version ${targetVersion}`)
async function makeRelease() {
// make a folder with the files
const destinationFolder = './release'
try {
await fs.remove(destinationFolder)
console.log(`Removed ${destinationFolder} folder`)
await fs.ensureDir(destinationFolder)
console.log(`Created ${destinationFolder} folder`)
await fs.copy(`./main.js`, `${destinationFolder}/main.js`)
console.log('main.js copied successfully')
await fs.copy(`./src/styles.css`, `${destinationFolder}/styles.css`)
console.log('styles.css copied successfully')
await fs.copy(`./manifest.json`, `${destinationFolder}/manifest.json`)
console.log('manifest.json copied successfully')
await fs.copy(`./versions.json`, `${destinationFolder}/versions.json`)
console.log('versions.json copied successfully')
// open the folder so I can drop it into github
exec('open ./release')
} catch (err) {
console.error('Error:', err)
}
}
makeRelease()