rollup-umd-scripts
Version:
CLI for rollup-umd projects
53 lines (47 loc) • 1.67 kB
JavaScript
;
/* eslint-disable */
var _require = require('child_process'),
exec = _require.exec,
spawn = _require.spawn;
var fs = require('fs');
global.exec = function (command, cb) {
exec(command, {
maxBuffer: 1024 * 1024
}, cb);
};
global.spawn = function (command, cb) {
var split = command.split(' ');
var program = split[0];
var args = split.slice(1);
var child = spawn(program, args || []);
var outputList = [];
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
child.stdout.on('data', function (data) {
return outputList.push(data) && console.log(data.replace(/\n$/, ''));
});
child.stderr.on('data', function (data) {
return outputList.push(data) && console.log(data.replace(/\n$/, ''));
});
child.on('close', function (code) {
return code === 1 ? cb(new Error('child process exited with code ' + code, [outputList.join('')])) : cb(null, [outputList.join('')]);
});
};
global.sedReplace = function (input, before, after, output) {
var cb = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : function () {};
var file = fs.readFileSync(input, 'utf8');
var re = new RegExp(escapeRegExp(before), 'gm');
var newFile = file.replace(re, after);
fs.writeFileSync(output, newFile, 'utf8');
cb();
};
global.withLog = function (cb) {
return function (err, stdout) {
console.log(stdout);return cb(err, stdout);
};
};
function escapeRegExp(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}
require('yargs').commandDir('cmds').demandCommand().help().wrap(100).epilog('Copyright 2017. Yeutech Company Limited.').argv;