cloud-ide-cide 2.0.39 → 2.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/appManager.js +119 -0
- package/package.json +2 -1
package/appManager.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cide app — manage deployed apps remotely via the upload listener.
|
|
3
|
+
*
|
|
4
|
+
* Commands:
|
|
5
|
+
* cide app --status Check if app is running
|
|
6
|
+
* cide app --start Start the app
|
|
7
|
+
* cide app --stop Stop the app
|
|
8
|
+
* cide app --restart Restart (stop + start)
|
|
9
|
+
* cide app --status -p 1 -s 1 Non-interactive
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const axios = require('axios');
|
|
13
|
+
const {
|
|
14
|
+
discoverUploadableProjects,
|
|
15
|
+
printProjectList,
|
|
16
|
+
selectProject,
|
|
17
|
+
selectServer,
|
|
18
|
+
resolveEndpoint,
|
|
19
|
+
getToken,
|
|
20
|
+
getAuthHeaders,
|
|
21
|
+
} = require('./uploadProject');
|
|
22
|
+
|
|
23
|
+
async function appManager(opts = {}) {
|
|
24
|
+
const action = opts.restart ? 'restart'
|
|
25
|
+
: opts.stop ? 'stop'
|
|
26
|
+
: opts.start ? 'start'
|
|
27
|
+
: 'status';
|
|
28
|
+
|
|
29
|
+
const projects = discoverUploadableProjects();
|
|
30
|
+
if (projects.length === 0) {
|
|
31
|
+
console.log('\nNo projects found with upload config in cide.json.\n');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (projects.length > 1) printProjectList(projects);
|
|
36
|
+
const project = projects.length === 1 ? projects[0] : await selectProject(projects, opts);
|
|
37
|
+
if (!project) return;
|
|
38
|
+
|
|
39
|
+
const server = await selectServer(project, opts);
|
|
40
|
+
if (!server) return;
|
|
41
|
+
|
|
42
|
+
const token = getToken(server);
|
|
43
|
+
const headers = getAuthHeaders(token);
|
|
44
|
+
const appCode = server.app_code || project.name;
|
|
45
|
+
const label = server.name || server.server_url;
|
|
46
|
+
|
|
47
|
+
console.log(`\n ${action.toUpperCase()} → ${project.name} on ${label}\n`);
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
if (action === 'status') {
|
|
51
|
+
const url = resolveEndpoint(server.server_url, `app/status`) + `?appCode=${encodeURIComponent(appCode)}`;
|
|
52
|
+
const { data } = await axios.get(url, { headers, timeout: 15000 });
|
|
53
|
+
|
|
54
|
+
console.log(` App : ${data.appCode}`);
|
|
55
|
+
console.log(` Status : ${data.running ? `Running (PID: ${data.pid})` : 'Stopped'}`);
|
|
56
|
+
if (data.appDir) console.log(` Path : ${data.appDir}`);
|
|
57
|
+
if (data.logFile) console.log(` Log : ${data.logFile}`);
|
|
58
|
+
console.log('');
|
|
59
|
+
|
|
60
|
+
} else if (action === 'stop') {
|
|
61
|
+
const url = resolveEndpoint(server.server_url, 'app/stop');
|
|
62
|
+
const { data } = await axios.post(url, { appCode }, { headers, timeout: 15000 });
|
|
63
|
+
|
|
64
|
+
if (data.stopped) {
|
|
65
|
+
console.log(` Stopped (was PID: ${data.pid})`);
|
|
66
|
+
} else {
|
|
67
|
+
console.log(` ${data.reason || 'Not running'}`);
|
|
68
|
+
}
|
|
69
|
+
console.log('');
|
|
70
|
+
|
|
71
|
+
} else if (action === 'start') {
|
|
72
|
+
const url = resolveEndpoint(server.server_url, 'app/start');
|
|
73
|
+
const { data } = await axios.post(url, { appCode }, { headers, timeout: 30000 });
|
|
74
|
+
|
|
75
|
+
if (data.started) {
|
|
76
|
+
console.log(` Started (PID: ${data.pid})`);
|
|
77
|
+
if (data.logFile) console.log(` Log : ${data.logFile}`);
|
|
78
|
+
} else {
|
|
79
|
+
console.log(` Failed to start: ${data.reason || 'unknown'}`);
|
|
80
|
+
}
|
|
81
|
+
if (data.output) {
|
|
82
|
+
console.log('');
|
|
83
|
+
console.log(' ── App Console Output ──────────────────────');
|
|
84
|
+
console.log(data.output.trim().split('\n').map(l => ` ${l}`).join('\n'));
|
|
85
|
+
console.log(' ─────────────────────────────────────────────');
|
|
86
|
+
}
|
|
87
|
+
console.log('');
|
|
88
|
+
|
|
89
|
+
} else if (action === 'restart') {
|
|
90
|
+
// Stop
|
|
91
|
+
const stopUrl = resolveEndpoint(server.server_url, 'app/stop');
|
|
92
|
+
await axios.post(stopUrl, { appCode }, { headers, timeout: 15000 }).catch(() => {});
|
|
93
|
+
|
|
94
|
+
// Start
|
|
95
|
+
const startUrl = resolveEndpoint(server.server_url, 'app/start');
|
|
96
|
+
const { data } = await axios.post(startUrl, { appCode }, { headers, timeout: 30000 });
|
|
97
|
+
|
|
98
|
+
if (data.started) {
|
|
99
|
+
console.log(` Restarted (PID: ${data.pid})`);
|
|
100
|
+
if (data.logFile) console.log(` Log : ${data.logFile}`);
|
|
101
|
+
} else {
|
|
102
|
+
console.log(` Failed to start: ${data.reason || 'unknown'}`);
|
|
103
|
+
}
|
|
104
|
+
if (data.output) {
|
|
105
|
+
console.log('');
|
|
106
|
+
console.log(' ── App Console Output ──────────────────────');
|
|
107
|
+
console.log(data.output.trim().split('\n').map(l => ` ${l}`).join('\n'));
|
|
108
|
+
console.log(' ─────────────────────────────────────────────');
|
|
109
|
+
}
|
|
110
|
+
console.log('');
|
|
111
|
+
}
|
|
112
|
+
} catch (err) {
|
|
113
|
+
const msg = err.response?.data?.message || err.message || err;
|
|
114
|
+
console.error(`\n Failed: ${msg}\n`);
|
|
115
|
+
process.exitCode = 1;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
module.exports = appManager;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloud-ide-cide",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.41",
|
|
4
4
|
"description": "Cloud IDE CLI — create, build, publish, upload and deploy Cloud IDE projects.",
|
|
5
5
|
"main": "cli.js",
|
|
6
6
|
"bin": {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"resolveNgProjectName.js",
|
|
20
20
|
"uploadProject.js",
|
|
21
21
|
"serverInit.js",
|
|
22
|
+
"appManager.js",
|
|
22
23
|
"deployer/"
|
|
23
24
|
],
|
|
24
25
|
"dependencies": {
|