All files / src starter.js

100% Statements 56/56
100% Branches 28/28
100% Functions 8/8
100% Lines 54/54

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106  32x 32x 32x 32x 32x 32x   32x     64x     64x     32x   29x     10x 3x     7x 6x           35x 1x       34x 33x   33x 1x 1x     32x 32x   32x 30x 28x 28x             28x   28x 28x 28x 27x 14x 25x 11x 11x 11x 11x     14x 14x 13x 13x 13x         13x 13x 13x 13x 13x       1x       2x         1x 1x       27x  
#!/usr/bin/env node
const Malta = require('./malta'),
    path = require('path'),
    functions = require('./functions'),
    execPath = process.cwd(),
    args = process.argv.slice(2),
    len = args.length;
 
process.title = 'Malta';
 
function print (msg, i, tot) {
    const perc = (typeof i !== 'undefined' && typeof tot !== 'undefined')
        ? [parseInt(100 * i / tot, 10), '% '].join('').white()
        : '';
    Malta.log_debug(perc + msg);
}
 
(function _M (_args, _len) {
    function go (_runs) {
        for (const tpl in _runs) {
            // check if is inclusion {whatever.json : true}
            //
            if (tpl.match(/\.json$/) && _runs[tpl] === true) {
                _M([tpl], 1);
            } else {
                // skip if key begins with !
                if (tpl.match(/^!/)) continue;
                functions.multi(tpl, _runs[tpl]);
            }
        }
    }
 
    // no params -> print help and exit
    if (_len === 0) {
        global.BIN_MODE && Malta.log_help();
 
        // just one param is given -> is a build json file
        //
    } else if (_len === 1) {
        Malta.outVersion();
 
        if (_args[0].match(/^-/)) {
            functions.subCommand(_args[0]);
            Malta.stop();
        }
 
        const p = path.resolve(execPath, _args[0]),
            runs = Malta.getRunsFromPath(p);
 
        if (!runs) Malta.badargs(p);
        if ('EXE' in runs) {
            (function (commands) {
                Malta.log_info([
                    Malta.NL,
                    'EXE'.red(),
                    'section for',
                    _args[0]
                ].join(' '));
 
                let i = 0;
 
                const isArray = commands instanceof Array,
                    clen = commands.length;
                if (clen) {
                    if (isArray) {
                        (function start () {
                            if (i < clen - 1) {
                                print(`execution: ${commands[i]}`, i + 1, clen);
                                Malta.execute(commands[i].split(/\s/), () => {
                                    ++i;
                                    start();
                                });
                            } else {
                                print(`execution: ${commands[i]}`, i + 1, clen);
                                Malta.execute(commands[i].split(/\s/), () => {
                                    print('...done!\n');
                                    delete runs.EXE;
                                    go(runs);
                                });
                            }
                        })();
                    } else {
                        print(`execution: ${commands}`, 1, 1);
                        Malta.execute(commands.split(/\s/), function () {
                            print(`...done!${Malta.NL}`);
                            delete runs.EXE;
                            go(runs);
                        });
                    }
                } else {
                    go(runs);
                }
            })(runs.EXE);
        } else {
            go(runs);
        }
 
        // single build
    } else {
        Malta.outVersion();
        Malta.get().check(_args).start();
    }
})(args, len);
 
module.exports = Malta;