简体   繁体   中英

Is it possible to restart a Vorpal application from the Vorpal prompt?

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

This would be the same problem as re-starting any Node add from within itself, really. The only difference is that you would have a Vorpal command trigger the action.

Here are some libraries that try to solve that.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM