@node-minify/core
Advanced tools
Comparing version 5.0.0 to 5.1.0
@@ -12,2 +12,4 @@ "use strict"; | ||
var _utils = require("@node-minify/utils"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -40,3 +42,3 @@ | ||
} else { | ||
return compressSingleFile(settings); | ||
return _utils.utils.compressSingleFile(settings); | ||
} | ||
@@ -55,4 +57,5 @@ }; | ||
return settings.input.forEach((input, index) => { | ||
const content = getContentFromFiles(input); | ||
return runSync({ | ||
const content = _utils.utils.getContentFromFiles(input); | ||
return _utils.utils.runSync({ | ||
settings, | ||
@@ -74,4 +77,5 @@ content, | ||
settings.input.forEach((input, index) => { | ||
const content = getContentFromFiles(input); | ||
sequence = sequence.then(() => runAsync({ | ||
const content = _utils.utils.getContentFromFiles(input); | ||
sequence = sequence.then(() => _utils.utils.runAsync({ | ||
settings, | ||
@@ -85,84 +89,2 @@ content, | ||
/** | ||
* Compress a single file. | ||
* | ||
* @param {Object} settings | ||
*/ | ||
const compressSingleFile = settings => { | ||
const content = getContentFromFiles(settings.input); | ||
return settings.sync ? runSync({ | ||
settings, | ||
content | ||
}) : runAsync({ | ||
settings, | ||
content | ||
}); | ||
}; | ||
/** | ||
* Run compressor in sync. | ||
* | ||
* @param {Object} settings | ||
* @param {String} content | ||
* @param {Number} index - index of the file being processed | ||
* @return {String} | ||
*/ | ||
const runSync = ({ | ||
settings, | ||
content, | ||
index | ||
}) => settings.compressor({ | ||
settings, | ||
content, | ||
callback: null, | ||
index | ||
}); | ||
/** | ||
* Run compressor in async. | ||
* | ||
* @param {Object} settings | ||
* @param {String} content | ||
* @param {Number} index - index of the file being processed | ||
* @return {Promise} | ||
*/ | ||
const runAsync = ({ | ||
settings, | ||
content, | ||
index | ||
}) => { | ||
return new Promise((resolve, reject) => { | ||
settings.compressor({ | ||
settings, | ||
content, | ||
callback: (err, min) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
resolve(min); | ||
}, | ||
index | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Concatenate all input files and get the data. | ||
* | ||
* @param {String|Array} input | ||
* @return {String} | ||
*/ | ||
const getContentFromFiles = input => { | ||
if (!Array.isArray(input)) { | ||
return _fs.default.readFileSync(input, 'utf8'); | ||
} | ||
return input.map(path => _fs.default.readFileSync(path, 'utf8')).join('\n'); | ||
}; | ||
/** | ||
* Create folder of the target file. | ||
@@ -169,0 +91,0 @@ * |
@@ -7,2 +7,4 @@ "use strict"; | ||
var _compressInMemory = require("./compressInMemory"); | ||
/*! | ||
@@ -25,6 +27,7 @@ * node-minify | ||
return new Promise((resolve, reject) => { | ||
const method = settings.content ? _compressInMemory.compressInMemory : _compress.compress; | ||
settings = (0, _setup.setup)(settings); | ||
if (!settings.sync) { | ||
(0, _compress.compress)(settings).then(minified => { | ||
method(settings).then(minified => { | ||
if (settings.callback) { | ||
@@ -43,3 +46,3 @@ settings.callback(null, minified); | ||
} else { | ||
const minified = (0, _compress.compress)(settings); | ||
const minified = method(settings); | ||
@@ -46,0 +49,0 @@ if (settings.callback) { |
@@ -43,4 +43,10 @@ "use strict"; | ||
const setup = inputSettings => { | ||
let settings = Object.assign(_utils.utils.clone(defaultSettings), inputSettings); // In memory | ||
if (settings.content) { | ||
checkMandatoriesMemoryContent(inputSettings); | ||
return settings; | ||
} | ||
checkMandatories(inputSettings); | ||
let settings = Object.assign(_utils.utils.clone(defaultSettings), inputSettings); | ||
settings = Object.assign(settings, wildcards(settings.input, settings.publicFolder)); | ||
@@ -212,2 +218,12 @@ settings = Object.assign(settings, checkOutput(settings.input, settings.output, settings.publicFolder)); | ||
/** | ||
* Check if some settings are here for memory content. | ||
* | ||
* @param {Object} settings | ||
*/ | ||
const checkMandatoriesMemoryContent = settings => { | ||
['compressor', 'content'].forEach(item => mandatory(item, settings)); | ||
}; | ||
/** | ||
* Check if the setting exist. | ||
@@ -214,0 +230,0 @@ * |
{ | ||
"name": "@node-minify/core", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"description": "core of @node-minify", | ||
@@ -35,7 +35,7 @@ "keywords": [ | ||
"dependencies": { | ||
"@node-minify/utils": "^5.0.0", | ||
"@node-minify/utils": "^5.1.0", | ||
"glob": "7.1.5", | ||
"mkdirp": "0.5.1" | ||
}, | ||
"gitHead": "2655e814697ddbce46dd57e945e2a8ddfb14b151" | ||
"gitHead": "bfb1832dae961da38c06f118c6e30eae52e46c56" | ||
} |
7
12902
352
Updated@node-minify/utils@^5.1.0