use directories for structure

This commit is contained in:
s2
2020-05-26 10:37:57 +02:00
parent 66580d4847
commit ae4aaf2668
1287 changed files with 92093 additions and 13113 deletions

7
node_modules/minify/lib/css.js generated vendored
View File

@@ -9,14 +9,17 @@ const Clean = require('clean-css');
* minify css data.
*
* @param data
* @param userOptions - (optional) object that may contain a `css` key with an object of options
*/
module.exports = (data) => {
module.exports = (data, userOptions) => {
assert(data);
const options = userOptions && userOptions.css || {};
const {
styles,
errors,
} = new Clean().minify(data);
} = new Clean(options).minify(data);
const [error] = errors;

13
node_modules/minify/lib/html.js generated vendored
View File

@@ -5,7 +5,7 @@
const assert = require('assert');
const Minifier = require('html-minifier');
const Options = {
const defaultOptions = {
removeComments: true,
removeCommentsFromCDATA: true,
removeCDATASectionsFromCDATA: true,
@@ -32,11 +32,16 @@ const Options = {
* minify html data.
*
* @param data
* @param callback
* @param userOptions - (optional) object that may contain an `html` key with an object of options
*/
module.exports = (data) => {
module.exports = (data, userOptions) => {
assert(data);
return Minifier.minify(data, Options);
const options = {
...defaultOptions,
...userOptions && userOptions.html || {},
};
return Minifier.minify(data, options);
};

16
node_modules/minify/lib/img.js generated vendored
View File

@@ -8,7 +8,9 @@ const fromString = promisify(require('css-b64-images').fromString);
const ONE_KB = 2 ** 10;
const maxSize = 100 * ONE_KB;
const defaultOptions = {
maxSize: 100 * ONE_KB,
};
/**
* minify css data.
@@ -16,16 +18,20 @@ const maxSize = 100 * ONE_KB;
*
* @param name
* @param data
* @param userOptions - (optional) object that may contain an `img` key with an object of options
*/
module.exports = async (name, data) => {
module.exports = async (name, data, userOptions) => {
const dir = path.dirname(name);
const dirRelative = dir + '/../';
const options = {
...defaultOptions,
...userOptions && userOptions.img || {},
};
assert(name);
assert(data);
return fromString(data, dir, dirRelative, {
maxSize,
});
return fromString(data, dir, dirRelative, options);
};

7
node_modules/minify/lib/js.js generated vendored
View File

@@ -7,14 +7,17 @@ const assert = require('assert');
* minify js data.
*
* @param data
* @param userOptions - (optional) object that may contain a `js` key with an object of options
*/
module.exports = (data) => {
module.exports = (data, userOptions) => {
assert(data);
const options = userOptions && userOptions.js || {};
const {
error,
code,
} = terser.minify(data);
} = terser.minify(data, options);
if (error)
throw error;

27
node_modules/minify/lib/minify.js generated vendored
View File

@@ -2,12 +2,10 @@
const DIR = __dirname + '/';
const fs = require('fs');
const {readFile} = require('fs').promises;
const path = require('path');
const {promisify} = require('util');
const tryToCatch = require('try-to-catch');
const readFile = promisify(fs.readFile);
const log = require('debug')('minify');
@@ -22,7 +20,7 @@ function check(name) {
throw Error('name could not be empty!');
}
async function minify(name) {
async function minify(name, userOptions) {
const EXT = ['js', 'html', 'css'];
check(name);
@@ -34,7 +32,7 @@ async function minify(name) {
throw Error(`File type "${ext}" not supported.`);
log('optimizing ' + path.basename(name));
return optimize(name);
return optimize(name, userOptions);
}
function getName(file) {
@@ -49,9 +47,10 @@ function getName(file) {
/**
* function minificate js,css and html files
*
* @param files - js, css or html file path
* @param {string} file - js, css or html file path
* @param {object} userOptions - object with optional `html`, `css, `js`, and `img` keys, which each can contain options to be combined with defaults and passed to the respective minifier
*/
async function optimize(file) {
async function optimize(file, userOptions) {
check(file);
const name = getName(file);
@@ -59,24 +58,26 @@ async function optimize(file) {
log('reading file ' + path.basename(name));
const data = await readFile(name, 'utf8');
return onDataRead(file, data);
return onDataRead(file, data, userOptions);
}
/**
* Processing of files
* @param fileData {name, data}
* Processing of files
* @param {string} filename
* @param {string} data - the contents of the file
* @param {object} userOptions - object with optional `html`, `css, `js`, and `img` keys, which each can contain options to be combined with defaults and passed to the respective minifier
*/
async function onDataRead(filename, data) {
async function onDataRead(filename, data, userOptions) {
log('file ' + path.basename(filename) + ' read');
const ext = path.extname(filename).replace(/^\./, '');
const optimizedData = await minify[ext](data);
const optimizedData = await minify[ext](data, userOptions);
let b64Optimize;
if (ext === 'css')
[, b64Optimize] = await tryToCatch(minify.img, filename, optimizedData);
[, b64Optimize] = await tryToCatch(minify.img, filename, optimizedData, userOptions);
return b64Optimize || optimizedData;
}