update packages

This commit is contained in:
s2
2019-04-15 15:46:34 +02:00
parent d5933a2d87
commit 3660e83b64
5 changed files with 63 additions and 88 deletions

2
node_modules/minifyfromhtml/.eslintignore generated vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules
dist

View File

@@ -2,12 +2,15 @@
This little helper minifies scripts and css starting from an html file. I made it after asking this question on stackoverflow: https://stackoverflow.com/questions/50188269/minify-js-and-css-in-one-go-starting-from-html/ This little helper minifies scripts and css starting from an html file. I made it after asking this question on stackoverflow: https://stackoverflow.com/questions/50188269/minify-js-and-css-in-one-go-starting-from-html/
It takes an input html file, parses it, and outputs all included javascript and css files minified to a file you specify: ## Quickstart
```
minifyfromhtml --js=<output js file> --css=<output css file> < <input file>
```
example:
``` ```
minifyfromhtml --js=dist/mywidget.min.js --css=dist/mywidget.min.css < example/index.html npm i git+https://github.com/S2-/minifyfromhtml.git#semver:1.x
node node_modules\minifyfromhtml\minifyfromhtml.js --js=dist.js --css=dist.css < index.html
```
=>
```
css/mywidget.css -> dist.css
js/jquery.js -> dist.js
js/spectacularwidget.js -> dist.js
``` ```

View File

