@chabokan.net/cli 0.8.5 → 0.8.7
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/README.md +33 -13
- package/lib/base.d.ts +1 -1
- package/lib/base.js +25 -26
- package/lib/commands/account/list.d.ts +2 -2
- package/lib/commands/account/list.js +9 -10
- package/lib/commands/account/remove.d.ts +2 -2
- package/lib/commands/account/remove.js +22 -23
- package/lib/commands/account/use.d.ts +3 -3
- package/lib/commands/account/use.js +25 -25
- package/lib/commands/deploy.d.ts +4 -4
- package/lib/commands/deploy.js +77 -67
- package/lib/commands/login.d.ts +5 -5
- package/lib/commands/login.js +24 -22
- package/lib/commands/service/list.d.ts +2 -2
- package/lib/commands/service/list.js +9 -10
- package/lib/commands/service/logs.d.ts +3 -3
- package/lib/commands/service/logs.js +17 -17
- package/lib/commands/service/resize.d.ts +6 -6
- package/lib/commands/service/resize.js +29 -26
- package/lib/commands/service/restart.d.ts +3 -3
- package/lib/commands/service/restart.js +27 -25
- package/lib/commands/service/start.d.ts +3 -3
- package/lib/commands/service/start.js +19 -19
- package/lib/commands/service/stop.d.ts +3 -3
- package/lib/commands/service/stop.js +19 -19
- package/lib/constants.js +5 -9
- package/lib/helper.js +35 -47
- package/lib/index.js +1 -5
- package/oclif.manifest.json +276 -154
- package/package.json +39 -38
package/lib/commands/deploy.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const os = tslib_1.__importStar(require("os"));
|
|
15
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
16
|
-
const tar_1 = tslib_1.__importDefault(require("tar"));
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import Command from "../base.js";
|
|
5
|
+
import { addIgnorePatterns, isEmptyObject } from "../helper.js";
|
|
6
|
+
import ProgressBar from "progress";
|
|
7
|
+
import FormData from "form-data";
|
|
8
|
+
import ignore from "ignore";
|
|
9
|
+
import { dirname } from "path";
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
import * as os from "os";
|
|
12
|
+
import fs from "fs-extra";
|
|
13
|
+
import * as tar from 'tar';
|
|
17
14
|
const MAX_SOURCE_SIZE = 100 * 1024 * 1024; // 100 MB
|
|
18
|
-
class Deploy extends
|
|
15
|
+
class Deploy extends Command {
|
|
19
16
|
async run() {
|
|
20
17
|
const { args, flags } = await this.parse(Deploy);
|
|
21
18
|
const cli = this;
|
|
@@ -25,26 +22,31 @@ class Deploy extends base_1.default {
|
|
|
25
22
|
let project_path = flags.path ? flags.path : process.cwd();
|
|
26
23
|
let chabok_file = { service: "" };
|
|
27
24
|
try {
|
|
28
|
-
chabok_file =
|
|
25
|
+
chabok_file =
|
|
26
|
+
JSON.parse(fs
|
|
27
|
+
.readFileSync(path.join(project_path, "chabok.json"))
|
|
28
|
+
.toString("utf-8")) || {};
|
|
29
29
|
cli.log("Reading Config from chabok.json ...");
|
|
30
30
|
}
|
|
31
|
-
catch
|
|
32
|
-
}
|
|
31
|
+
catch { }
|
|
33
32
|
if (chabok_file.service) {
|
|
34
33
|
selected_service = chabok_file.service;
|
|
35
34
|
}
|
|
36
|
-
if (
|
|
37
|
-
cli.log(`${
|
|
35
|
+
if (isEmptyObject(config_json.users)) {
|
|
36
|
+
cli.log(`${chalk.red("[Error]")} first you should login!`);
|
|
38
37
|
return;
|
|
39
38
|
}
|
|
40
39
|
if (!selected_service) {
|
|
41
|
-
let all_services = await this.get_services({
|
|
40
|
+
let all_services = await this.get_services({
|
|
41
|
+
has_deploy: "true",
|
|
42
|
+
status: "on",
|
|
43
|
+
});
|
|
42
44
|
if (all_services.length > 0) {
|
|
43
|
-
let { service } = await
|
|
44
|
-
type:
|
|
45
|
-
message:
|
|
46
|
-
name:
|
|
47
|
-
choices: all_services
|
|
45
|
+
let { service } = await inquirer.prompt({
|
|
46
|
+
type: "list",
|
|
47
|
+
message: "Please select a service:",
|
|
48
|
+
name: "service",
|
|
49
|
+
choices: all_services,
|
|
48
50
|
});
|
|
49
51
|
selected_service = service;
|
|
50
52
|
}
|
|
@@ -56,36 +58,36 @@ class Deploy extends base_1.default {
|
|
|
56
58
|
let archive_path = await this.prepare_archive(project_path);
|
|
57
59
|
let upload_response = await this.upload(archive_path, selected_service, cli, chabok_file);
|
|
58
60
|
if (upload_response.success) {
|
|
59
|
-
cli.log(
|
|
61
|
+
cli.log(chalk.green(upload_response.message));
|
|
60
62
|
}
|
|
61
63
|
else {
|
|
62
|
-
cli.log(
|
|
64
|
+
cli.log(chalk.red("[Error] " + upload_response.message));
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
async prepare_archive(project_path) {
|
|
66
68
|
const defaultIgnores = [
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
69
|
+
".npm",
|
|
70
|
+
".git",
|
|
71
|
+
".idea",
|
|
72
|
+
".DS_Store",
|
|
73
|
+
".vscode",
|
|
74
|
+
"__pycache__",
|
|
75
|
+
".next",
|
|
76
|
+
".nuxt",
|
|
77
|
+
"*.*~",
|
|
78
|
+
"node_modules",
|
|
79
|
+
"bower_components",
|
|
80
|
+
"venv",
|
|
81
|
+
"/vendor",
|
|
82
|
+
"*.log",
|
|
81
83
|
];
|
|
82
84
|
const ignoreCache = {};
|
|
83
|
-
const ignoreInstance =
|
|
85
|
+
const ignoreInstance = ignore.default({ ignorecase: false });
|
|
84
86
|
ignoreInstance.add(defaultIgnores);
|
|
85
87
|
const ignoreFN = (f) => {
|
|
86
|
-
const dir =
|
|
88
|
+
const dir = dirname(f);
|
|
87
89
|
if (!ignoreCache[dir]) {
|
|
88
|
-
|
|
90
|
+
addIgnorePatterns(ignoreInstance, project_path, dir);
|
|
89
91
|
ignoreCache[dir] = true;
|
|
90
92
|
}
|
|
91
93
|
if (!ignoreInstance.ignores(f)) {
|
|
@@ -94,11 +96,11 @@ class Deploy extends base_1.default {
|
|
|
94
96
|
console.log(`ignoring ${f}`);
|
|
95
97
|
return false;
|
|
96
98
|
};
|
|
97
|
-
const tmpDir = path.join(os.tmpdir(),
|
|
99
|
+
const tmpDir = path.join(os.tmpdir(), "/chabok-cli");
|
|
98
100
|
const archivePath = path.join(tmpDir, `${Date.now()}.tar.gz`);
|
|
99
|
-
|
|
100
|
-
const fileList =
|
|
101
|
-
|
|
101
|
+
fs.ensureDirSync(tmpDir);
|
|
102
|
+
const fileList = fs.readdirSync(project_path).filter(ignoreFN);
|
|
103
|
+
tar.c({
|
|
102
104
|
gzip: {
|
|
103
105
|
level: 9,
|
|
104
106
|
},
|
|
@@ -112,29 +114,31 @@ class Deploy extends base_1.default {
|
|
|
112
114
|
async upload(archive_path, selected_service, cli, chabok_file) {
|
|
113
115
|
let upload_response = {
|
|
114
116
|
success: false,
|
|
115
|
-
message: "some problem"
|
|
117
|
+
message: "some problem",
|
|
116
118
|
};
|
|
117
|
-
const body = new
|
|
119
|
+
const body = new FormData();
|
|
118
120
|
// @ts-ignore
|
|
119
|
-
body.append(
|
|
120
|
-
body.append(
|
|
121
|
-
const { size: sourceSize } =
|
|
121
|
+
body.append("file", fs.createReadStream(archive_path));
|
|
122
|
+
body.append("options", JSON.stringify(chabok_file));
|
|
123
|
+
const { size: sourceSize } = fs.statSync(archive_path);
|
|
122
124
|
if (sourceSize > MAX_SOURCE_SIZE) {
|
|
123
125
|
upload_response.message = "Source is too large. (max: 100MB)";
|
|
124
126
|
return upload_response;
|
|
125
127
|
}
|
|
126
|
-
const bar = new
|
|
128
|
+
const bar = new ProgressBar("Uploading [:bar] :percent :etas", {
|
|
127
129
|
total: sourceSize,
|
|
128
130
|
width: 20,
|
|
129
|
-
complete:
|
|
130
|
-
incomplete:
|
|
131
|
+
complete: "=",
|
|
132
|
+
incomplete: "",
|
|
131
133
|
clear: true,
|
|
132
134
|
});
|
|
133
135
|
try {
|
|
134
|
-
const response = await this.got
|
|
135
|
-
.
|
|
136
|
+
const response = await this.got
|
|
137
|
+
.post(`services/${selected_service}/deploy/`, { body })
|
|
138
|
+
.on("uploadProgress", (progress) => {
|
|
136
139
|
bar.tick(progress.transferred - bar.curr);
|
|
137
|
-
})
|
|
140
|
+
})
|
|
141
|
+
.json();
|
|
138
142
|
if (response.success) {
|
|
139
143
|
upload_response.success = true;
|
|
140
144
|
upload_response.message = "Deployment finished successfully.";
|
|
@@ -154,11 +158,17 @@ class Deploy extends base_1.default {
|
|
|
154
158
|
}
|
|
155
159
|
finally {
|
|
156
160
|
// cleanup
|
|
157
|
-
|
|
158
|
-
});
|
|
161
|
+
fs.unlink(archive_path).catch(() => { });
|
|
159
162
|
}
|
|
160
163
|
}
|
|
161
164
|
}
|
|
162
|
-
|
|
163
|
-
Deploy.
|
|
164
|
-
|
|
165
|
+
Deploy.description = "this command help you build and deploy your service to chabokan in easy way.";
|
|
166
|
+
Deploy.flags = {
|
|
167
|
+
...Command.flags,
|
|
168
|
+
path: Flags.string({
|
|
169
|
+
char: "p",
|
|
170
|
+
description: "service path in your computer",
|
|
171
|
+
}),
|
|
172
|
+
service: Flags.string({ char: "s", description: "service name" }),
|
|
173
|
+
};
|
|
174
|
+
export default Deploy;
|
package/lib/commands/login.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import Command from "../base";
|
|
1
|
+
import Command from "../base.js";
|
|
2
2
|
export default class Login extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static flags: {
|
|
5
|
-
username: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
6
|
-
password: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
7
|
-
token: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
8
|
-
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
5
|
+
username: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
6
|
+
password: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
+
token: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
+
help: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<void>;
|
|
9
9
|
};
|
|
10
10
|
run(): Promise<void>;
|
|
11
11
|
}
|
package/lib/commands/login.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const helper_1 = require("../helper");
|
|
9
|
-
const base_1 = tslib_1.__importDefault(require("../base"));
|
|
10
|
-
class Login extends base_1.default {
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import { isObject } from "../helper.js";
|
|
6
|
+
import Command from "../base.js";
|
|
7
|
+
class Login extends Command {
|
|
11
8
|
async run() {
|
|
12
9
|
const { args, flags } = await this.parse(Login);
|
|
13
10
|
const cli = this;
|
|
@@ -16,7 +13,7 @@ class Login extends base_1.default {
|
|
|
16
13
|
const body = { username: flags.username, password: flags.password };
|
|
17
14
|
if (!flags.token) {
|
|
18
15
|
if (!flags.username) {
|
|
19
|
-
let { username } = await
|
|
16
|
+
let { username } = await inquirer.prompt({
|
|
20
17
|
type: 'input',
|
|
21
18
|
message: 'Enter your username:',
|
|
22
19
|
name: 'username',
|
|
@@ -30,7 +27,7 @@ class Login extends base_1.default {
|
|
|
30
27
|
body.username = username;
|
|
31
28
|
}
|
|
32
29
|
if (!flags.password) {
|
|
33
|
-
let { password } = await
|
|
30
|
+
let { password } = await inquirer.prompt({
|
|
34
31
|
type: 'password',
|
|
35
32
|
name: 'password',
|
|
36
33
|
message: 'Enter your password:',
|
|
@@ -43,9 +40,9 @@ class Login extends base_1.default {
|
|
|
43
40
|
});
|
|
44
41
|
body.password = password;
|
|
45
42
|
}
|
|
46
|
-
const { data } = await
|
|
43
|
+
const { data } = await axios.post("accounts/login/", body, this.axiosConfig);
|
|
47
44
|
if (data.success) {
|
|
48
|
-
if (!
|
|
45
|
+
if (!isObject(config_json.users)) {
|
|
49
46
|
config_json.users = {};
|
|
50
47
|
}
|
|
51
48
|
// @ts-ignore
|
|
@@ -54,17 +51,17 @@ class Login extends base_1.default {
|
|
|
54
51
|
};
|
|
55
52
|
config_json["default_user"] = body.username;
|
|
56
53
|
this.write_config(config_json);
|
|
57
|
-
cli.log(`${
|
|
54
|
+
cli.log(`${chalk.green('[Success]')} you are logged in successfully.`);
|
|
58
55
|
}
|
|
59
56
|
else {
|
|
60
|
-
cli.log(`${
|
|
57
|
+
cli.log(`${chalk.red('[Error]')} your username or password is wrong!`);
|
|
61
58
|
}
|
|
62
59
|
}
|
|
63
60
|
else {
|
|
64
61
|
try {
|
|
65
62
|
this.axiosConfig.headers.Authorization = `Token ${flags.token}`;
|
|
66
|
-
const { data } = await
|
|
67
|
-
if (!
|
|
63
|
+
const { data } = await axios.get("accounts/info/", this.axiosConfig);
|
|
64
|
+
if (!isObject(config_json.users)) {
|
|
68
65
|
config_json.users = {};
|
|
69
66
|
}
|
|
70
67
|
// @ts-ignore
|
|
@@ -73,18 +70,23 @@ class Login extends base_1.default {
|
|
|
73
70
|
};
|
|
74
71
|
config_json["default_user"] = data.user.email;
|
|
75
72
|
await this.write_config(config_json);
|
|
76
|
-
cli.log(`${
|
|
73
|
+
cli.log(`${chalk.green('[Success]')} you are logged in successfully.`);
|
|
77
74
|
}
|
|
78
75
|
catch (e) {
|
|
79
76
|
if (process.env.CHABOK_DEBUG == "true") {
|
|
80
77
|
// @ts-ignore
|
|
81
78
|
cli.log(e);
|
|
82
79
|
}
|
|
83
|
-
cli.log(`${
|
|
80
|
+
cli.log(`${chalk.red('[Error]')} your token is wrong!`);
|
|
84
81
|
}
|
|
85
82
|
}
|
|
86
83
|
}
|
|
87
84
|
}
|
|
88
|
-
exports.default = Login;
|
|
89
85
|
Login.description = 'login to hub.chabokan.net account';
|
|
90
|
-
Login.flags =
|
|
86
|
+
Login.flags = {
|
|
87
|
+
...Command.flags,
|
|
88
|
+
username: Flags.string({ char: 'u', description: 'your username' }),
|
|
89
|
+
password: Flags.string({ char: 'p', description: 'your password' }),
|
|
90
|
+
token: Flags.string({ char: 't', description: 'login with api token' }),
|
|
91
|
+
};
|
|
92
|
+
export default Login;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import Command from "../../base";
|
|
1
|
+
import Command from "../../base.js";
|
|
2
2
|
export default class ServiceList extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static flags: {
|
|
5
|
-
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
5
|
+
help: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<void>;
|
|
6
6
|
};
|
|
7
7
|
run(): Promise<void>;
|
|
8
8
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const base_1 = tslib_1.__importDefault(require("../../base"));
|
|
5
|
-
const core_1 = require("@oclif/core");
|
|
6
|
-
class ServiceList extends base_1.default {
|
|
1
|
+
import Command from "../../base.js";
|
|
2
|
+
import { ux } from "@oclif/core";
|
|
3
|
+
class ServiceList extends Command {
|
|
7
4
|
async run() {
|
|
8
5
|
const { args, flags } = await this.parse(ServiceList);
|
|
9
6
|
const cli = this;
|
|
@@ -19,7 +16,7 @@ class ServiceList extends base_1.default {
|
|
|
19
16
|
Name: service.name,
|
|
20
17
|
};
|
|
21
18
|
});
|
|
22
|
-
|
|
19
|
+
ux.table(services_data, {
|
|
23
20
|
Name: {},
|
|
24
21
|
}, flags);
|
|
25
22
|
}
|
|
@@ -29,6 +26,8 @@ class ServiceList extends base_1.default {
|
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
|
-
|
|
33
|
-
ServiceList.
|
|
34
|
-
|
|
29
|
+
ServiceList.description = "show account services list";
|
|
30
|
+
ServiceList.flags = {
|
|
31
|
+
...Command.flags,
|
|
32
|
+
};
|
|
33
|
+
export default ServiceList;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Command from "../../base";
|
|
1
|
+
import Command from "../../base.js";
|
|
2
2
|
export default class ServiceLogs extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static flags: {
|
|
5
|
-
service: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
6
|
-
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
5
|
+
service: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
6
|
+
help: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<void>;
|
|
7
7
|
};
|
|
8
8
|
run(): Promise<void>;
|
|
9
9
|
send_request(cli: any, selected_service: any): Promise<void>;
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
9
|
-
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
10
|
-
class ServiceLogs extends base_1.default {
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import Command from "../../base.js";
|
|
3
|
+
import { isEmptyObject } from "../../helper.js";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import inquirer from 'inquirer';
|
|
6
|
+
import axios from "axios";
|
|
7
|
+
class ServiceLogs extends Command {
|
|
11
8
|
async run() {
|
|
12
9
|
const { args, flags } = await this.parse(ServiceLogs);
|
|
13
10
|
const cli = this;
|
|
14
11
|
await this.init_run();
|
|
15
12
|
const config_json = await this.read_config();
|
|
16
13
|
let selected_service = flags.service;
|
|
17
|
-
if (
|
|
18
|
-
cli.log(`${
|
|
14
|
+
if (isEmptyObject(config_json.users)) {
|
|
15
|
+
cli.log(`${chalk.red('[Error]')} first you should login!`);
|
|
19
16
|
return;
|
|
20
17
|
}
|
|
21
18
|
if (!flags.service) {
|
|
22
19
|
let all_services = await this.get_services();
|
|
23
20
|
if (all_services.length > 0) {
|
|
24
|
-
let { service } = await
|
|
21
|
+
let { service } = await inquirer.prompt({
|
|
25
22
|
type: 'list',
|
|
26
23
|
message: 'Please select a service:',
|
|
27
24
|
name: 'service',
|
|
@@ -39,7 +36,7 @@ class ServiceLogs extends base_1.default {
|
|
|
39
36
|
async send_request(cli, selected_service) {
|
|
40
37
|
try {
|
|
41
38
|
if (selected_service) {
|
|
42
|
-
const { data } = await
|
|
39
|
+
const { data } = await axios.get("services/" + selected_service + "/logs/", this.axiosConfig);
|
|
43
40
|
if (data.success) {
|
|
44
41
|
cli.log(data.logs);
|
|
45
42
|
}
|
|
@@ -47,7 +44,7 @@ class ServiceLogs extends base_1.default {
|
|
|
47
44
|
}
|
|
48
45
|
catch (e) {
|
|
49
46
|
if (e.response.status == 404) {
|
|
50
|
-
cli.log(
|
|
47
|
+
cli.log(chalk.blue("Selected Service Not Founded."));
|
|
51
48
|
}
|
|
52
49
|
else {
|
|
53
50
|
console.log(e.data);
|
|
@@ -55,6 +52,9 @@ class ServiceLogs extends base_1.default {
|
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
54
|
}
|
|
58
|
-
exports.default = ServiceLogs;
|
|
59
55
|
ServiceLogs.description = 'read latest logs from service';
|
|
60
|
-
ServiceLogs.flags =
|
|
56
|
+
ServiceLogs.flags = {
|
|
57
|
+
...Command.flags,
|
|
58
|
+
service: Flags.string({ char: 's', description: 'service name' }),
|
|
59
|
+
};
|
|
60
|
+
export default ServiceLogs;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import Command from "../../base";
|
|
1
|
+
import Command from "../../base.js";
|
|
2
2
|
export default class ServiceResize extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static flags: {
|
|
5
|
-
service: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
6
|
-
ram: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
7
|
-
cpu: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
8
|
-
disk: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
9
|
-
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
5
|
+
service: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
6
|
+
ram: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
+
cpu: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
+
disk: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
9
|
+
help: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<void>;
|
|
10
10
|
};
|
|
11
11
|
run(): Promise<void>;
|
|
12
12
|
send_request(cli: any, selected_service: any, ram: any, cpu: any, disk: any): Promise<void>;
|
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
9
|
-
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
10
|
-
class ServiceResize extends base_1.default {
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import Command from "../../base.js";
|
|
3
|
+
import { isEmptyObject } from "../../helper.js";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import inquirer from 'inquirer';
|
|
6
|
+
import axios from "axios";
|
|
7
|
+
class ServiceResize extends Command {
|
|
11
8
|
async run() {
|
|
12
9
|
const { args, flags } = await this.parse(ServiceResize);
|
|
13
10
|
const cli = this;
|
|
14
|
-
this.init_run();
|
|
11
|
+
await this.init_run();
|
|
15
12
|
const config_json = await this.read_config();
|
|
16
13
|
let selected_service = flags.service;
|
|
17
14
|
let selected_ram = flags.ram;
|
|
18
15
|
let selected_cpu = flags.cpu;
|
|
19
16
|
let selected_disk = flags.disk;
|
|
20
|
-
if (
|
|
21
|
-
cli.log(`${
|
|
17
|
+
if (isEmptyObject(config_json.users)) {
|
|
18
|
+
cli.log(`${chalk.red('[Error]')} first you should login!`);
|
|
22
19
|
return;
|
|
23
20
|
}
|
|
24
21
|
if (!selected_service) {
|
|
25
22
|
let all_services = await this.get_services({ 'not_status': 'pending', 'has_custom_plan': 'true' });
|
|
26
23
|
if (all_services) {
|
|
27
|
-
let { service } = await
|
|
24
|
+
let { service } = await inquirer.prompt({
|
|
28
25
|
type: 'list',
|
|
29
26
|
message: 'Please select a service:',
|
|
30
27
|
name: 'service',
|
|
@@ -34,7 +31,7 @@ class ServiceResize extends base_1.default {
|
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
33
|
if (!selected_ram) {
|
|
37
|
-
let { ram } = await
|
|
34
|
+
let { ram } = await inquirer.prompt({
|
|
38
35
|
type: 'list',
|
|
39
36
|
message: 'Please select service ram:',
|
|
40
37
|
name: 'ram',
|
|
@@ -50,7 +47,7 @@ class ServiceResize extends base_1.default {
|
|
|
50
47
|
selected_ram = ram;
|
|
51
48
|
}
|
|
52
49
|
if (!selected_cpu) {
|
|
53
|
-
let { cpu } = await
|
|
50
|
+
let { cpu } = await inquirer.prompt({
|
|
54
51
|
type: 'list',
|
|
55
52
|
message: 'Please select service cpu:',
|
|
56
53
|
name: 'cpu',
|
|
@@ -65,7 +62,7 @@ class ServiceResize extends base_1.default {
|
|
|
65
62
|
selected_cpu = cpu;
|
|
66
63
|
}
|
|
67
64
|
if (!selected_disk) {
|
|
68
|
-
let { disk } = await
|
|
65
|
+
let { disk } = await inquirer.prompt({
|
|
69
66
|
type: 'list',
|
|
70
67
|
message: 'Please select service disk:',
|
|
71
68
|
name: 'disk',
|
|
@@ -82,15 +79,15 @@ class ServiceResize extends base_1.default {
|
|
|
82
79
|
}
|
|
83
80
|
let wrong_value = false;
|
|
84
81
|
if (selected_ram % 0.5 != 0) {
|
|
85
|
-
cli.log(`${
|
|
82
|
+
cli.log(`${chalk.red('[Error]')} ram amount should coefficient of 0.5`);
|
|
86
83
|
wrong_value = true;
|
|
87
84
|
}
|
|
88
85
|
if (selected_cpu % 0.5 != 0) {
|
|
89
|
-
cli.log(`${
|
|
86
|
+
cli.log(`${chalk.red('[Error]')} cpu amount should coefficient of 0.5`);
|
|
90
87
|
wrong_value = true;
|
|
91
88
|
}
|
|
92
89
|
if (selected_disk % 5 != 0) {
|
|
93
|
-
cli.log(`${
|
|
90
|
+
cli.log(`${chalk.red('[Error]')} disk amount should coefficient of 5`);
|
|
94
91
|
wrong_value = true;
|
|
95
92
|
}
|
|
96
93
|
if (selected_service && selected_ram && selected_cpu && selected_disk && !wrong_value) {
|
|
@@ -100,22 +97,22 @@ class ServiceResize extends base_1.default {
|
|
|
100
97
|
async send_request(cli, selected_service, ram, cpu, disk) {
|
|
101
98
|
try {
|
|
102
99
|
if (selected_service) {
|
|
103
|
-
const { data } = await
|
|
100
|
+
const { data } = await axios.post("services/" + selected_service + "/resize/", {
|
|
104
101
|
"ram": ram,
|
|
105
102
|
"cpu": cpu,
|
|
106
103
|
"disk": disk,
|
|
107
104
|
}, this.axiosConfig);
|
|
108
105
|
if (data.success) {
|
|
109
|
-
cli.log(`${
|
|
106
|
+
cli.log(`${chalk.green('[Success]')} service resized successfully.`);
|
|
110
107
|
}
|
|
111
108
|
else {
|
|
112
|
-
cli.log(`${
|
|
109
|
+
cli.log(`${chalk.red('[Error]')} some problem in resize.`);
|
|
113
110
|
}
|
|
114
111
|
}
|
|
115
112
|
}
|
|
116
113
|
catch (e) {
|
|
117
114
|
if (e.response.status == 404) {
|
|
118
|
-
cli.log(
|
|
115
|
+
cli.log(chalk.blue("Selected Service Not Founded."));
|
|
119
116
|
}
|
|
120
117
|
else {
|
|
121
118
|
console.log(e.data);
|
|
@@ -123,6 +120,12 @@ class ServiceResize extends base_1.default {
|
|
|
123
120
|
}
|
|
124
121
|
}
|
|
125
122
|
}
|
|
126
|
-
exports.default = ServiceResize;
|
|
127
123
|
ServiceResize.description = 'resize a service';
|
|
128
|
-
ServiceResize.flags =
|
|
124
|
+
ServiceResize.flags = {
|
|
125
|
+
...Command.flags,
|
|
126
|
+
service: Flags.string({ char: 's', description: 'service name' }),
|
|
127
|
+
ram: Flags.string({ char: 'r', description: 'RAM' }),
|
|
128
|
+
cpu: Flags.string({ char: 'c', description: 'CPU' }),
|
|
129
|
+
disk: Flags.string({ char: 'd', description: 'DISK' }),
|
|
130
|
+
};
|
|
131
|
+
export default ServiceResize;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Command from "../../base";
|
|
1
|
+
import Command from "../../base.js";
|
|
2
2
|
export default class ServiceRestart extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static flags: {
|
|
5
|
-
service: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
6
|
-
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
5
|
+
service: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
6
|
+
help: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<void>;
|
|
7
7
|
};
|
|
8
8
|
run(): Promise<void>;
|
|
9
9
|
send_request(cli: any, selected_service: any): Promise<void>;
|