minify-all 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: minify_all
3
+ Version: 0.1.1
4
+ Summary: Aggressive multi-language single-line flattening minifier
5
+ Requires-Python: >=3.8
6
+ Description-Content-Type: text/markdown
File without changes
@@ -0,0 +1,17 @@
1
+ from .core import (
2
+ js_minify,
3
+ css_minify,
4
+ json_minify,
5
+ html_minify,
6
+ compiled_lang_minify,
7
+ file_minify
8
+ )
9
+
10
+ __all__ = [
11
+ "js_minify",
12
+ "css_minify",
13
+ "json_minify",
14
+ "html_minify",
15
+ "compiled_lang_minify",
16
+ "file_minify"
17
+ ]
@@ -0,0 +1,111 @@
1
+ import os
2
+ import re
3
+ import json
4
+
5
+ def js_minify(code: str) -> str:
6
+ """Aggressively flattens JavaScript with smart semicolon insertion."""
7
+ code = re.sub(r'/\*[\s\S]*?\*/', '', code)
8
+ code = re.sub(r'//.*', '', code)
9
+ lines = []
10
+ for line in code.splitlines():
11
+ stripped = line.strip()
12
+ if not stripped:
13
+ continue
14
+ if not re.search(r'[\{\}\;\,\=\+\-\*\/\[\(\:\&\|]$', stripped):
15
+ stripped += ';'
16
+ lines.append(stripped)
17
+ combined = " ".join(lines)
18
+ combined = re.sub(r'\s+', ' ', combined)
19
+ return re.sub(r'\s*([\{\}\(\)\[\]\;\,\=\+\-\*\/\:\<\>\!])\s*', r'\1', combined).strip()
20
+
21
+ def css_minify(code: str) -> str:
22
+ """Aggressively flattens CSS into a single line."""
23
+ code = re.sub(r'/\*[\s\S]*?\*/', '', code)
24
+ code = re.sub(r'\s+', ' ', code)
25
+ return re.sub(r'\s*([\{\}\:\;\,\>])\s*', r'\1', code).strip()
26
+
27
+ def json_minify(code: str) -> str:
28
+ """Removes all whitespace from JSON strings."""
29
+ try:
30
+ data = json.loads(code)
31
+ return json.dumps(data, separators=(',', ':'))
32
+ except json.JSONDecodeError:
33
+ return re.sub(r'\s+', '', code)
34
+
35
+ def html_minify(code: str) -> str:
36
+ """Aggressively flattens HTML into a single line, stripping comments."""
37
+ # Remove HTML comments <!-- ... -->
38
+ code = re.sub(r'<!--[\s\S]*?-->', '', code)
39
+ # Collapse multiple spaces/newlines down to a single space
40
+ code = re.sub(r'\s+', ' ', code)
41
+ # Tightly pack spaces around tag brackets where safe (e.g., ' <div ' -> '<div ')
42
+ code = re.sub(r'\s*([<>])\s*', r'\1', code)
43
+ return code.strip()
44
+
45
+ def compiled_lang_minify(code: str) -> str:
46
+ """
47
+ Unified minifier for Java, C#, and C++. Removes multi-line comments,
48
+ single-line comments, preprocessor directives (if chosen), and collapses newlines
49
+ while preserving mandatory keyword spacing.
50
+ """
51
+ # 1. Remove multi-line comments /* ... */
52
+ code = re.sub(r'/\*[\s\S]*?\*/', '', code)
53
+
54
+ # 2. Remove single-line comments // ...
55
+ # Bug prevention: Ensure we don't accidentally match // inside URLs or strings if passed
56
+ code = re.sub(r'//.*', '', code)
57
+
58
+ # 3. Handle Preprocessor Directives (Crucial for C++ and C# like #include or #using)
59
+ # These MUST end with a newline in their native syntax. To keep them on one line,
60
+ # we ensure they have a space separating them from the next block of code.
61
+ lines = []
62
+ for line in code.splitlines():
63
+ stripped = line.strip()
64
+ if not stripped:
65
+ continue
66
+ if stripped.startswith('#'):
67
+ # Keep the preprocessor directive isolated with a clear boundary space
68
+ lines.append(stripped + " ")
69
+ else:
70
+ lines.append(stripped)
71
+
72
+ combined = " ".join(lines)
73
+
74
+ # 4. Collapse spaces
75
+ combined = re.sub(r'\s+', ' ', combined)
76
+
77
+ # 5. Safe punctuation space stripping (leaves word syntax like 'public class' intact)
78
+ combined = re.sub(r'\s*([\{\}\(\)\[\]\;\,\=\+\-\*\/\:\<\>\!])\s*', r'\1', combined)
79
+
80
+ return combined.strip()
81
+
82
+ def file_minify(input_path: str, output_path: str = None) -> str:
83
+ """Reads a file, automatically routes to the right minifier, and saves it."""
84
+ if not os.path.exists(input_path):
85
+ raise FileNotFoundError(f"The file '{input_path}' could not be found.")
86
+
87
+ with open(input_path, 'r', encoding='utf-8') as f:
88
+ raw_content = f.read()
89
+
90
+ _, ext = os.path.splitext(input_path.lower())
91
+
92
+ # Dynamic Routing Architecture
93
+ if ext == '.js':
94
+ minified = js_minify(raw_content)
95
+ elif ext == '.css':
96
+ minified = css_minify(raw_content)
97
+ elif ext == '.json':
98
+ minified = json_minify(raw_content)
99
+ elif ext in ['.html', '.htm']:
100
+ minified = html_minify(raw_content)
101
+ elif ext in ['.java', '.cs', '.cpp', '.h', '.hpp', '.cc']:
102
+ minified = compiled_lang_minify(raw_content)
103
+ else:
104
+ # Generic fallback
105
+ minified = re.sub(r'\s+', ' ', raw_content).strip()
106
+
107
+ if output_path:
108
+ with open(output_path, 'w', encoding='utf-8') as f:
109
+ f.write(minified)
110
+
111
+ return minified
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: minify_all
3
+ Version: 0.1.1
4
+ Summary: Aggressive multi-language single-line flattening minifier
5
+ Requires-Python: >=3.8
6
+ Description-Content-Type: text/markdown
@@ -0,0 +1,8 @@
1
+ README.md
2
+ pyproject.toml
3
+ minify_all/__init__.py
4
+ minify_all/core.py
5
+ minify_all.egg-info/PKG-INFO
6
+ minify_all.egg-info/SOURCES.txt
7
+ minify_all.egg-info/dependency_links.txt
8
+ minify_all.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ minify_all
@@ -0,0 +1,10 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "minify_all"
7
+ version = "0.1.1"
8
+ description = "Aggressive multi-language single-line flattening minifier"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+