first commit

This commit is contained in:
s2
2024-12-13 08:53:01 +01:00
commit 2746dc9c4e
5477 changed files with 682458 additions and 0 deletions

14
node_modules/minifyfromhtml/.editorconfig generated vendored Normal file
View File

@@ -0,0 +1,14 @@
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = tab
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
[*.md]
max_line_length = off
trim_trailing_whitespace = false

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

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

33
node_modules/minifyfromhtml/.eslintrc.json generated vendored Normal file
View File

@@ -0,0 +1,33 @@
{"parserOptions":
{"ecmaVersion": 6},
"rules": {
"quotes": [2, "single", {"allowTemplateLiterals": true}],
"curly": [2, "all"],
"keyword-spacing": [2, {"overrides": {"else": {"before": true}, "catch": {"before": true, "after": false}}}],
"space-before-blocks": [2, "always"],
"wrap-iife": [2, "inside"],
"space-before-function-paren": [2, "never"],
"one-var": [2, "never"],
"vars-on-top": 0, "no-empty": [2, {"allowEmptyCatch": true}],
"array-bracket-spacing": [2, "never"],
"space-in-parens": [2, "never"],
"no-underscore-dangle": 0,
"comma-style": [2, "last"],
"comma-spacing": [2, {"before": false, "after": true}],
"space-unary-ops": [2, {"words": false, "nonwords": false}],
"no-multi-spaces": 2,
"space-infix-ops": 2,
"no-with": 2,
"indent": [2, "tab", {"SwitchCase": 1, "FunctionExpression": {"body": 1, "parameters": 1}, "MemberExpression": 0}],
"no-mixed-spaces-and-tabs": 2,
"no-trailing-spaces": 2,
"comma-dangle": [2, "never"],
"semi": [2, "always"],
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
"eol-last": 2,
"dot-notation": 0,
"no-multi-str": 2,
"key-spacing": [2, {"afterColon": true}],
"func-call-spacing": [2, "never"]
}
}

25
node_modules/minifyfromhtml/.vscode/launch.json generated vendored Normal file
View File

@@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to Remote",
"address": "127.0.0.1",
"port": 9229,
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}"
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}\\minifyfromhtml.js",
"args": ["--js=../dist/mywidget.min.js", "--css=../dist/mywidget.min.css", "< index.html"],
"cwd": "${workspaceFolder}\\example"
}
]
}

3
node_modules/minifyfromhtml/.vscode/settings.json generated vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}

77
node_modules/minifyfromhtml/README.md generated vendored Normal file
View File

@@ -0,0 +1,77 @@
# minifyfromhtml
This little helper minifies scripts and css starting from an html file.
## What it is
I am making a `js` widget, like a map, or a calendar field or something. This is the `index.html` I use while developing the widget:
```
<!DOCTYPE html>
<html lang="en">
<head>
<title>example page</title>
<script src="somelib.js"></script>
<script src="someotherlib.js"></script>
<script src="awesomelib.js"></script>
<script src="spectacularlib.js"></script>
<script src="app.js"></script>
<link rel="stylesheet" type="text/css" href="some.css" />
<link rel="stylesheet" type="text/css" href="app.css" />
</head>
<body>
<div id="widget"></div>
<script>
myapp(document.getElementById('widget'));
</script>
</body>
</html>
```
I am not using a framework like angular or react. I am coding along in `app.js`, and add libraries as I need them to `index.html`.
Then comes a time I want to distribute my widget to the world. To do that, I would like to
- minify all referenced js files in index.html
- minify all css files
so that users of my widget can just include `widget.js` and `widget.css` and be good to go.
Is there something I can use that does that for me **with minimal hassle**? Something like
```
$ magictool index.html
- nice html you have. let me parse that and see what I need to do...
- oh, you have somelib.js. let me minify that for you and put it in dist.js
- oh, you have someotherlib.js. let me minify that for you and put it in dist.js
- oh, you have awesomelib.js. let me minify that for you and put it in dist.js
- oh, you have spectacularlib.js. let me minify that for you and put it in dist.js
- oh, you have app.js. let me minify that for you and put it in dist.js
- oh, you have some.css. let me minify that for you and put it in dist.css
- oh, you have app.css. let me minify that for you and put it in dist.css
! dist.js and dist.css created!
```
that reads `index.html` and creates a `dist.js` and `dist.css`.
the magictool is **minifyfromhtml**.
## Quickstart
```
npm i -g minifyfromhtml
minifyfromhtml --js=dist.js --css=dist.css < index.html
```
=>
```
some.css -> dist.css
app.css -> dist.css
somelib.js -> dist.js
someotherlib.js -> dist.js
awesomelib.js -> dist.js
spectacularlib.js -> dist.js
app.js -> dist.js
```

