@chabokan.net/cli 0.8.0 → 0.8.2
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 +6 -6
- package/lib/base.js +1 -0
- package/lib/commands/deploy.d.ts +1 -1
- package/lib/commands/deploy.js +15 -4
- package/lib/commands/login.d.ts +0 -3
- package/lib/commands/login.js +0 -1
- package/lib/constants.d.ts +1 -1
- package/lib/constants.js +1 -1
- package/lib/helper.d.ts +1 -0
- package/lib/helper.js +34 -4
- package/oclif.manifest.json +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ $ npm install -g @chabokan.net/cli
|
|
|
18
18
|
$ chabok COMMAND
|
|
19
19
|
running command...
|
|
20
20
|
$ chabok (--version|-v)
|
|
21
|
-
@chabokan.net/cli/0.8.
|
|
21
|
+
@chabokan.net/cli/0.8.2 darwin-x64 node-v14.17.5
|
|
22
22
|
$ chabok --help [COMMAND]
|
|
23
23
|
USAGE
|
|
24
24
|
$ chabok COMMAND
|
|
@@ -33,7 +33,7 @@ USAGE
|
|
|
33
33
|
* [`chabok autocomplete [SHELL]`](#chabok-autocomplete-shell)
|
|
34
34
|
* [`chabok deploy`](#chabok-deploy)
|
|
35
35
|
* [`chabok help [COMMAND]`](#chabok-help-command)
|
|
36
|
-
* [`chabok login
|
|
36
|
+
* [`chabok login`](#chabok-login)
|
|
37
37
|
* [`chabok service list`](#chabok-service-list)
|
|
38
38
|
* [`chabok service logs`](#chabok-service-logs)
|
|
39
39
|
* [`chabok service resize`](#chabok-service-resize)
|
|
@@ -134,7 +134,7 @@ DESCRIPTION
|
|
|
134
134
|
this command help you build and deploy your service to chabokan in easy way.
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
-
_See code: [src/commands/deploy.ts](https://github.com/chabokan/cli/blob/v0.8.
|
|
137
|
+
_See code: [src/commands/deploy.ts](https://github.com/chabokan/cli/blob/v0.8.2/src/commands/deploy.ts)_
|
|
138
138
|
|
|
139
139
|
## `chabok help [COMMAND]`
|
|
140
140
|
|
|
@@ -156,13 +156,13 @@ DESCRIPTION
|
|
|
156
156
|
|
|
157
157
|
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.1.15/src/commands/help.ts)_
|
|
158
158
|
|
|
159
|
-
## `chabok login
|
|
159
|
+
## `chabok login`
|
|
160
160
|
|
|
161
161
|
login to hub.chabokan.net account
|
|
162
162
|
|
|
163
163
|
```
|
|
164
164
|
USAGE
|
|
165
|
-
$ chabok login [
|
|
165
|
+
$ chabok login [-h] [-u <value>] [-p <value>] [-t <value>]
|
|
166
166
|
|
|
167
167
|
FLAGS
|
|
168
168
|
-h, --help Show CLI help.
|
|
@@ -174,7 +174,7 @@ DESCRIPTION
|
|
|
174
174
|
login to hub.chabokan.net account
|
|
175
175
|
```
|
|
176
176
|
|
|
177
|
-
_See code: [src/commands/login.ts](https://github.com/chabokan/cli/blob/v0.8.
|
|
177
|
+
_See code: [src/commands/login.ts](https://github.com/chabokan/cli/blob/v0.8.2/src/commands/login.ts)_
|
|
178
178
|
|
|
179
179
|
## `chabok service list`
|
|
180
180
|
|
package/lib/base.js
CHANGED
|
@@ -25,6 +25,7 @@ class default_1 extends core_1.Command {
|
|
|
25
25
|
return await (0, helper_1.get_all_services)(filter, this.axiosConfig);
|
|
26
26
|
}
|
|
27
27
|
async init_run() {
|
|
28
|
+
await (0, helper_1.checkUpdate)(this.config.version);
|
|
28
29
|
const main_agent = new https.Agent({
|
|
29
30
|
rejectUnauthorized: false
|
|
30
31
|
});
|
package/lib/commands/deploy.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export default class Deploy extends Command {
|
|
|
8
8
|
};
|
|
9
9
|
run(): Promise<void>;
|
|
10
10
|
prepare_archive(project_path: any): Promise<string>;
|
|
11
|
-
upload(archive_path: any, selected_service: any, cli: any): Promise<{
|
|
11
|
+
upload(archive_path: any, selected_service: any, cli: any, chabok_file: any): Promise<{
|
|
12
12
|
success: boolean;
|
|
13
13
|
message: string;
|
|
14
14
|
}>;
|
package/lib/commands/deploy.js
CHANGED
|
@@ -19,15 +19,25 @@ class Deploy extends base_1.default {
|
|
|
19
19
|
async run() {
|
|
20
20
|
const { args, flags } = await this.parse(Deploy);
|
|
21
21
|
const cli = this;
|
|
22
|
-
this.init_run();
|
|
22
|
+
await this.init_run();
|
|
23
23
|
const config_json = await this.read_config();
|
|
24
24
|
let selected_service = flags.service;
|
|
25
25
|
let project_path = flags.path ? flags.path : process.cwd();
|
|
26
|
+
let chabok_file = { service: "" };
|
|
27
|
+
try {
|
|
28
|
+
chabok_file = JSON.parse(fs_extra_1.default.readFileSync(path.join(project_path, 'chabok.json')).toString('utf-8')) || {};
|
|
29
|
+
cli.log("Reading Config from chabok.json ...");
|
|
30
|
+
}
|
|
31
|
+
catch (_a) {
|
|
32
|
+
}
|
|
33
|
+
if (chabok_file.service) {
|
|
34
|
+
selected_service = chabok_file.service;
|
|
35
|
+
}
|
|
26
36
|
if ((0, helper_1.isEmptyObject)(config_json.users)) {
|
|
27
37
|
cli.log(`${chalk_1.default.red('[Error]')} first you should login!`);
|
|
28
38
|
return;
|
|
29
39
|
}
|
|
30
|
-
if (!
|
|
40
|
+
if (!selected_service) {
|
|
31
41
|
let all_services = await this.get_services({ "has_deploy": "true", "status": "on" });
|
|
32
42
|
if (all_services.length > 0) {
|
|
33
43
|
let { service } = await inquirer_1.default.prompt({
|
|
@@ -44,7 +54,7 @@ class Deploy extends base_1.default {
|
|
|
44
54
|
}
|
|
45
55
|
}
|
|
46
56
|
let archive_path = await this.prepare_archive(project_path);
|
|
47
|
-
let upload_response = await this.upload(archive_path, selected_service, cli);
|
|
57
|
+
let upload_response = await this.upload(archive_path, selected_service, cli, chabok_file);
|
|
48
58
|
if (upload_response.success) {
|
|
49
59
|
cli.log(chalk_1.default.green(upload_response.message));
|
|
50
60
|
}
|
|
@@ -100,7 +110,7 @@ class Deploy extends base_1.default {
|
|
|
100
110
|
}, fileList);
|
|
101
111
|
return archivePath;
|
|
102
112
|
}
|
|
103
|
-
async upload(archive_path, selected_service, cli) {
|
|
113
|
+
async upload(archive_path, selected_service, cli, chabok_file) {
|
|
104
114
|
let upload_response = {
|
|
105
115
|
success: false,
|
|
106
116
|
message: "some problem"
|
|
@@ -108,6 +118,7 @@ class Deploy extends base_1.default {
|
|
|
108
118
|
const body = new form_data_1.default();
|
|
109
119
|
// @ts-ignore
|
|
110
120
|
body.append('file', fs_extra_1.default.createReadStream(archive_path));
|
|
121
|
+
body.append('options', JSON.stringify(chabok_file));
|
|
111
122
|
const { size: sourceSize } = fs_extra_1.default.statSync(archive_path);
|
|
112
123
|
if (sourceSize > MAX_SOURCE_SIZE) {
|
|
113
124
|
upload_response.message = "Source is too large. (max: 100MB)";
|
package/lib/commands/login.d.ts
CHANGED
package/lib/commands/login.js
CHANGED
|
@@ -84,4 +84,3 @@ class Login extends base_1.default {
|
|
|
84
84
|
exports.default = Login;
|
|
85
85
|
Login.description = 'login to hub.chabokan.net account';
|
|
86
86
|
Login.flags = Object.assign(Object.assign({}, base_1.default.flags), { username: core_1.Flags.string({ char: 'u', description: 'your username' }), password: core_1.Flags.string({ char: 'p', description: 'your password' }), token: core_1.Flags.string({ char: 't', description: 'login with api token' }) });
|
|
87
|
-
Login.args = [{ name: 'file' }];
|
package/lib/constants.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const GLOBAL_CONF_PATH: string;
|
|
2
|
-
export declare const BASE_API_URL = "https://
|
|
2
|
+
export declare const BASE_API_URL = "https://apihub.chabokan.net/fa/api/v1/";
|
package/lib/constants.js
CHANGED
|
@@ -5,4 +5,4 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const path = tslib_1.__importStar(require("path"));
|
|
6
6
|
const os = tslib_1.__importStar(require("os"));
|
|
7
7
|
exports.GLOBAL_CONF_PATH = path.join(os.homedir(), '.chabok.json');
|
|
8
|
-
exports.BASE_API_URL = 'https://
|
|
8
|
+
exports.BASE_API_URL = 'https://apihub.chabokan.net/fa/api/v1/';
|
package/lib/helper.d.ts
CHANGED
|
@@ -9,3 +9,4 @@ export declare function get_all_services(filter: {} | undefined, axiosConfig: an
|
|
|
9
9
|
export declare function trimLines(lines: string[]): string[];
|
|
10
10
|
export declare const loadIgnoreFile: (ignoreInstance: Ignore, ignoreFilePath: string, projectPath: string) => void;
|
|
11
11
|
export declare function addIgnorePatterns(ignoreInstance: Ignore, projectPath: string, dir: string): void;
|
|
12
|
+
export declare const checkUpdate: (version: any) => Promise<void>;
|
package/lib/helper.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addIgnorePatterns = exports.loadIgnoreFile = exports.trimLines = exports.get_all_services = exports.read_config_file = exports.isEmptyObject = exports.isObject = void 0;
|
|
3
|
+
exports.checkUpdate = exports.addIgnorePatterns = exports.loadIgnoreFile = exports.trimLines = exports.get_all_services = exports.read_config_file = exports.isEmptyObject = exports.isObject = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs = tslib_1.__importStar(require("fs"));
|
|
6
6
|
const constants_1 = require("./constants");
|
|
7
7
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
8
8
|
const path_1 = require("path");
|
|
9
|
+
const boxen_1 = tslib_1.__importDefault(require("boxen"));
|
|
10
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
11
|
+
const semver_1 = tslib_1.__importDefault(require("semver"));
|
|
12
|
+
const package_json_1 = tslib_1.__importDefault(require("package-json"));
|
|
13
|
+
const semver_diff_1 = tslib_1.__importDefault(require("semver-diff"));
|
|
9
14
|
function isObject(obj) {
|
|
10
15
|
return obj != null && obj.constructor.name === "Object";
|
|
11
16
|
}
|
|
@@ -79,11 +84,11 @@ const loadIgnoreFile = (ignoreInstance, ignoreFilePath, projectPath) => {
|
|
|
79
84
|
};
|
|
80
85
|
exports.loadIgnoreFile = loadIgnoreFile;
|
|
81
86
|
function addIgnorePatterns(ignoreInstance, projectPath, dir) {
|
|
82
|
-
const
|
|
87
|
+
const chabokignorePath = (0, path_1.join)(projectPath, dir, '.chabokignore');
|
|
83
88
|
const dockerignorePath = (0, path_1.join)(projectPath, dir, '.dockerignore');
|
|
84
89
|
const gitignorePath = (0, path_1.join)(projectPath, dir, '.gitignore');
|
|
85
|
-
if (fs.existsSync(
|
|
86
|
-
(0, exports.loadIgnoreFile)(ignoreInstance,
|
|
90
|
+
if (fs.existsSync(chabokignorePath)) {
|
|
91
|
+
(0, exports.loadIgnoreFile)(ignoreInstance, chabokignorePath, projectPath);
|
|
87
92
|
}
|
|
88
93
|
else if (fs.existsSync(dockerignorePath)) {
|
|
89
94
|
(0, exports.loadIgnoreFile)(ignoreInstance, dockerignorePath, projectPath);
|
|
@@ -93,3 +98,28 @@ function addIgnorePatterns(ignoreInstance, projectPath, dir) {
|
|
|
93
98
|
}
|
|
94
99
|
}
|
|
95
100
|
exports.addIgnorePatterns = addIgnorePatterns;
|
|
101
|
+
const checkUpdate = async (version) => {
|
|
102
|
+
const name = "@chabokan.net/cli";
|
|
103
|
+
const { version: latestVersion } = await (0, package_json_1.default)(name);
|
|
104
|
+
// check if local package version is less than the remote version
|
|
105
|
+
const updateAvailable = semver_1.default.lt(version, latestVersion);
|
|
106
|
+
if (updateAvailable) {
|
|
107
|
+
let updateType = '';
|
|
108
|
+
// check the type of version difference which is usually patch, minor, major etc.
|
|
109
|
+
let verDiff = (0, semver_diff_1.default)(version, latestVersion);
|
|
110
|
+
if (verDiff) {
|
|
111
|
+
updateType = verDiff;
|
|
112
|
+
}
|
|
113
|
+
const msg = {
|
|
114
|
+
updateAvailable: `${updateType} update available ${chalk_1.default.dim(version)} → ${chalk_1.default.green(latestVersion)}`,
|
|
115
|
+
runUpdate: `Run ${chalk_1.default.cyan(`npm i -g ${name}`)} to update`,
|
|
116
|
+
};
|
|
117
|
+
// notify the user about the available udpate
|
|
118
|
+
console.log((0, boxen_1.default)(`${msg.updateAvailable}\n${msg.runUpdate}`, {
|
|
119
|
+
margin: 1,
|
|
120
|
+
padding: 1,
|
|
121
|
+
align: 'center',
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
exports.checkUpdate = checkUpdate;
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.8.
|
|
1
|
+
{"version":"0.8.2","commands":{"deploy":{"id":"deploy","description":"this command help you build and deploy your service to chabokan in easy way.","strict":true,"pluginName":"@chabokan.net/cli","pluginAlias":"@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","multiple":false},"service":{"name":"service","type":"option","char":"s","description":"service name","multiple":false}},"args":[]},"login":{"id":"login","description":"login to hub.chabokan.net account","strict":true,"pluginName":"@chabokan.net/cli","pluginAlias":"@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","multiple":false},"password":{"name":"password","type":"option","char":"p","description":"your password","multiple":false},"token":{"name":"token","type":"option","char":"t","description":"login with api token","multiple":false}},"args":[]},"account:list":{"id":"account:list","description":"show accounts list","strict":true,"pluginName":"@chabokan.net/cli","pluginAlias":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"Show CLI help.","allowNo":false}},"args":[]},"account:remove":{"id":"account:remove","description":"remove account from list","strict":true,"pluginName":"@chabokan.net/cli","pluginAlias":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"Show CLI help.","allowNo":false}},"args":[]},"account:use":{"id":"account:use","description":"switch your default user between logged in users","strict":true,"pluginName":"@chabokan.net/cli","pluginAlias":"@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","multiple":false}},"args":[]},"service:list":{"id":"service:list","description":"show account services list","strict":true,"pluginName":"@chabokan.net/cli","pluginAlias":"@chabokan.net/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"Show CLI help.","allowNo":false}},"args":[]},"service:logs":{"id":"service:logs","description":"read latest logs from service","strict":true,"pluginName":"@chabokan.net/cli","pluginAlias":"@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","multiple":false}},"args":[]},"service:resize":{"id":"service:resize","description":"resize a service","strict":true,"pluginName":"@chabokan.net/cli","pluginAlias":"@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","multiple":false},"ram":{"name":"ram","type":"option","char":"r","description":"RAM","multiple":false},"cpu":{"name":"cpu","type":"option","char":"c","description":"CPU","multiple":false},"disk":{"name":"disk","type":"option","char":"d","description":"DISK","multiple":false}},"args":[]},"service:restart":{"id":"service:restart","description":"restart a service","strict":true,"pluginName":"@chabokan.net/cli","pluginAlias":"@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","multiple":false}},"args":[]},"service:start":{"id":"service:start","description":"start a service","strict":true,"pluginName":"@chabokan.net/cli","pluginAlias":"@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","multiple":false}},"args":[]},"service:stop":{"id":"service:stop","description":"stop a service","strict":true,"pluginName":"@chabokan.net/cli","pluginAlias":"@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","multiple":false}},"args":[]}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chabokan.net/cli",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "Chabokan Cli for PaaS Services",
|
|
5
5
|
"author": "Mohammad Abdi",
|
|
6
6
|
"bin": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"@oclif/plugin-plugins": "^2.1.2",
|
|
24
24
|
"@oclif/plugin-version": "^1.1.3",
|
|
25
25
|
"axios": "^1.1.3",
|
|
26
|
+
"boxen": "^5.1.2",
|
|
26
27
|
"chalk": "^4.1.2",
|
|
27
28
|
"form-data": "^4.0.0",
|
|
28
29
|
"fs-extra": "^9.1.0",
|
|
@@ -31,7 +32,10 @@
|
|
|
31
32
|
"https-proxy-agent": "^5.0.1",
|
|
32
33
|
"ignore": "^5.1.0",
|
|
33
34
|
"inquirer": "^8.2.4",
|
|
35
|
+
"package-json": "^6.5.0",
|
|
34
36
|
"progress": "^2.0.3",
|
|
37
|
+
"semver": "^7.3.8",
|
|
38
|
+
"semver-diff": "^3.1.1",
|
|
35
39
|
"tar": "^6.1.11"
|
|
36
40
|
},
|
|
37
41
|
"devDependencies": {
|
|
@@ -42,6 +46,7 @@
|
|
|
42
46
|
"@types/mocha": "^9.0.0",
|
|
43
47
|
"@types/node": "^16.11.65",
|
|
44
48
|
"@types/progress": "^2.0.3",
|
|
49
|
+
"@types/semver": "^7.3.12",
|
|
45
50
|
"@types/tar": "^6.1.3",
|
|
46
51
|
"chai": "^4",
|
|
47
52
|
"eslint": "^7.32.0",
|