uglify-js-minify-css-allfiles 1.3.1 → 2.0.0
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.
- package/.vscode/settings.json +13 -0
- package/CHANGELOG.md +85 -19
- package/LICENSE +21 -21
- package/README.md +74 -80
- package/demo.js +16 -4
- package/dist/module.js +111 -89
- package/dist/modules/fileHandler.js +51 -0
- package/dist/modules/logger.js +115 -0
- package/dist/modules/minifier.js +42 -0
- package/logs/error.log +6 -0
- package/logs/summary.log +96 -0
- package/minify.js +1 -1
- package/package.json +49 -46
- package/test/lib/test.css +9 -0
- package/test/lib/test.js +3 -0
- package/test/test.css +1 -0
- package/test/test.js +26 -0
- package/test/common.js +0 -1
- package/test/lib/comon.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,19 +1,85 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [2.0.0] - 2024-08-19
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- New logging system for better error tracking and debugging
|
|
13
|
+
- Optional Babel integration for advanced JavaScript transpilation
|
|
14
|
+
- Support for ES modules, allowing use of `import` statements in your projects
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Switched from CommonJS (`require`) to ES modules (`import`) for better compatibility with modern JavaScript
|
|
19
|
+
- Improved error handling and reporting, providing clearer messages for troubleshooting
|
|
20
|
+
- Enhanced CLI interface with more user-friendly options and feedback
|
|
21
|
+
|
|
22
|
+
### Improved
|
|
23
|
+
|
|
24
|
+
- Significantly faster processing of large directories with many files
|
|
25
|
+
- More robust handling of different file types and encodings
|
|
26
|
+
- Better preservation of source maps in minified files
|
|
27
|
+
|
|
28
|
+
### Breaking Changes
|
|
29
|
+
|
|
30
|
+
- Minimum Node.js version requirement increased to v14.0.0
|
|
31
|
+
- Configuration file format changed (see migration guide for details)
|
|
32
|
+
- Some CLI options have been renamed for clarity (see documentation for new option names)
|
|
33
|
+
|
|
34
|
+
## [1.3.2] - 2023-05-28
|
|
35
|
+
|
|
36
|
+
### Added
|
|
37
|
+
|
|
38
|
+
- New `CHANGELOG.md` file
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
|
|
42
|
+
- When CSS warnings exist, no code is minified (2022-04-13)
|
|
43
|
+
- Updated UglifyJS to remove 'console.info, console.warn, console.error' (2021-11-12)
|
|
44
|
+
- Updated UglifyJS to work without 'console.log' but keep console.error, info, etc. (2021-03-17)
|
|
45
|
+
|
|
46
|
+
### Fixed
|
|
47
|
+
|
|
48
|
+
- Bug fix (v1.1.7): Solved CleanCSS first line delete error (2020-08-21)
|
|
49
|
+
- Bug fix (v1.1.3): [Description missing] (2020-08-15)
|
|
50
|
+
|
|
51
|
+
## [1.3.1] - 2020-11-03
|
|
52
|
+
|
|
53
|
+
### Changed
|
|
54
|
+
|
|
55
|
+
- Updated UglifyJS to support minification of JavaScript files with ES6 syntax
|
|
56
|
+
|
|
57
|
+
## [1.3.0] - 2020-08-26
|
|
58
|
+
|
|
59
|
+
### Changed
|
|
60
|
+
|
|
61
|
+
- Moved DevDependencies to Dependencies for production use
|
|
62
|
+
|
|
63
|
+
## [1.2.0] - 2020-08-21
|
|
64
|
+
|
|
65
|
+
### Fixed
|
|
66
|
+
|
|
67
|
+
- Solved CleanCSS commentary issue due to changed CSS options
|
|
68
|
+
|
|
69
|
+
### Added
|
|
70
|
+
|
|
71
|
+
- Support for command line execution with 2 parameters
|
|
72
|
+
|
|
73
|
+
## [1.1.0] - 2020-08-20
|
|
74
|
+
|
|
75
|
+
### Added
|
|
76
|
+
|
|
77
|
+
- New `exceptFolder` parameter to exclude specific folders from minification
|
|
78
|
+
- Support for using relative paths
|
|
79
|
+
|
|
80
|
+
[2.0.0]: https://github.com/oinochoe/uglify-js-minify-css-allfiles/compare/v1.3.2...v2.0.0
|
|
81
|
+
[1.3.2]: https://github.com/oinochoe/uglify-js-minify-css-allfiles/compare/v1.3.1...v1.3.2
|
|
82
|
+
[1.3.1]: https://github.com/oinochoe/uglify-js-minify-css-allfiles/compare/v1.3.0...v1.3.1
|
|
83
|
+
[1.3.0]: https://github.com/oinochoe/uglify-js-minify-css-allfiles/compare/v1.2.0...v1.3.0
|
|
84
|
+
[1.2.0]: https://github.com/oinochoe/uglify-js-minify-css-allfiles/compare/v1.1.0...v1.2.0
|
|
85
|
+
[1.1.0]: https://github.com/oinochoe/uglify-js-minify-css-allfiles/compare/releases/tag/v1.1.0
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c)
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 NOEL <copstyle86@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,80 +1,74 @@
|
|
|
1
|
-
[![NPM downloads][npm-downloads]][npm-url]
|
|
2
|
-
[![NPM total downloads][npm-total-downloads]][npm-url]
|
|
3
|
-
|
|
4
|
-
| <br>[![Donate][donate-badge]][donate-url] <br> | Your help is appreciated! [Create a PR][create-pr] or just [buy me a coffee][donate-url] |
|
|
5
|
-
| ---------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
6
|
-
|
|
7
|
-
[npm-url]: https://www.npmjs.com/package/uglify-js-minify-css-allfiles
|
|
8
|
-
[npm-downloads]: https://img.shields.io/npm/dm/uglify-js-minify-css-allfiles.svg
|
|
9
|
-
[npm-total-downloads]: https://img.shields.io/npm/dt/uglify-js-minify-css-allfiles.svg?label=total+downloads
|
|
10
|
-
[donate-badge]: https://img.shields.io/badge/Buy%20me%20a%20coffee-Donate-red.svg
|
|
11
|
-
[donate-url]: https://github.com/sponsors/oinochoe
|
|
12
|
-
[create-pr]: https://github.com/oinochoe/
|
|
13
|
-
|
|
14
|
-
# uglify-js-minify-css-allfiles
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
- [
|
|
27
|
-
- [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
## Installation
|
|
32
|
-
|
|
33
|
-
Install with `npm`:
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
$ npm i uglify-js-minify-css-allfiles
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
##
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* @
|
|
48
|
-
* @
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
[Changelog](/CHANGELOG.md)
|
|
77
|
-
|
|
78
|
-
## License
|
|
79
|
-
|
|
80
|
-
MIT. See [LICENSE.md](https://github.com/oinochoe/ugly-code/blob/master/LICENSE) for details.
|
|
1
|
+
[![NPM downloads][npm-downloads]][npm-url]
|
|
2
|
+
[![NPM total downloads][npm-total-downloads]][npm-url]
|
|
3
|
+
|
|
4
|
+
| <br>[![Donate][donate-badge]][donate-url] <br> | Your help is appreciated! [Create a PR][create-pr] or just [buy me a coffee][donate-url] |
|
|
5
|
+
| ---------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
6
|
+
|
|
7
|
+
[npm-url]: https://www.npmjs.com/package/uglify-js-minify-css-allfiles
|
|
8
|
+
[npm-downloads]: https://img.shields.io/npm/dm/uglify-js-minify-css-allfiles.svg
|
|
9
|
+
[npm-total-downloads]: https://img.shields.io/npm/dt/uglify-js-minify-css-allfiles.svg?label=total+downloads
|
|
10
|
+
[donate-badge]: https://img.shields.io/badge/Buy%20me%20a%20coffee-Donate-red.svg
|
|
11
|
+
[donate-url]: https://github.com/sponsors/oinochoe
|
|
12
|
+
[create-pr]: https://github.com/oinochoe/uglify-js-minify-css-allfiles/pulls
|
|
13
|
+
|
|
14
|
+
# uglify-js-minify-css-allfiles
|
|
15
|
+
|
|
16
|
+
A powerful tool to minify and obfuscate JavaScript and CSS files in your project.
|
|
17
|
+
It helps protect your code in deployment environments and makes it less recognizable to others, all through a simple CLI interface.
|
|
18
|
+
You can easily minify all files in a specific folder, with the option to exclude certain directories.
|
|
19
|
+
|
|
20
|
+
[](https://www.npmjs.com/package/uglify-js-minify-css-allfiles)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Table of Contents
|
|
25
|
+
|
|
26
|
+
- [Installation](#installation)
|
|
27
|
+
- [Usage](#usage)
|
|
28
|
+
- [Changelog](#changelog)
|
|
29
|
+
- [License](#license)
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
Install with `npm`:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
$ npm i uglify-js-minify-css-allfiles
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
Import the module in your script:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import minifyAll from './dist/module.js';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {string} minifyFolder - The folder containing files to minify.
|
|
48
|
+
* @param {string} [excludeFolder] - The folder to exclude from minification (optional).
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
minifyAll(minifyFolder, excludeFolder);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Execute script:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
import minifyAll from 'uglify-js-minify-css-allfiles';
|
|
58
|
+
|
|
59
|
+
// Example 1: Minify all files in '../test/' except those in 'lib' folder
|
|
60
|
+
minifyAll('../test/', 'lib');
|
|
61
|
+
|
|
62
|
+
// Example 2: Use command line arguments
|
|
63
|
+
minifyAll(process.argv[2], process.argv[3]);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Changelog
|
|
67
|
+
|
|
68
|
+
See CHANGELOG.md for details on each release.
|
|
69
|
+
|
|
70
|
+
[Changelog](/CHANGELOG.md)
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
MIT. See [LICENSE.md](https://github.com/oinochoe/uglify-js-minify-css-allfiles/blob/master/LICENSE) for details.
|
package/demo.js
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import minifyAll from './dist/module.js';
|
|
2
|
+
|
|
3
|
+
minifyAll('./test/', 'lib', {
|
|
4
|
+
presets: [
|
|
5
|
+
[
|
|
6
|
+
'@babel/preset-env',
|
|
7
|
+
{
|
|
8
|
+
targets: {
|
|
9
|
+
esmodules: false, // Target ES2015
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
],
|
|
14
|
+
});
|
|
15
|
+
// console.log(process.argv.slice(2)[0], process.argv.slice(2)[1]);
|
|
16
|
+
// minifyAll(process.argv.slice(2)[0], process.argv.slice(2)[1]);
|
package/dist/module.js
CHANGED
|
@@ -1,89 +1,111 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* uglify-js and minify-css
|
|
3
|
-
* Released under the terms of MIT license
|
|
4
|
-
*
|
|
5
|
-
* Copyright (C)
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
1
|
+
/**
|
|
2
|
+
* uglify-js and minify-css for all files
|
|
3
|
+
* Released under the terms of MIT license
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2024 yeongmin
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { promises as fs } from 'fs';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import Logger from './modules/logger.js';
|
|
11
|
+
import { getAllFiles, writeFile } from './modules/fileHandler.js';
|
|
12
|
+
import { minifyJS, minifyCSS } from './modules/minifier.js';
|
|
13
|
+
import babelCore from '@babel/core';
|
|
14
|
+
|
|
15
|
+
const FILE_HANDLERS = {
|
|
16
|
+
'.js': async (filePath, content, logger, babelOptions) => {
|
|
17
|
+
try {
|
|
18
|
+
// Transform the code using Babel with preset-env
|
|
19
|
+
let transformed = content;
|
|
20
|
+
|
|
21
|
+
// Convert code to Babel when Babel option is provided
|
|
22
|
+
if (babelOptions) {
|
|
23
|
+
transformed = babelCore.transformSync(content, babelOptions).code;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const result = minifyJS(transformed);
|
|
27
|
+
await writeFile(filePath, result, logger);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
await logger.logError(filePath, `Babel transformation failed: ${error.message}`);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
'.css': async (filePath, content, logger) => {
|
|
33
|
+
const output = await minifyCSS(content);
|
|
34
|
+
if (output.warnings.length > 0) {
|
|
35
|
+
await logger.logError(filePath, `CSS warnings: ${output.warnings.join(', ')}`);
|
|
36
|
+
await writeFile(filePath, null, logger);
|
|
37
|
+
} else {
|
|
38
|
+
await writeFile(filePath, output.styles, logger);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Processes a single file based on its extension.
|
|
45
|
+
* @async
|
|
46
|
+
* @param {string} filePath - The path of the file to process.
|
|
47
|
+
* @param {Logger} logger - The logger instance.
|
|
48
|
+
* @param {Object} [babelOptions=null] - Babel options for converting JavaScript files.
|
|
49
|
+
* @returns {Promise<void>}
|
|
50
|
+
*/
|
|
51
|
+
async function processFile(filePath, logger, babelOptions = null) {
|
|
52
|
+
const fileContent = await fs.readFile(filePath, 'utf-8');
|
|
53
|
+
const fileExtension = path.extname(filePath);
|
|
54
|
+
const handler = FILE_HANDLERS[fileExtension];
|
|
55
|
+
|
|
56
|
+
if (handler) {
|
|
57
|
+
await handler(filePath, fileContent, logger, babelOptions);
|
|
58
|
+
} else {
|
|
59
|
+
logger.logInfo(`지원되지 않는 파일 형식 건너뜀: ${filePath}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Minifies all JavaScript and CSS files in the specified directory and its subdirectories.
|
|
65
|
+
*
|
|
66
|
+
* @async
|
|
67
|
+
* @function minifyAll
|
|
68
|
+
* @param {string} contentPath - The path to the directory containing the files to be minified.
|
|
69
|
+
* @param {string} [excludeFolder=''] - The name of a folder to exclude from minification.
|
|
70
|
+
* @param {Object} [babelOptions=null] - Babel options for converting JavaScript files.
|
|
71
|
+
* @returns {Promise<void>} A promise that resolves when all files have been processed.
|
|
72
|
+
* @throws {Error} If there's an issue reading or writing files.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* // Minify all files in './test/' directory, excluding 'lib' folder
|
|
76
|
+
* import minifyAll from './main.js';
|
|
77
|
+
* await minifyAll('./test/', 'lib');
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* // Minify all files in a directory specified as a command line argument
|
|
81
|
+
* import minifyAll from './main.js';
|
|
82
|
+
* await minifyAll(process.argv[2], process.argv[3]);
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* // Add babel options for converting JavaScript files.
|
|
86
|
+
* minifyAll('./test/', 'lib', {
|
|
87
|
+
* presets: [
|
|
88
|
+
* [
|
|
89
|
+
* '@babel/preset-env',
|
|
90
|
+
* {
|
|
91
|
+
* targets: {
|
|
92
|
+
* esmodules: false, // Target ES2015
|
|
93
|
+
* },
|
|
94
|
+
* },
|
|
95
|
+
* ],
|
|
96
|
+
* ],
|
|
97
|
+
* });
|
|
98
|
+
*/
|
|
99
|
+
export default async function minifyAll(contentPath, excludeFolder = '', babelOptions = null) {
|
|
100
|
+
const logger = new Logger();
|
|
101
|
+
await logger.initialize();
|
|
102
|
+
|
|
103
|
+
const rootDir = contentPath || '';
|
|
104
|
+
|
|
105
|
+
await getAllFiles(rootDir, async (filePath) => {
|
|
106
|
+
if (excludeFolder && filePath.includes(excludeFolder)) return;
|
|
107
|
+
await processFile(filePath, logger, babelOptions);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
await logger.summarize();
|
|
111
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File handling module for minification process.
|
|
3
|
+
* @module fileHandler
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { promises as fs } from 'fs';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Recursively gets all files in a directory and its subdirectories.
|
|
11
|
+
*
|
|
12
|
+
* @async
|
|
13
|
+
* @param {string} dirPath - The path to the directory to search.
|
|
14
|
+
* @param {Function} callback - The callback function to execute for each file.
|
|
15
|
+
* @returns {Promise<void>}
|
|
16
|
+
*/
|
|
17
|
+
export async function getAllFiles(dirPath, callback) {
|
|
18
|
+
const files = await fs.readdir(dirPath);
|
|
19
|
+
for (const file of files) {
|
|
20
|
+
const filePath = path.join(dirPath, file);
|
|
21
|
+
const fileStat = await fs.stat(filePath);
|
|
22
|
+
if (fileStat.isFile()) {
|
|
23
|
+
await callback(filePath, fileStat);
|
|
24
|
+
} else if (fileStat.isDirectory()) {
|
|
25
|
+
await getAllFiles(filePath, callback);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Writes content to a file.
|
|
32
|
+
*
|
|
33
|
+
* @async
|
|
34
|
+
* @param {string} filePath - The path of the file to write.
|
|
35
|
+
* @param {string} content - The content to write to the file.
|
|
36
|
+
* @param {Object} logger - The logger object for logging operations.
|
|
37
|
+
* @returns {Promise<void>}
|
|
38
|
+
*/
|
|
39
|
+
export async function writeFile(filePath, content, logger) {
|
|
40
|
+
if (typeof content === 'undefined' || content === '' || content === null) {
|
|
41
|
+
await logger.logError(filePath, 'Invalid or empty content');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
logger.logInfo(`Writing file: ${filePath}`);
|
|
46
|
+
try {
|
|
47
|
+
await fs.writeFile(filePath, content, 'utf-8');
|
|
48
|
+
} catch (error) {
|
|
49
|
+
await logger.logError(filePath, `Write failed: ${error.message}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger module for handling log operations.
|
|
3
|
+
* @module logger
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from 'fs/promises';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get current formatted time string
|
|
11
|
+
* @returns {string} Formatted time string
|
|
12
|
+
*/
|
|
13
|
+
function getCurrentTime() {
|
|
14
|
+
const now = new Date();
|
|
15
|
+
return now.toLocaleString('en-US', {
|
|
16
|
+
year: 'numeric',
|
|
17
|
+
month: '2-digit',
|
|
18
|
+
day: '2-digit',
|
|
19
|
+
hour: '2-digit',
|
|
20
|
+
minute: '2-digit',
|
|
21
|
+
second: '2-digit',
|
|
22
|
+
hour12: false,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Logger class for handling log operations.
|
|
28
|
+
* @class
|
|
29
|
+
*/
|
|
30
|
+
class Logger {
|
|
31
|
+
/**
|
|
32
|
+
* Create a Logger instance.
|
|
33
|
+
* @param {string} [logDir='logs'] - The directory to store log files.
|
|
34
|
+
*/
|
|
35
|
+
constructor(logDir = 'logs') {
|
|
36
|
+
this.logDir = logDir;
|
|
37
|
+
this.errorCount = 0;
|
|
38
|
+
this.errorFiles = [];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Initialize the logger by creating the log directory.
|
|
43
|
+
* @async
|
|
44
|
+
* @returns {Promise<void>}
|
|
45
|
+
*/
|
|
46
|
+
async initialize() {
|
|
47
|
+
try {
|
|
48
|
+
await fs.mkdir(this.logDir, { recursive: true });
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error(`Failed to create log directory: ${error.message}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Log an error message and write it to the error log file.
|
|
56
|
+
* @async
|
|
57
|
+
* @param {string} filePath - The path of the file where the error occurred.
|
|
58
|
+
* @param {string} reason - The reason for the error.
|
|
59
|
+
* @returns {Promise<void>}
|
|
60
|
+
*/
|
|
61
|
+
async logError(filePath, reason) {
|
|
62
|
+
const logMessage = `
|
|
63
|
+
=============== File Error ===============
|
|
64
|
+
Time: ${getCurrentTime()}
|
|
65
|
+
File: ${filePath}
|
|
66
|
+
Reason: ${reason}
|
|
67
|
+
==========================================
|
|
68
|
+
`;
|
|
69
|
+
|
|
70
|
+
console.error(logMessage);
|
|
71
|
+
this.errorCount++;
|
|
72
|
+
this.errorFiles.push(filePath);
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
await fs.appendFile(path.join(this.logDir, 'error.log'), logMessage);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error(`Failed to write to error log: ${error.message}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Log an informational message to the console.
|
|
83
|
+
* @param {string} message - The message to log.
|
|
84
|
+
*/
|
|
85
|
+
logInfo(message) {
|
|
86
|
+
console.info(`[${getCurrentTime()}] ${message}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Generate and log a summary of the processing results.
|
|
91
|
+
* @async
|
|
92
|
+
* @returns {Promise<void>}
|
|
93
|
+
*/
|
|
94
|
+
async summarize() {
|
|
95
|
+
const summary = `
|
|
96
|
+
=============== Processing Summary ===============
|
|
97
|
+
Time: ${getCurrentTime()}
|
|
98
|
+
Total files processed: ${this.errorCount + this.errorFiles.length}
|
|
99
|
+
Files with errors: ${this.errorCount}
|
|
100
|
+
Error files:
|
|
101
|
+
${this.errorFiles.map((file, index) => ` ${index + 1}. ${file}`).join('\n')}
|
|
102
|
+
==================================================
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
console.info(summary);
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
await fs.appendFile(path.join(this.logDir, 'summary.log'), summary);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error(`Failed to write to summary log: ${error.message}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export default Logger;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minification module for JavaScript and CSS files.
|
|
3
|
+
* @module minifier
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { minify as uglifyJS } from 'uglify-js';
|
|
7
|
+
import CleanCSS from 'clean-css';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Options for CSS minification.
|
|
11
|
+
* @constant {Object}
|
|
12
|
+
*/
|
|
13
|
+
const CSS_OPTIONS = {
|
|
14
|
+
level: { 1: { all: false } },
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Minifies JavaScript content.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} content - The JavaScript content to minify.
|
|
21
|
+
* @returns {string} The minified JavaScript content.
|
|
22
|
+
*/
|
|
23
|
+
export function minifyJS(content) {
|
|
24
|
+
return uglifyJS(content, {
|
|
25
|
+
compress: {
|
|
26
|
+
pure_funcs: ['console.log', 'console.error', 'console.warn', 'console.info'],
|
|
27
|
+
},
|
|
28
|
+
}).code;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Minifies CSS content.
|
|
33
|
+
*
|
|
34
|
+
* @async
|
|
35
|
+
* @param {string} content - The CSS content to minify.
|
|
36
|
+
* @returns {Promise<Object>} A promise that resolves to the minification result.
|
|
37
|
+
*/
|
|
38
|
+
export function minifyCSS(content) {
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
new CleanCSS(CSS_OPTIONS).minify(content, (error, output) => resolve(output));
|
|
41
|
+
});
|
|
42
|
+
}
|
package/logs/error.log
ADDED
package/logs/summary.log
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
|
|
2
|
+
=============== Processing Summary ===============
|
|
3
|
+
Time: 08/19/2024, 21:39:36
|
|
4
|
+
Total files processed: 2
|
|
5
|
+
Files with errors: 1
|
|
6
|
+
Error files:
|
|
7
|
+
1. test\test.js
|
|
8
|
+
==================================================
|
|
9
|
+
|
|
10
|
+
=============== Processing Summary ===============
|
|
11
|
+
Time: 08/19/2024, 21:40:08
|
|
12
|
+
Total files processed: 0
|
|
13
|
+
Files with errors: 0
|
|
14
|
+
Error files:
|
|
15
|
+
|
|
16
|
+
==================================================
|
|
17
|
+
|
|
18
|
+
=============== Processing Summary ===============
|
|
19
|
+
Time: 08/19/2024, 21:57:46
|
|
20
|
+
Total files processed: 0
|
|
21
|
+
Files with errors: 0
|
|
22
|
+
Error files:
|
|
23
|
+
|
|
24
|
+
==================================================
|
|
25
|
+
|
|
26
|
+
=============== Processing Summary ===============
|
|
27
|
+
Time: 08/19/2024, 22:14:47
|
|
28
|
+
Total files processed: 0
|
|
29
|
+
Files with errors: 0
|
|
30
|
+
Error files:
|
|
31
|
+
|
|
32
|
+
==================================================
|
|
33
|
+
|
|
34
|
+
=============== Processing Summary ===============
|
|
35
|
+
Time: 08/19/2024, 22:20:22
|
|
36
|
+
Total files processed: 0
|
|
37
|
+
Files with errors: 0
|
|
38
|
+
Error files:
|
|
39
|
+
|
|
40
|
+
==================================================
|
|
41
|
+
|
|
42
|
+
=============== Processing Summary ===============
|
|
43
|
+
Time: 08/19/2024, 22:24:04
|
|
44
|
+
Total files processed: 0
|
|
45
|
+
Files with errors: 0
|
|
46
|
+
Error files:
|
|
47
|
+
|
|
48
|
+
==================================================
|
|
49
|
+
|
|
50
|
+
=============== Processing Summary ===============
|
|
51
|
+
Time: 08/19/2024, 22:25:15
|
|
52
|
+
Total files processed: 0
|
|
53
|
+
Files with errors: 0
|
|
54
|
+
Error files:
|
|
55
|
+
|
|
56
|
+
==================================================
|
|
57
|
+
|
|
58
|
+
=============== Processing Summary ===============
|
|
59
|
+
Time: 08/19/2024, 22:32:13
|
|
60
|
+
Total files processed: 0
|
|
61
|
+
Files with errors: 0
|
|
62
|
+
Error files:
|
|
63
|
+
|
|
64
|
+
==================================================
|
|
65
|
+
|
|
66
|
+
=============== Processing Summary ===============
|
|
67
|
+
Time: 08/19/2024, 22:32:49
|
|
68
|
+
Total files processed: 0
|
|
69
|
+
Files with errors: 0
|
|
70
|
+
Error files:
|
|
71
|
+
|
|
72
|
+
==================================================
|
|
73
|
+
|
|
74
|
+
=============== Processing Summary ===============
|
|
75
|
+
Time: 08/19/2024, 22:33:35
|
|
76
|
+
Total files processed: 0
|
|
77
|
+
Files with errors: 0
|
|
78
|
+
Error files:
|
|
79
|
+
|
|
80
|
+
==================================================
|
|
81
|
+
|
|
82
|
+
=============== Processing Summary ===============
|
|
83
|
+
Time: 08/19/2024, 22:42:58
|
|
84
|
+
Total files processed: 0
|
|
85
|
+
Files with errors: 0
|
|
86
|
+
Error files:
|
|
87
|
+
|
|
88
|
+
==================================================
|
|
89
|
+
|
|
90
|
+
=============== Processing Summary ===============
|
|
91
|
+
Time: 08/19/2024, 22:43:10
|
|
92
|
+
Total files processed: 0
|
|
93
|
+
Files with errors: 0
|
|
94
|
+
Error files:
|
|
95
|
+
|
|
96
|
+
==================================================
|
package/minify.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('./dist/module');
|
|
1
|
+
module.exports = require('./dist/module');
|
package/package.json
CHANGED
|
@@ -1,46 +1,49 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "uglify-js-minify-css-allfiles",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "you will be able to minify all files as same file names which is js or css",
|
|
5
|
-
"main": "minify.js",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "uglify-js-minify-css-allfiles",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "you will be able to minify all files as same file names which is js or css",
|
|
5
|
+
"main": "minify.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/oinochoe/uglify-js-minify-css-allfiles.git"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"ugly-code",
|
|
16
|
+
"uglyCode",
|
|
17
|
+
"uglify-js",
|
|
18
|
+
"minify-es6",
|
|
19
|
+
"uglifyjs-es6",
|
|
20
|
+
"minifycss",
|
|
21
|
+
"miniCss",
|
|
22
|
+
"cleanCss",
|
|
23
|
+
"minifyCss",
|
|
24
|
+
"comporessor",
|
|
25
|
+
"allfile minify",
|
|
26
|
+
"allfiles minify",
|
|
27
|
+
"all files uglify"
|
|
28
|
+
],
|
|
29
|
+
"author": {
|
|
30
|
+
"name": "yeongmin kim",
|
|
31
|
+
"email": "copstyle86@gmail.com",
|
|
32
|
+
"url": "https://oinochoe.github.io/portfolio/"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/oinochoe/uglify-js-minify-css-allfiles/issues",
|
|
37
|
+
"email": "copstyle86@gmail.com"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/oinochoe/uglify-js-minify-css-allfiles#readme",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"clean-css": "^4.2.4",
|
|
42
|
+
"uglify-js": "^3.19.2",
|
|
43
|
+
"uglify-js-es6": "^2.8.9"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@babel/core": "^7.25.2",
|
|
47
|
+
"@babel/preset-env": "^7.25.3"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/test/lib/test.js
ADDED
package/test/test.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.dragon{width:30px;height:50px}.dragon a{display:block;margin:30px}
|
package/test/test.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class MyPhone {
|
|
2
|
+
inst = '';
|
|
3
|
+
#brand;
|
|
4
|
+
static phoneType = 'smartphone';
|
|
5
|
+
static #counter = 0;
|
|
6
|
+
constructor(n) {
|
|
7
|
+
(this.#brand = n), MyPhone.#counter++;
|
|
8
|
+
}
|
|
9
|
+
makeCall(n) {
|
|
10
|
+
this.#brand;
|
|
11
|
+
}
|
|
12
|
+
static getPhoneCount() {
|
|
13
|
+
return MyPhone.#counter;
|
|
14
|
+
}
|
|
15
|
+
get phoneInfo() {
|
|
16
|
+
return this.#brand + ' ' + MyPhone.phoneType;
|
|
17
|
+
}
|
|
18
|
+
set updateBrand(n) {
|
|
19
|
+
this.#brand = n;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
let myPhone = new MyPhone('Samsung');
|
|
23
|
+
myPhone.makeCall('123-456-7890'),
|
|
24
|
+
myPhone.phoneInfo,
|
|
25
|
+
(myPhone.updateBrand = 'Apple'),
|
|
26
|
+
MyPhone.getPhoneCount();
|
package/test/common.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var dragon=()=>{alert("dd")};
|
package/test/lib/comon.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function dragon(){console.assert("sdsfdsd")}
|