3
node_modules/minifyfromhtml/example/css/more.css generated vendored Normal file
View File

@@ -0,0 +1,3 @@
#mywidget {
color: blue;
}

View File

@@ -0,0 +1,3 @@
#mywidget {
border: 2px solid blue;
}

3
node_modules/minifyfromhtml/example/css/mywidget.css generated vendored Normal file
View File

@@ -0,0 +1,3 @@
#mywidget {
border: 2px solid red;
}

1
node_modules/minifyfromhtml/example/dist/dist.css generated vendored Normal file
View File

@@ -0,0 +1 @@
#mywidget{border:2px solid red}#mywidget{color:#00f}

2
node_modules/minifyfromhtml/example/dist/dist.js generated vendored Normal file

File diff suppressed because one or more lines are too long

1
node_modules/minifyfromhtml/example/dist/dist.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

24
node_modules/minifyfromhtml/example/dist/index.html generated vendored Normal file
View File

@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Example</title>
<!-- just the minified stuff -->
<script type="text/javascript" charset="utf-8" src="dist.js"></script>
<link rel="stylesheet" type="text/css" href="dist.css" />
</head>
<body>
<div id="mywidget"></div>
<script>
//widget init
spectacularwidget(document.getElementById('mywidget'));
</script>
</body>
</html>

29
node_modules/minifyfromhtml/example/index.html generated vendored Normal file
View File

@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Example</title>
<!-- jquery is not used in this example, it's just here to demo the compression -->
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
<!-- the widget -->
<script type="text/javascript" charset="utf-8" src="js/spectacularwidget.js"></script>
<!-- some css -->
<link rel="stylesheet" type="text/css" href="css/mywidget.css" />
<link rel="alternate stylesheet" type="text/css" href="css/mywidget.css" />
<link rel="stylesheet" type="text/css" href="css/more.css" />
</head>
<body>
<div id="mywidget"></div>
<script>
//widget init
spectacularwidget(document.getElementById('mywidget'));
</script>
</body>
</html>

10364
node_modules/minifyfromhtml/example/js/jquery.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,5 @@
var spectacularwidget = function(me) {
me.innerHTML = 'this is so spectacular!';
};
window.spectacularwidget = spectacularwidget;

119
node_modules/minifyfromhtml/minifyfromhtml.js generated vendored Normal file
View File

