minify-all-cli
Version:
Minify All JS, CSS and HTML files in a folder by using UglifyJS, CSSNano and HTMLMinifier with an option to gzip all the files as well.
27 lines (24 loc) • 797 B
JavaScript
const spawn = require("child_process").spawn;
const concat = require("concat-stream");
function createProcess(processPath, args = []) {
args = [processPath].concat(args);
return spawn("node", args);
}
function execute(processPath, args = [], opts = {}) {
const { env = null } = opts;
const childProcess = createProcess(processPath, args, env);
childProcess.stdin.setEncoding("utf-8");
const promise = new Promise((resolve, reject) => {
childProcess.stderr.once("data", err => {
reject(err.toString());
});
childProcess.on("error", reject);
childProcess.stdout.pipe(
concat(result => {
resolve(result.toString());
})
);
});
return promise;
}
module.exports = { execute };