mirror of
https://github.com/Unitech/pm2.git
synced 2026-02-01 16:57:09 +00:00
module:cmd prefixes - add pm2 module:generate to generate a sample module
This commit is contained in:
parent
b4f191cc7c
commit
d1514139f6
@ -2,13 +2,13 @@
|
||||
# 1.0.0-beta
|
||||
|
||||
- beta pmx // rm
|
||||
- pm2 module:update <module_name>
|
||||
- New command: pm2 module:update <module_name> -> Update a module
|
||||
- New command: pm2 module:publish -> Publish module in current folder + Git push
|
||||
- New command: pm2 module:generate -> Generate a sample module
|
||||
- alias pm2 install with pm2 i
|
||||
- pm2 publish publish module on NPM + commit on Git
|
||||
|
||||
# 0.14.7
|
||||
|
||||
-
|
||||
- New flag `--no-pmx` : starts an app without injecting pmx
|
||||
- New feature : cron restart now works in fork mode as well
|
||||
- Disabled auto-gc on interactor
|
||||
|
||||
14
bin/pm2
14
bin/pm2
@ -342,26 +342,28 @@ commander.command('update')
|
||||
* Module specifics
|
||||
*/
|
||||
commander.command('install <module|git:// url>')
|
||||
.alias('i')
|
||||
.alias('module:install')
|
||||
.description('install or update a module and run it forever')
|
||||
.action(function(plugin_name) {
|
||||
CLI.install(plugin_name);
|
||||
});
|
||||
|
||||
commander.command('module:update <module|git:// url>')
|
||||
.description('install or update a module and run it forever')
|
||||
.action(function(plugin_name) {
|
||||
CLI.install(plugin_name);
|
||||
commander.command('module:generate')
|
||||
.description('Generate a sample module in current folder')
|
||||
.action(function() {
|
||||
CLI.generateModuleSample();
|
||||
});
|
||||
|
||||
commander.command('uninstall <module>')
|
||||
.alias('ui')
|
||||
.alias('module:uninstall')
|
||||
.description('stop and uninstall a module')
|
||||
.action(function(plugin_name) {
|
||||
CLI.uninstall(plugin_name);
|
||||
});
|
||||
|
||||
|
||||
commander.command('publish')
|
||||
.alias('module:publish')
|
||||
.description('Publish the module you are currently on')
|
||||
.action(CLI.publish);
|
||||
|
||||
|
||||
11
lib/CLI.js
11
lib/CLI.js
@ -1846,6 +1846,17 @@ CLI.publish = function(module_name, cb) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Publish module on NPM + Git push
|
||||
*/
|
||||
CLI.generateModuleSample = function(cb) {
|
||||
Modularizer.generateSample(function(err, data) {
|
||||
if (err)
|
||||
return cb ? cb(err) : exitCli(cst.ERROR_EXIT);
|
||||
return cb ? cb(null, data) : exitCli(cst.SUCCESS_EXIT);
|
||||
});
|
||||
};
|
||||
|
||||
CLI.killAllModules = function(cb) {
|
||||
Common.getAllModulesId(function(err, modules_id) {
|
||||
async.forEachLimit(modules_id, 1, function(id, next) {
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
|
||||
var Modularizer = module.exports = {};
|
||||
|
||||
var shelljs = require('shelljs');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var async = require('async');
|
||||
var p = path;
|
||||
var shelljs = require('shelljs');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var async = require('async');
|
||||
var p = path;
|
||||
var readline = require('readline');
|
||||
|
||||
var Configuration = require('./Configuration.js');
|
||||
var cst = require('../constants.js');
|
||||
@ -23,7 +24,7 @@ var UX = require('./CliUx.js');
|
||||
// [X] Block all tentatives to stop a module
|
||||
// [X] NO NEED pm2 generate module = Provide a module skeleton
|
||||
// [X] pm2 update=install <module> = not deleting the conf file
|
||||
// pm2 publish module (increment version, git push, npm publish)
|
||||
// [X] pm2 publish module (increment version, git push, npm publish)
|
||||
// [X] API normalization = dont block adoption, find common way to transform current software into propack
|
||||
|
||||
function startModule(opts, cb) {
|
||||
@ -278,9 +279,6 @@ Modularizer.uninstall = function(module_name, cb) {
|
||||
* Publish a module
|
||||
*/
|
||||
Modularizer.publish = function(cb) {
|
||||
var readline = require('readline');
|
||||
|
||||
|
||||
var rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
@ -327,6 +325,51 @@ Modularizer.publish = function(cb) {
|
||||
});
|
||||
};
|
||||
|
||||
Modularizer.generateSample = function(cb) {
|
||||
var rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
rl.question(cst.PREFIX_MSG_MOD + "Module name: ", function(module_name) {
|
||||
|
||||
var cmd1 = 'git clone https://github.com/pm2-hive/sample-module.git ' + module_name + '; cd ' + module_name + '; rm -rf .git';
|
||||
var cmd2 = 'cd ' + module_name + ' ; sed -i "s:sample-module:'+ module_name +':g" package.json';
|
||||
var cmd3 = 'cd ' + module_name + ' ; npm install';
|
||||
|
||||
Common.printOut(cst.PREFIX_MSG_MOD + 'Getting sample app');
|
||||
shelljs.exec(cmd1, function(err) {
|
||||
if (err) Common.printError(cst.PREFIX_MSG_MOD_ERR + err.message);
|
||||
shelljs.exec(cmd2, function(err) {
|
||||
console.log('');
|
||||
shelljs.exec(cmd3, function(err) {
|
||||
console.log('');
|
||||
Common.printOut(cst.PREFIX_MSG_MOD + 'Module sample created in folder: ', path.join(process.cwd(), module_name));
|
||||
console.log('');
|
||||
Common.printOut('Start module in development mode:');
|
||||
Common.printOut('$ cd ' + module_name + '/');
|
||||
Common.printOut('$ pm2 install . ');
|
||||
console.log('');
|
||||
|
||||
Common.printOut('Probe values: ');
|
||||
Common.printOut('$ pm2 iprobe');
|
||||
console.log('');
|
||||
Common.printOut('Module Log: ');
|
||||
Common.printOut('$ pm2 logs ' + module_name);
|
||||
console.log('');
|
||||
Common.printOut('Uninstall module: ');
|
||||
Common.printOut('$ pm2 uninstall ' + module_name);
|
||||
console.log('');
|
||||
Common.printOut('Force restart: ');
|
||||
Common.printOut('$ pm2 restart ' + module_name);
|
||||
return cb ? cb() : false;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
function isValidModule(conf) {
|
||||
var valid = true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user