1
0
mirror of https://github.com/S2-/minifyfromhtml.git synced 2025-08-02 12:00:03 +02:00
This commit is contained in:
s2
2018-05-05 14:29:20 +02:00
parent 62dd054f83
commit d17c4fe70c
1809 changed files with 262593 additions and 219 deletions

View File

@@ -0,0 +1,40 @@
var argv = require('minimist')(process.argv.slice(2));
var jsdom = require("jsdom");
var {JSDOM} = jsdom;
var usage = `usage:
minifyfromhtml < <input file>
`;
var inputFile = argv.i;
if (argv.h) {
console.log(usage);
}
//read stdin
var html = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(buf) {
html += buf;
});
process.stdin.on('end', function() {
var dom = new JSDOM(html);
var getScripts = function(dom) {
var scripts = [];
var document = dom.window.document;
var scriptTags = document.getElementsByTagName('script');
var i = scriptTags.length;
while (i--) {
var src = scriptTags[i].getAttribute('src');
if (src) {
scripts.push(src);
}
}
return scripts;
}
console.log(getScripts(dom));
});