@chabokan.net/cli 0.8.6 → 0.8.7

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,31 +1,30 @@
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 {
1
+ import { Flags } from "@oclif/core";
2
+ import Command from "../../base.js";
3
+ import { isEmptyObject } from "../../helper.js";
4
+ import chalk from "chalk";
5
+ import inquirer from "inquirer";
6
+ import axios from "axios";
7
+ class ServiceRestart extends Command {
11
8
  async run() {
12
9
  const { args, flags } = await this.parse(ServiceRestart);
13
10
  const cli = this;
14
11
  await this.init_run();
15
12
  const config_json = await this.read_config();
16
13
  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!`);
14
+ if (isEmptyObject(config_json.users)) {
15
+ cli.log(`${chalk.red("[Error]")} first you should login!`);
19
16
  return;
20
17
  }
21
18
  if (!flags.service) {
22
- let all_services = await this.get_services({ 'not_status': 'pending' });
19
+ let all_services = await this.get_services({
20
+ not_status: "pending",
21
+ });
23
22
  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
23
+ let { service } = await inquirer.prompt({
24
+ type: "list",
25
+ message: "Please select a service:",
26
+ name: "service",
27
+ choices: all_services,
29
28
  });
30
29
  selected_service = service;
31
30
  }
@@ -35,15 +34,15 @@ class ServiceRestart extends base_1.default {
35
34
  async send_request(cli, selected_service) {
36
35
  try {
37
36
  if (selected_service) {
38
- const { data } = await axios_1.default.get("services/" + selected_service + "/restart/", this.axiosConfig);
37
+ const { data } = await axios.get("services/" + selected_service + "/restart/", this.axiosConfig);
39
38
  if (data.success) {
40
- cli.log(`${chalk_1.default.green('[Success]')} service restarted successfully.`);
39
+ cli.log(`${chalk.green("[Success]")} service restarted successfully.`);
41
40
  }
42
41
  }
43
42
  }
44
43
  catch (e) {
45
44
  if (e.response.status == 404) {
46
- cli.log(chalk_1.default.blue("Selected Service Not Founded."));
45
+ cli.log(chalk.blue("Selected Service Not Founded."));
47
46
  }
48
47
  else {
49
48
  console.log(e.data);
@@ -51,6 +50,9 @@ class ServiceRestart extends base_1.default {
51
50
  }
52
51
  }
53
52
  }
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' }) });
53
+ ServiceRestart.description = "restart a service";
54
+ ServiceRestart.flags = {
55
+ ...Command.flags,
56
+ service: Flags.string({ char: "s", description: "service name" }),
57
+ };
58
+ export default ServiceRestart;
@@ -1,9 +1,9 @@
1
- import Command from "../../base";
1
+ import Command from "../../base.js";
2
2
  export default class ServiceStart extends Command {
3
3
  static description: string;
4
4
  static flags: {
5
- service: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
6
- help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
5
+ service: 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
7
  };
8
8
  run(): Promise<void>;
9
9
  send_request(cli: any, selected_service: any): Promise<void>;
@@ -1,27 +1,24 @@
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 {
1
+ import { Flags } from '@oclif/core';
2
+ import Command from "../../base.js";
3
+ import { isEmptyObject } from "../../helper.js";
4
+ import chalk from "chalk";
5
+ import inquirer from 'inquirer';
6
+ import axios from "axios";
7
+ class ServiceStart extends Command {
11
8
  async run() {
12
9
  const { args, flags } = await this.parse(ServiceStart);
13
10
  const cli = this;
14
11
  await this.init_run();
15
12
  const config_json = await this.read_config();
16
13
  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!`);
14
+ if (isEmptyObject(config_json.users)) {
15
+ cli.log(`${chalk.red('[Error]')} first you should login!`);
19
16
  return;
20
17
  }
21
18
  if (!flags.service) {
22
19
  let all_services = await this.get_services({ 'not_status': 'pending' });
23
20
  if (all_services) {
24
- let { service } = await inquirer_1.default.prompt({
21
+ let { service } = await inquirer.prompt({
25
22
  type: 'list',
26
23
  message: 'Please select a service:',
27
24
  name: 'service',
@@ -35,15 +32,15 @@ class ServiceStart extends base_1.default {
35
32
  async send_request(cli, selected_service) {
36
33
  try {
37
34
  if (selected_service) {
38
- const { data } = await axios_1.default.get("services/" + selected_service + "/start/", this.axiosConfig);
35
+ const { data } = await axios.get("services/" + selected_service + "/start/", this.axiosConfig);
39
36
  if (data.success) {
40
- cli.log(`${chalk_1.default.green('[Success]')} service start successfully.`);
37
+ cli.log(`${chalk.green('[Success]')} service start successfully.`);
41
38
  }
42
39
  }
43
40
  }
44
41
  catch (e) {
45
42
  if (e.response.status == 404) {
46
- cli.log(chalk_1.default.blue("Selected Service Not Founded."));
43
+ cli.log(chalk.blue("Selected Service Not Founded."));
47
44
  }
48
45
  else {
49
46
  console.log(e.data);
@@ -51,6 +48,9 @@ class ServiceStart extends base_1.default {
51
48
  }
52
49
  }
53
50
  }
54
- exports.default = ServiceStart;
55
51
  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' }) });
52
+ ServiceStart.flags = {
53
+ ...Command.flags,
54
+ service: Flags.string({ char: 's', description: 'service name' }),
55
+ };
56
+ export default ServiceStart;
@@ -1,9 +1,9 @@
1
- import Command from "../../base";
1
+ import Command from "../../base.js";
2
2
  export default class ServiceStop extends Command {
3
3
  static description: string;
4
4
  static flags: {
5
- service: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
6
- help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
5
+ service: 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
7
  };
8
8
  run(): Promise<void>;
9
9
  send_request(cli: any, selected_service: any): Promise<void>;
@@ -1,27 +1,24 @@
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 {
1
+ import { Flags } from '@oclif/core';
2
+ import Command from "../../base.js";
3
+ import { isEmptyObject } from "../../helper.js";
4
+ import chalk from "chalk";
5
+ import inquirer from 'inquirer';
6
+ import axios from "axios";
7
+ class ServiceStop extends Command {
11
8
  async run() {
12
9
  const { args, flags } = await this.parse(ServiceStop);
13
10
  const cli = this;
14
11
  await this.init_run();
15
12
  const config_json = await this.read_config();
16
13
  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!`);
14
+ if (isEmptyObject(config_json.users)) {
15
+ cli.log(`${chalk.red('[Error]')} first you should login!`);
19
16
  return;
20
17
  }
21
18
  if (!flags.service) {
22
19
  let all_services = await this.get_services({ 'not_status': 'pending' });
23
20
  if (all_services) {
24
- let { service } = await inquirer_1.default.prompt({
21
+ let { service } = await inquirer.prompt({
25
22
  type: 'list',
26
23
  message: 'Please select a service:',
27
24
  name: 'service',
@@ -35,15 +32,15 @@ class ServiceStop extends base_1.default {
35
32
  async send_request(cli, selected_service) {
36
33
  try {
37
34
  if (selected_service) {
38
- const { data } = await axios_1.default.get("services/" + selected_service + "/stop/", this.axiosConfig);
35
+ const { data } = await axios.get("services/" + selected_service + "/stop/", this.axiosConfig);
39
36
  if (data.success) {
40
- cli.log(`${chalk_1.default.green('[Success]')} service stop successfully.`);
37
+ cli.log(`${chalk.green('[Success]')} service stop successfully.`);
41
38
  }
42
39
  }
43
40
  }
44
41
  catch (e) {
45
42
  if (e.response.status == 404) {
46
- cli.log(chalk_1.default.blue("Selected Service Not Founded."));
43
+ cli.log(chalk.blue("Selected Service Not Founded."));
47
44
  }
48
45
  else {
49
46
  console.log(e.data);
@@ -51,6 +48,9 @@ class ServiceStop extends base_1.default {
51
48
  }
52
49
  }
53
50
  }
54
- exports.default = ServiceStop;
55
51
  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' }) });
52
+ ServiceStop.flags = {
53
+ ...Command.flags,
54
+ service: Flags.string({ char: 's', description: 'service name' }),
55
+ };
56
+ export default ServiceStop;
package/lib/constants.js CHANGED
@@ -1,11 +1,7 @@
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/';
1
+ import * as path from 'path';
2
+ import * as os from 'os';
3
+ export const GLOBAL_CONF_PATH = path.join(os.homedir(), '.chabok.json');
4
+ export let BASE_API_URL = 'https://apihub.chabokan.net/fa/api/v1/';
9
5
  if (process.env.CHABOK_API_URL) {
10
- exports.BASE_API_URL = process.env.CHABOK_API_URL;
6
+ BASE_API_URL = process.env.CHABOK_API_URL;
11
7
  }
package/lib/helper.js CHANGED
@@ -1,38 +1,31 @@
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) {
1
+ import * as fs from "fs";
2
+ import { GLOBAL_CONF_PATH } from "./constants.js";
3
+ import axios from "axios";
4
+ import { dirname, join, relative } from "path";
5
+ import boxen from 'boxen';
6
+ import chalk from 'chalk';
7
+ import semver from 'semver';
8
+ import pkgJson from 'package-json';
9
+ import semverDiff from 'semver-diff';
10
+ export function isObject(obj) {
15
11
  return obj != null && obj.constructor.name === "Object";
16
12
  }
17
- exports.isObject = isObject;
18
- function isEmptyObject(obj) {
13
+ export function isEmptyObject(obj) {
19
14
  return obj && obj.constructor === Object && Object.keys(obj).length === 0;
20
15
  }
21
- exports.isEmptyObject = isEmptyObject;
22
- function read_config_file() {
16
+ export function read_config_file() {
23
17
  let config_json = {
24
18
  users: {},
25
19
  default_user: ""
26
20
  };
27
21
  try {
28
- config_json = JSON.parse(fs.readFileSync(constants_1.GLOBAL_CONF_PATH).toString('utf-8')) || {};
22
+ config_json = JSON.parse(fs.readFileSync(GLOBAL_CONF_PATH).toString('utf-8')) || {};
29
23
  }
30
- catch (_a) {
24
+ catch {
31
25
  }
32
26
  return config_json;
33
27
  }
34
- exports.read_config_file = read_config_file;
35
- async function get_all_services(filter = {}, axiosConfig) {
28
+ export async function get_all_services(filter = {}, axiosConfig) {
36
29
  let all_services = [];
37
30
  try {
38
31
  let url_filter = "";
@@ -47,7 +40,7 @@ async function get_all_services(filter = {}, axiosConfig) {
47
40
  url_filter += `&${key}=${value}`;
48
41
  }
49
42
  });
50
- const { data } = await axios_1.default.get("services/" + url_filter, axiosConfig);
43
+ const { data } = await axios.get("services/" + url_filter, axiosConfig);
51
44
  data.services.forEach(function (item) {
52
45
  // @ts-ignore
53
46
  all_services.push({ "value": item.main_name, "name": `${item.main_name} (${item.platform.name})` });
@@ -58,8 +51,7 @@ async function get_all_services(filter = {}, axiosConfig) {
58
51
  }
59
52
  return all_services;
60
53
  }
61
- exports.get_all_services = get_all_services;
62
- function trimLines(lines) {
54
+ export function trimLines(lines) {
63
55
  return lines.reduce((prev, line) => {
64
56
  if (!line.trim() || line.startsWith('#')) {
65
57
  return prev;
@@ -67,59 +59,55 @@ function trimLines(lines) {
67
59
  return [...prev, line];
68
60
  }, []);
69
61
  }
70
- exports.trimLines = trimLines;
71
- const loadIgnoreFile = (ignoreInstance, ignoreFilePath, projectPath) => {
62
+ export const loadIgnoreFile = (ignoreInstance, ignoreFilePath, projectPath) => {
72
63
  const patterns = trimLines(fs.readFileSync(ignoreFilePath).toString().split('\n'));
73
64
  const relativeToProjectPath = patterns.map((pattern) => {
74
- const dir = (0, path_1.dirname)(ignoreFilePath);
65
+ const dir = dirname(ignoreFilePath);
75
66
  if (pattern.startsWith('!')) {
76
67
  const absolutePrefix = pattern.substr(1).startsWith('/') ? '/' : '';
77
- return '!' + absolutePrefix + (0, path_1.relative)(projectPath, (0, path_1.join)(dir, pattern.substr(1)));
68
+ return '!' + absolutePrefix + relative(projectPath, join(dir, pattern.substr(1)));
78
69
  }
79
70
  const absolutePrefix = pattern.startsWith('/') ? '/' : '';
80
- return absolutePrefix + (0, path_1.relative)(projectPath, (0, path_1.join)(dir, pattern));
71
+ return absolutePrefix + relative(projectPath, join(dir, pattern));
81
72
  });
82
73
  const linuxify = relativeToProjectPath.map(p => p.replace(/\\/g, '/'));
83
74
  ignoreInstance.add(linuxify);
84
75
  };
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');
76
+ export function addIgnorePatterns(ignoreInstance, projectPath, dir) {
77
+ const chabokignorePath = join(projectPath, dir, '.chabokignore');
78
+ const dockerignorePath = join(projectPath, dir, '.dockerignore');
79
+ const gitignorePath = join(projectPath, dir, '.gitignore');
90
80
  if (fs.existsSync(chabokignorePath)) {
91
- (0, exports.loadIgnoreFile)(ignoreInstance, chabokignorePath, projectPath);
81
+ loadIgnoreFile(ignoreInstance, chabokignorePath, projectPath);
92
82
  }
93
83
  else if (fs.existsSync(dockerignorePath)) {
94
- (0, exports.loadIgnoreFile)(ignoreInstance, dockerignorePath, projectPath);
84
+ loadIgnoreFile(ignoreInstance, dockerignorePath, projectPath);
95
85
  }
96
86
  else if (fs.existsSync(gitignorePath)) {
97
- (0, exports.loadIgnoreFile)(ignoreInstance, gitignorePath, projectPath);
87
+ loadIgnoreFile(ignoreInstance, gitignorePath, projectPath);
98
88
  }
99
89
  }
100
- exports.addIgnorePatterns = addIgnorePatterns;
101
- const checkUpdate = async (version) => {
90
+ export const checkUpdate = async (version) => {
102
91
  const name = "@chabokan.net/cli";
103
- const { version: latestVersion } = await (0, package_json_1.default)(name);
92
+ const { version: latestVersion } = await pkgJson(name);
104
93
  // check if local package version is less than the remote version
105
- const updateAvailable = semver_1.default.lt(version, latestVersion);
94
+ const updateAvailable = semver.lt(version, latestVersion);
106
95
  if (updateAvailable) {
107
96
  let updateType = '';
108
97
  // check the type of version difference which is usually patch, minor, major etc.
109
- let verDiff = (0, semver_diff_1.default)(version, latestVersion);
98
+ let verDiff = semverDiff(version, latestVersion);
110
99
  if (verDiff) {
111
100
  updateType = verDiff;
112
101
  }
113
102
  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`,
103
+ updateAvailable: `${updateType} update available ${chalk.dim(version)} → ${chalk.green(latestVersion)}`,
104
+ runUpdate: `Run ${chalk.cyan(`npm i -g ${name}`)} to update`,
116
105
  };
117
106
  // notify the user about the available udpate
118
- console.log((0, boxen_1.default)(`${msg.updateAvailable}\n${msg.runUpdate}`, {
107
+ console.log(boxen(`${msg.updateAvailable}\n${msg.runUpdate}`, {
119
108
  margin: 1,
120
109
  padding: 1,
121
110
  align: 'center',
122
111
  }));
123
112
  }
124
113
  };
125
- exports.checkUpdate = checkUpdate;
package/lib/index.js CHANGED
@@ -1,5 +1 @@
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; } });
1
+ export { run } from '@oclif/core';