@chabokan.net/cli 0.3.0 → 0.7.1

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 CHANGED
@@ -19,7 +19,7 @@ $ npm install -g @chabokan.net/cli
19
19
  $ chabok COMMAND
20
20
  running command...
21
21
  $ chabok (-v|--version|version)
22
- @chabokan.net/cli/0.3.0 darwin-x64 node-v12.16.1
22
+ @chabokan.net/cli/0.7.1 darwin-x64 node-v14.17.5
23
23
  $ chabok --help [COMMAND]
24
24
  USAGE
25
25
  $ chabok COMMAND
@@ -33,13 +33,15 @@ USAGE
33
33
  * [`chabok deploy`](#chabok-deploy)
34
34
  * [`chabok help [COMMAND]`](#chabok-help-command)
35
35
  * [`chabok login`](#chabok-login)
36
+ * [`chabok logs`](#chabok-logs)
37
+ * [`chabok resize`](#chabok-resize)
36
38
  * [`chabok restart`](#chabok-restart)
37
- * [`chabok start [FILE]`](#chabok-start-file)
38
- * [`chabok stop [FILE]`](#chabok-stop-file)
39
+ * [`chabok start`](#chabok-start)
40
+ * [`chabok stop`](#chabok-stop)
39
41
 
40
42
  ## `chabok change-user`
41
43
 
42
- describe the command here
44
+ switch your default user between logged in users
43
45
 
44
46
  ```
45
47
  USAGE
@@ -50,11 +52,11 @@ OPTIONS
50
52
  -u, --user=user default user
51
53
  ```
52
54
 
53
- _See code: [src/commands/change-user.ts](https://github.com/chabokan/cli/blob/v0.3.0/src/commands/change-user.ts)_
55
+ _See code: [src/commands/change-user.ts](https://github.com/chabokan/cli/blob/v0.7.1/src/commands/change-user.ts)_
54
56
 
55
57
  ## `chabok config-clear`
56
58
 
57
- describe the command here
59
+ clear config file, data such as auth will be removed.
58
60
 
59
61
  ```
60
62
  USAGE
@@ -64,11 +66,11 @@ OPTIONS
64
66
  -h, --help show CLI help
65
67
  ```
66
68
 
67
- _See code: [src/commands/config-clear.ts](https://github.com/chabokan/cli/blob/v0.3.0/src/commands/config-clear.ts)_
69
+ _See code: [src/commands/config-clear.ts](https://github.com/chabokan/cli/blob/v0.7.1/src/commands/config-clear.ts)_
68
70
 
69
71
  ## `chabok deploy`
70
72
 
71
- describe the command here
73
+ this command help you build and deploy your service to chabokan in easy way.
72
74
 
73
75
  ```
74
76
  USAGE
@@ -80,7 +82,7 @@ OPTIONS
80
82
  -s, --service=service service name
81
83
  ```
82
84
 
83
- _See code: [src/commands/deploy.ts](https://github.com/chabokan/cli/blob/v0.3.0/src/commands/deploy.ts)_
85
+ _See code: [src/commands/deploy.ts](https://github.com/chabokan/cli/blob/v0.7.1/src/commands/deploy.ts)_
84
86
 
85
87
  ## `chabok help [COMMAND]`
86
88
 
@@ -101,7 +103,7 @@ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.2
101
103
 
102
104
  ## `chabok login`
103
105
 
104
- describe the command here
106
+ login to hub.chabokan.net account
105
107
 
106
108
  ```
107
109
  USAGE
@@ -114,11 +116,44 @@ OPTIONS
114
116
  -u, --username=username your username
115
117
  ```
116
118
 
117
- _See code: [src/commands/login.ts](https://github.com/chabokan/cli/blob/v0.3.0/src/commands/login.ts)_
119
+ _See code: [src/commands/login.ts](https://github.com/chabokan/cli/blob/v0.7.1/src/commands/login.ts)_
120
+
121
+ ## `chabok logs`
122
+
123
+ read latest logs from service
124
+
125
+ ```
126
+ USAGE
127
+ $ chabok logs
128
+
129
+ OPTIONS
130
+ -h, --help show CLI help
131
+ -s, --service=service service name
132
+ ```
133
+
134
+ _See code: [src/commands/logs.ts](https://github.com/chabokan/cli/blob/v0.7.1/src/commands/logs.ts)_
135
+
136
+ ## `chabok resize`
137
+
138
+ resize a service
139
+
140
+ ```
141
+ USAGE
142
+ $ chabok resize
143
+
144
+ OPTIONS
145
+ -c, --cpu=cpu CPU
146
+ -d, --disk=disk DISK
147
+ -h, --help show CLI help
148
+ -r, --ram=ram RAM
149
+ -s, --service=service service name
150
+ ```
151
+
152
+ _See code: [src/commands/resize.ts](https://github.com/chabokan/cli/blob/v0.7.1/src/commands/resize.ts)_
118
153
 
119
154
  ## `chabok restart`
120
155
 
121
- describe the command here
156
+ restart a service
122
157
 
123
158
  ```
124
159
  USAGE
@@ -129,37 +164,35 @@ OPTIONS
129
164
  -s, --service=service service name
130
165
  ```
131
166
 
132
- _See code: [src/commands/restart.ts](https://github.com/chabokan/cli/blob/v0.3.0/src/commands/restart.ts)_
167
+ _See code: [src/commands/restart.ts](https://github.com/chabokan/cli/blob/v0.7.1/src/commands/restart.ts)_
133
168
 
134
- ## `chabok start [FILE]`
169
+ ## `chabok start`
135
170
 
136
- describe the command here
171
+ start a service
137
172
 
138
173
  ```
139
174
  USAGE
140
- $ chabok start [FILE]
175
+ $ chabok start
141
176
 
142
177
  OPTIONS
143
- -f, --force
144
- -h, --help show CLI help
145
- -n, --name=name name to print
178
+ -h, --help show CLI help
179
+ -s, --service=service service name
146
180
  ```
147
181
 
148
- _See code: [src/commands/start.ts](https://github.com/chabokan/cli/blob/v0.3.0/src/commands/start.ts)_
182
+ _See code: [src/commands/start.ts](https://github.com/chabokan/cli/blob/v0.7.1/src/commands/start.ts)_
149
183
 
150
- ## `chabok stop [FILE]`
184
+ ## `chabok stop`
151
185
 
152
- describe the command here
186
+ stop a service
153
187
 
154
188
  ```
155
189
  USAGE
156
- $ chabok stop [FILE]
190
+ $ chabok stop
157
191
 
158
192
  OPTIONS
159
- -f, --force
160
- -h, --help show CLI help
161
- -n, --name=name name to print
193
+ -h, --help show CLI help
194
+ -s, --service=service service name
162
195
  ```
163
196
 
164
- _See code: [src/commands/stop.ts](https://github.com/chabokan/cli/blob/v0.3.0/src/commands/stop.ts)_
197
+ _See code: [src/commands/stop.ts](https://github.com/chabokan/cli/blob/v0.7.1/src/commands/stop.ts)_
165
198
  <!-- commandsstop -->
package/lib/base.js CHANGED
@@ -5,7 +5,7 @@ const command_1 = tslib_1.__importStar(require("@oclif/command"));
5
5
  const axios_1 = tslib_1.__importDefault(require("axios"));
6
6
  const constants_1 = require("./constants");
7
7
  const helper_1 = require("./helper");
8
- const agent_1 = tslib_1.__importDefault(require("https-proxy-agent/dist/agent"));
8
+ const proxy_http_agent_1 = require("proxy-http-agent");
9
9
  const fs = tslib_1.__importStar(require("fs"));
10
10
  const got_1 = tslib_1.__importDefault(require("got"));
11
11
  class default_1 extends command_1.default {
@@ -31,9 +31,13 @@ class default_1 extends command_1.default {
31
31
  if (proxy) {
32
32
  this.log(`Using proxy server ${proxy}`);
33
33
  // @ts-ignore
34
- const agent = new agent_1.default(proxy);
34
+ const agent = proxy_http_agent_1.getProxyHttpAgent({
35
+ proxy: proxy,
36
+ rejectUnauthorized: false
37
+ });
35
38
  this.axiosConfig.httpsAgent = agent;
36
39
  this.axiosConfig.proxy = false;
40
+ // @ts-ignore
37
41
  gotConfig.agent = { https: agent };
38
42
  }
39
43
  const config_json = helper_1.read_config_file();
@@ -37,7 +37,7 @@ class ChangeUser extends command_1.Command {
37
37
  }
38
38
  }
39
39
  exports.default = ChangeUser;
40
- ChangeUser.description = 'describe the command here';
40
+ ChangeUser.description = 'switch your default user between logged in users';
41
41
  ChangeUser.flags = {
42
42
  help: command_1.flags.help({ char: 'h' }),
43
43
  user: command_1.flags.string({ char: 'u', description: 'default user' }),
@@ -13,5 +13,5 @@ class ConfigClear extends base_1.default {
13
13
  }
14
14
  }
15
15
  exports.default = ConfigClear;
16
- ConfigClear.description = 'describe the command here';
16
+ ConfigClear.description = 'clear config file, data such as auth will be removed.';
17
17
  ConfigClear.flags = Object.assign({}, base_1.default.flags);
@@ -7,5 +7,10 @@ export default class Deploy extends Command {
7
7
  service: flags.IOptionFlag<string | undefined>;
8
8
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
9
9
  };
10
- run(): Promise<string>;
10
+ run(): Promise<void>;
11
+ prepare_archive(project_path: any): Promise<string>;
12
+ upload(archive_path: any, selected_service: any): Promise<{
13
+ success: boolean;
14
+ message: string;
15
+ }>;
11
16
  }
@@ -10,11 +10,49 @@ const ignore_1 = tslib_1.__importDefault(require("ignore"));
10
10
  const path = tslib_1.__importStar(require("path"));
11
11
  const os = tslib_1.__importStar(require("os"));
12
12
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
14
+ const inquirer = tslib_1.__importStar(require("inquirer"));
15
+ const progress_1 = tslib_1.__importDefault(require("progress"));
16
+ const form_data_1 = tslib_1.__importDefault(require("form-data"));
17
+ const MAX_SOURCE_SIZE = 200 * 1024 * 1024; // 200 MB
13
18
  class Deploy extends base_1.default {
14
19
  async run() {
15
20
  const { args, flags } = this.parse(Deploy);
16
21
  const cli = this;
17
22
  this.init_run();
23
+ const config_json = this.read_config();
24
+ let selected_service = flags.service;
25
+ let project_path = flags.path ? flags.path : process.cwd();
26
+ if (helper_1.isEmptyObject(config_json.users)) {
27
+ cli.log(`${chalk_1.default.red('[Error]')} first you should login!`);
28
+ return;
29
+ }
30
+ if (!flags.service) {
31
+ let all_services = await this.get_services({ "has_deploy": "true", "status": "on" });
32
+ if (all_services.length > 0) {
33
+ let { service } = await inquirer.prompt({
34
+ type: 'list',
35
+ message: 'Please select a service:',
36
+ name: 'service',
37
+ choices: all_services
38
+ });
39
+ selected_service = service;
40
+ }
41
+ else {
42
+ cli.log("first you should create service");
43
+ return;
44
+ }
45
+ }
46
+ let archive_path = await this.prepare_archive(project_path);
47
+ let upload_response = await this.upload(archive_path, selected_service);
48
+ if (upload_response.success) {
49
+ cli.log(chalk_1.default.green(upload_response.message));
50
+ }
51
+ else {
52
+ cli.log(chalk_1.default.red("[Error] " + upload_response.message));
53
+ }
54
+ }
55
+ async prepare_archive(project_path) {
18
56
  const defaultIgnores = [
19
57
  '.git',
20
58
  '.idea',
@@ -26,14 +64,13 @@ class Deploy extends base_1.default {
26
64
  'node_modules',
27
65
  'bower_components',
28
66
  ];
29
- let projectPath = flags.path ? flags.path : process.cwd();
30
67
  const ignoreCache = {};
31
68
  const ignoreInstance = ignore_1.default({ ignorecase: false });
32
69
  ignoreInstance.add(defaultIgnores);
33
70
  const ignoreFN = (f) => {
34
71
  const dir = path_1.dirname(f);
35
72
  if (!ignoreCache[dir]) {
36
- helper_1.addIgnorePatterns(ignoreInstance, projectPath, dir);
73
+ helper_1.addIgnorePatterns(ignoreInstance, project_path, dir);
37
74
  ignoreCache[dir] = true;
38
75
  }
39
76
  if (!ignoreInstance.ignores(f)) {
@@ -45,35 +82,59 @@ class Deploy extends base_1.default {
45
82
  const tmpDir = path.join(os.tmpdir(), '/chabok-cli');
46
83
  const archivePath = path.join(tmpDir, `${Date.now()}.tar.gz`);
47
84
  fs_extra_1.default.ensureDirSync(tmpDir);
48
- const fileList = fs_extra_1.default.readdirSync(projectPath).filter(ignoreFN);
85
+ const fileList = fs_extra_1.default.readdirSync(project_path).filter(ignoreFN);
49
86
  tar_1.default.c({
50
87
  gzip: {
51
88
  level: 9,
52
89
  },
53
90
  sync: true,
54
- cwd: projectPath,
91
+ cwd: project_path,
55
92
  filter: ignoreFN,
56
93
  file: archivePath,
57
94
  }, fileList);
95
+ return archivePath;
96
+ }
97
+ async upload(archive_path, selected_service) {
98
+ let upload_response = {
99
+ success: false,
100
+ message: "some problem"
101
+ };
102
+ const body = new form_data_1.default();
103
+ // @ts-ignore
104
+ body.append('file', fs_extra_1.default.createReadStream(archive_path));
105
+ const { size: sourceSize } = fs_extra_1.default.statSync(archive_path);
106
+ if (sourceSize > MAX_SOURCE_SIZE) {
107
+ upload_response.message = "Source is too large. (max: 500MB)";
108
+ return upload_response;
109
+ }
110
+ const bar = new progress_1.default('Uploading [:bar] :percent :etas', {
111
+ total: sourceSize,
112
+ width: 20,
113
+ complete: '=',
114
+ incomplete: '',
115
+ clear: true,
116
+ });
58
117
  try {
59
- const response = await this.got.post(`sources`, {})
118
+ const response = await this.got.post(`services/${selected_service}/deploy/`, { body })
60
119
  .on('uploadProgress', progress => {
61
- // bar.tick(progress.transferred - bar.curr)
62
- })
63
- .json();
64
- // this.spinner.succeed('Upload finished.')
65
- return response.sourceID;
120
+ bar.tick(progress.transferred - bar.curr);
121
+ }).json();
122
+ if (response.success) {
123
+ upload_response.success = true;
124
+ upload_response.message = "Deployment finished successfully.";
125
+ }
126
+ return upload_response;
66
127
  }
67
128
  catch (error) {
68
- // this.spinner.fail('Upload failed.')
69
- throw error;
129
+ return upload_response;
70
130
  }
71
131
  finally {
72
132
  // cleanup
73
- fs_extra_1.default.unlink(archivePath).catch(() => { });
133
+ fs_extra_1.default.unlink(archive_path).catch(() => {
134
+ });
74
135
  }
75
136
  }
76
137
  }
77
138
  exports.default = Deploy;
78
- Deploy.description = 'describe the command here';
139
+ Deploy.description = 'this command help you build and deploy your service to chabokan in easy way.';
79
140
  Deploy.flags = Object.assign(Object.assign({}, base_1.default.flags), { path: command_1.flags.string({ char: 'p', description: 'service path in your computer' }), service: command_1.flags.string({ char: 's', description: 'service name' }) });
@@ -82,5 +82,5 @@ class Login extends base_1.default {
82
82
  }
83
83
  }
84
84
  exports.default = Login;
85
- Login.description = 'describe the command here';
85
+ Login.description = 'login to hub.chabokan.net account';
86
86
  Login.flags = Object.assign(Object.assign({}, base_1.default.flags), { username: command_1.flags.string({ char: 'u', description: 'your username' }), password: command_1.flags.string({ char: 'p', description: 'your password' }), token: command_1.flags.string({ char: 't', description: 'login with api token' }) });
@@ -0,0 +1,11 @@
1
+ import { flags } from '@oclif/command';
2
+ import Command from "../base";
3
+ export default class Logs extends Command {
4
+ static description: string;
5
+ static flags: {
6
+ service: flags.IOptionFlag<string | undefined>;
7
+ help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
8
+ };
9
+ run(): Promise<void>;
10
+ send_request(cli: any, selected_service: any): Promise<void>;
11
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const command_1 = require("@oclif/command");
5
+ const base_1 = tslib_1.__importDefault(require("../base"));
6
+ const helper_1 = require("../helper");
7
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
+ const inquirer = tslib_1.__importStar(require("inquirer"));
9
+ const axios_1 = tslib_1.__importDefault(require("axios"));
10
+ class Logs extends base_1.default {
11
+ async run() {
12
+ const { args, flags } = this.parse(Logs);
13
+ const cli = this;
14
+ this.init_run();
15
+ const config_json = this.read_config();
16
+ let selected_service = flags.service;
17
+ if (helper_1.isEmptyObject(config_json.users)) {
18
+ cli.log(`${chalk_1.default.red('[Error]')} first you should login!`);
19
+ return;
20
+ }
21
+ if (!flags.service) {
22
+ let all_services = await this.get_services();
23
+ if (all_services.length > 0) {
24
+ let { service } = await inquirer.prompt({
25
+ type: 'list',
26
+ message: 'Please select a service:',
27
+ name: 'service',
28
+ choices: all_services
29
+ });
30
+ selected_service = service;
31
+ }
32
+ else {
33
+ cli.log("first you should create service");
34
+ return;
35
+ }
36
+ }
37
+ await this.send_request(cli, selected_service);
38
+ }
39
+ async send_request(cli, selected_service) {
40
+ try {
41
+ if (selected_service) {
42
+ const { data } = await axios_1.default.get("services/" + selected_service + "/logs/", this.axiosConfig);
43
+ if (data.success) {
44
+ cli.log(data.logs);
45
+ }
46
+ }
47
+ }
48
+ catch (e) {
49
+ if (e.response.status == 404) {
50
+ cli.log(chalk_1.default.blue("Selected Service Not Founded."));
51
+ }
52
+ else {
53
+ console.log(e.data);
54
+ }
55
+ }
56
+ }
57
+ }
58
+ exports.default = Logs;
59
+ Logs.description = 'read latest logs from service';
60
+ Logs.flags = Object.assign(Object.assign({}, base_1.default.flags), { service: command_1.flags.string({ char: 's', description: 'service name' }) });
@@ -0,0 +1,14 @@
1
+ import { flags } from '@oclif/command';
2
+ import Command from "../base";
3
+ export default class Resize extends Command {
4
+ static description: string;
5
+ static flags: {
6
+ service: flags.IOptionFlag<string | undefined>;
7
+ ram: flags.IOptionFlag<string | undefined>;
8
+ cpu: flags.IOptionFlag<string | undefined>;
9
+ disk: flags.IOptionFlag<string | undefined>;
10
+ help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
11
+ };
12
+ run(): Promise<void>;
13
+ send_request(cli: any, selected_service: any, ram: any, cpu: any, disk: any): Promise<void>;
14
+ }
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const command_1 = require("@oclif/command");
5
+ const base_1 = tslib_1.__importDefault(require("../base"));
6
+ const helper_1 = require("../helper");
7
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
+ const inquirer = tslib_1.__importStar(require("inquirer"));
9
+ const axios_1 = tslib_1.__importDefault(require("axios"));
10
+ class Resize extends base_1.default {
11
+ async run() {
12
+ const { args, flags } = this.parse(Resize);
13
+ const cli = this;
14
+ this.init_run();
15
+ const config_json = this.read_config();
16
+ let selected_service = flags.service;
17
+ let selected_ram = flags.ram;
18
+ let selected_cpu = flags.cpu;
19
+ let selected_disk = flags.disk;
20
+ if (helper_1.isEmptyObject(config_json.users)) {
21
+ cli.log(`${chalk_1.default.red('[Error]')} first you should login!`);
22
+ return;
23
+ }
24
+ if (!selected_service) {
25
+ let all_services = await this.get_services({ 'not_status': 'pending', 'has_custom_plan': 'true' });
26
+ if (all_services) {
27
+ let { service } = await inquirer.prompt({
28
+ type: 'list',
29
+ message: 'Please select a service:',
30
+ name: 'service',
31
+ choices: all_services
32
+ });
33
+ selected_service = service;
34
+ }
35
+ }
36
+ if (!selected_ram) {
37
+ let { ram } = await inquirer.prompt({
38
+ type: 'list',
39
+ message: 'Please select service ram:',
40
+ name: 'ram',
41
+ choices: [
42
+ { value: "0.5", name: "0.5G" },
43
+ { value: "1", name: "1G" },
44
+ { value: "2", name: "2G" },
45
+ { value: "4", name: "4G" },
46
+ { value: "6", name: "6G" },
47
+ { value: "8", name: "8G" },
48
+ ]
49
+ });
50
+ selected_ram = ram;
51
+ }
52
+ if (!selected_cpu) {
53
+ let { cpu } = await inquirer.prompt({
54
+ type: 'list',
55
+ message: 'Please select service cpu:',
56
+ name: 'cpu',
57
+ choices: [
58
+ { value: "0.5", name: "0.5 Core" },
59
+ { value: "1", name: "1 Core" },
60
+ { value: "2", name: "2 Core" },
61
+ { value: "3", name: "3 Core" },
62
+ { value: "4", name: "4 Core" },
63
+ ]
64
+ });
65
+ selected_cpu = cpu;
66
+ }
67
+ if (!selected_disk) {
68
+ let { disk } = await inquirer.prompt({
69
+ type: 'list',
70
+ message: 'Please select service disk:',
71
+ name: 'disk',
72
+ choices: [
73
+ { value: "5", name: "5G" },
74
+ { value: "10", name: "10G" },
75
+ { value: "15", name: "15G" },
76
+ { value: "30", name: "30G" },
77
+ { value: "40", name: "40G" },
78
+ { value: "50", name: "50G" },
79
+ ]
80
+ });
81
+ selected_disk = disk;
82
+ }
83
+ let wrong_value = false;
84
+ if (selected_ram % 0.5 != 0) {
85
+ cli.log(`${chalk_1.default.red('[Error]')} ram amount should coefficient of 0.5`);
86
+ wrong_value = true;
87
+ }
88
+ if (selected_cpu % 0.5 != 0) {
89
+ cli.log(`${chalk_1.default.red('[Error]')} cpu amount should coefficient of 0.5`);
90
+ wrong_value = true;
91
+ }
92
+ if (selected_disk % 5 != 0) {
93
+ cli.log(`${chalk_1.default.red('[Error]')} disk amount should coefficient of 5`);
94
+ wrong_value = true;
95
+ }
96
+ if (selected_service && selected_ram && selected_cpu && selected_disk && !wrong_value) {
97
+ await this.send_request(cli, selected_service, selected_ram, selected_cpu, selected_disk);
98
+ }
99
+ }
100
+ async send_request(cli, selected_service, ram, cpu, disk) {
101
+ try {
102
+ if (selected_service) {
103
+ const { data } = await axios_1.default.post("services/" + selected_service + "/resize/", {
104
+ "ram": ram,
105
+ "cpu": cpu,
106
+ "disk": disk,
107
+ }, this.axiosConfig);
108
+ if (data.success) {
109
+ cli.log(`${chalk_1.default.green('[Success]')} service resized successfully.`);
110
+ }
111
+ else {
112
+ cli.log(`${chalk_1.default.red('[Error]')} some problem in resize.`);
113
+ }
114
+ }
115
+ }
116
+ catch (e) {
117
+ if (e.response.status == 404) {
118
+ cli.log(chalk_1.default.blue("Selected Service Not Founded."));
119
+ }
120
+ else {
121
+ console.log(e.data);
122
+ }
123
+ }
124
+ }
125
+ }
126
+ exports.default = Resize;
127
+ Resize.description = 'resize a service';
128
+ Resize.flags = Object.assign(Object.assign({}, base_1.default.flags), { service: command_1.flags.string({ char: 's', description: 'service name' }), ram: command_1.flags.string({ char: 'r', description: 'RAM' }), cpu: command_1.flags.string({ char: 'c', description: 'CPU' }), disk: command_1.flags.string({ char: 'd', description: 'DISK' }) });
@@ -7,4 +7,5 @@ export default class Restart extends Command {
7
7
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
8
8
  };
9
9
  run(): Promise<void>;
10
+ send_request(cli: any, selected_service: any): Promise<void>;
10
11
  }
@@ -19,7 +19,7 @@ class Restart extends base_1.default {
19
19
  return;
20
20
  }
21
21
  if (!flags.service) {
22
- let all_services = await this.get_services();
22
+ let all_services = await this.get_services({ 'not_status': 'pending' });
23
23
  if (all_services) {
24
24
  let { service } = await inquirer.prompt({
25
25
  type: 'list',
@@ -30,14 +30,27 @@ class Restart extends base_1.default {
30
30
  selected_service = service;
31
31
  }
32
32
  }
33
- if (selected_service) {
34
- const { data } = await axios_1.default.get("services/" + selected_service + "/restart/", this.axiosConfig);
35
- if (data.success) {
36
- cli.log(`${chalk_1.default.green('[Success]')} service restarted successfully.`);
33
+ await this.send_request(cli, selected_service);
34
+ }
35
+ async send_request(cli, selected_service) {
36
+ try {
37
+ if (selected_service) {
38
+ const { data } = await axios_1.default.get("services/" + selected_service + "/restart/", this.axiosConfig);
39
+ if (data.success) {
40
+ cli.log(`${chalk_1.default.green('[Success]')} service restarted successfully.`);
41
+ }
42
+ }
43
+ }
44
+ catch (e) {
45
+ if (e.response.status == 404) {
46
+ cli.log(chalk_1.default.blue("Selected Service Not Founded."));
47
+ }
48
+ else {
49
+ console.log(e.data);
37
50
  }
38
51
  }
39
52
  }
40
53
  }
41
54
  exports.default = Restart;
42
- Restart.description = 'describe the command here';
55
+ Restart.description = 'restart a service';
43
56
  Restart.flags = Object.assign(Object.assign({}, base_1.default.flags), { service: command_1.flags.string({ char: 's', description: 'service name' }) });
@@ -1,13 +1,11 @@
1
- import { Command, flags } from '@oclif/command';
1
+ import { flags } from '@oclif/command';
2
+ import Command from "../base";
2
3
  export default class Start extends Command {
3
4
  static description: string;
4
5
  static flags: {
6
+ service: flags.IOptionFlag<string | undefined>;
5
7
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
6
- name: flags.IOptionFlag<string | undefined>;
7
- force: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
8
8
  };
9
- static args: {
10
- name: string;
11
- }[];
12
9
  run(): Promise<void>;
10
+ send_request(cli: any, selected_service: any): Promise<void>;
13
11
  }
@@ -1,24 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
3
4
  const command_1 = require("@oclif/command");
4
- class Start extends command_1.Command {
5
+ const base_1 = tslib_1.__importDefault(require("../base"));
6
+ const helper_1 = require("../helper");
7
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
+ const inquirer = tslib_1.__importStar(require("inquirer"));
9
+ const axios_1 = tslib_1.__importDefault(require("axios"));
10
+ class Start extends base_1.default {
5
11
  async run() {
6
- var _a;
7
12
  const { args, flags } = this.parse(Start);
8
- const name = (_a = flags.name) !== null && _a !== void 0 ? _a : 'world';
9
- this.log(`hello ${name} from /Users/mohammadabdi/projects/chabokan-cli/src/commands/start.ts`);
10
- if (args.file && flags.force) {
11
- this.log(`you input --force and --file: ${args.file}`);
13
+ const cli = this;
14
+ this.init_run();
15
+ const config_json = this.read_config();
16
+ let selected_service = flags.service;
17
+ if (helper_1.isEmptyObject(config_json.users)) {
18
+ cli.log(`${chalk_1.default.red('[Error]')} first you should login!`);
19
+ return;
20
+ }
21
+ if (!flags.service) {
22
+ let all_services = await this.get_services({ 'not_status': 'pending' });
23
+ if (all_services) {
24
+ let { service } = await inquirer.prompt({
25
+ type: 'list',
26
+ message: 'Please select a service:',
27
+ name: 'service',
28
+ choices: all_services
29
+ });
30
+ selected_service = service;
31
+ }
32
+ }
33
+ await this.send_request(cli, selected_service);
34
+ }
35
+ async send_request(cli, selected_service) {
36
+ try {
37
+ if (selected_service) {
38
+ const { data } = await axios_1.default.get("services/" + selected_service + "/start/", this.axiosConfig);
39
+ if (data.success) {
40
+ cli.log(`${chalk_1.default.green('[Success]')} service start successfully.`);
41
+ }
42
+ }
43
+ }
44
+ catch (e) {
45
+ if (e.response.status == 404) {
46
+ cli.log(chalk_1.default.blue("Selected Service Not Founded."));
47
+ }
48
+ else {
49
+ console.log(e.data);
50
+ }
12
51
  }
13
52
  }
14
53
  }
15
54
  exports.default = Start;
16
- Start.description = 'describe the command here';
17
- Start.flags = {
18
- help: command_1.flags.help({ char: 'h' }),
19
- // flag with a value (-n, --name=VALUE)
20
- name: command_1.flags.string({ char: 'n', description: 'name to print' }),
21
- // flag with no value (-f, --force)
22
- force: command_1.flags.boolean({ char: 'f' }),
23
- };
24
- Start.args = [{ name: 'file' }];
55
+ Start.description = 'start a service';
56
+ Start.flags = Object.assign(Object.assign({}, base_1.default.flags), { service: command_1.flags.string({ char: 's', description: 'service name' }) });
@@ -1,13 +1,11 @@
1
- import { Command, flags } from '@oclif/command';
1
+ import { flags } from '@oclif/command';
2
+ import Command from "../base";
2
3
  export default class Stop extends Command {
3
4
  static description: string;
4
5
  static flags: {
6
+ service: flags.IOptionFlag<string | undefined>;
5
7
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
6
- name: flags.IOptionFlag<string | undefined>;
7
- force: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
8
8
  };
9
- static args: {
10
- name: string;
11
- }[];
12
9
  run(): Promise<void>;
10
+ send_request(cli: any, selected_service: any): Promise<void>;
13
11
  }
@@ -1,24 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
3
4
  const command_1 = require("@oclif/command");
4
- class Stop extends command_1.Command {
5
+ const base_1 = tslib_1.__importDefault(require("../base"));
6
+ const helper_1 = require("../helper");
7
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
+ const inquirer = tslib_1.__importStar(require("inquirer"));
9
+ const axios_1 = tslib_1.__importDefault(require("axios"));
10
+ class Stop extends base_1.default {
5
11
  async run() {
6
- var _a;
7
12
  const { args, flags } = this.parse(Stop);
8
- const name = (_a = flags.name) !== null && _a !== void 0 ? _a : 'world';
9
- this.log(`hello ${name} from /Users/mohammadabdi/projects/chabokan-cli/src/commands/stop.ts`);
10
- if (args.file && flags.force) {
11
- this.log(`you input --force and --file: ${args.file}`);
13
+ const cli = this;
14
+ this.init_run();
15
+ const config_json = this.read_config();
16
+ let selected_service = flags.service;
17
+ if (helper_1.isEmptyObject(config_json.users)) {
18
+ cli.log(`${chalk_1.default.red('[Error]')} first you should login!`);
19
+ return;
20
+ }
21
+ if (!flags.service) {
22
+ let all_services = await this.get_services({ 'not_status': 'pending' });
23
+ if (all_services) {
24
+ let { service } = await inquirer.prompt({
25
+ type: 'list',
26
+ message: 'Please select a service:',
27
+ name: 'service',
28
+ choices: all_services
29
+ });
30
+ selected_service = service;
31
+ }
32
+ }
33
+ await this.send_request(cli, selected_service);
34
+ }
35
+ async send_request(cli, selected_service) {
36
+ try {
37
+ if (selected_service) {
38
+ const { data } = await axios_1.default.get("services/" + selected_service + "/stop/", this.axiosConfig);
39
+ if (data.success) {
40
+ cli.log(`${chalk_1.default.green('[Success]')} service stop successfully.`);
41
+ }
42
+ }
43
+ }
44
+ catch (e) {
45
+ if (e.response.status == 404) {
46
+ cli.log(chalk_1.default.blue("Selected Service Not Founded."));
47
+ }
48
+ else {
49
+ console.log(e.data);
50
+ }
12
51
  }
13
52
  }
14
53
  }
15
54
  exports.default = Stop;
16
- Stop.description = 'describe the command here';
17
- Stop.flags = {
18
- help: command_1.flags.help({ char: 'h' }),
19
- // flag with a value (-n, --name=VALUE)
20
- name: command_1.flags.string({ char: 'n', description: 'name to print' }),
21
- // flag with no value (-f, --force)
22
- force: command_1.flags.boolean({ char: 'f' }),
23
- };
24
- Stop.args = [{ name: 'file' }];
55
+ Stop.description = 'stop a service';
56
+ Stop.flags = Object.assign(Object.assign({}, base_1.default.flags), { service: command_1.flags.string({ char: 's', description: 'service name' }) });
package/lib/helper.js CHANGED
@@ -45,7 +45,7 @@ async function get_all_services(filter = {}, axiosConfig) {
45
45
  const { data } = await axios_1.default.get("services/" + url_filter, axiosConfig);
46
46
  data.services.forEach(function (item) {
47
47
  // @ts-ignore
48
- all_services.push(item.main_name);
48
+ all_services.push({ "value": item.main_name, "name": `${item.main_name} (${item.platform.name})` });
49
49
  });
50
50
  }
51
51
  catch (e) {
@@ -1 +1 @@
1
- {"version":"0.3.0","commands":{"change-user":{"id":"change-user","description":"describe the command here","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"user":{"name":"user","type":"option","char":"u","description":"default user"}},"args":[]},"config-clear":{"id":"config-clear","description":"describe the command here","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"deploy":{"id":"deploy","description":"describe the command here","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"path":{"name":"path","type":"option","char":"p","description":"service path in your computer"},"service":{"name":"service","type":"option","char":"s","description":"service name"}},"args":[]},"login":{"id":"login","description":"describe the command here","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"username":{"name":"username","type":"option","char":"u","description":"your username"},"password":{"name":"password","type":"option","char":"p","description":"your password"},"token":{"name":"token","type":"option","char":"t","description":"login with api token"}},"args":[]},"restart":{"id":"restart","description":"describe the command here","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"service":{"name":"service","type":"option","char":"s","description":"service name"}},"args":[]},"start":{"id":"start","description":"describe the command here","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"name":{"name":"name","type":"option","char":"n","description":"name to print"},"force":{"name":"force","type":"boolean","char":"f","allowNo":false}},"args":[{"name":"file"}]},"stop":{"id":"stop","description":"describe the command here","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"name":{"name":"name","type":"option","char":"n","description":"name to print"},"force":{"name":"force","type":"boolean","char":"f","allowNo":false}},"args":[{"name":"file"}]}}}
1
+ {"version":"0.7.1","commands":{"change-user":{"id":"change-user","description":"switch your default user between logged in users","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"user":{"name":"user","type":"option","char":"u","description":"default user"}},"args":[]},"config-clear":{"id":"config-clear","description":"clear config file, data such as auth will be removed.","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"deploy":{"id":"deploy","description":"this command help you build and deploy your service to chabokan in easy way.","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"path":{"name":"path","type":"option","char":"p","description":"service path in your computer"},"service":{"name":"service","type":"option","char":"s","description":"service name"}},"args":[]},"login":{"id":"login","description":"login to hub.chabokan.net account","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"username":{"name":"username","type":"option","char":"u","description":"your username"},"password":{"name":"password","type":"option","char":"p","description":"your password"},"token":{"name":"token","type":"option","char":"t","description":"login with api token"}},"args":[]},"logs":{"id":"logs","description":"read latest logs from service","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"service":{"name":"service","type":"option","char":"s","description":"service name"}},"args":[]},"resize":{"id":"resize","description":"resize a service","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"service":{"name":"service","type":"option","char":"s","description":"service name"},"ram":{"name":"ram","type":"option","char":"r","description":"RAM"},"cpu":{"name":"cpu","type":"option","char":"c","description":"CPU"},"disk":{"name":"disk","type":"option","char":"d","description":"DISK"}},"args":[]},"restart":{"id":"restart","description":"restart a service","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"service":{"name":"service","type":"option","char":"s","description":"service name"}},"args":[]},"start":{"id":"start","description":"start a service","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"service":{"name":"service","type":"option","char":"s","description":"service name"}},"args":[]},"stop":{"id":"stop","description":"stop a service","pluginName":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"service":{"name":"service","type":"option","char":"s","description":"service name"}},"args":[]}}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chabokan.net/cli",
3
3
  "description": "Chabokan Cli for PaaS Services",
4
- "version": "0.3.0",
4
+ "version": "0.7.1",
5
5
  "author": "Mohammad Abdi",
6
6
  "bin": {
7
7
  "chabok": "./bin/run"
@@ -14,6 +14,7 @@
14
14
  "@types/fs-extra": "^5.0.5",
15
15
  "@types/mocha": "^5.2.7",
16
16
  "@types/node": "^10.17.60",
17
+ "@types/progress": "^2.0.4",
17
18
  "@types/tar": "^4.0.5",
18
19
  "chai": "^4.3.4",
19
20
  "globby": "^10.0.2",
@@ -33,7 +34,10 @@
33
34
  ],
34
35
  "homepage": "https://github.com/chabokan/cli",
35
36
  "keywords": [
36
- "oclif"
37
+ "chabokan",
38
+ "paas",
39
+ "hosting",
40
+ "cloud"
37
41
  ],
38
42
  "license": "MIT",
39
43
  "main": "lib/index.js",
@@ -61,12 +65,15 @@
61
65
  "axios": "^0.21.1",
62
66
  "chalk": "^2.4.2",
63
67
  "cli-ux": "^5.6.3",
68
+ "form-data": "^4.0.0",
64
69
  "fs-extra": "^7.0.1",
65
70
  "got": "^11.8.2",
66
71
  "https-proxy-agent": "^5.0.0",
67
72
  "ignore": "^5.1.8",
68
73
  "inquirer": "^6.5.2",
74
+ "progress": "^2.0.3",
69
75
  "tar": "^6.1.2",
70
- "tslib": "^1.14.1"
76
+ "tslib": "^1.14.1",
77
+ "proxy-http-agent": "latest"
71
78
  }
72
79
  }