Commit modules
This commit is contained in:
96
node_modules/@node-minify/cli/lib/cli.js
generated
vendored
Normal file
96
node_modules/@node-minify/cli/lib/cli.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.run = void 0;
|
||||
|
||||
var _chalk = _interopRequireDefault(require("chalk"));
|
||||
|
||||
var _compress = require("./compress");
|
||||
|
||||
var _spinner = require("./spinner");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/*!
|
||||
* node-minify
|
||||
* Copyright(c) 2011-2019 Rodolphe Stoclin
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module variables.
|
||||
*/
|
||||
let silence = false;
|
||||
/**
|
||||
* Run one compressor.
|
||||
*/
|
||||
|
||||
const runOne = cli => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const compressor = typeof cli.compressor === 'string' ? require(`@node-minify/${cli.compressor}`) : cli.compressor;
|
||||
const options = {
|
||||
compressorLabel: cli.compressor,
|
||||
compressor,
|
||||
input: cli.input.split(','),
|
||||
output: cli.output
|
||||
};
|
||||
|
||||
if (cli.option) {
|
||||
options.options = JSON.parse(cli.option);
|
||||
}
|
||||
|
||||
if (!silence) {
|
||||
(0, _spinner.spinnerStart)(options);
|
||||
}
|
||||
|
||||
return (0, _compress.compress)(options).then(result => {
|
||||
if (!silence) {
|
||||
(0, _spinner.spinnerStop)(result);
|
||||
}
|
||||
|
||||
resolve(result);
|
||||
}).catch(err => {
|
||||
if (!silence) {
|
||||
(0, _spinner.spinnerError)(options);
|
||||
}
|
||||
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Run cli.
|
||||
*/
|
||||
|
||||
|
||||
const run = cli => {
|
||||
silence = !!cli.silence;
|
||||
|
||||
if (!silence) {
|
||||
console.log('');
|
||||
console.log(_chalk.default.bgBlue.black(' INFO '), 'Starting compression...');
|
||||
console.log('');
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
runOne(cli).then(() => {
|
||||
if (!silence) {
|
||||
console.log('');
|
||||
console.log(_chalk.default.bgGreen.black(' DONE '), _chalk.default.green('Done!'));
|
||||
console.log('');
|
||||
}
|
||||
}).then(resolve).catch(reject);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Expose `run()`.
|
||||
*/
|
||||
|
||||
|
||||
exports.run = run;
|
||||
48
node_modules/@node-minify/cli/lib/compress.js
generated
vendored
Normal file
48
node_modules/@node-minify/cli/lib/compress.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.compress = void 0;
|
||||
|
||||
var _core = _interopRequireDefault(require("@node-minify/core"));
|
||||
|
||||
var _utils = require("@node-minify/utils");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/*!
|
||||
* node-minify
|
||||
* Copyright(c) 2011-2019 Rodolphe Stoclin
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Run compression.
|
||||
*
|
||||
* @param {Object} options
|
||||
*/
|
||||
const compress = options => {
|
||||
return new Promise((resolve, reject) => {
|
||||
(0, _core.default)(options).then(() => {
|
||||
_utils.utils.getFilesizeGzippedInBytes(options.output).then(sizeGzip => {
|
||||
resolve({
|
||||
compressorLabel: options.compressorLabel,
|
||||
compressor: options.compressor,
|
||||
size: _utils.utils.getFilesizeInBytes(options.output),
|
||||
sizeGzip: sizeGzip
|
||||
});
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Expose `compress()`.
|
||||
*/
|
||||
|
||||
|
||||
exports.compress = compress;
|
||||
65
node_modules/@node-minify/cli/lib/spinner.js
generated
vendored
Normal file
65
node_modules/@node-minify/cli/lib/spinner.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.spinnerError = exports.spinnerStop = exports.spinnerStart = void 0;
|
||||
|
||||
var _chalk = _interopRequireDefault(require("chalk"));
|
||||
|
||||
var _ora = _interopRequireDefault(require("ora"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/*!
|
||||
* node-minify
|
||||
* Copyright(c) 2011-2019 Rodolphe Stoclin
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
const spinner = (0, _ora.default)();
|
||||
/**
|
||||
* Start spinner.
|
||||
*
|
||||
* @param {Object} options
|
||||
*/
|
||||
|
||||
const start = options => {
|
||||
spinner.text = 'Compressing file(s) with ' + _chalk.default.green(options.compressorLabel) + '...';
|
||||
spinner.start();
|
||||
};
|
||||
/**
|
||||
* Stop spinner.
|
||||
*
|
||||
* @param {Object} result
|
||||
*/
|
||||
|
||||
|
||||
exports.spinnerStart = start;
|
||||
|
||||
const stop = result => {
|
||||
spinner.text = 'File(s) compressed successfully with ' + _chalk.default.green(result.compressorLabel) + ' (' + _chalk.default.green(result.size) + ' minified, ' + _chalk.default.green(result.sizeGzip) + ' gzipped)';
|
||||
spinner.succeed();
|
||||
};
|
||||
/**
|
||||
* Mark spinner as failed.
|
||||
*
|
||||
* @param {Object} options
|
||||
*/
|
||||
|
||||
|
||||
exports.spinnerStop = stop;
|
||||
|
||||
const error = options => {
|
||||
spinner.text = 'Error - file(s) not compressed with ' + _chalk.default.red(options.compressorLabel);
|
||||
spinner.fail();
|
||||
};
|
||||
/**
|
||||
* Expose `start(), stop() and error()`.
|
||||
*/
|
||||
|
||||
|
||||
exports.spinnerError = error;
|
||||
Reference in New Issue
Block a user