1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var cst = require('../../../constants.js');
|
9 | var Common = require('../../Common.js');
|
10 | var chalk = require('chalk');
|
11 | var forEachLimit = require('async/forEachLimit');
|
12 |
|
13 | var Modularizer = require('./Modularizer.js');
|
14 |
|
15 | module.exports = function(CLI) {
|
16 | |
17 |
|
18 |
|
19 | CLI.prototype.install = function(module_name, opts, cb) {
|
20 | var that = this;
|
21 |
|
22 | if (typeof(opts) == 'function') {
|
23 | cb = opts;
|
24 | opts = {};
|
25 | }
|
26 |
|
27 | Modularizer.install(this, module_name, opts, function(err, data) {
|
28 | if (err) {
|
29 | Common.printError(cst.PREFIX_MSG_ERR + (err.message || err));
|
30 | return cb ? cb(Common.retErr(err)) : that.speedList(cst.ERROR_EXIT);
|
31 | }
|
32 | return cb ? cb(null, data) : that.speedList(cst.SUCCESS_EXIT);
|
33 | });
|
34 | };
|
35 |
|
36 | |
37 |
|
38 |
|
39 | CLI.prototype.uninstall = function(module_name, cb) {
|
40 | var that = this;
|
41 |
|
42 | Modularizer.uninstall(this, module_name, function(err, data) {
|
43 | if (err)
|
44 | return cb ? cb(Common.retErr(err)) : that.speedList(cst.ERROR_EXIT);
|
45 | return cb ? cb(null, data) : that.speedList(cst.SUCCESS_EXIT);
|
46 | });
|
47 | };
|
48 |
|
49 | CLI.prototype.launchAll = function(CLI, cb) {
|
50 | Modularizer.launchModules(CLI, cb);
|
51 | };
|
52 |
|
53 | CLI.prototype.package = function(module_path, cb) {
|
54 | Modularizer.package(this, module_path, (err, res) => {
|
55 | if (err) {
|
56 | Common.errMod(err)
|
57 | return cb ? cb(err) : this.exitCli(1)
|
58 | }
|
59 | Common.logMod(`Module packaged in ${res.path}`)
|
60 | return cb ? cb(err) : this.exitCli(0)
|
61 | })
|
62 | };
|
63 |
|
64 | |
65 |
|
66 |
|
67 | CLI.prototype.publish = function(folder, opts, cb) {
|
68 | var that = this;
|
69 |
|
70 | Modularizer.publish(this, folder, opts, function(err, data) {
|
71 | if (err)
|
72 | return cb ? cb(Common.retErr(err)) : that.speedList(cst.ERROR_EXIT);
|
73 | return cb ? cb(null, data) : that.speedList(cst.SUCCESS_EXIT);
|
74 | });
|
75 | };
|
76 |
|
77 | |
78 |
|
79 |
|
80 | CLI.prototype.generateModuleSample = function(app_name, cb) {
|
81 | var that = this;
|
82 |
|
83 | Modularizer.generateSample(app_name, function(err, data) {
|
84 | if (err)
|
85 | return cb ? cb(Common.retErr(err)) : that.exitCli(cst.ERROR_EXIT);
|
86 | return cb ? cb(null, data) : that.exitCli(cst.SUCCESS_EXIT);
|
87 | });
|
88 | };
|
89 |
|
90 | |
91 |
|
92 |
|
93 | CLI.prototype.deleteModule = function(module_name, cb) {
|
94 | var that = this;
|
95 |
|
96 | var found_proc = [];
|
97 |
|
98 | this.Client.getAllProcess(function(err, procs) {
|
99 | if (err) {
|
100 | Common.printError('Error retrieving process list: ' + err);
|
101 | return cb(Common.retErr(err));
|
102 | }
|
103 |
|
104 | procs.forEach(function(proc) {
|
105 | if (proc.pm2_env.name == module_name && proc.pm2_env.pmx_module) {
|
106 | found_proc.push(proc.pm_id);
|
107 | }
|
108 | });
|
109 |
|
110 | if (found_proc.length == 0)
|
111 | return cb();
|
112 |
|
113 | that._operate('deleteProcessId', found_proc[0], function(err) {
|
114 | if (err) return cb(Common.retErr(err));
|
115 | Common.printOut('In memory process deleted');
|
116 | return cb();
|
117 | });
|
118 | });
|
119 | };
|
120 | };
|