-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart.js
executable file
·175 lines (156 loc) · 5.41 KB
/
start.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#! /usr/bin/env node
const { program } = require('commander')
const Local = require('./methods-local')
const Remote = require('./methods-remote')
const Base = require('./remote-image-base')
program.version('1.0.0')
program
.command('init')
.description('init application config')
.action(async function () {
//await Local.init()
//await Base.init()
})
program
.command('start')
.description('start deploy your App to the server(s)')
.option('-c, --config [type]', 'Config File')
.action(async function () {
const config =
this.config !== undefined && this.config !== true
? this.config
: 'config.json'
const config_json = Remote.config(config)
const ssh = await Remote.connect(config_json)
await Base.check_package();
let isRemoteBase = await Base.existsRemoteImage(config_json, ssh);
if (isRemoteBase === false) {
const result_init = await Base.initHost(config_json, ssh)
if (result_init === false) {
ssh.dispose()
return false
}
const result_uptoserver = await Base.upToServer(config_json, ssh)
if (result_uptoserver === false) {
ssh.dispose()
return false
}
const buildImage = await Base.buildImage(config_json, ssh)
if (buildImage === false) {
ssh.dispose()
return false
}
}
const local_build = await Local.build();
if (!local_build) {
ssh.dispose();
console.log('BUILD ---------------------------------------- FAIL');
return false
}
const result_check = await Remote.checkHost(ssh)
if (!result_check) {
ssh.dispose()
return false
}
const result_init = await Remote.initHost(config_json, ssh)
if (result_init === false) {
ssh.dispose()
return false
}
const result_uptoserver = await Remote.upToServer(config_json, ssh)
if (result_uptoserver === false) {
ssh.dispose()
return false
}
const result_upzip = await Remote.upzip(config_json, ssh)
if (result_upzip === false) {
ssh.dispose()
return false
}
const result_runApp = await Remote.runAppNotBuild(config_json, ssh, isRemoteBase)
if (result_runApp === false) {
ssh.dispose()
return false
}
const result_clean_image = await Remote.clean(config_json, ssh)
if (result_clean_image === false) {
ssh.dispose()
return false
}
const result_removeFile = await Remote.deleteFiles(config_json, ssh)
if (result_removeFile === false) {
ssh.dispose()
return false
}
await Local.remove();
console.log('------- ... LOADING ... -------')
await Local.waiting(5000)
const result = await Remote.isSuccess(config_json, ssh)
if (result === true) {
console.log('------- DEPLOY STATUS SUCCESS -------')
} else {
console.log('------- DEPLOY STATUS FAIL -------')
}
ssh.dispose()
})
program
.command('restart')
.option('-c, --config [type]', 'Config File')
.description('init application config')
.action(async function () {
const config =
this.config !== undefined && this.config !== true
? this.config
: 'config.json'
const config_json = Remote.config(config)
const ssh = await Remote.connect(config_json)
await Remote.restart(config_json, ssh)
console.log('------- STOP SUCCESS -------')
ssh.dispose()
})
program
.command('stop')
.option('-c, --config [type]', 'Config File')
.description('init application config')
.action(async function () {
const config =
this.config !== undefined && this.config !== true
? this.config
: 'config.json'
const config_json = Remote.config(config)
const ssh = await Remote.connect(config_json)
await Remote.stop(config_json, ssh)
console.log('------- STOP SUCCESS -------')
ssh.dispose()
})
program
.command('clean')
.option('-c, --config [type]', 'Config File')
.description('init application config')
.action(async function () {
const config =
this.config !== undefined && this.config !== true
? this.config
: 'config.json'
const config_json = Remote.config(config)
const ssh = await Remote.connect(config_json)
await Remote.clean(config_json, ssh)
console.log('------- CLEAN SUCCESS -------')
ssh.dispose()
})
program
.command('delete')
.option('-c, --config [type]', 'Config File')
.description('init application config')
.action(async function () {
const config =
this.config !== undefined && this.config !== true
? this.config
: 'config.json'
const config_json = Remote.config(config)
const ssh = await Remote.connect(config_json)
await Remote.delete(config_json, ssh)
console.log('------- DELETE SUCCESS -------')
ssh.dispose()
})
program.parse(process.argv)