@chabokan.net/cli 0.8.8 → 0.8.9
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 +215 -3
- package/dist/base.d.ts +15 -0
- package/dist/base.js +60 -0
- package/dist/commands/account/list.d.ts +8 -0
- package/dist/commands/account/list.js +28 -0
- package/dist/commands/account/remove.d.ts +8 -0
- package/dist/commands/account/remove.js +34 -0
- package/dist/commands/account/use.d.ts +9 -0
- package/dist/commands/account/use.js +41 -0
- package/dist/commands/deploy.d.ts +15 -0
- package/dist/commands/deploy.js +173 -0
- package/dist/commands/login.d.ts +11 -0
- package/dist/commands/login.js +91 -0
- package/dist/commands/service/list.d.ts +8 -0
- package/dist/commands/service/list.js +32 -0
- package/dist/commands/service/logs.d.ts +10 -0
- package/dist/commands/service/logs.js +59 -0
- package/dist/commands/service/resize.d.ts +13 -0
- package/dist/commands/service/resize.js +130 -0
- package/dist/commands/service/restart.d.ts +10 -0
- package/dist/commands/service/restart.js +57 -0
- package/dist/commands/service/start.d.ts +10 -0
- package/dist/commands/service/start.js +55 -0
- package/dist/commands/service/stop.d.ts +10 -0
- package/dist/commands/service/stop.js +55 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +7 -0
- package/dist/helper.d.ts +12 -0
- package/dist/helper.js +113 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/oclif.manifest.json +432 -2
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ $ npm install -g @chabokan.net/cli
|
|
|
20
20
|
$ chabok COMMAND
|
|
21
21
|
running command...
|
|
22
22
|
$ chabok (--version|-v)
|
|
23
|
-
@chabokan.net/cli/0.8.
|
|
23
|
+
@chabokan.net/cli/0.8.9 darwin-arm64 node-v20.13.1
|
|
24
24
|
$ chabok --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ chabok COMMAND
|
|
@@ -29,8 +29,13 @@ USAGE
|
|
|
29
29
|
<!-- usagestop -->
|
|
30
30
|
# Commands
|
|
31
31
|
<!-- commands -->
|
|
32
|
+
* [`chabok account list`](#chabok-account-list)
|
|
33
|
+
* [`chabok account remove`](#chabok-account-remove)
|
|
34
|
+
* [`chabok account use`](#chabok-account-use)
|
|
32
35
|
* [`chabok autocomplete [SHELL]`](#chabok-autocomplete-shell)
|
|
36
|
+
* [`chabok deploy`](#chabok-deploy)
|
|
33
37
|
* [`chabok help [COMMAND]`](#chabok-help-command)
|
|
38
|
+
* [`chabok login`](#chabok-login)
|
|
34
39
|
* [`chabok plugins`](#chabok-plugins)
|
|
35
40
|
* [`chabok plugins add PLUGIN`](#chabok-plugins-add-plugin)
|
|
36
41
|
* [`chabok plugins:inspect PLUGIN...`](#chabok-pluginsinspect-plugin)
|
|
@@ -41,8 +46,66 @@ USAGE
|
|
|
41
46
|
* [`chabok plugins uninstall [PLUGIN]`](#chabok-plugins-uninstall-plugin)
|
|
42
47
|
* [`chabok plugins unlink [PLUGIN]`](#chabok-plugins-unlink-plugin)
|
|
43
48
|
* [`chabok plugins update`](#chabok-plugins-update)
|
|
49
|
+
* [`chabok service list`](#chabok-service-list)
|
|
50
|
+
* [`chabok service logs`](#chabok-service-logs)
|
|
51
|
+
* [`chabok service resize`](#chabok-service-resize)
|
|
52
|
+
* [`chabok service restart`](#chabok-service-restart)
|
|
53
|
+
* [`chabok service start`](#chabok-service-start)
|
|
54
|
+
* [`chabok service stop`](#chabok-service-stop)
|
|
44
55
|
* [`chabok version`](#chabok-version)
|
|
45
56
|
|
|
57
|
+
## `chabok account list`
|
|
58
|
+
|
|
59
|
+
show accounts list
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
USAGE
|
|
63
|
+
$ chabok account list [-h]
|
|
64
|
+
|
|
65
|
+
FLAGS
|
|
66
|
+
-h, --help Show CLI help.
|
|
67
|
+
|
|
68
|
+
DESCRIPTION
|
|
69
|
+
show accounts list
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
_See code: [src/commands/account/list.ts](https://github.com/chabokan/cli/blob/v0.8.9/src/commands/account/list.ts)_
|
|
73
|
+
|
|
74
|
+
## `chabok account remove`
|
|
75
|
+
|
|
76
|
+
remove account from list
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
USAGE
|
|
80
|
+
$ chabok account remove [-h]
|
|
81
|
+
|
|
82
|
+
FLAGS
|
|
83
|
+
-h, --help Show CLI help.
|
|
84
|
+
|
|
85
|
+
DESCRIPTION
|
|
86
|
+
remove account from list
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
_See code: [src/commands/account/remove.ts](https://github.com/chabokan/cli/blob/v0.8.9/src/commands/account/remove.ts)_
|
|
90
|
+
|
|
91
|
+
## `chabok account use`
|
|
92
|
+
|
|
93
|
+
switch your default user between logged in users
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
USAGE
|
|
97
|
+
$ chabok account use [-h] [-u <value>]
|
|
98
|
+
|
|
99
|
+
FLAGS
|
|
100
|
+
-h, --help Show CLI help.
|
|
101
|
+
-u, --user=<value> default user
|
|
102
|
+
|
|
103
|
+
DESCRIPTION
|
|
104
|
+
switch your default user between logged in users
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
_See code: [src/commands/account/use.ts](https://github.com/chabokan/cli/blob/v0.8.9/src/commands/account/use.ts)_
|
|
108
|
+
|
|
46
109
|
## `chabok autocomplete [SHELL]`
|
|
47
110
|
|
|
48
111
|
Display autocomplete installation instructions.
|
|
@@ -74,6 +137,25 @@ EXAMPLES
|
|
|
74
137
|
|
|
75
138
|
_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v3.0.18/src/commands/autocomplete/index.ts)_
|
|
76
139
|
|
|
140
|
+
## `chabok deploy`
|
|
141
|
+
|
|
142
|
+
this command help you build and deploy your service to chabokan in easy way.
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
USAGE
|
|
146
|
+
$ chabok deploy [-h] [-p <value>] [-s <value>]
|
|
147
|
+
|
|
148
|
+
FLAGS
|
|
149
|
+
-h, --help Show CLI help.
|
|
150
|
+
-p, --path=<value> service path in your computer
|
|
151
|
+
-s, --service=<value> service name
|
|
152
|
+
|
|
153
|
+
DESCRIPTION
|
|
154
|
+
this command help you build and deploy your service to chabokan in easy way.
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
_See code: [src/commands/deploy.ts](https://github.com/chabokan/cli/blob/v0.8.9/src/commands/deploy.ts)_
|
|
158
|
+
|
|
77
159
|
## `chabok help [COMMAND]`
|
|
78
160
|
|
|
79
161
|
Display help for chabok.
|
|
@@ -94,6 +176,26 @@ DESCRIPTION
|
|
|
94
176
|
|
|
95
177
|
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.0.22/src/commands/help.ts)_
|
|
96
178
|
|
|
179
|
+
## `chabok login`
|
|
180
|
+
|
|
181
|
+
login to hub.chabokan.net account
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
USAGE
|
|
185
|
+
$ chabok login [-h] [-u <value>] [-p <value>] [-t <value>]
|
|
186
|
+
|
|
187
|
+
FLAGS
|
|
188
|
+
-h, --help Show CLI help.
|
|
189
|
+
-p, --password=<value> your password
|
|
190
|
+
-t, --token=<value> login with api token
|
|
191
|
+
-u, --username=<value> your username
|
|
192
|
+
|
|
193
|
+
DESCRIPTION
|
|
194
|
+
login to hub.chabokan.net account
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
_See code: [src/commands/login.ts](https://github.com/chabokan/cli/blob/v0.8.9/src/commands/login.ts)_
|
|
198
|
+
|
|
97
199
|
## `chabok plugins`
|
|
98
200
|
|
|
99
201
|
List installed plugins.
|
|
@@ -140,7 +242,7 @@ GLOBAL FLAGS
|
|
|
140
242
|
DESCRIPTION
|
|
141
243
|
Installs a plugin into chabok.
|
|
142
244
|
|
|
143
|
-
Uses bundled npm executable to install plugins into /Users/mohammad/.local/share
|
|
245
|
+
Uses bundled npm executable to install plugins into /Users/mohammad/.local/share/cli
|
|
144
246
|
|
|
145
247
|
Installation of a user-installed plugin will override a core plugin.
|
|
146
248
|
|
|
@@ -214,7 +316,7 @@ GLOBAL FLAGS
|
|
|
214
316
|
DESCRIPTION
|
|
215
317
|
Installs a plugin into chabok.
|
|
216
318
|
|
|
217
|
-
Uses bundled npm executable to install plugins into /Users/mohammad/.local/share
|
|
319
|
+
Uses bundled npm executable to install plugins into /Users/mohammad/.local/share/cli
|
|
218
320
|
|
|
219
321
|
Installation of a user-installed plugin will override a core plugin.
|
|
220
322
|
|
|
@@ -383,6 +485,116 @@ DESCRIPTION
|
|
|
383
485
|
|
|
384
486
|
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.3/src/commands/plugins/update.ts)_
|
|
385
487
|
|
|
488
|
+
## `chabok service list`
|
|
489
|
+
|
|
490
|
+
show account services list
|
|
491
|
+
|
|
492
|
+
```
|
|
493
|
+
USAGE
|
|
494
|
+
$ chabok service list [-h]
|
|
495
|
+
|
|
496
|
+
FLAGS
|
|
497
|
+
-h, --help Show CLI help.
|
|
498
|
+
|
|
499
|
+
DESCRIPTION
|
|
500
|
+
show account services list
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
_See code: [src/commands/service/list.ts](https://github.com/chabokan/cli/blob/v0.8.9/src/commands/service/list.ts)_
|
|
504
|
+
|
|
505
|
+
## `chabok service logs`
|
|
506
|
+
|
|
507
|
+
read latest logs from service
|
|
508
|
+
|
|
509
|
+
```
|
|
510
|
+
USAGE
|
|
511
|
+
$ chabok service logs [-h] [-s <value>]
|
|
512
|
+
|
|
513
|
+
FLAGS
|
|
514
|
+
-h, --help Show CLI help.
|
|
515
|
+
-s, --service=<value> service name
|
|
516
|
+
|
|
517
|
+
DESCRIPTION
|
|
518
|
+
read latest logs from service
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
_See code: [src/commands/service/logs.ts](https://github.com/chabokan/cli/blob/v0.8.9/src/commands/service/logs.ts)_
|
|
522
|
+
|
|
523
|
+
## `chabok service resize`
|
|
524
|
+
|
|
525
|
+
resize a service
|
|
526
|
+
|
|
527
|
+
```
|
|
528
|
+
USAGE
|
|
529
|
+
$ chabok service resize [-h] [-s <value>] [-r <value>] [-c <value>] [-d <value>]
|
|
530
|
+
|
|
531
|
+
FLAGS
|
|
532
|
+
-c, --cpu=<value> CPU
|
|
533
|
+
-d, --disk=<value> DISK
|
|
534
|
+
-h, --help Show CLI help.
|
|
535
|
+
-r, --ram=<value> RAM
|
|
536
|
+
-s, --service=<value> service name
|
|
537
|
+
|
|
538
|
+
DESCRIPTION
|
|
539
|
+
resize a service
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
_See code: [src/commands/service/resize.ts](https://github.com/chabokan/cli/blob/v0.8.9/src/commands/service/resize.ts)_
|
|
543
|
+
|
|
544
|
+
## `chabok service restart`
|
|
545
|
+
|
|
546
|
+
restart a service
|
|
547
|
+
|
|
548
|
+
```
|
|
549
|
+
USAGE
|
|
550
|
+
$ chabok service restart [-h] [-s <value>]
|
|
551
|
+
|
|
552
|
+
FLAGS
|
|
553
|
+
-h, --help Show CLI help.
|
|
554
|
+
-s, --service=<value> service name
|
|
555
|
+
|
|
556
|
+
DESCRIPTION
|
|
557
|
+
restart a service
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
_See code: [src/commands/service/restart.ts](https://github.com/chabokan/cli/blob/v0.8.9/src/commands/service/restart.ts)_
|
|
561
|
+
|
|
562
|
+
## `chabok service start`
|
|
563
|
+
|
|
564
|
+
start a service
|
|
565
|
+
|
|
566
|
+
```
|
|
567
|
+
USAGE
|
|
568
|
+
$ chabok service start [-h] [-s <value>]
|
|
569
|
+
|
|
570
|
+
FLAGS
|
|
571
|
+
-h, --help Show CLI help.
|
|
572
|
+
-s, --service=<value> service name
|
|
573
|
+
|
|
574
|
+
DESCRIPTION
|
|
575
|
+
start a service
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
_See code: [src/commands/service/start.ts](https://github.com/chabokan/cli/blob/v0.8.9/src/commands/service/start.ts)_
|
|
579
|
+
|
|
580
|
+
## `chabok service stop`
|
|
581
|
+
|
|
582
|
+
stop a service
|
|
583
|
+
|
|
584
|
+
```
|
|
585
|
+
USAGE
|
|
586
|
+
$ chabok service stop [-h] [-s <value>]
|
|
587
|
+
|
|
588
|
+
FLAGS
|
|
589
|
+
-h, --help Show CLI help.
|
|
590
|
+
-s, --service=<value> service name
|
|
591
|
+
|
|
592
|
+
DESCRIPTION
|
|
593
|
+
stop a service
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
_See code: [src/commands/service/stop.ts](https://github.com/chabokan/cli/blob/v0.8.9/src/commands/service/stop.ts)_
|
|
597
|
+
|
|
386
598
|
## `chabok version`
|
|
387
599
|
|
|
388
600
|
```
|
package/dist/base.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default abstract class extends Command {
|
|
3
|
+
static flags: {
|
|
4
|
+
help: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<void>;
|
|
5
|
+
};
|
|
6
|
+
axiosConfig: any;
|
|
7
|
+
got: import("got").Got;
|
|
8
|
+
read_config(): Promise<{
|
|
9
|
+
users: {};
|
|
10
|
+
default_user: string;
|
|
11
|
+
}>;
|
|
12
|
+
write_config(object: any): Promise<void>;
|
|
13
|
+
get_services(filter?: {}): Promise<any>;
|
|
14
|
+
init_run(): Promise<void>;
|
|
15
|
+
}
|
package/dist/base.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Command, Flags } from '@oclif/core';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { BASE_API_URL, GLOBAL_CONF_PATH } from './constants.js';
|
|
4
|
+
import { checkUpdate, get_all_services, isEmptyObject, read_config_file } from './helper.js';
|
|
5
|
+
import HttpsProxyAgent from 'https-proxy-agent';
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import got from 'got';
|
|
8
|
+
import * as https from 'https';
|
|
9
|
+
export default class default_1 extends Command {
|
|
10
|
+
static flags = {
|
|
11
|
+
help: Flags.help({ char: 'h' }),
|
|
12
|
+
};
|
|
13
|
+
axiosConfig = {
|
|
14
|
+
...axios.defaults
|
|
15
|
+
};
|
|
16
|
+
got = got.extend();
|
|
17
|
+
async read_config() {
|
|
18
|
+
return read_config_file();
|
|
19
|
+
}
|
|
20
|
+
async write_config(object) {
|
|
21
|
+
fs.writeFileSync(GLOBAL_CONF_PATH, JSON.stringify(object));
|
|
22
|
+
}
|
|
23
|
+
async get_services(filter = {}) {
|
|
24
|
+
return await get_all_services(filter, this.axiosConfig);
|
|
25
|
+
}
|
|
26
|
+
async init_run() {
|
|
27
|
+
await checkUpdate(this.config.version);
|
|
28
|
+
const main_agent = new https.Agent({
|
|
29
|
+
rejectUnauthorized: false
|
|
30
|
+
});
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
const gotConfig = {};
|
|
33
|
+
this.axiosConfig.httpsAgent = main_agent;
|
|
34
|
+
this.axiosConfig.baseURL = BASE_API_URL;
|
|
35
|
+
gotConfig.prefixUrl = this.axiosConfig.baseURL;
|
|
36
|
+
gotConfig.agent = { https: main_agent };
|
|
37
|
+
const proxy = process.env.http_proxy || process.env.https_proxy;
|
|
38
|
+
if (proxy) {
|
|
39
|
+
this.log(`Using proxy server ${proxy}`);
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
const agent = new HttpsProxyAgent(proxy);
|
|
42
|
+
this.axiosConfig.httpsAgent = agent;
|
|
43
|
+
this.axiosConfig.proxy = false;
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
gotConfig.agent = { https: agent };
|
|
46
|
+
}
|
|
47
|
+
const config_json = read_config_file();
|
|
48
|
+
this.got = got.extend(gotConfig);
|
|
49
|
+
if (isEmptyObject(config_json) || isEmptyObject(config_json.users)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
const token = config_json.users[config_json.default_user]["token"] || null;
|
|
54
|
+
if (token) {
|
|
55
|
+
this.axiosConfig.headers.Authorization = `Token ${token}`;
|
|
56
|
+
gotConfig.headers = { Authorization: `Token ${token}` };
|
|
57
|
+
}
|
|
58
|
+
this.got = got.extend(gotConfig);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import Command from "../../base.js";
|
|
2
|
+
import { ux } from "@oclif/core";
|
|
3
|
+
export default class AccountList extends Command {
|
|
4
|
+
static description = "show accounts list";
|
|
5
|
+
static flags = {
|
|
6
|
+
...Command.flags,
|
|
7
|
+
};
|
|
8
|
+
async run() {
|
|
9
|
+
const { args, flags } = await this.parse(AccountList);
|
|
10
|
+
const cli = this;
|
|
11
|
+
await this.init_run();
|
|
12
|
+
const config_json = await this.read_config();
|
|
13
|
+
if (Object.keys(config_json.users).length > 0) {
|
|
14
|
+
const accounts_data = Object.keys(config_json.users).map((account) => {
|
|
15
|
+
return {
|
|
16
|
+
Name: account,
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
ux.table(accounts_data, {
|
|
20
|
+
Name: {},
|
|
21
|
+
}, flags);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
cli.log("first you should login");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { isEmptyObject, read_config_file } from "../../helper.js";
|
|
4
|
+
import Command from "../../base.js";
|
|
5
|
+
import { GLOBAL_CONF_PATH } from "../../constants.js";
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
export default class AccountRemove extends Command {
|
|
8
|
+
static description = "remove account from list";
|
|
9
|
+
static flags = {
|
|
10
|
+
...Command.flags,
|
|
11
|
+
};
|
|
12
|
+
async run() {
|
|
13
|
+
const cli = this;
|
|
14
|
+
const { args, flags } = await this.parse(AccountRemove);
|
|
15
|
+
const config_json = read_config_file();
|
|
16
|
+
if (isEmptyObject(config_json.users)) {
|
|
17
|
+
cli.log(`${chalk.red("[Error]")} first you should login!`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
let { user } = await inquirer.prompt({
|
|
21
|
+
type: "list",
|
|
22
|
+
message: "Please select a user:",
|
|
23
|
+
name: "user",
|
|
24
|
+
choices: Object.keys(config_json.users),
|
|
25
|
+
});
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
delete config_json.users[user];
|
|
28
|
+
if (config_json["default_user"] == user) {
|
|
29
|
+
config_json["default_user"] = "";
|
|
30
|
+
}
|
|
31
|
+
fs.writeFileSync(GLOBAL_CONF_PATH, JSON.stringify(config_json));
|
|
32
|
+
cli.log(`${chalk.green("[Success]")} user deleted successfully.`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Command from "../../base.js";
|
|
2
|
+
export default class AccountUse extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
user: 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
|
+
};
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
import * as fs from "fs";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import { isEmptyObject, read_config_file } from "../../helper.js";
|
|
6
|
+
import Command from "../../base.js";
|
|
7
|
+
import { GLOBAL_CONF_PATH } from "../../constants.js";
|
|
8
|
+
export default class AccountUse extends Command {
|
|
9
|
+
static description = "switch your default user between logged in users";
|
|
10
|
+
static flags = {
|
|
11
|
+
...Command.flags,
|
|
12
|
+
user: Flags.string({ char: "u", description: "default user" }),
|
|
13
|
+
};
|
|
14
|
+
async run() {
|
|
15
|
+
const cli = this;
|
|
16
|
+
const { args, flags } = await this.parse(AccountUse);
|
|
17
|
+
const config_json = read_config_file();
|
|
18
|
+
let default_user = flags.user;
|
|
19
|
+
if (isEmptyObject(config_json.users)) {
|
|
20
|
+
cli.log(`${chalk.red("[Error]")} first you should login!`);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!flags.user) {
|
|
24
|
+
let { user } = await inquirer.prompt({
|
|
25
|
+
type: "list",
|
|
26
|
+
message: "Please select a user:",
|
|
27
|
+
name: "user",
|
|
28
|
+
choices: Object.keys(config_json.users),
|
|
29
|
+
});
|
|
30
|
+
default_user = user;
|
|
31
|
+
}
|
|
32
|
+
if (default_user in config_json.users) {
|
|
33
|
+
config_json["default_user"] = default_user;
|
|
34
|
+
fs.writeFileSync(GLOBAL_CONF_PATH, JSON.stringify(config_json));
|
|
35
|
+
cli.log(`${chalk.green("[Success]")} user changed successfully.`);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
cli.log(`${chalk.red("[Error]")} selected user not exist!`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Command from "../base.js";
|
|
2
|
+
export default class Deploy extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
path: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
6
|
+
service: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
+
help: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<void>;
|
|
8
|
+
};
|
|
9
|
+
run(): Promise<void>;
|
|
10
|
+
prepare_archive(project_path: any): Promise<string>;
|
|
11
|
+
upload(archive_path: any, selected_service: any, cli: any, chabok_file: any): Promise<{
|
|
12
|
+
success: boolean;
|
|
13
|
+
message: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
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';
|
|
14
|
+
const MAX_SOURCE_SIZE = 100 * 1024 * 1024; // 100 MB
|
|
15
|
+
export default class Deploy extends Command {
|
|
16
|
+
static description = "this command help you build and deploy your service to chabokan in easy way.";
|
|
17
|
+
static flags = {
|
|
18
|
+
...Command.flags,
|
|
19
|
+
path: Flags.string({
|
|
20
|
+
char: "p",
|
|
21
|
+
description: "service path in your computer",
|
|
22
|
+
}),
|
|
23
|
+
service: Flags.string({ char: "s", description: "service name" }),
|
|
24
|
+
};
|
|
25
|
+
async run() {
|
|
26
|
+
const { args, flags } = await this.parse(Deploy);
|
|
27
|
+
const cli = this;
|
|
28
|
+
await this.init_run();
|
|
29
|
+
const config_json = await this.read_config();
|
|
30
|
+
let selected_service = flags.service;
|
|
31
|
+
let project_path = flags.path ? flags.path : process.cwd();
|
|
32
|
+
let chabok_file = { service: "" };
|
|
33
|
+
try {
|
|
34
|
+
chabok_file =
|
|
35
|
+
JSON.parse(fs
|
|
36
|
+
.readFileSync(path.join(project_path, "chabok.json"))
|
|
37
|
+
.toString("utf-8")) || {};
|
|
38
|
+
cli.log("Reading Config from chabok.json ...");
|
|
39
|
+
}
|
|
40
|
+
catch { }
|
|
41
|
+
if (chabok_file.service) {
|
|
42
|
+
selected_service = chabok_file.service;
|
|
43
|
+
}
|
|
44
|
+
if (isEmptyObject(config_json.users)) {
|
|
45
|
+
cli.log(`${chalk.red("[Error]")} first you should login!`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (!selected_service) {
|
|
49
|
+
let all_services = await this.get_services({
|
|
50
|
+
has_deploy: "true",
|
|
51
|
+
status: "on",
|
|
52
|
+
});
|
|
53
|
+
if (all_services.length > 0) {
|
|
54
|
+
let { service } = await inquirer.prompt({
|
|
55
|
+
type: "list",
|
|
56
|
+
message: "Please select a service:",
|
|
57
|
+
name: "service",
|
|
58
|
+
choices: all_services,
|
|
59
|
+
});
|
|
60
|
+
selected_service = service;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
cli.log("first you should create service");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
let archive_path = await this.prepare_archive(project_path);
|
|
68
|
+
let upload_response = await this.upload(archive_path, selected_service, cli, chabok_file);
|
|
69
|
+
if (upload_response.success) {
|
|
70
|
+
cli.log(chalk.green(upload_response.message));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
cli.log(chalk.red("[Error] " + upload_response.message));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async prepare_archive(project_path) {
|
|
77
|
+
const defaultIgnores = [
|
|
78
|
+
".npm",
|
|
79
|
+
".git",
|
|
80
|
+
".idea",
|
|
81
|
+
".DS_Store",
|
|
82
|
+
".vscode",
|
|
83
|
+
"__pycache__",
|
|
84
|
+
".next",
|
|
85
|
+
".nuxt",
|
|
86
|
+
"*.*~",
|
|
87
|
+
"node_modules",
|
|
88
|
+
"bower_components",
|
|
89
|
+
"venv",
|
|
90
|
+
"/vendor",
|
|
91
|
+
"*.log",
|
|
92
|
+
];
|
|
93
|
+
const ignoreCache = {};
|
|
94
|
+
const ignoreInstance = ignore.default({ ignorecase: false });
|
|
95
|
+
ignoreInstance.add(defaultIgnores);
|
|
96
|
+
const ignoreFN = (f) => {
|
|
97
|
+
const dir = dirname(f);
|
|
98
|
+
if (!ignoreCache[dir]) {
|
|
99
|
+
addIgnorePatterns(ignoreInstance, project_path, dir);
|
|
100
|
+
ignoreCache[dir] = true;
|
|
101
|
+
}
|
|
102
|
+
if (!ignoreInstance.ignores(f)) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
console.log(`ignoring ${f}`);
|
|
106
|
+
return false;
|
|
107
|
+
};
|
|
108
|
+
const tmpDir = path.join(os.tmpdir(), "/chabok-cli");
|
|
109
|
+
const archivePath = path.join(tmpDir, `${Date.now()}.tar.gz`);
|
|
110
|
+
fs.ensureDirSync(tmpDir);
|
|
111
|
+
const fileList = fs.readdirSync(project_path).filter(ignoreFN);
|
|
112
|
+
tar.c({
|
|
113
|
+
gzip: {
|
|
114
|
+
level: 9,
|
|
115
|
+
},
|
|
116
|
+
sync: true,
|
|
117
|
+
cwd: project_path,
|
|
118
|
+
filter: ignoreFN,
|
|
119
|
+
file: archivePath,
|
|
120
|
+
}, fileList);
|
|
121
|
+
return archivePath;
|
|
122
|
+
}
|
|
123
|
+
async upload(archive_path, selected_service, cli, chabok_file) {
|
|
124
|
+
let upload_response = {
|
|
125
|
+
success: false,
|
|
126
|
+
message: "some problem",
|
|
127
|
+
};
|
|
128
|
+
const body = new FormData();
|
|
129
|
+
// @ts-ignore
|
|
130
|
+
body.append("file", fs.createReadStream(archive_path));
|
|
131
|
+
body.append("options", JSON.stringify(chabok_file));
|
|
132
|
+
const { size: sourceSize } = fs.statSync(archive_path);
|
|
133
|
+
if (sourceSize > MAX_SOURCE_SIZE) {
|
|
134
|
+
upload_response.message = "Source is too large. (max: 100MB)";
|
|
135
|
+
return upload_response;
|
|
136
|
+
}
|
|
137
|
+
const bar = new ProgressBar("Uploading [:bar] :percent :etas", {
|
|
138
|
+
total: sourceSize,
|
|
139
|
+
width: 20,
|
|
140
|
+
complete: "=",
|
|
141
|
+
incomplete: "",
|
|
142
|
+
clear: true,
|
|
143
|
+
});
|
|
144
|
+
try {
|
|
145
|
+
const response = await this.got
|
|
146
|
+
.post(`services/${selected_service}/deploy/`, { body })
|
|
147
|
+
.on("uploadProgress", (progress) => {
|
|
148
|
+
bar.tick(progress.transferred - bar.curr);
|
|
149
|
+
})
|
|
150
|
+
.json();
|
|
151
|
+
if (response.success) {
|
|
152
|
+
upload_response.success = true;
|
|
153
|
+
upload_response.message = "Deployment finished successfully.";
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
if (process.env.CHABOK_DEBUG == "true") {
|
|
157
|
+
cli.log(response);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return upload_response;
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
if (process.env.CHABOK_DEBUG == "true") {
|
|
164
|
+
cli.log(error);
|
|
165
|
+
}
|
|
166
|
+
return upload_response;
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
// cleanup
|
|
170
|
+
fs.unlink(archive_path).catch(() => { });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Command from "../base.js";
|
|
2
|
+
export default class Login extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
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
|
+
};
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|