-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauto-deployment.js
48 lines (31 loc) · 935 Bytes
/
auto-deployment.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
// get previous env
const path = require('path')
const { writeFileSync } = require('fs');
const envJson = require('./src/env.json');
const { execSync } = require('child_process');
const commitMessage = process.argv[2];
if (!commitMessage){
throw "empty commit message"
}
const prevVersion = envJson.version + ''
let newVersion = ''
prevVersion.split('.').forEach((n, i) => {
if (i < 2) {
newVersion += n
newVersion += '.'
} else {
newVersion += (parseInt(n) + 1)
}
})
const newEnv = {
...envJson, prod: true, version: newVersion
}
writeFileSync(path.resolve(__dirname, './src/env.json'), JSON.stringify(newEnv));
// run git add
execSync('git add .')
// run commit
execSync(`git commit -m "${commitMessage}"`)
execSync(`git push origin master`)
// switch env back to false
newEnv.prod = false
writeFileSync(path.resolve(__dirname, './src/env.json'), JSON.stringify(newEnv));