add lisp packages

This commit is contained in:
2020-12-05 21:29:49 +01:00
parent 85e20365ae
commit a6e2395755
7272 changed files with 1363243 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,114 @@
Minify
===============
[NPM_INFO_IMG]: https://nodei.co/npm/minify.png?stars
[Minify](http://coderaiser.github.io/minify "Minify") - a minifier of js, css, html and img files,
used in [Cloud Commander](http://cloudcmd.io "Cloud Commander") project.
To use `minify` as middleware try [Mollify](https://github.com/coderaiser/node-mollify "Mollify").
Install
---------------
![NPM_INFO][NPM_INFO_IMG]
You can install minify via [npm](https://www.npmjs.org/):
```
npm i minify -g
```
Command Line
---------------
Command line syntax:
```
minify <input-file1> <input-file2> <input-fileN> > output
stdout | minify --<flag>
```
For example:
```
minify client.js util.js > all.js
minify screen.css reset.css > all.css
cat client.js | minify --js
cat *.css | minify --css
```
API
---------------
The **Minify** module contains an api for interacting with other js files.
```js
minify = require('minify');
```
After minification, a file will be saved in the temporary directory.
minify - function to minificate js, html and css-files.
- **file** - path to file.
- **options**(optional) - object contains options.
- **callback**
Possible options:
- **name**
- **stream**
**Examples**:
## Optimize file
```js
var minify = require('minify');
minify('client.js', 'name', function(error, name) {
console.log(error || name);
});
```
```js
minify('client.js', 'stream', function(error, stream) {
var streamWrite = fs.createWriteStream('client.min.js');
if (error)
console.error(error.message);
else
stream.pipe(streamWrite);
});
```
if post processing is need:
```js
minify('client.js', function(error, data) {
});
```
## Optimize data
Parameters:
- Data
- Callback
**Example**:
```js
minify.js('function hello() { if (2 > 3) console.log(\'for real\')}', function(error, data) {
console.log(error, data);
});
minify.css('div { color: #000000}', function(error, data) {
console.log(error, data);
});
```
## Express middleware
To use as express middleware [mollify](https://github.com/coderaiser/node-mollify Mollify) could be used.
License
---------------
MIT

View File

@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2012-2019 Coderaiser <mnemonic.enemy@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,71 @@
Minify [![License][LicenseIMGURL]][LicenseURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![NPM version][NPMIMGURL]][NPMURL]
===============
[NPMIMGURL]: https://img.shields.io/npm/v/minify.svg?style=flat
[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/minify/master.svg?style=flat
[DependencyStatusIMGURL]: https://img.shields.io/david/coderaiser/minify.svg?style=flat
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
[NPM_INFO_IMG]: https://nodei.co/npm/minify.png?stars
[NPMURL]: http://npmjs.org/package/minify
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
[BuildStatusURL]: http://travis-ci.org/coderaiser/minify "Build Status"
[DependencyStatusURL]: https://david-dm.org/coderaiser/minify "Dependency Status"
[Minify](http://coderaiser.github.io/minify "Minify") - a minifier of js, css, html and img files.
To use `minify` as middleware try [Mollify](https://github.com/coderaiser/node-mollify "Mollify").
## Install
```
npm i minify -g
```
## How to use?
### CLI
```js
$ cat > hello.js
const hello = 'world';
for (let i = 0; i < hello.length; i++) {
console.log(hello[i]);
}
^D
$ minify hello.js
const hello="world";for(let l=0;l<hello.length;l++)console.log(hello[l]);
```
### Code Example
`minify` can be used as a `promise`:
```js
const minify = require('minify');
minify('./client.js')
.then(console.log)
.catch(console.error);
```
Or with `async-await` and [try-to-catch](https://github.com/coderaiser/try-to-catch'):
```js
const minify = require('minify');
const tryToCatch = require('try-to-catch');
async () => {
const [error, data] = await tryToCatch(minify, './client.js');
if (error)
return console.error(error.message);
console.log(data);
}();
```
## License
MIT

View File

@@ -0,0 +1,101 @@
#!/usr/bin/env node
'use strict';
const Pack = require('../package');
const Version = Pack.version;
const log = function(...args) {
console.log(...args);
process.stdin.pause();
};
const Argv = process.argv;
const files = Argv.slice(2);
const [In] = files;
log.error = function(e) {
console.error(e);
process.stdin.pause();
};
process.on('uncaughtException', (error) => {
if (error.code !== 'EPIPE')
log(error);
});
minify();
function readStd(callback) {
const {stdin} = process;
let chunks = '';
const read = () => {
const chunk = stdin.read();
if (chunk)
return chunks += chunk;
stdin.removeListener('readable', read);
callback(chunks);
};
stdin.setEncoding('utf8');
stdin.addListener('readable', read);
}
function minify() {
if (!In || /^(-h|--help)$/.test(In))
return help();
if (/^--(js|css|html)$/.test(In))
return readStd(processStream);
if (/^(-v|--version)$/.test(In))
return log('v' + Version);
uglifyFiles(files);
}
function processStream(chunks) {
const minify = require('..');
const tryCatch = require('try-catch');
if (!chunks || !In)
return;
const name = In.replace('--', '');
const [e, data] = tryCatch(minify[name], chunks);
if (e)
return log.error(e);
log(data);
}
function uglifyFiles(files) {
const minify = require('..');
const minifiers = files.map(minify);
Promise.all(minifiers)
.then(logAll)
.catch(log.error);
}
function logAll(array) {
for (const item of array)
log(item);
}
function help() {
const bin = require('../help');
const usage = 'Usage: minify [options]';
console.log(usage);
console.log('Options:');
for (const name of Object.keys(bin)) {
console.log(' %s %s', name, bin[name]);
}
}

View File

@@ -0,0 +1,7 @@
{
"-h, --help ": "display this help and exit",
"-v, --version ": "display version and exit",
"--js ": "minify javascript",
"--css ": "minify css",
"--html ": "minify html"
}

View File

@@ -0,0 +1,28 @@
/* сжимаем код через 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;
};

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);
};

View File

@@ -0,0 +1,31 @@
'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 = 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,
});
};

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;
};

View File

@@ -0,0 +1,83 @@
'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');
for (const name of ['js', 'html', 'css', 'img']) {
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;
}

View File

@@ -0,0 +1 @@
../../../css-b64-images/bin/css-b64-images

View File

@@ -0,0 +1 @@
../../../html-minifier/cli.js

View File

@@ -0,0 +1 @@
../../../terser/bin/terser

View File

@@ -0,0 +1,62 @@
{
"name": "minify",
"version": "4.1.3",
"description": "Minifier of js, css, html and img",
"homepage": "http://coderaiser.github.io/minify",
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
"keywords": [
"minify",
"minimize",
"js",
"css",
"img",
"html",
"base64"
],
"repository": {
"type": "git",
"url": "http://github.com/coderaiser/minify.git"
},
"bin": {
"minify": "bin/minify.js"
},
"scripts": {
"test": "madrun test",
"coverage": "madrun coverage",
"report": "madrun report",
"lint": "madrun lint",
"fix:lint": "madrun fix:lint",
"lint:bin": "madrun lint:bin",
"lint:lib": "madrun lint:lib",
"putout": "madrun putout"
},
"dependencies": {
"clean-css": "^4.1.6",
"css-b64-images": "~0.2.5",
"debug": "^4.1.0",
"html-minifier": "^4.0.0",
"terser": "^4.0.0",
"try-catch": "^2.0.0",
"try-to-catch": "^1.0.2"
},
"main": "lib/minify.js",
"license": "MIT",
"engines": {
"node": ">= 8.0.0"
},
"devDependencies": {
"coveralls": "^3.0.0",
"eslint": "^6.0.0",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-putout": "^1.5.0",
"madrun": "^2.1.2",
"nyc": "^14.1.1",
"putout": "^4.32.0",
"redrun": "^7.0.2",
"rimraf": "^2.6.1",
"supertape": "^1.2.3"
},
"publishConfig": {
"access": "public"
}
}