all files / prolific.root/ commandable.js

100% Statements 17/17
100% Branches 12/12
100% Functions 1/1
100% Lines 17/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27                    
module.exports = function (terminal, argv) {
    if (terminal || argv[0] == 'node') {
        return null
    }
    var command = argv[0], url = null
    if (~command.indexOf(':')) {
        url = command
        command = command.split(':')[0]
    }
    var pkg = command[0] == '@'
            ? command.substring(1)
            : 'prolific.' + command
    try {
        var required = require(pkg)
        if (!required.isProlific) {
            return null
        }
        argv.shift()
        if (url != null) {
            argv.unshift('--url', url)
        }
        return required
    } catch (e) {
        return null
    }
}