UNPKG

malta

Version:

Lightning builder allows to compose on the fly and update packed and full coded huge files, edit its parts as files, splitted and glued as You need.

125 lines (112 loc) 4.51 kB
#!/usr/bin/env node require('./stringproto'); const Malta = require('./malta'), colors = require('./colors'), 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') ? colors.white([parseInt(100 * i / tot, 10), '% '].join('')) : ''; Malta.log_debug(perc + msg); }; process.title = 'Malta'; try { (function _M (_args, _len) { function go (_runs) { for (const tpl in _runs) { if (!Object.prototype.hasOwnProperty.call(_runs, tpl)) continue; // 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, colors.red('EXE'), '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/), (err) => { if (err) { Malta.log_err(err.message); process.exit(1); } ++i; start(); }); } else { print(`execution: ${commands[i]}`, i + 1, clen); Malta.execute(commands[i].split(/\s/), (err) => { if (err) { Malta.log_err(err.message); process.exit(1); } print('...done!\n'); delete runs.EXE; go(runs); }); } })(); } else { print(`execution: ${commands}`, 1, 1); Malta.execute(commands.split(/\s/), function (err) { if (err) { Malta.log_err(err.message); process.exit(1); } 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;