add build

This commit is contained in:
s2
2019-04-15 11:34:09 +02:00
parent 9d3cd7ec4f
commit 224b6828c7
2948 changed files with 348000 additions and 35 deletions

27
node_modules/minify/lib/css.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
/* сжимаем код через clean-css */
'use strict';
const assert = require('assert');
const Clean = require('clean-css');
/**
* minify css data.
*
* @param data
*/
module.exports = (data) => {
assert(data);
const {
styles,
errors,
} = new Clean().minify(data);
const [error] = errors;
if (error)
throw error;
return styles;
};

42
node_modules/minify/lib/html.js generated vendored Normal file
View File

@@ -0,0 +1,42 @@
/* сжимаем код через htmlMinify */
'use strict';
const assert = require('assert');
const Minifier = require('html-minifier');
const Options = {
removeComments: true,
removeCommentsFromCDATA: true,
removeCDATASectionsFromCDATA: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
/* оставляем, поскольку у нас
* в элемент fm генерируеться
* таблица файлов
*/
removeEmptyElements: false,
removeOptionalTags: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
minifyJS: true,
minifyCSS: true
};
/**
* minify html data.
*
* @param data
* @param callback
*/
module.exports = (data) => {
assert(data);
return Minifier.minify(data, Options);
};

33
node_modules/minify/lib/img.js generated vendored Normal file
View File

@@ -0,0 +1,33 @@
'use strict';
const path = require('path');
const assert = require('assert');
const {
promisify,
} = require('util');
const fromString = promisify(require('css-b64-images').fromString);
const ONE_KB = Math.pow(2, 10);
const maxSize = 100 * ONE_KB;
/**
* minify css data.
* if can not minify return data
*
* @param name
* @param data
*/
module.exports = async (name, data) => {
const dir = path.dirname(name);
const dirRelative = dir + '/../';
assert(name);
assert(data);
return fromString(data, dir, dirRelative, {
maxSize
});
};

24
node_modules/minify/lib/js.js generated vendored Normal file
View File

@@ -0,0 +1,24 @@
'use strict';
const terser = require('terser');
const assert = require('assert');
/**
* minify js data.
*
* @param data
*/
module.exports = (data) => {
assert(data);
const {
error,
code,
} = terser.minify(data);
if (error)
throw error;
return code;
};

84
node_modules/minify/lib/minify.js generated vendored Normal file
View File

@@ -0,0 +1,84 @@
'use strict';
const DIR = __dirname + '/';
const fs = require('fs');
const path = require('path');
const {
promisify,
} = require('util');
const tryToCatch = require('try-to-catch');
const readFile = promisify(fs.readFile);
const log = require('debug')('minify');
['js', 'html', 'css', 'img'].forEach((name) => {
minify[name] = require(DIR + name);
});
module.exports = minify;
function check(name) {
if (!name)
throw Error('name could not be empty!');
}
async function minify(name) {
const EXT = ['js', 'html', 'css'];
check(name);
const ext = path.extname(name).slice(1);
const is = ~EXT.indexOf(ext);
if (!is)
throw Error(`File type "${ext}" not supported.`);
log('optimizing ' + path.basename(name));
return optimize(name);
}
function getName(file) {
const notObj = typeof file !== 'object';
if (notObj)
return file;
return Object.keys(file)[0];
}
/**
* function minificate js,css and html files
*
* @param files - js, css or html file path
*/
async function optimize(file) {
check(file);
const name = getName(file);
log('reading file ' + path.basename(name));
const data = await readFile(name, 'utf8');
return onDataRead(file, data);
}
/**
* Processing of files
* @param fileData {name, data}
*/
async function onDataRead(filename, data) {
log('file ' + path.basename(filename) + ' read');
const ext = path.extname(filename).replace(/^\./, '');
const optimizedData = await minify[ext](data);
let b64Optimize;
if (ext === 'css')
[, b64Optimize] = await tryToCatch(minify.img, filename, optimizedData);
return b64Optimize || optimizedData;
}