@@ -0,0 +1,119 @@
let argv = require('minimist')(process.argv.slice(2));
let fs = require('fs');
let path = require('path');
let Terser = require('terser');
let CleanCSS = require('clean-css');
let jsdom = require('jsdom');
let JSDOM = jsdom.JSDOM;
process.on('unhandledRejection', up => { throw up; });
let usage = `usage:
minifyfromhtml --js=<output js file> --css=<output css file> --exclude=<exclude files> < <input file>
the minification process uses minify under the hood.
http://coderaiser.github.io/minify/
example:
minifyfromhtml --js=dist/mywidget.min.js --css=dist/mywidget.min.css --exclude=js/jquery.js < example/index.html
`;
if (argv.h) {
console.log(usage);
process.exit(0);
}
if (!argv.js && !argv.css) {
console.log(usage);
process.exit(0);
}
let excludeFiles = argv.exclude || [];
if (typeof(excludeFiles) === 'string') {
excludeFiles = [excludeFiles];
}
let readStdin = function(cb) {
let stdin = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(buf) {
stdin += buf;
});
process.stdin.on('end', function() {
cb(stdin);
});
};
readStdin(function(html) {
let dom = new JSDOM(html);
let getTagAttrs = function(dom, tag, attr, filter) {
let elements = [];
let document = dom.window.document;
let elementTags = document.getElementsByTagName(tag);
let i = elementTags.length;
for (let i = 0; i < elementTags.length; i++) {
if (!filter ||
(filter && elementTags[i].getAttribute(Object.keys(filter)[0]) === filter[Object.keys(filter)[0]])) {
let src = elementTags[i].getAttribute(attr);
if (src) {
elements.push(src);
}
}
}
return elements;
};
let processJs = function(things, outFile) {
let terserOptions = {
output: {
comments: false
},
sourceMap: {
includeSources: true,
url: path.basename(outFile) + '.map'
}
};
//remove exluded
excludeFiles.forEach(i => {
let index = things.indexOf(i);
if (index !== -1) {
things.splice(index, 1);
}
});
let code = {};
for (let i = 0; i < things.length; i++) {
let thing = things[i];
code[thing] = fs.readFileSync(thing, 'utf8');
console.log(thing + ' -> ' + outFile);
}
const data = Terser.minify(code, terserOptions);
fs.writeFileSync(outFile, data.code);
if (data.map) {
fs.writeFileSync(outFile + '.map', data.map);
}
};
let processCss = function(things, outFile) {
fs.writeFileSync(outFile, '');
for (let i = 0; i < things.length; i++) {
let thing = things[i];
console.log(thing + ' -> ' + outFile);
let minified = new CleanCSS().minify(fs.readFileSync(thing, 'utf8'));
fs.appendFileSync(outFile, minified.styles);
}
};
if (argv.js) {
processJs(getTagAttrs(dom, 'script', 'src'), argv.js);
}
if (argv.css) {
processCss(getTagAttrs(dom, 'link', 'href', {rel: 'stylesheet'}), argv.css);
}
});

61
node_modules/minifyfromhtml/package.json generated vendored Normal file
View File

@@ -0,0 +1,61 @@
{
"_from": "minifyfromhtml@latest",
"_id": "minifyfromhtml@2.0.4",
"_inBundle": false,
"_integrity": "sha512-tg6rSm32T7f/5EiycLN+fVz8KRXqZ/3b/3EAP0v26RkM0ZbN7jl0WBwVz/i8HyRSydZaf9YOeBRurU1OJaaYxg==",
"_location": "/minifyfromhtml",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "minifyfromhtml@latest",
"name": "minifyfromhtml",
"escapedName": "minifyfromhtml",
"rawSpec": "latest",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#DEV:/",
"#USER"
],
"_resolved": "https://registry.npmjs.org/minifyfromhtml/-/minifyfromhtml-2.0.4.tgz",
"_shasum": "00addc787dbc581c97aff981edf21fa6a0cd49e0",
"_spec": "minifyfromhtml@latest",
"_where": "D:\\Projects\\vanillajs-seed",
"author": "",
"bin": {
"minifyfromhtml": "minifyfromhtml.js"
},
"bugs": {
"url": "https://github.com/S2-/minifyfromhtml/issues"
},
"bundleDependencies": false,
"dependencies": {
"clean-css": "^4.2.3",
"jsdom": "^16.3.0",
"minimist": "^1.2.2",
"terser": "^4.8.0"
},
"deprecated": false,
"description": "minify scripts and css starting from an html file",
"homepage": "https://github.com/S2-/minifyfromhtml#readme",
"keywords": [
"minify",
"javascript",
"html",
"css",
"script"
],
"license": "ISC",
"main": "minifyfromhtml.js",
"name": "minifyfromhtml",
"repository": {
"type": "git",
"url": "git+https://github.com/S2-/minifyfromhtml.git"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "2.0.4"
}