@chabokan.net/cli 0.6.0 → 0.7.3

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.6.0 darwin-x64 node-v14.17.5
22
+ @chabokan.net/cli/0.7.3 darwin-x64 node-v14.17.5
23
23
  $ chabok --help [COMMAND]
24
24
  USAGE
25
25
  $ chabok COMMAND
@@ -34,6 +34,7 @@ USAGE
34
34
  * [`chabok help [COMMAND]`](#chabok-help-command)
35
35
  * [`chabok login`](#chabok-login)
36
36
  * [`chabok logs`](#chabok-logs)
37
+ * [`chabok resize`](#chabok-resize)
37
38
  * [`chabok restart`](#chabok-restart)
38
39
  * [`chabok start`](#chabok-start)
39
40
  * [`chabok stop`](#chabok-stop)
@@ -51,7 +52,7 @@ OPTIONS
51
52
  -u, --user=user default user
52
53
  ```
53
54
 
54
- _See code: [src/commands/change-user.ts](https://github.com/chabokan/cli/blob/v0.6.0/src/commands/change-user.ts)_
55
+ _See code: [src/commands/change-user.ts](https://github.com/chabokan/cli/blob/v0.7.3/src/commands/change-user.ts)_
55
56
 
56
57
  ## `chabok config-clear`
57
58
 
@@ -65,7 +66,7 @@ OPTIONS
65
66
  -h, --help show CLI help
66
67
  ```
67
68
 
68
- _See code: [src/commands/config-clear.ts](https://github.com/chabokan/cli/blob/v0.6.0/src/commands/config-clear.ts)_
69
+ _See code: [src/commands/config-clear.ts](https://github.com/chabokan/cli/blob/v0.7.3/src/commands/config-clear.ts)_
69
70
 
70
71
  ## `chabok deploy`
71
72
 
@@ -81,7 +82,7 @@ OPTIONS
81
82
  -s, --service=service service name
82
83
  ```
83
84
 
84
- _See code: [src/commands/deploy.ts](https://github.com/chabokan/cli/blob/v0.6.0/src/commands/deploy.ts)_
85
+ _See code: [src/commands/deploy.ts](https://github.com/chabokan/cli/blob/v0.7.3/src/commands/deploy.ts)_
85
86
 
86
87
  ## `chabok help [COMMAND]`
87
88
 
@@ -115,7 +116,7 @@ OPTIONS
115
116
  -u, --username=username your username
116
117
  ```
117
118
 
118
- _See code: [src/commands/login.ts](https://github.com/chabokan/cli/blob/v0.6.0/src/commands/login.ts)_
119
+ _See code: [src/commands/login.ts](https://github.com/chabokan/cli/blob/v0.7.3/src/commands/login.ts)_
119
120
 
120
121
  ## `chabok logs`
121
122
 
@@ -130,7 +131,25 @@ OPTIONS
130
131
  -s, --service=service service name
131
132
  ```
132
133
 
133
- _See code: [src/commands/logs.ts](https://github.com/chabokan/cli/blob/v0.6.0/src/commands/logs.ts)_
134
+ _See code: [src/commands/logs.ts](https://github.com/chabokan/cli/blob/v0.7.3/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.3/src/commands/resize.ts)_
134
153
 
135
154
  ## `chabok restart`
136
155
 
@@ -145,7 +164,7 @@ OPTIONS
145
164
  -s, --service=service service name
146
165
  ```
147
166
 
148
- _See code: [src/commands/restart.ts](https://github.com/chabokan/cli/blob/v0.6.0/src/commands/restart.ts)_
167
+ _See code: [src/commands/restart.ts](https://github.com/chabokan/cli/blob/v0.7.3/src/commands/restart.ts)_
149
168
 
150
169
  ## `chabok start`
151
170
 
@@ -160,7 +179,7 @@ OPTIONS
160
179
  -s, --service=service service name
161
180
  ```
162
181
 
163
- _See code: [src/commands/start.ts](https://github.com/chabokan/cli/blob/v0.6.0/src/commands/start.ts)_
182
+ _See code: [src/commands/start.ts](https://github.com/chabokan/cli/blob/v0.7.3/src/commands/start.ts)_
164
183
 
165
184
  ## `chabok stop`
166
185
 
@@ -175,5 +194,5 @@ OPTIONS
175
194
  -s, --service=service service name
176
195
  ```
177
196
 
178
- _See code: [src/commands/stop.ts](https://github.com/chabokan/cli/blob/v0.6.0/src/commands/stop.ts)_
197
+ _See code: [src/commands/stop.ts](https://github.com/chabokan/cli/blob/v0.7.3/src/commands/stop.ts)_
179
198
  <!-- commandsstop -->
package/lib/base.js CHANGED
@@ -5,9 +5,10 @@ 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
+ const https = tslib_1.__importStar(require("https"));
11
12
  class default_1 extends command_1.default {
12
13
  constructor() {
13
14
  super(...arguments);
@@ -24,16 +25,25 @@ class default_1 extends command_1.default {
24
25
  return await helper_1.get_all_services(filter, this.axiosConfig);
25
26
  }
26
27
  init_run() {
27
- const gotConfig = {};
28
+ const main_agent = new https.Agent({
29
+ rejectUnauthorized: false
30
+ });
31
+ // @ts-ignore
32
+ const gotConfig = { https: main_agent };
33
+ this.axiosConfig.httpsAgent = main_agent;
28
34
  this.axiosConfig.baseURL = constants_1.BASE_API_URL;
29
35
  gotConfig.prefixUrl = this.axiosConfig.baseURL;
30
36
  const proxy = process.env.http_proxy || process.env.https_proxy;
31
37
  if (proxy) {
32
38
  this.log(`Using proxy server ${proxy}`);
33
39
  // @ts-ignore
34
- const agent = new agent_1.default(proxy);
40
+ const agent = proxy_http_agent_1.getProxyHttpAgent({
41
+ proxy: proxy,
42
+ rejectUnauthorized: false
43
+ });
35
44
  this.axiosConfig.httpsAgent = agent;
36
45
  this.axiosConfig.proxy = false;
46
+ // @ts-ignore
37
47
  gotConfig.agent = { https: agent };
38
48
  }
39
49
  const config_json = helper_1.read_config_file();
@@ -9,7 +9,7 @@ export default class Deploy extends Command {
9
9
  };
10
10
  run(): Promise<void>;
11
11
  prepare_archive(project_path: any): Promise<string>;
12
- upload(archive_path: any, selected_service: any): Promise<{
12
+ upload(archive_path: any, selected_service: any, cli: any): Promise<{
13
13
  success: boolean;
14
14
  message: string;
15
15
  }>;
@@ -44,7 +44,7 @@ class Deploy extends base_1.default {
44
44
  }
45
45
  }
46
46
  let archive_path = await this.prepare_archive(project_path);
47
- let upload_response = await this.upload(archive_path, selected_service);
47
+ let upload_response = await this.upload(archive_path, selected_service, cli);
48
48
  if (upload_response.success) {
49
49
  cli.log(chalk_1.default.green(upload_response.message));
50
50
  }
@@ -94,7 +94,7 @@ class Deploy extends base_1.default {
94
94
  }, fileList);
95
95
  return archivePath;
96
96
  }
97
- async upload(archive_path, selected_service) {
97
+ async upload(archive_path, selected_service, cli) {
98
98
  let upload_response = {
99
99
  success: false,
100
100
  message: "some problem"
@@ -115,7 +115,7 @@ class Deploy extends base_1.default {
115
115
  clear: true,
116
116
  });
117
117
  try {
118
- const response = await this.got.post(`services/${selected_service}/deploy/`, { body })
118
+ const response = await this.got.post(`ervices/${selected_service}/deploy/`, { body })
119
119
  .on('uploadProgress', progress => {
120
120
  bar.tick(progress.transferred - bar.curr);
121
121
  }).json();
@@ -123,9 +123,17 @@ class Deploy extends base_1.default {
123
123
  upload_response.success = true;
124
124
  upload_response.message = "Deployment finished successfully.";
125
125
  }
126
+ else {
127
+ if (process.env.CHABOK_DEBUG == "true") {
128
+ cli.log(response);
129
+ }
130
+ }
126
131
  return upload_response;
127
132
  }
128
133
  catch (error) {
134
+ if (process.env.CHABOK_DEBUG == "true") {
135
+ cli.log(error);
136
+ }
129
137
  return upload_response;
130
138
  }
131
139
  finally {
@@ -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' }) });
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.6.0","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":[]},"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":[]}}}
1
+ {"version":"0.7.3","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.6.0",
4
+ "version": "0.7.3",
5
5
  "author": "Mohammad Abdi",
6
6
  "bin": {
7
7
  "chabok": "./bin/run"
@@ -34,7 +34,10 @@
34
34
  ],
35
35
  "homepage": "https://github.com/chabokan/cli",
36
36
  "keywords": [
37
- "oclif"
37
+ "chabokan",
38
+ "paas",
39
+ "hosting",
40
+ "cloud"
38
41
  ],
39
42
  "license": "MIT",
40
43
  "main": "lib/index.js",
@@ -70,6 +73,7 @@
70
73
  "inquirer": "^6.5.2",
71
74
  "progress": "^2.0.3",
72
75
  "tar": "^6.1.2",
73
- "tslib": "^1.14.1"
76
+ "tslib": "^1.14.1",
77
+ "proxy-http-agent": "latest"
74
78
  }
75
79
  }