All files starter.js

98.3% Statements 58/59
100% Branches 28/28
100% Functions 8/8
98.24% Lines 56/57

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 107 108 109  36x 36x 36x 36x 36x 36x 36x 66x     66x     36x   36x 36x   33x     13x 3x     10x 9x           39x 1x       38x 37x   37x 1x 1x     36x 36x   36x 34x 29x 29x             29x   29x 29x 29x 28x 15x 26x 11x 11x 11x 11x     15x 15x 14x 14x 14x         13x 13x 13x 13x 13x       1x       5x         1x 1x             31x  
#!/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,
    print = (msg, i, tot) => {
        const perc = (typeof i !== 'undefined' && typeof tot !== 'undefined')
            ? [parseInt(100 * i / tot, 10), '% '].join('').white()
            : '';
        Malta.log_debug(perc + msg);
    };
 
process.title = 'Malta';
 
try {
    (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);
} catch (e) {
    Malta.log_err(e);
}
 
module.exports = Malta;