@chabokan.net/cli 0.8.6 → 0.8.8

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.
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const core_1 = require("@oclif/core");
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_1 = tslib_1.__importDefault(require("inquirer"));
9
- const axios_1 = tslib_1.__importDefault(require("axios"));
10
- class ServiceRestart extends base_1.default {
11
- async run() {
12
- const { args, flags } = await this.parse(ServiceRestart);
13
- const cli = this;
14
- await this.init_run();
15
- const config_json = await this.read_config();
16
- let selected_service = flags.service;
17
- if ((0, 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_1.default.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 + "/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);
50
- }
51
- }
52
- }
53
- }
54
- exports.default = ServiceRestart;
55
- ServiceRestart.description = 'restart a service';
56
- ServiceRestart.flags = Object.assign(Object.assign({}, base_1.default.flags), { service: core_1.Flags.string({ char: 's', description: 'service name' }) });
@@ -1,10 +0,0 @@
1
- import Command from "../../base";
2
- export default class ServiceStart extends Command {
3
- static description: string;
4
- static flags: {
5
- service: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
6
- help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
7
- };
8
- run(): Promise<void>;
9
- send_request(cli: any, selected_service: any): Promise<void>;
10
- }
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const core_1 = require("@oclif/core");
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_1 = tslib_1.__importDefault(require("inquirer"));
9
- const axios_1 = tslib_1.__importDefault(require("axios"));
10
- class ServiceStart extends base_1.default {
11
- async run() {
12
- const { args, flags } = await this.parse(ServiceStart);
13
- const cli = this;
14
- await this.init_run();
15
- const config_json = await this.read_config();
16
- let selected_service = flags.service;
17
- if ((0, 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_1.default.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
- }
51
- }
52
- }
53
- }
54
- exports.default = ServiceStart;
55
- ServiceStart.description = 'start a service';
56
- ServiceStart.flags = Object.assign(Object.assign({}, base_1.default.flags), { service: core_1.Flags.string({ char: 's', description: 'service name' }) });
@@ -1,10 +0,0 @@
1
- import Command from "../../base";
2
- export default class ServiceStop extends Command {
3
- static description: string;
4
- static flags: {
5
- service: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
6
- help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
7
- };
8
- run(): Promise<void>;
9
- send_request(cli: any, selected_service: any): Promise<void>;
10
- }
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const core_1 = require("@oclif/core");
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_1 = tslib_1.__importDefault(require("inquirer"));
9
- const axios_1 = tslib_1.__importDefault(require("axios"));
10
- class ServiceStop extends base_1.default {
11
- async run() {
12
- const { args, flags } = await this.parse(ServiceStop);
13
- const cli = this;
14
- await this.init_run();
15
- const config_json = await this.read_config();
16
- let selected_service = flags.service;
17
- if ((0, 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_1.default.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
- }
51
- }
52
- }
53
- }
54
- exports.default = ServiceStop;
55
- ServiceStop.description = 'stop a service';
56
- ServiceStop.flags = Object.assign(Object.assign({}, base_1.default.flags), { service: core_1.Flags.string({ char: 's', description: 'service name' }) });
@@ -1,2 +0,0 @@
1
- export declare const GLOBAL_CONF_PATH: string;
2
- export declare let BASE_API_URL: string;
package/lib/constants.js DELETED
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BASE_API_URL = exports.GLOBAL_CONF_PATH = void 0;
4
- const tslib_1 = require("tslib");
5
- const path = tslib_1.__importStar(require("path"));
6
- const os = tslib_1.__importStar(require("os"));
7
- exports.GLOBAL_CONF_PATH = path.join(os.homedir(), '.chabok.json');
8
- exports.BASE_API_URL = 'https://apihub.chabokan.net/fa/api/v1/';
9
- if (process.env.CHABOK_API_URL) {
10
- exports.BASE_API_URL = process.env.CHABOK_API_URL;
11
- }
package/lib/helper.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { Ignore } from 'ignore';
2
- export declare function isObject(obj: any): boolean;
3
- export declare function isEmptyObject(obj: any): any;
4
- export declare function read_config_file(): {
5
- users: {};
6
- default_user: string;
7
- };
8
- export declare function get_all_services(filter: {} | undefined, axiosConfig: any): Promise<any>;
9
- export declare function trimLines(lines: string[]): string[];
10
- export declare const loadIgnoreFile: (ignoreInstance: Ignore, ignoreFilePath: string, projectPath: string) => void;
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 DELETED
@@ -1,125 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkUpdate = exports.addIgnorePatterns = exports.loadIgnoreFile = exports.trimLines = exports.get_all_services = exports.read_config_file = exports.isEmptyObject = exports.isObject = void 0;
4
- const tslib_1 = require("tslib");
5
- const fs = tslib_1.__importStar(require("fs"));
6
- const constants_1 = require("./constants");
7
- const axios_1 = tslib_1.__importDefault(require("axios"));
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"));
14
- function isObject(obj) {
15
- return obj != null && obj.constructor.name === "Object";
16
- }
17
- exports.isObject = isObject;
18
- function isEmptyObject(obj) {
19
- return obj && obj.constructor === Object && Object.keys(obj).length === 0;
20
- }
21
- exports.isEmptyObject = isEmptyObject;
22
- function read_config_file() {
23
- let config_json = {
24
- users: {},
25
- default_user: ""
26
- };
27
- try {
28
- config_json = JSON.parse(fs.readFileSync(constants_1.GLOBAL_CONF_PATH).toString('utf-8')) || {};
29
- }
30
- catch (_a) {
31
- }
32
- return config_json;
33
- }
34
- exports.read_config_file = read_config_file;
35
- async function get_all_services(filter = {}, axiosConfig) {
36
- let all_services = [];
37
- try {
38
- let url_filter = "";
39
- Object.keys(filter).forEach((item, index) => {
40
- let key = item;
41
- // @ts-ignore
42
- let value = filter[item];
43
- if (index == 0) {
44
- url_filter += `?${key}=${value}`;
45
- }
46
- else {
47
- url_filter += `&${key}=${value}`;
48
- }
49
- });
50
- const { data } = await axios_1.default.get("services/" + url_filter, axiosConfig);
51
- data.services.forEach(function (item) {
52
- // @ts-ignore
53
- all_services.push({ "value": item.main_name, "name": `${item.main_name} (${item.platform.name})` });
54
- });
55
- }
56
- catch (e) {
57
- console.log(e.response.data);
58
- }
59
- return all_services;
60
- }
61
- exports.get_all_services = get_all_services;
62
- function trimLines(lines) {
63
- return lines.reduce((prev, line) => {
64
- if (!line.trim() || line.startsWith('#')) {
65
- return prev;
66
- }
67
- return [...prev, line];
68
- }, []);
69
- }
70
- exports.trimLines = trimLines;
71
- const loadIgnoreFile = (ignoreInstance, ignoreFilePath, projectPath) => {
72
- const patterns = trimLines(fs.readFileSync(ignoreFilePath).toString().split('\n'));
73
- const relativeToProjectPath = patterns.map((pattern) => {
74
- const dir = (0, path_1.dirname)(ignoreFilePath);
75
- if (pattern.startsWith('!')) {
76
- const absolutePrefix = pattern.substr(1).startsWith('/') ? '/' : '';
77
- return '!' + absolutePrefix + (0, path_1.relative)(projectPath, (0, path_1.join)(dir, pattern.substr(1)));
78
- }
79
- const absolutePrefix = pattern.startsWith('/') ? '/' : '';
80
- return absolutePrefix + (0, path_1.relative)(projectPath, (0, path_1.join)(dir, pattern));
81
- });
82
- const linuxify = relativeToProjectPath.map(p => p.replace(/\\/g, '/'));
83
- ignoreInstance.add(linuxify);
84
- };
85
- exports.loadIgnoreFile = loadIgnoreFile;
86
- function addIgnorePatterns(ignoreInstance, projectPath, dir) {
87
- const chabokignorePath = (0, path_1.join)(projectPath, dir, '.chabokignore');
88
- const dockerignorePath = (0, path_1.join)(projectPath, dir, '.dockerignore');
89
- const gitignorePath = (0, path_1.join)(projectPath, dir, '.gitignore');
90
- if (fs.existsSync(chabokignorePath)) {
91
- (0, exports.loadIgnoreFile)(ignoreInstance, chabokignorePath, projectPath);
92
- }
93
- else if (fs.existsSync(dockerignorePath)) {
94
- (0, exports.loadIgnoreFile)(ignoreInstance, dockerignorePath, projectPath);
95
- }
96
- else if (fs.existsSync(gitignorePath)) {
97
- (0, exports.loadIgnoreFile)(ignoreInstance, gitignorePath, projectPath);
98
- }
99
- }
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/lib/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { run } from '@oclif/core';
package/lib/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.run = void 0;
4
- var core_1 = require("@oclif/core");
5
- Object.defineProperty(exports, "run", { enumerable: true, get: function () { return core_1.run; } });