-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.js
109 lines (101 loc) · 2.81 KB
/
release.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const chalk = require('chalk')
const clear = require('clear')
const figlet = require('figlet')
const inquirer = require('inquirer')
const currentVersion = require('./package.json').version
const request = require('request');
const fs = require('fs');
const opn = require('opn')
var fileName = './package.json';
var package = require(fileName);
var shell = require('shelljs');
let askGithubCredentials = () => {
const questions = [{
name: 'username',
type: 'input',
message: 'Enter your GitHub username or e-mail address:',
validate: function (value) {
if (value.length) {
return true;
} else {
return 'Please enter your username or e-mail address.';
}
}
},
{
name: 'password',
type: 'password',
message: 'Enter your password:',
validate: function (value) {
if (value.length) {
return true;
} else {
return 'Please enter your password.';
}
}
},
{
name: 'version',
type: 'input',
message: `What version would you like to release? (current: ${currentVersion})`,
validate: function (value) {
if (value.length) {
return true;
} else {
return 'Please enter a version';
}
}
},
];
return inquirer.prompt(questions);
}
clear()
console.log(
chalk.green(
figlet.textSync('Myst', {
horizontalLayout: 'full'
})
)
)
const run = async () => {
const params = await askGithubCredentials()
console.log(params)
package.version = params.version;
fs.writeFile(fileName, JSON.stringify(package, null, 2), function (err) {
if (err) return console.log(err);
console.log(JSON.stringify(package));
console.log('writing to ' + fileName);
if (shell.exec('npm run build').code !== 0) {
shell.echo('Error: build failed');
shell.exit(1);
} else {
shell.echo('Success built');
if (shell.exec('firebase deploy').code !== 0) {
shell.echo('Error: deploy failed');
shell.exit(1);
} else {
shell.echo('Success deployed');
if (shell.exec('git add .').code !== 0) {
shell.echo('Error: Git add failed');
shell.exit(1);
} else {
shell.echo('Success added');
if (shell.exec(`git commit -m"version ${params.version}"`).code !== 0) {
shell.echo('Error: Git commit failed');
shell.exit(1);
} else {
shell.echo('Success commited');
if (shell.exec('git push').code !== 0) {
shell.echo('Error: Git push failed');
shell.exit(1);
} else {
shell.echo('Success pushed');
opn('https://github.com/StompRocket/Myst/releases/new')
}
}
}
}
}
});
}
run()