@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/dist/helper.js ADDED
@@ -0,0 +1,113 @@
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) {
11
+ return obj != null && obj.constructor.name === "Object";
12
+ }
13
+ export function isEmptyObject(obj) {
14
+ return obj && obj.constructor === Object && Object.keys(obj).length === 0;
15
+ }
16
+ export function read_config_file() {
17
+ let config_json = {
18
+ users: {},
19
+ default_user: ""
20
+ };
21
+ try {
22
+ config_json = JSON.parse(fs.readFileSync(GLOBAL_CONF_PATH).toString('utf-8')) || {};
23
+ }
24
+ catch {
25
+ }
26
+ return config_json;
27
+ }
28
+ export async function get_all_services(filter = {}, axiosConfig) {
29
+ let all_services = [];
30
+ try {
31
+ let url_filter = "";
32
+ Object.keys(filter).forEach((item, index) => {
33
+ let key = item;
34
+ // @ts-ignore
35
+ let value = filter[item];
36
+ if (index == 0) {
37
+ url_filter += `?${key}=${value}`;
38
+ }
39
+ else {
40
+ url_filter += `&${key}=${value}`;
41
+ }
42
+ });
43
+ const { data } = await axios.get("services/" + url_filter, axiosConfig);
44
+ data.services.forEach(function (item) {
45
+ // @ts-ignore
46
+ all_services.push({ "value": item.main_name, "name": `${item.main_name} (${item.platform.name})` });
47
+ });
48
+ }
49
+ catch (e) {
50
+ console.log(e.response.data);
51
+ }
52
+ return all_services;
53
+ }
54
+ export function trimLines(lines) {
55
+ return lines.reduce((prev, line) => {
56
+ if (!line.trim() || line.startsWith('#')) {
57
+ return prev;
58
+ }
59
+ return [...prev, line];
60
+ }, []);
61
+ }
62
+ export const loadIgnoreFile = (ignoreInstance, ignoreFilePath, projectPath) => {
63
+ const patterns = trimLines(fs.readFileSync(ignoreFilePath).toString().split('\n'));
64
+ const relativeToProjectPath = patterns.map((pattern) => {
65
+ const dir = dirname(ignoreFilePath);
66
+ if (pattern.startsWith('!')) {
67
+ const absolutePrefix = pattern.substr(1).startsWith('/') ? '/' : '';
68
+ return '!' + absolutePrefix + relative(projectPath, join(dir, pattern.substr(1)));
69
+ }
70
+ const absolutePrefix = pattern.startsWith('/') ? '/' : '';
71
+ return absolutePrefix + relative(projectPath, join(dir, pattern));
72
+ });
73
+ const linuxify = relativeToProjectPath.map(p => p.replace(/\\/g, '/'));
74
+ ignoreInstance.add(linuxify);
75
+ };
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');
80
+ if (fs.existsSync(chabokignorePath)) {
81
+ loadIgnoreFile(ignoreInstance, chabokignorePath, projectPath);
82
+ }
83
+ else if (fs.existsSync(dockerignorePath)) {
84
+ loadIgnoreFile(ignoreInstance, dockerignorePath, projectPath);
85
+ }
86
+ else if (fs.existsSync(gitignorePath)) {
87
+ loadIgnoreFile(ignoreInstance, gitignorePath, projectPath);
88
+ }
89
+ }
90
+ export const checkUpdate = async (version) => {
91
+ const name = "@chabokan.net/cli";
92
+ const { version: latestVersion } = await pkgJson(name);
93
+ // check if local package version is less than the remote version
94
+ const updateAvailable = semver.lt(version, latestVersion);
95
+ if (updateAvailable) {
96
+ let updateType = '';
97
+ // check the type of version difference which is usually patch, minor, major etc.
98
+ let verDiff = semverDiff(version, latestVersion);
99
+ if (verDiff) {
100
+ updateType = verDiff;
101
+ }
102
+ const msg = {
103
+ updateAvailable: `${updateType} update available ${chalk.dim(version)} → ${chalk.green(latestVersion)}`,
104
+ runUpdate: `Run ${chalk.cyan(`npm i -g ${name}`)} to update`,
105
+ };
106
+ // notify the user about the available udpate
107
+ console.log(boxen(`${msg.updateAvailable}\n${msg.runUpdate}`, {
108
+ margin: 1,
109
+ padding: 1,
110
+ align: 'center',
111
+ }));
112
+ }
113
+ };
@@ -0,0 +1 @@
1
+ export { run } from '@oclif/core';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { run } from '@oclif/core';
@@ -1,4 +1,434 @@
1
1
  {
2
- "commands": {},
3
- "version": "0.8.8"
2
+ "commands": {
3
+ "deploy": {
4
+ "aliases": [],
5
+ "args": {},
6
+ "description": "this command help you build and deploy your service to chabokan in easy way.",
7
+ "flags": {
8
+ "help": {
9
+ "char": "h",
10
+ "description": "Show CLI help.",
11
+ "name": "help",
12
+ "allowNo": false,
13
+ "type": "boolean"
14
+ },
15
+ "path": {
16
+ "char": "p",
17
+ "description": "service path in your computer",
18
+ "name": "path",
19
+ "hasDynamicHelp": false,
20
+ "multiple": false,
21
+ "type": "option"
22
+ },
23
+ "service": {
24
+ "char": "s",
25
+ "description": "service name",
26
+ "name": "service",
27
+ "hasDynamicHelp": false,
28
+ "multiple": false,
29
+ "type": "option"
30
+ }
31
+ },
32
+ "hasDynamicHelp": false,
33
+ "hiddenAliases": [],
34
+ "id": "deploy",
35
+ "pluginAlias": "@chabokan.net/cli",
36
+ "pluginName": "@chabokan.net/cli",
37
+ "pluginType": "core",
38
+ "strict": true,
39
+ "enableJsonFlag": false,
40
+ "isESM": true,
41
+ "relativePath": [
42
+ "dist",
43
+ "commands",
44
+ "deploy.js"
45
+ ]
46
+ },
47
+ "login": {
48
+ "aliases": [],
49
+ "args": {},
50
+ "description": "login to hub.chabokan.net account",
51
+ "flags": {
52
+ "help": {
53
+ "char": "h",
54
+ "description": "Show CLI help.",
55
+ "name": "help",
56
+ "allowNo": false,
57
+ "type": "boolean"
58
+ },
59
+ "username": {
60
+ "char": "u",
61
+ "description": "your username",
62
+ "name": "username",
63
+ "hasDynamicHelp": false,
64
+ "multiple": false,
65
+ "type": "option"
66
+ },
67
+ "password": {
68
+ "char": "p",
69
+ "description": "your password",
70
+ "name": "password",
71
+ "hasDynamicHelp": false,
72
+ "multiple": false,
73
+ "type": "option"
74
+ },
75
+ "token": {
76
+ "char": "t",
77
+ "description": "login with api token",
78
+ "name": "token",
79
+ "hasDynamicHelp": false,
80
+ "multiple": false,
81
+ "type": "option"
82
+ }
83
+ },
84
+ "hasDynamicHelp": false,
85
+ "hiddenAliases": [],
86
+ "id": "login",
87
+ "pluginAlias": "@chabokan.net/cli",
88
+ "pluginName": "@chabokan.net/cli",
89
+ "pluginType": "core",
90
+ "strict": true,
91
+ "enableJsonFlag": false,
92
+ "isESM": true,
93
+ "relativePath": [
94
+ "dist",
95
+ "commands",
96
+ "login.js"
97
+ ]
98
+ },
99
+ "account:list": {
100
+ "aliases": [],
101
+ "args": {},
102
+ "description": "show accounts list",
103
+ "flags": {
104
+ "help": {
105
+ "char": "h",
106
+ "description": "Show CLI help.",
107
+ "name": "help",
108
+ "allowNo": false,
109
+ "type": "boolean"
110
+ }
111
+ },
112
+ "hasDynamicHelp": false,
113
+ "hiddenAliases": [],
114
+ "id": "account:list",
115
+ "pluginAlias": "@chabokan.net/cli",
116
+ "pluginName": "@chabokan.net/cli",
117
+ "pluginType": "core",
118
+ "strict": true,
119
+ "enableJsonFlag": false,
120
+ "isESM": true,
121
+ "relativePath": [
122
+ "dist",
123
+ "commands",
124
+ "account",
125
+ "list.js"
126
+ ]
127
+ },
128
+ "account:remove": {
129
+ "aliases": [],
130
+ "args": {},
131
+ "description": "remove account from list",
132
+ "flags": {
133
+ "help": {
134
+ "char": "h",
135
+ "description": "Show CLI help.",
136
+ "name": "help",
137
+ "allowNo": false,
138
+ "type": "boolean"
139
+ }
140
+ },
141
+ "hasDynamicHelp": false,
142
+ "hiddenAliases": [],
143
+ "id": "account:remove",
144
+ "pluginAlias": "@chabokan.net/cli",
145
+ "pluginName": "@chabokan.net/cli",
146
+ "pluginType": "core",
147
+ "strict": true,
148
+ "enableJsonFlag": false,
149
+ "isESM": true,
150
+ "relativePath": [
151
+ "dist",
152
+ "commands",
153
+ "account",
154
+ "remove.js"
155
+ ]
156
+ },
157
+ "account:use": {
158
+ "aliases": [],
159
+ "args": {},
160
+ "description": "switch your default user between logged in users",
161
+ "flags": {
162
+ "help": {
163
+ "char": "h",
164
+ "description": "Show CLI help.",
165
+ "name": "help",
166
+ "allowNo": false,
167
+ "type": "boolean"
168
+ },
169
+ "user": {
170
+ "char": "u",
171
+ "description": "default user",
172
+ "name": "user",
173
+ "hasDynamicHelp": false,
174
+ "multiple": false,
175
+ "type": "option"
176
+ }
177
+ },
178
+ "hasDynamicHelp": false,
179
+ "hiddenAliases": [],
180
+ "id": "account:use",
181
+ "pluginAlias": "@chabokan.net/cli",
182
+ "pluginName": "@chabokan.net/cli",
183
+ "pluginType": "core",
184
+ "strict": true,
185
+ "enableJsonFlag": false,
186
+ "isESM": true,
187
+ "relativePath": [
188
+ "dist",
189
+ "commands",
190
+ "account",
191
+ "use.js"
192
+ ]
193
+ },
194
+ "service:list": {
195
+ "aliases": [],
196
+ "args": {},
197
+ "description": "show account services list",
198
+ "flags": {
199
+ "help": {
200
+ "char": "h",
201
+ "description": "Show CLI help.",
202
+ "name": "help",
203
+ "allowNo": false,
204
+ "type": "boolean"
205
+ }
206
+ },
207
+ "hasDynamicHelp": false,
208
+ "hiddenAliases": [],
209
+ "id": "service:list",
210
+ "pluginAlias": "@chabokan.net/cli",
211
+ "pluginName": "@chabokan.net/cli",
212
+ "pluginType": "core",
213
+ "strict": true,
214
+ "enableJsonFlag": false,
215
+ "isESM": true,
216
+ "relativePath": [
217
+ "dist",
218
+ "commands",
219
+ "service",
220
+ "list.js"
221
+ ]
222
+ },
223
+ "service:logs": {
224
+ "aliases": [],
225
+ "args": {},
226
+ "description": "read latest logs from service",
227
+ "flags": {
228
+ "help": {
229
+ "char": "h",
230
+ "description": "Show CLI help.",
231
+ "name": "help",
232
+ "allowNo": false,
233
+ "type": "boolean"
234
+ },
235
+ "service": {
236
+ "char": "s",
237
+ "description": "service name",
238
+ "name": "service",
239
+ "hasDynamicHelp": false,
240
+ "multiple": false,
241
+ "type": "option"
242
+ }
243
+ },
244
+ "hasDynamicHelp": false,
245
+ "hiddenAliases": [],
246
+ "id": "service:logs",
247
+ "pluginAlias": "@chabokan.net/cli",
248
+ "pluginName": "@chabokan.net/cli",
249
+ "pluginType": "core",
250
+ "strict": true,
251
+ "enableJsonFlag": false,
252
+ "isESM": true,
253
+ "relativePath": [
254
+ "dist",
255
+ "commands",
256
+ "service",
257
+ "logs.js"
258
+ ]
259
+ },
260
+ "service:resize": {
261
+ "aliases": [],
262
+ "args": {},
263
+ "description": "resize a service",
264
+ "flags": {
265
+ "help": {
266
+ "char": "h",
267
+ "description": "Show CLI help.",
268
+ "name": "help",
269
+ "allowNo": false,
270
+ "type": "boolean"
271
+ },
272
+ "service": {
273
+ "char": "s",
274
+ "description": "service name",
275
+ "name": "service",
276
+ "hasDynamicHelp": false,
277
+ "multiple": false,
278
+ "type": "option"
279
+ },
280
+ "ram": {
281
+ "char": "r",
282
+ "description": "RAM",
283
+ "name": "ram",
284
+ "hasDynamicHelp": false,
285
+ "multiple": false,
286
+ "type": "option"
287
+ },
288
+ "cpu": {
289
+ "char": "c",
290
+ "description": "CPU",
291
+ "name": "cpu",
292
+ "hasDynamicHelp": false,
293
+ "multiple": false,
294
+ "type": "option"
295
+ },
296
+ "disk": {
297
+ "char": "d",
298
+ "description": "DISK",
299
+ "name": "disk",
300
+ "hasDynamicHelp": false,
301
+ "multiple": false,
302
+ "type": "option"
303
+ }
304
+ },
305
+ "hasDynamicHelp": false,
306
+ "hiddenAliases": [],
307
+ "id": "service:resize",
308
+ "pluginAlias": "@chabokan.net/cli",
309
+ "pluginName": "@chabokan.net/cli",
310
+ "pluginType": "core",
311
+ "strict": true,
312
+ "enableJsonFlag": false,
313
+ "isESM": true,
314
+ "relativePath": [
315
+ "dist",
316
+ "commands",
317
+ "service",
318
+ "resize.js"
319
+ ]
320
+ },
321
+ "service:restart": {
322
+ "aliases": [],
323
+ "args": {},
324
+ "description": "restart a service",
325
+ "flags": {
326
+ "help": {
327
+ "char": "h",
328
+ "description": "Show CLI help.",
329
+ "name": "help",
330
+ "allowNo": false,
331
+ "type": "boolean"
332
+ },
333
+ "service": {
334
+ "char": "s",
335
+ "description": "service name",
336
+ "name": "service",
337
+ "hasDynamicHelp": false,
338
+ "multiple": false,
339
+ "type": "option"
340
+ }
341
+ },
342
+ "hasDynamicHelp": false,
343
+ "hiddenAliases": [],
344
+ "id": "service:restart",
345
+ "pluginAlias": "@chabokan.net/cli",
346
+ "pluginName": "@chabokan.net/cli",
347
+ "pluginType": "core",
348
+ "strict": true,
349
+ "enableJsonFlag": false,
350
+ "isESM": true,
351
+ "relativePath": [
352
+ "dist",
353
+ "commands",
354
+ "service",
355
+ "restart.js"
356
+ ]
357
+ },
358
+ "service:start": {
359
+ "aliases": [],
360
+ "args": {},
361
+ "description": "start a service",
362
+ "flags": {
363
+ "help": {
364
+ "char": "h",
365
+ "description": "Show CLI help.",
366
+ "name": "help",
367
+ "allowNo": false,
368
+ "type": "boolean"
369
+ },
370
+ "service": {
371
+ "char": "s",
372
+ "description": "service name",
373
+ "name": "service",
374
+ "hasDynamicHelp": false,
375
+ "multiple": false,
376
+ "type": "option"
377
+ }
378
+ },
379
+ "hasDynamicHelp": false,
380
+ "hiddenAliases": [],
381
+ "id": "service:start",
382
+ "pluginAlias": "@chabokan.net/cli",
383
+ "pluginName": "@chabokan.net/cli",
384
+ "pluginType": "core",
385
+ "strict": true,
386
+ "enableJsonFlag": false,
387
+ "isESM": true,
388
+ "relativePath": [
389
+ "dist",
390
+ "commands",
391
+ "service",
392
+ "start.js"
393
+ ]
394
+ },
395
+ "service:stop": {
396
+ "aliases": [],
397
+ "args": {},
398
+ "description": "stop a service",
399
+ "flags": {
400
+ "help": {
401
+ "char": "h",
402
+ "description": "Show CLI help.",
403
+ "name": "help",
404
+ "allowNo": false,
405
+ "type": "boolean"
406
+ },
407
+ "service": {
408
+ "char": "s",
409
+ "description": "service name",
410
+ "name": "service",
411
+ "hasDynamicHelp": false,
412
+ "multiple": false,
413
+ "type": "option"
414
+ }
415
+ },
416
+ "hasDynamicHelp": false,
417
+ "hiddenAliases": [],
418
+ "id": "service:stop",
419
+ "pluginAlias": "@chabokan.net/cli",
420
+ "pluginName": "@chabokan.net/cli",
421
+ "pluginType": "core",
422
+ "strict": true,
423
+ "enableJsonFlag": false,
424
+ "isESM": true,
425
+ "relativePath": [
426
+ "dist",
427
+ "commands",
428
+ "service",
429
+ "stop.js"
430
+ ]
431
+ }
432
+ },
433
+ "version": "0.8.9"
4
434
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chabokan.net/cli",
3
- "version": "0.8.8",
3
+ "version": "0.8.9",
4
4
  "description": "Chabokan Cli for PaaS Services",
5
5
  "author": "Mohammad Abdi",
6
6
  "bin": {
@@ -61,6 +61,7 @@
61
61
  "type": "module",
62
62
  "oclif": {
63
63
  "bin": "chabok",
64
+ "dirname": "cli",
64
65
  "commands": "./dist/commands",
65
66
  "additionalHelpFlags": [
66
67
  "-h"