@adamlui/minify.js 1.0.0 → 1.0.2

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.
Files changed (3) hide show
  1. package/README.md +116 -107
  2. package/minify.js +10 -6
  3. package/package.json +43 -37
package/README.md CHANGED
@@ -1,107 +1,116 @@
1
- # <> minify.js
2
-
3
- <a href="#%EF%B8%8F-mit-license"><img height=25 src="https://img.shields.io/badge/License-MIT-fcde7b.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
4
-
5
- ### Minify JavaScript files from the CLI (recursively or indivdually)
6
-
7
- <img height=10px width="100%" src="https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/aqua.png">
8
-
9
- ## ⚡ Installation
10
-
11
- - As a **global utility**:
12
-
13
- ```
14
- npm install -g @adamlui/minify.js
15
- ```
16
-
17
- - As a **dev dependency**, from your project root:
18
-
19
- ```
20
- npm install -D @adamlui/minify.js
21
- ```
22
-
23
- ## 💻 Usage
24
-
25
- - The basic **global command** is:
26
-
27
- ```
28
- minify-js
29
- ```
30
-
31
- - To specify **input/output** directories:
32
-
33
- ```
34
- minify-js <input_path> <output_path>
35
- ```
36
-
37
- - `<input_path>`: Path to directory containing JavaScript files to be minified, relative to the current working directory.
38
- - `<output_path>`: Path to directory where minified files will be stored, relative to original file location. (If not provided, `./minified` is used.)
39
-
40
- **💡 Note:** The paths can be either folders or specific files. If folders are passed, files will be processed recursively.<br><br>
41
-
42
- - To use as a **package script**, edit your project's `package.json` like this:
43
-
44
- ```json
45
- "scripts": {
46
- "build:js": "<minify-js-cmd>"
47
- },
48
- ```
49
-
50
- Replace `<minify-js-cmd>` with `minify-js` + optional args. Then, `npm run build:js` can be used to run the command.
51
- <br><br>
52
-
53
- ## 📃 Examples:
54
-
55
- - Minify all JavaScript files in the **current directory** (outputs to `./minified/`):
56
-
57
- ```
58
- minify-js
59
- ```
60
-
61
- - Minify all JavaScript files in a **specific directory** (outputs to `path/to/your/directory/minified/`):
62
-
63
- ```
64
- minify-js path/to/your/directory
65
- ```
66
-
67
- - Minify a **specific file** (outputs to `path/to/your/minified/file.min.js`):
68
-
69
- ```
70
- minify-js path/to/your/file.js
71
- ```
72
-
73
- - Specify both **input and output** directories (outputs to `output_folder/`):
74
-
75
- ```
76
- minify-js input_folder output_folder
77
- ```
78
-
79
- ## 🏛️ MIT License
80
-
81
- **Copyright (c) 2024 [Adam Lui](https://github.com/adamlui)**
82
-
83
- Permission is hereby granted, free of charge, to any person obtaining a copy
84
- of this software and associated documentation files (the "Software"), to deal
85
- in the Software without restriction, including without limitation the rights
86
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
87
- copies of the Software, and to permit persons to whom the Software is
88
- furnished to do so, subject to the following conditions:
89
-
90
- The above copyright notice and this permission notice shall be included in all
91
- copies or substantial portions of the Software.
92
-
93
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
94
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
95
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
96
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
97
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
98
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
99
- SOFTWARE.
100
-
101
- <br>
102
-
103
- <img height=6px width="100%" src="https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/aqua.png">
104
-
105
- <a href="https://github.com/adamlui">**Home**</a> /
106
- <a href="https://github.com/adamlui/js-utils/discussions">Discuss</a> /
107
- <a href="#--scss-to-cssjs">Back to top ↑</a>
1
+ # <> minify.js
2
+
3
+ ### Minify JavaScript files by CLI (recursively or individually)
4
+
5
+ <a href="https://www.npmjs.com/package/@adamlui/minify.js"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.0.2-fc7811.svg?logo=npm&logoColor=white&labelColor=464646&style=for-the-badge"></a>
6
+ <a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-fcde7b.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
7
+
8
+ <img src="https://github.com/adamlui/js-utils/blob/main/minify.js/media/images/minify-js-docs-demo.png">
9
+
10
+ <br>
11
+
12
+ <img height=8px width="100%" src="https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/aqua.png">
13
+
14
+ ## Installation
15
+
16
+ As a **global utility**:
17
+
18
+ ```
19
+ npm install -g @adamlui/minify.js
20
+ ```
21
+
22
+ As a **dev dependency**, from your project root:
23
+
24
+ ```
25
+ npm install -D @adamlui/minify.js
26
+ ```
27
+
28
+ ## 💻 Usage
29
+
30
+ The basic **global command** is:
31
+
32
+ ```
33
+ minify-js
34
+ ```
35
+
36
+ #
37
+
38
+ To specify **input/output** directories:
39
+
40
+ ```
41
+ minify-js <input_path> <output_path>
42
+ ```
43
+
44
+ - `<input_path>`: Path to directory containing JavaScript files to be minified, relative to the current working directory.
45
+ - `<output_path>`: Path to directory where minified files will be stored, relative to original file location. (If not provided, `min/` is used.)
46
+
47
+ **💡 Note:** The paths can be either folders or specific files. If folders are passed, files will be processed recursively.
48
+
49
+ #
50
+
51
+ To use as a **package script**, edit your project's `package.json` like this:
52
+
53
+ ```json
54
+ "scripts": {
55
+ "build:js": "<minify-js-cmd>"
56
+ },
57
+ ```
58
+
59
+ Replace `<minify-js-cmd>` with `minify-js` + optional args. Then, `npm run build:js` can be used to run the command.
60
+ <br><br>
61
+
62
+ ## 📃 Example commands:
63
+
64
+ - Minify all JavaScript files in the **current directory** (outputs to `min/`):
65
+
66
+ ```
67
+ minify-js
68
+ ```
69
+
70
+ - Minify all JavaScript files in a **specific directory** (outputs to `path/to/your/directory/min/`):
71
+
72
+ ```
73
+ minify-js path/to/your/directory
74
+ ```
75
+
76
+ - Minify a **specific file** (outputs to `path/to/your/min/file.min.js`):
77
+
78
+ ```
79
+ minify-js path/to/your/file.js
80
+ ```
81
+
82
+ - Specify both **input and output** directories (outputs to `output_folder/`):
83
+
84
+ ```
85
+ minify-js input_folder output_folder
86
+ ```
87
+
88
+ ## 🏛️ MIT License
89
+
90
+ **Copyright (c) 2024 [Adam Lui](https://github.com/adamlui)**
91
+
92
+ Permission is hereby granted, free of charge, to any person obtaining a copy
93
+ of this software and associated documentation files (the "Software"), to deal
94
+ in the Software without restriction, including without limitation the rights
95
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
96
+ copies of the Software, and to permit persons to whom the Software is
97
+ furnished to do so, subject to the following conditions:
98
+
99
+ The above copyright notice and this permission notice shall be included in all
100
+ copies or substantial portions of the Software.
101
+
102
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
103
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
104
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
105
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
106
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
107
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
108
+ SOFTWARE.
109
+
110
+ <br>
111
+
112
+ <img height=6px width="100%" src="https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/aqua.png">
113
+
114
+ <a href="https://github.com/adamlui/js-utils">**Home**</a> /
115
+ <a href="https://github.com/adamlui/js-utils/discussions">Discuss</a> /
116
+ <a href="#-minifyjs">Back to top ↑</a>
package/minify.js CHANGED
@@ -45,21 +45,25 @@ console.log(''); // line break before first log
45
45
  jsFiles.forEach(jsPath => {
46
46
  const outputDir = path.join(
47
47
  path.dirname(jsPath), // path of file to be minified
48
- path.dirname(outputArg), // path from output arg
49
- outputArg ? '' : 'minified' // minified/ if no output arg used
48
+ /so?u?rce?$/.test(path.dirname(jsPath)) ? '../min' // + ../min/ if in *(src|source)/
49
+ : outputArg.endsWith('.js') ? path.dirname(outputArg) // or path from file output arg
50
+ : outputArg || 'min' // or path from path output arg or min/ from no arg
50
51
  );
51
52
  const outputFilename = (
52
53
  outputArg.endsWith('.js') && inputArg.endsWith('.js')
53
54
  ? path.basename(outputArg).replace(/(\.min)?\.js$/, '')
54
55
  : path.basename(jsPath, '.js')
55
56
  ) + '.min.js';
57
+ const outputPath = path.join(outputDir, outputFilename);
56
58
  console.info(`Minifying ${ jsPath }...`);
57
59
  const minifiedCode = uglifyJS.minify(fs.readFileSync(jsPath, 'utf8')).code;
58
60
  if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
59
- fs.writeFileSync(path.join(outputDir, outputFilename), minifiedCode, 'utf8');
61
+ fs.writeFileSync(outputPath, minifiedCode, 'utf8');
60
62
  minifiedCnt++;
61
63
  });
62
64
 
63
- // Final summary
64
- if (minifiedCnt) console.info(`\n${bg}Minification complete!${nc}\n${ minifiedCnt } files minified.`);
65
- else console.info(`\n${by}No unminified JavaScript files found.${nc}`);
65
+ // Print final summary
66
+ if (minifiedCnt) {
67
+ console.info(`\n${bg}Minification complete!${nc}`);
68
+ console.info(`\n${ minifiedCnt } file${ minifiedCnt > 1 ? 's' : '' } minified.`);
69
+ } else console.info(`${by}No unminified JavaScript files found.${nc}`);
package/package.json CHANGED
@@ -1,37 +1,43 @@
1
- {
2
- "name": "@adamlui/minify.js",
3
- "version": "1.0.0",
4
- "description": "Minify JavaScript files",
5
- "author": {
6
- "name": "Adam Lui",
7
- "email": "adam@kudoai.com",
8
- "url": "https://github.com/adamlui"
9
- },
10
- "homepage": "https://github.com/adamlui/js-utils",
11
- "license": "MIT",
12
- "main": "minify.js",
13
- "bin": {
14
- "minify-js": "minify.js"
15
- },
16
- "scripts": {
17
- "test": "echo \"Error: no test specified\" && exit 1"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "git+https://github.com/adamlui/js-utils.git"
22
- },
23
- "keywords": [
24
- "javascript",
25
- "js",
26
- "js-utils",
27
- "utils",
28
- "utilities",
29
- "minifier"
30
- ],
31
- "bugs": {
32
- "url": "https://github.com/adamlui/js-utils/issues"
33
- },
34
- "dependencies": {
35
- "uglify-js": "^3.17.4"
36
- }
37
- }
1
+ {
2
+ "name": "@adamlui/minify.js",
3
+ "version": "1.0.2",
4
+ "description": "Minify JavaScript files",
5
+ "author": {
6
+ "name": "Adam Lui",
7
+ "email": "adam@kudoai.com",
8
+ "url": "https://github.com/adamlui"
9
+ },
10
+ "homepage": "https://github.com/adamlui/js-utils",
11
+ "license": "MIT",
12
+ "main": "minify.js",
13
+ "bin": {
14
+ "minify-js": "minify.js"
15
+ },
16
+ "scripts": {
17
+ "test": "echo \"Error: no test specified\" && exit 1",
18
+ "bump:patch": "bash utils/bump.sh patch",
19
+ "bump:minor": "bash utils/bump.sh minor",
20
+ "bump:major": "bash utils/bump.sh major",
21
+ "publish:patch": "bash utils/bump.sh patch --publish",
22
+ "publish:minor": "bash utils/bump.sh minor --publish",
23
+ "publish:major": "bash utils/bump.sh major --publish"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/adamlui/js-utils.git"
28
+ },
29
+ "keywords": [
30
+ "javascript",
31
+ "js",
32
+ "js-utils",
33
+ "utils",
34
+ "utilities",
35
+ "minifier"
36
+ ],
37
+ "bugs": {
38
+ "url": "https://github.com/adamlui/js-utils/issues"
39
+ },
40
+ "dependencies": {
41
+ "uglify-js": "^3.17.4"
42
+ }
43
+ }