UNPKG

3.17 kBJavaScriptView Raw
1
2/***************************
3 *
4 * Module methods
5 *
6 **************************/
7
8var cst = require('../../../constants.js');
9var Common = require('../../Common.js');
10var chalk = require('chalk');
11var forEachLimit = require('async/forEachLimit');
12
13var Modularizer = require('./Modularizer.js');
14
15module.exports = function(CLI) {
16 /**
17 * Install / Update a module
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 * Uninstall a module
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 * Publish module on NPM + Git push
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 * Publish module on NPM + Git push
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 * Special delete method
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};