@zappinginc/zm2 6.0.14

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.
Files changed (133) hide show
  1. package/.claude/settings.local.json +8 -0
  2. package/.gitattributes +4 -0
  3. package/.mocharc.js +14 -0
  4. package/CHANGELOG.md +2416 -0
  5. package/CLAUDE.md +84 -0
  6. package/CONTRIBUTING.md +124 -0
  7. package/GNU-AGPL-3.0.txt +665 -0
  8. package/LICENSE +1 -0
  9. package/README.md +248 -0
  10. package/bin/zm2 +3 -0
  11. package/bin/zm2-dev +3 -0
  12. package/bin/zm2-docker +3 -0
  13. package/bin/zm2-runtime +3 -0
  14. package/bin/zm2-windows +3 -0
  15. package/bin/zm2.ps1 +3 -0
  16. package/bun.lock +421 -0
  17. package/constants.js +114 -0
  18. package/index.js +13 -0
  19. package/lib/API/Configuration.js +212 -0
  20. package/lib/API/Containerizer.js +335 -0
  21. package/lib/API/Dashboard.js +459 -0
  22. package/lib/API/Deploy.js +117 -0
  23. package/lib/API/Extra.js +775 -0
  24. package/lib/API/ExtraMgmt/Docker.js +30 -0
  25. package/lib/API/Log.js +315 -0
  26. package/lib/API/LogManagement.js +371 -0
  27. package/lib/API/Modules/LOCAL.js +122 -0
  28. package/lib/API/Modules/Modularizer.js +148 -0
  29. package/lib/API/Modules/NPM.js +445 -0
  30. package/lib/API/Modules/TAR.js +362 -0
  31. package/lib/API/Modules/flagExt.js +46 -0
  32. package/lib/API/Modules/index.js +120 -0
  33. package/lib/API/Monit.js +247 -0
  34. package/lib/API/Serve.js +343 -0
  35. package/lib/API/Startup.js +629 -0
  36. package/lib/API/UX/helpers.js +213 -0
  37. package/lib/API/UX/index.js +9 -0
  38. package/lib/API/UX/pm2-describe.js +193 -0
  39. package/lib/API/UX/pm2-ls-minimal.js +31 -0
  40. package/lib/API/UX/pm2-ls.js +483 -0
  41. package/lib/API/Version.js +382 -0
  42. package/lib/API/interpreter.json +12 -0
  43. package/lib/API/pm2-plus/PM2IO.js +372 -0
  44. package/lib/API/pm2-plus/auth-strategies/CliAuth.js +288 -0
  45. package/lib/API/pm2-plus/auth-strategies/WebAuth.js +187 -0
  46. package/lib/API/pm2-plus/helpers.js +97 -0
  47. package/lib/API/pm2-plus/link.js +126 -0
  48. package/lib/API/pm2-plus/pres/motd +16 -0
  49. package/lib/API/pm2-plus/pres/motd.update +26 -0
  50. package/lib/API/pm2-plus/pres/welcome +28 -0
  51. package/lib/API/pm2-plus/process-selector.js +52 -0
  52. package/lib/API/schema.json +379 -0
  53. package/lib/API.js +1931 -0
  54. package/lib/Client.js +776 -0
  55. package/lib/Common.js +911 -0
  56. package/lib/Configuration.js +304 -0
  57. package/lib/Daemon.js +456 -0
  58. package/lib/Event.js +37 -0
  59. package/lib/God/ActionMethods.js +909 -0
  60. package/lib/God/ClusterMode.js +97 -0
  61. package/lib/God/ForkMode.js +297 -0
  62. package/lib/God/Methods.js +265 -0
  63. package/lib/God/Reload.js +240 -0
  64. package/lib/God.js +632 -0
  65. package/lib/HttpInterface.js +76 -0
  66. package/lib/ProcessContainer.js +305 -0
  67. package/lib/ProcessContainerBun.js +360 -0
  68. package/lib/ProcessContainerFork.js +42 -0
  69. package/lib/ProcessContainerForkBun.js +33 -0
  70. package/lib/ProcessUtils.js +55 -0
  71. package/lib/TreeKill.js +118 -0
  72. package/lib/Utility.js +430 -0
  73. package/lib/VersionCheck.js +46 -0
  74. package/lib/Watcher.js +117 -0
  75. package/lib/Worker.js +169 -0
  76. package/lib/binaries/CLI.js +1041 -0
  77. package/lib/binaries/DevCLI.js +183 -0
  78. package/lib/binaries/Runtime.js +101 -0
  79. package/lib/binaries/Runtime4Docker.js +192 -0
  80. package/lib/completion.js +229 -0
  81. package/lib/completion.sh +40 -0
  82. package/lib/motd +36 -0
  83. package/lib/templates/Dockerfiles/Dockerfile-java.tpl +7 -0
  84. package/lib/templates/Dockerfiles/Dockerfile-nodejs.tpl +8 -0
  85. package/lib/templates/Dockerfiles/Dockerfile-ruby.tpl +7 -0
  86. package/lib/templates/ecosystem-es.tpl +24 -0
  87. package/lib/templates/ecosystem-simple-es.tpl +8 -0
  88. package/lib/templates/ecosystem-simple.tpl +6 -0
  89. package/lib/templates/ecosystem.tpl +22 -0
  90. package/lib/templates/init-scripts/launchd.tpl +35 -0
  91. package/lib/templates/init-scripts/openrc.tpl +52 -0
  92. package/lib/templates/init-scripts/pm2-init-amazon.sh +86 -0
  93. package/lib/templates/init-scripts/rcd-openbsd.tpl +41 -0
  94. package/lib/templates/init-scripts/rcd.tpl +44 -0
  95. package/lib/templates/init-scripts/smf.tpl +43 -0
  96. package/lib/templates/init-scripts/systemd-online.tpl +22 -0
  97. package/lib/templates/init-scripts/systemd.tpl +22 -0
  98. package/lib/templates/init-scripts/upstart.tpl +103 -0
  99. package/lib/templates/logrotate.d/pm2 +10 -0
  100. package/lib/templates/sample-apps/http-server/README.md +14 -0
  101. package/lib/templates/sample-apps/http-server/api.js +9 -0
  102. package/lib/templates/sample-apps/http-server/ecosystem.config.js +14 -0
  103. package/lib/templates/sample-apps/http-server/package.json +11 -0
  104. package/lib/templates/sample-apps/pm2-plus-metrics-actions/README.md +45 -0
  105. package/lib/templates/sample-apps/pm2-plus-metrics-actions/custom-metrics.js +66 -0
  106. package/lib/templates/sample-apps/pm2-plus-metrics-actions/ecosystem.config.js +12 -0
  107. package/lib/templates/sample-apps/pm2-plus-metrics-actions/package.json +11 -0
  108. package/lib/templates/sample-apps/python-app/README.md +4 -0
  109. package/lib/templates/sample-apps/python-app/echo.py +7 -0
  110. package/lib/templates/sample-apps/python-app/ecosystem.config.js +12 -0
  111. package/lib/templates/sample-apps/python-app/package.json +11 -0
  112. package/lib/tools/Config.js +248 -0
  113. package/lib/tools/IsAbsolute.js +20 -0
  114. package/lib/tools/copydirSync.js +101 -0
  115. package/lib/tools/deleteFolderRecursive.js +19 -0
  116. package/lib/tools/find-package-json.js +74 -0
  117. package/lib/tools/fmt.js +72 -0
  118. package/lib/tools/isbinaryfile.js +94 -0
  119. package/lib/tools/json5.js +752 -0
  120. package/lib/tools/open.js +63 -0
  121. package/lib/tools/passwd.js +58 -0
  122. package/lib/tools/promise.min.js +1 -0
  123. package/lib/tools/sexec.js +55 -0
  124. package/lib/tools/treeify.js +113 -0
  125. package/lib/tools/which.js +120 -0
  126. package/lib/tools/xdg-open +861 -0
  127. package/package.json +219 -0
  128. package/paths.js +93 -0
  129. package/pm2 +11 -0
  130. package/preinstall.js +24 -0
  131. package/run.sh +9 -0
  132. package/types/index.d.ts +722 -0
  133. package/types/tsconfig.json +14 -0