@@ -17,15 +17,15 @@ let usage = `usage:
if (argv.h) { if (argv.h) {
console.log(usage); console.log(usage);
return; process.exit(0);
} }
if (!argv.js || !argv.css) { if (!argv.js || !argv.css) {
console.log(usage); console.log(usage);
return; process.exit(0);
} }
var excludeFiles = argv.exclude || []; let excludeFiles = argv.exclude || [];
if (typeof(excludeFiles) === 'string') { if (typeof(excludeFiles) === 'string') {
excludeFiles = [excludeFiles]; excludeFiles = [excludeFiles];
} }
@@ -40,7 +40,8 @@ let readStdin = function(cb) {
process.stdin.on('end', function() { process.stdin.on('end', function() {
cb(stdin); cb(stdin);
}); });
} };
readStdin(function(html) { readStdin(function(html) {
let dom = new JSDOM(html); let dom = new JSDOM(html);
@@ -57,79 +58,49 @@ readStdin(function(html) {
} }
} }
return scripts; return scripts;
} };
//process scripts
let scripts = getTagAttrs(dom, 'script', 'src');
let processThings = function(things, outFile) {
//remove exluded //remove exluded
excludeFiles.forEach(i => { excludeFiles.forEach(i => {
var index = scripts.indexOf(i); let index = things.indexOf(i);
if (index !== -1) { if (index !== -1) {
scripts.splice(index, 1); things.splice(index, 1);
} }
}); });
let processedScripts = {}; let processedThings = {};
for (let i = 0; i < scripts.length; i++) { for (let i = 0; i < things.length; i++) {
let script = scripts[i]; let thing = things[i];
minify(script, 'stream') minify(thing)
.then(function(data) { .then(function(data) {
processedScripts[script] = data; processedThings[thing] = data;
if (Object.keys(processedScripts).length === scripts.length) { if (Object.keys(processedThings).length === things.length) {
//write scripts //write things
//clear out dist file //clear out dist file
fs.writeFileSync(argv.js, ''); fs.writeFileSync(outFile, '');
//write files //write files
for (let i = 0; i < scripts.length; i++) { for (let i = 0; i < things.length; i++) {
const script = scripts[i]; const thing = things[i];
console.log(script + ' -> ' + argv.js); console.log(thing + ' -> ' + outFile);
fs.appendFileSync(argv.js, processedScripts[script] + '\n'); fs.appendFileSync(outFile, processedThings[thing] + '\n');
} }
} }
}); });
} }
};
if (argv.js) {
//process css processThings(getTagAttrs(dom, 'script', 'src'), argv.js);
let styles = getTagAttrs(dom, 'link', 'href');
//remove exluded
excludeFiles.forEach(i => {
var index = styles.indexOf(i);
if (index !== -1) {
styles.splice(index, 1);
} }
});
let processedStyles = {}; if (argv.css) {
fs.writeFileSync(argv.css, ''); processThings(getTagAttrs(dom, 'link', 'href'), argv.css);
for (let i = 0; i < styles.length; i++) {
let style = styles[i];
minify(style, 'stream')
.then(function(data) {
processedStyles[style] = data;
if (Object.keys(processedStyles).length === styles.length) {
//write styles
//clear out dist file
fs.writeFileSync(argv.css, '');
//write files
for (let i = 0; i < styles.length; i++) {
const style = styles[i];
console.log(style + ' -> ' + argv.css);
fs.appendFileSync(argv.css, processedStyles[style] + '\n');
}
}
});
} }
}); });

View File

@@ -1,15 +1,13 @@
{ {
"_from": "git+https://github.com/S2-/minifyfromhtml.git#semver:1.x", "_from": "git+https://github.com/S2-/minifyfromhtml.git#semver:1.x",
"_id": "minifyfromhtml@1.1.0", "_id": "minifyfromhtml@1.1.1",
"_inBundle": false, "_inBundle": false,
"_integrity": "", "_integrity": "",
"_location": "/minifyfromhtml", "_location": "/minifyfromhtml",
"_phantomChildren": {}, "_phantomChildren": {},
"_requested": { "_requested": {
"type": "git", "type": "git",
"raw": "minifyfromhtml@git+https://github.com/S2-/minifyfromhtml.git#semver:1.x", "raw": "git+https://github.com/S2-/minifyfromhtml.git#semver:1.x",
"name": "minifyfromhtml",
"escapedName": "minifyfromhtml",
"rawSpec": "git+https://github.com/S2-/minifyfromhtml.git#semver:1.x", "rawSpec": "git+https://github.com/S2-/minifyfromhtml.git#semver:1.x",
"saveSpec": "git+https://github.com/S2-/minifyfromhtml.git#semver:1.x", "saveSpec": "git+https://github.com/S2-/minifyfromhtml.git#semver:1.x",
"fetchSpec": "https://github.com/S2-/minifyfromhtml.git", "fetchSpec": "https://github.com/S2-/minifyfromhtml.git",
@@ -17,11 +15,12 @@
"gitCommittish": null "gitCommittish": null
}, },
"_requiredBy": [ "_requiredBy": [
"#DEV:/" "#DEV:/",
"#USER"
], ],
"_resolved": "git+https://github.com/S2-/minifyfromhtml.git#9aa30e929e5ea539f4d0dff0cf6858174039e21f", "_resolved": "git+https://github.com/S2-/minifyfromhtml.git#5a7294bcf9811ce1c9bc0ee78a43941c1d330f36",
"_spec": "minifyfromhtml@git+https://github.com/S2-/minifyfromhtml.git#semver:1.x", "_spec": "git+https://github.com/S2-/minifyfromhtml.git#semver:1.x",
"_where": "F:\\projects\\vanillajs-seed", "_where": "F:\\projects\\p\\vanillajs-seed",
"author": "", "author": "",
"bin": { "bin": {
"minifyfromhtml": "./minifyfromhtml.js" "minifyfromhtml": "./minifyfromhtml.js"
@@ -48,5 +47,5 @@
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"version": "1.1.0" "version": "1.1.1"
} }

2
package-lock.json generated
View File

@@ -577,7 +577,7 @@
} }
}, },
"minifyfromhtml": { "minifyfromhtml": {
"version": "git+https://github.com/S2-/minifyfromhtml.git#9aa30e929e5ea539f4d0dff0cf6858174039e21f", "version": "git+https://github.com/S2-/minifyfromhtml.git#5a7294bcf9811ce1c9bc0ee78a43941c1d330f36",
"from": "git+https://github.com/S2-/minifyfromhtml.git#semver:1.x", "from": "git+https://github.com/S2-/minifyfromhtml.git#semver:1.x",
"dev": true, "dev": true,
"requires": { "requires": {