diff --git a/node_modules/minifyfromhtml/.eslintignore b/node_modules/minifyfromhtml/.eslintignore new file mode 100644 index 0000000..f06235c --- /dev/null +++ b/node_modules/minifyfromhtml/.eslintignore @@ -0,0 +1,2 @@ +node_modules +dist diff --git a/node_modules/minifyfromhtml/README.md b/node_modules/minifyfromhtml/README.md index 80470cd..ac8f85e 100644 --- a/node_modules/minifyfromhtml/README.md +++ b/node_modules/minifyfromhtml/README.md @@ -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/ -It takes an input html file, parses it, and outputs all included javascript and css files minified to a file you specify: -``` -minifyfromhtml --js= --css= < -``` +## Quickstart -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 ``` diff --git a/node_modules/minifyfromhtml/minifyfromhtml.js b/node_modules/minifyfromhtml/minifyfromhtml.js index 0c7f046..ba0d900 100644 --- a/node_modules/minifyfromhtml/minifyfromhtml.js +++ b/node_modules/minifyfromhtml/minifyfromhtml.js @@ -17,15 +17,15 @@ let usage = `usage: if (argv.h) { console.log(usage); - return; + process.exit(0); } if (!argv.js || !argv.css) { console.log(usage); - return; + process.exit(0); } -var excludeFiles = argv.exclude || []; +let excludeFiles = argv.exclude || []; if (typeof(excludeFiles) === 'string') { excludeFiles = [excludeFiles]; } @@ -40,7 +40,8 @@ let readStdin = function(cb) { process.stdin.on('end', function() { cb(stdin); }); -} +}; + readStdin(function(html) { let dom = new JSDOM(html); @@ -57,79 +58,49 @@ readStdin(function(html) { } } return scripts; - } + }; - //process scripts - let scripts = getTagAttrs(dom, 'script', 'src'); - //remove exluded - excludeFiles.forEach(i => { - var index = scripts.indexOf(i); - if (index !== -1) { - scripts.splice(index, 1); - } - }); - - let processedScripts = {}; - for (let i = 0; i < scripts.length; i++) { - let script = scripts[i]; - - minify(script, 'stream') - .then(function(data) { - processedScripts[script] = data; - - if (Object.keys(processedScripts).length === scripts.length) { - //write scripts - - //clear out dist file - fs.writeFileSync(argv.js, ''); - - //write files - for (let i = 0; i < scripts.length; i++) { - const script = scripts[i]; - - console.log(script + ' -> ' + argv.js); - fs.appendFileSync(argv.js, processedScripts[script] + '\n'); - } + let processThings = function(things, outFile) { + //remove exluded + excludeFiles.forEach(i => { + let index = things.indexOf(i); + if (index !== -1) { + things.splice(index, 1); } }); + + let processedThings = {}; + for (let i = 0; i < things.length; i++) { + let thing = things[i]; + + minify(thing) + .then(function(data) { + processedThings[thing] = data; + + if (Object.keys(processedThings).length === things.length) { + //write things + + //clear out dist file + fs.writeFileSync(outFile, ''); + + //write files + for (let i = 0; i < things.length; i++) { + const thing = things[i]; + + console.log(thing + ' -> ' + outFile); + fs.appendFileSync(outFile, processedThings[thing] + '\n'); + } + } + }); + } + }; + + if (argv.js) { + processThings(getTagAttrs(dom, 'script', 'src'), argv.js); } - - //process css - 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 = {}; - fs.writeFileSync(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'); - } - } - }); + if (argv.css) { + processThings(getTagAttrs(dom, 'link', 'href'), argv.css); } }); diff --git a/node_modules/minifyfromhtml/package.json b/node_modules/minifyfromhtml/package.json index d701f24..f119106 100644 --- a/node_modules/minifyfromhtml/package.json +++ b/node_modules/minifyfromhtml/package.json @@ -1,15 +1,13 @@ { "_from": "git+https://github.com/S2-/minifyfromhtml.git#semver:1.x", - "_id": "minifyfromhtml@1.1.0", + "_id": "minifyfromhtml@1.1.1", "_inBundle": false, "_integrity": "", "_location": "/minifyfromhtml", "_phantomChildren": {}, "_requested": { "type": "git", - "raw": "minifyfromhtml@git+https://github.com/S2-/minifyfromhtml.git#semver:1.x", - "name": "minifyfromhtml", - "escapedName": "minifyfromhtml", + "raw": "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", "fetchSpec": "https://github.com/S2-/minifyfromhtml.git", @@ -17,11 +15,12 @@ "gitCommittish": null }, "_requiredBy": [ - "#DEV:/" + "#DEV:/", + "#USER" ], - "_resolved": "git+https://github.com/S2-/minifyfromhtml.git#9aa30e929e5ea539f4d0dff0cf6858174039e21f", - "_spec": "minifyfromhtml@git+https://github.com/S2-/minifyfromhtml.git#semver:1.x", - "_where": "F:\\projects\\vanillajs-seed", + "_resolved": "git+https://github.com/S2-/minifyfromhtml.git#5a7294bcf9811ce1c9bc0ee78a43941c1d330f36", + "_spec": "git+https://github.com/S2-/minifyfromhtml.git#semver:1.x", + "_where": "F:\\projects\\p\\vanillajs-seed", "author": "", "bin": { "minifyfromhtml": "./minifyfromhtml.js" @@ -48,5 +47,5 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "version": "1.1.0" + "version": "1.1.1" } diff --git a/package-lock.json b/package-lock.json index ace9d32..dad3c3b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -577,7 +577,7 @@ } }, "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", "dev": true, "requires": {