@@ -0,0 +1,362 @@
1
+
2
+ var Configuration = require('../../Configuration.js');
3
+ var cst = require('../../../constants.js');
4
+ var Common = require('../../Common');
5
+ var forEachLimit = require('async/forEachLimit');
6
+ const sexec = require('../../tools/sexec.js');
7
+ const deleteFolderRecursive = require('../../tools/deleteFolderRecursive.js');
8
+
9
+ var path = require('path');
10
+ var fs = require('fs');
11
+ var os = require('os');
12
+ var spawn = require('child_process').spawn;
13
+ var exec = require('child_process').exec;
14
+ var execSync = require('child_process').execSync;
15
+
16
+ module.exports = {
17
+ install,
18
+ uninstall,
19
+ start,
20
+ publish,
21
+ packager
22
+ }
23
+
24
+ /**
25
+ * Module management to manage tarball packages
26
+ *
27
+ * pm2 install http.tar.gz
28
+ * pm2 uninstall http
29
+ *
30
+ * - the first and only folder in the tarball must be called module (tar zcvf http module/)
31
+ * - a package.json must be present with attribute "name", "version" and "pm2" to declare apps to run
32
+ */
33
+
34
+ function install(PM2, module_filepath, opts, cb) {
35
+ // Remote file retrieval
36
+ if (module_filepath.includes('http') === true) {
37
+ var target_file = module_filepath.split('/').pop()
38
+ var target_filepath = path.join(os.tmpdir(), target_file)
39
+
40
+ opts.install_url = module_filepath
41
+
42
+ return retrieveRemote(module_filepath, target_filepath, (err) => {
43
+ if (err) {
44
+ Common.errMod(err)
45
+ process.exit(1)
46
+ }
47
+ installLocal(PM2, target_filepath, opts, cb)
48
+ })
49
+ }
50
+
51
+ // Local install
52
+ installLocal(PM2, module_filepath, opts, cb)
53
+ }
54
+
55
+ function retrieveRemote(url, dest, cb) {
56
+ Common.logMod(`Retrieving remote package ${url}...`)
57
+
58
+ var wget = spawn('wget', [url, '-O', dest, '-q'], {
59
+ stdio : 'inherit',
60
+ env: process.env,
61
+ windowsHide: true,
62
+ shell : true
63
+ })
64
+
65
+ wget.on('error', (err) => {
66
+ console.error(err.stack || err)
67
+ })
68
+
69
+ wget.on('close', (code) => {
70
+ if (code !== 0)
71
+ return cb(new Error('Could not download'))
72
+ return cb(null)
73
+ })
74
+ }
75
+
76
+ function installLocal(PM2, module_filepath, opts, cb) {
77
+ Common.logMod(`Installing package ${module_filepath}`)
78
+
79
+ // Get module name by unpacking the module/package.json only and read the name attribute
80
+ getModuleName(module_filepath, function(err, module_name) {
81
+ if (err) return cb(err)
82
+
83
+ Common.logMod(`Module name is ${module_name}`)
84
+
85
+ Common.logMod(`Depackaging module...`)
86
+
87
+ var install_path = path.join(cst.DEFAULT_MODULE_PATH, module_name);
88
+
89
+ require('mkdirp').sync(install_path)
90
+
91
+ var install_instance = spawn('tar', ['zxf', module_filepath, '-C', install_path, '--strip-components 1'], {
92
+ stdio : 'inherit',
93
+ env: process.env,
94
+ shell : true
95
+ })
96
+
97
+ install_instance.on('close', function(code) {
98
+ Common.logMod(`Module depackaged in ${install_path}`)
99
+ if (code == 0)
100
+ return runInstall(PM2, install_path, module_name, opts, cb)
101
+ return PM2.exitCli(1)
102
+ });
103
+
104
+ install_instance.on('error', function (err) {
105
+ console.error(err.stack || err);
106
+ });
107
+ })
108
+ }
109
+
110
+ function deleteModulePath(module_name) {
111
+ var sanitized = module_name.replace(/\./g, '')
112
+ deleteFolderRecursive(path.join(cst.DEFAULT_MODULE_PATH, module_name));
113
+ }
114
+
115
+ function runInstall(PM2, target_path, module_name, opts, cb) {
116
+ var config_file = path.join(target_path, 'package.json')
117
+ var conf
118
+
119
+ try {
120
+ conf = require(config_file)
121
+ module_name = conf.name
122
+ } catch(e) {
123
+ Common.errMod(new Error('Cannot find package.json file with name attribute at least'));
124
+ }
125
+
126
+ // Force with the name in the package.json
127
+ opts.started_as_module = true
128
+ opts.cwd = target_path
129
+
130
+ if (needPrefix(conf))
131
+ opts.name_prefix = module_name
132
+
133
+ if (opts.install) {
134
+ Common.logMod(`Running YARN install...`)
135
+
136
+ sexec(`cd ${target_path} ; yarn install`, {silent: false}, function(code) {
137
+ // Start apps under "apps" or "pm2" attribute
138
+ Common.logMod(`Starting ${target_path}`)
139
+ PM2.start(conf, opts, function(err, data) {
140
+ if (err) return cb(err)
141
+
142
+ Configuration.setSync(`${cst.MODULE_CONF_PREFIX_TAR}:${module_name}`, {
143
+ source: 'tarball',
144
+ install_url: opts.install_url,
145
+ installed_at: Date.now()
146
+ })
147
+
148
+ Common.logMod(`Module INSTALLED and STARTED`)
149
+ return cb(null, 'Module installed & Started')
150
+ })
151
+ })
152
+ }
153
+ else {
154
+ PM2.start(conf, opts, function(err, data) {
155
+ if (err) return cb(err)
156
+
157
+ Configuration.setSync(`${cst.MODULE_CONF_PREFIX_TAR}:${module_name}`, {
158
+ source: 'tarball',
159
+ install_url: opts.install_url,
160
+ installed_at: Date.now()
161
+ })
162
+
163
+ Common.logMod(`Module INSTALLED and STARTED`)
164
+ return cb(null, 'Module installed & Started')
165
+ })
166
+ }
167
+ }
168
+
169
+ function start(PM2, module_name, cb) {
170
+ var module_path = path.join(cst.DEFAULT_MODULE_PATH, module_name);
171
+ Common.printOut(cst.PREFIX_MSG_MOD + 'Starting TAR module ' + module_name);
172
+ var package_json_path = path.join(module_path, 'package.json');
173
+ var module_conf = Configuration.getSync(`${cst.MODULE_CONF_PREFIX_TAR}:${module_name}`)
174
+
175
+ try {
176
+ var conf = require(package_json_path)
177
+ } catch(e) {
178
+ Common.printError(`Could not find package.json as ${package_json_path}`)
179
+ return cb()
180
+ }
181
+
182
+ var opts = {};
183
+
184
+ opts.started_as_module = true
185
+ opts.cwd = module_path
186
+
187
+ if (module_conf.install_url)
188
+ opts.install_url = module_conf.install_url
189
+
190
+ if (needPrefix(conf))
191
+ opts.name_prefix = module_name
192
+
193
+ PM2.start(conf, opts, function(err, data) {
194
+ if (err) {
195
+ Common.printError(`Could not start ${module_name} ${module_path}`)
196
+ return cb()
197
+ }
198
+
199
+ Common.printOut(`${cst.PREFIX_MSG_MOD} Module ${module_name} STARTED`)
200
+ return cb();
201
+ })
202
+ }
203
+
204
+ /**
205
+ * Retrieve from module package.json the name of each application
206
+ * delete process and delete folder
207
+ */
208
+ function uninstall(PM2, module_name, cb) {
209
+ var module_path = path.join(cst.DEFAULT_MODULE_PATH, module_name);
210
+
211
+ Common.logMod(`Removing ${module_name} from auto startup`)
212
+
213
+ try {
214
+ var pkg = require(path.join(module_path, 'package.json'))
215
+ } catch(e) {
216
+ Common.errMod('Could not retrieve module package.json');
217
+ return cb(e)
218
+ }
219
+
220
+ var apps = pkg.apps || pkg.pm2
221
+ apps = [].concat(apps);
222
+
223
+ /**
224
+ * Some time a module can have multiple processes
225
+ */
226
+ forEachLimit(apps, 1, (app, next) => {
227
+ var app_name
228
+
229
+ if (!app.name) {
230
+ Common.renderApplicationName(app)
231
+ }
232
+
233
+ if (apps.length > 1)
234
+ app_name = `${module_name}:${app.name}`
235
+ else if (apps.length == 1 && pkg.name != apps[0].name)
236
+ app_name = `${module_name}:${app.name}`
237
+ else
238
+ app_name = app.name
239
+
240
+ PM2._operate('deleteProcessId', app_name, () => {
241
+ deleteModulePath(module_name)
242
+ next()
243
+ })
244
+ }, () => {
245
+ Configuration.unsetSync(`${cst.MODULE_CONF_PREFIX_TAR}:${module_name}`)
246
+ cb(null)
247
+ })
248
+ }
249
+
250
+
251
+ /**
252
+ * Uncompress only module/package.json and retrieve the "name" attribute in the package.json
253
+ */
254
+ function getModuleName(module_filepath, cb) {
255
+ var tmp_folder = path.join(os.tmpdir(), cst.MODULE_BASEFOLDER)
256
+
257
+ var install_instance = spawn('tar', ['zxf', module_filepath, '-C', os.tmpdir(), `${cst.MODULE_BASEFOLDER}/package.json`], {
258
+ stdio : 'inherit',
259
+ env: process.env,
260
+ shell : true
261
+ })
262
+
263
+ install_instance.on('close', function(code) {
264
+ try {
265
+ var pkg = JSON.parse(fs.readFileSync(path.join(tmp_folder, `package.json`)))
266
+ return cb(null, pkg.name)
267
+ } catch(e) {
268
+ return cb(e)
269
+ }
270
+ });
271
+ }
272
+
273
+ function packager(module_path, target_path, cb) {
274
+ var base_folder = path.dirname(module_path)
275
+ var module_folder_name = path.basename(module_path)
276
+ var pkg = require(path.join(module_path, 'package.json'))
277
+ var pkg_name = `${module_folder_name}-v${pkg.version.replace(/\./g, '-')}.tar.gz`
278
+ var target_fullpath = path.join(target_path, pkg_name)
279
+
280
+ var cmd = `tar zcf ${target_fullpath} -C ${base_folder} --transform 's,${module_folder_name},module,' ${module_folder_name}`
281
+
282
+ Common.logMod(`Gziping ${module_path} to ${target_fullpath}`)
283
+
284
+ var tar = exec(cmd, (err, sto, ste) => {
285
+ if (err) {
286
+ console.error(sto.toString().trim())
287
+ console.error(ste.toString().trim())
288
+ }
289
+ })
290
+
291
+ tar.on('close', function (code) {
292
+ cb(code == 0 ? null : code, {
293
+ package_name: pkg_name,
294
+ path: target_fullpath
295
+ })
296
+ })
297
+ }
298
+
299
+ function publish(PM2, folder, cb) {
300
+ var target_folder = folder ? path.resolve(folder) : process.cwd()
301
+
302
+ try {
303
+ var pkg = JSON.parse(fs.readFileSync(path.join(target_folder, 'package.json')).toString())
304
+ } catch(e) {
305
+ Common.errMod(`${process.cwd()} module does not contain any package.json`)
306
+ process.exit(1)
307
+ }
308
+
309
+ if (!pkg.name) throw new Error('Attribute name should be present')
310
+ if (!pkg.version) throw new Error('Attribute version should be present')
311
+ if (!pkg.pm2 && !pkg.apps) throw new Error('Attribute apps should be present')
312
+
313
+ var current_path = target_folder
314
+ var module_name = path.basename(current_path)
315
+ var target_path = os.tmpdir()
316
+
317
+ Common.logMod(`Starting publishing procedure for ${module_name}@${pkg.version}`)
318
+
319
+ packager(current_path, target_path, (err, res) => {
320
+ if (err) {
321
+ Common.errMod('Can\'t package, exiting')
322
+ process.exit(1)
323
+ }
324
+
325
+ Common.logMod(`Package [${pkg.name}] created in path ${res.path}`)
326
+
327
+ var data = {
328
+ module_data: {
329
+ file: res.path,
330
+ content_type: 'content/gzip'
331
+ },
332
+ id: pkg.name,
333
+ name: pkg.name,
334
+ version: pkg.version
335
+ };
336
+
337
+ var uri = `${PM2.pm2_configuration.registry}/api/v1/modules`
338
+ Common.logMod(`Sending Package to remote ${pkg.name} ${uri}`)
339
+
340
+ require('needle')
341
+ .post(uri, data, { multipart: true }, function(err, res, body) {
342
+ if (err) {
343
+ Common.errMod(err)
344
+ process.exit(1)
345
+ }
346
+ if (res.statusCode !== 200) {
347
+ Common.errMod(`${pkg.name}-${pkg.version}: ${res.body.msg}`)
348
+ process.exit(1)
349
+ }
350
+ Common.logMod(`Module ${module_name} published under version ${pkg.version}`)
351
+ process.exit(0)
352
+ })
353
+ })
354
+ }
355
+
356
+ function needPrefix(conf) {
357
+ if ((conf.apps && conf.apps.length > 1) ||
358
+ (conf.pm2 && conf.pm2.length > 1) ||
359
+ (conf.apps.length == 1 && conf.name != conf.apps[0].name))
360
+ return true
361
+ return false
362
+ }
@@ -0,0 +1,46 @@
1
+ var fs = require('fs');
2
+ var conf = require('../../../constants.js');
3
+
4
+ function find_extensions(folder, ext, ret)
5
+ {
6
+ try {
7
+ fs.accessSync(folder, fs.constants.R_OK);
8
+ } catch (err) {
9
+ return;
10
+ }
11
+ if(fs.statSync(folder).isDirectory() && folder.indexOf('node_modules') == -1 && (fs.statSync(folder)["mode"] & 4))
12
+ {
13
+ fs.readdirSync(folder).forEach(file => {
14
+ var tmp;
15
+ if(Number.parseInt(folder.lastIndexOf('/') + 1) === folder.length)
16
+ tmp = folder + file;
17
+ else
18
+ tmp = folder + '/' + file;
19
+ if(fs.statSync(tmp).isDirectory())
20
+ find_extensions(tmp, ext, ret);
21
+ else
22
+ {
23
+ var p = true;
24
+ for(var i = 0; i < ext.length;i++)
25
+ if(ext[i].test(file))
26
+ p = false;
27
+ if(p)
28
+ ret.push(folder + '/' + file);
29
+ }
30
+ });
31
+ }
32
+ }
33
+
34
+ module.exports.make_available_extension = function make_available_extension(opts, ret)
35
+ {
36
+ if(typeof opts == 'object' && typeof ret == 'object')
37
+ {
38
+ var mas = opts.ext.split(',');
39
+ for(var i = 0;i < mas.length;i++)
40
+ mas[i] = '.' + mas[i];
41
+ var res = [];
42
+ for(var i = 0;i < mas.length;i++)
43
+ res[i] = new RegExp(mas[i] + '$');
44
+ find_extensions(process.cwd(), res, ret);
45
+ }
46
+ }
@@ -0,0 +1,120 @@
1
+
2
+ /***************************
3
+ *
4
+ * Module methods
5
+ *
6
+ **************************/
7
+
8
+ var cst = require('../../../constants.js');
9
+ var Common = require('../../Common.js');
10
+ var chalk = require('ansis');
11
+ var forEachLimit = require('async/forEachLimit');
12
+
13
+ var Modularizer = require('./Modularizer.js');
14
+
15
+ module.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
+ };