Say we wanted to restart the Vorpal app from within the prompt.
Eg with a command:
> restart
I have tried different things including executing a shell script that kills the process and executes node app.js without luck
Any tips
I have a vorpal script that reloads the required files every time a command is executed.
const vorpal = require('vorpal')();
function genFn(name){
return function(args, callback) {
delete require.cache[require.resolve('./example.js')];
const script = require('./example.js');
script[name](args, callback);
};
}
const commands = {
'listAllRoles' : 'list all roles for development purposes',
};
for(var key in commands){
vorpal
.command(key, commands[key])
.action(genFn(key));
}
vorpal
.delimiter('example')
.show();
And in example.js
module.exports.listAllRoles = function(args, callback) {
this.log('bar');
callback();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.