@adamlui/minify.js 1.2.0 → 1.2.1
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/README.md +12 -11
- package/docs/SECURITY.md +1 -1
- package/minify.js +36 -34
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# </> minify.js
|
|
2
2
|
|
|
3
3
|
### Recursively minify all JavaScript files.
|
|
4
4
|
|
|
5
5
|
<a href="https://www.npmjs.com/package/@adamlui/minify.js"><img height=31 src="https://img.shields.io/npm/dt/%40adamlui%2Fminify.js?logo=npm&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
6
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
|
-
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=versions"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.2.
|
|
7
|
+
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=versions"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.2.1-fc7811.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/@adamlui/minify.js?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/%40adamlui%2Fminify.js?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646"></a>
|
|
8
9
|
|
|
9
|
-
<img src="https://github.com/adamlui/js-utils/blob/main/minify.js/media/images/minify
|
|
10
|
+
<img src="https://github.com/adamlui/js-utils/blob/main/minify.js/media/images/minify.js-docs-demo.png">
|
|
10
11
|
|
|
11
12
|
<br>
|
|
12
13
|
|
|
@@ -31,7 +32,7 @@ npm install -D @adamlui/minify.js
|
|
|
31
32
|
The basic **global command** is:
|
|
32
33
|
|
|
33
34
|
```
|
|
34
|
-
|
|
35
|
+
minifyjs
|
|
35
36
|
```
|
|
36
37
|
|
|
37
38
|
#
|
|
@@ -39,7 +40,7 @@ minify-js
|
|
|
39
40
|
To specify **input/output** paths:
|
|
40
41
|
|
|
41
42
|
```
|
|
42
|
-
|
|
43
|
+
minifyjs [input_path] [output_path]
|
|
43
44
|
```
|
|
44
45
|
|
|
45
46
|
- `[input_path]`: Path to JS file or directory containing JS files to be minified, relative to the current working directory.
|
|
@@ -53,11 +54,11 @@ To use as a **package script**, edit your project's `package.json` like this:
|
|
|
53
54
|
|
|
54
55
|
```json
|
|
55
56
|
"scripts": {
|
|
56
|
-
"build:js": "<minify
|
|
57
|
+
"build:js": "<minify.js-cmd>"
|
|
57
58
|
},
|
|
58
59
|
```
|
|
59
60
|
|
|
60
|
-
Replace `<minify
|
|
61
|
+
Replace `<minify.js-cmd>` with `minifyjs` + optional args. Then, `npm run build:js` can be used to run the command.
|
|
61
62
|
<br><br>
|
|
62
63
|
|
|
63
64
|
## 📃 Example commands:
|
|
@@ -65,25 +66,25 @@ Replace `<minify-js-cmd>` with `minify-js` + optional args. Then, `npm run build
|
|
|
65
66
|
- Minify all JavaScript files in the **current directory** (outputs to `min/`):
|
|
66
67
|
|
|
67
68
|
```
|
|
68
|
-
|
|
69
|
+
minifyjs
|
|
69
70
|
```
|
|
70
71
|
|
|
71
72
|
- Minify all JavaScript files in a **specific directory** (outputs to `path/to/your/directory/min/`):
|
|
72
73
|
|
|
73
74
|
```
|
|
74
|
-
|
|
75
|
+
minifyjs path/to/your/directory
|
|
75
76
|
```
|
|
76
77
|
|
|
77
78
|
- Minify a **specific file** (outputs to `path/to/your/min/file.min.js`):
|
|
78
79
|
|
|
79
80
|
```
|
|
80
|
-
|
|
81
|
+
minifyjs path/to/your/file.js
|
|
81
82
|
```
|
|
82
83
|
|
|
83
84
|
- Specify both **input and output** directories (outputs to `output_folder/`):
|
|
84
85
|
|
|
85
86
|
```
|
|
86
|
-
|
|
87
|
+
minifyjs input_folder output_folder
|
|
87
88
|
```
|
|
88
89
|
|
|
89
90
|
## 🏛️ MIT License
|
package/docs/SECURITY.md
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
If you find a vulnerability, please open a [draft security advisory](https://github.com/adamlui/js-utils/security/advisories/new).
|
|
4
4
|
|
|
5
|
-
Pull requests are also welcome, but for safety reasons, send an email to adam@kudoai.com and wait for a response before making it public.
|
|
5
|
+
Pull requests are also welcome, but for safety reasons, send an email to <adam@kudoai.com> and wait for a response before making it public.
|
package/minify.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// Import
|
|
3
|
+
// Import LIBS
|
|
4
4
|
const fs = require('fs'),
|
|
5
5
|
path = require('path'),
|
|
6
6
|
uglifyJS = require('uglify-js');
|
|
@@ -11,51 +11,30 @@ const nc = '\x1b[0m', // no color
|
|
|
11
11
|
by = '\x1b[1;33m', // bright yellow
|
|
12
12
|
bg = '\x1b[1;92m'; // bright green
|
|
13
13
|
|
|
14
|
-
// Show
|
|
14
|
+
// Show HELP screen if -h or --help passed
|
|
15
15
|
if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
16
16
|
|
|
17
17
|
// Print help
|
|
18
|
-
console.info(`\n${by}
|
|
18
|
+
console.info(`\n${by}minifyjs [inputPath] [outputPath] [options]${nc}`);
|
|
19
19
|
console.info('\nPath arguments:');
|
|
20
|
-
printWrappedMsg(' [
|
|
20
|
+
printWrappedMsg(' [inputPath] '
|
|
21
21
|
+ 'Path to JS file or directory containing JS files to be minified,'
|
|
22
22
|
+ ' relative to the current working directory.');
|
|
23
|
-
printWrappedMsg(' [
|
|
23
|
+
printWrappedMsg(' [outputPath] '
|
|
24
24
|
+ 'Path to file or directory where minified files will be stored,'
|
|
25
25
|
+ ' relative to original file location (if not provided, min/ is used).');
|
|
26
26
|
console.info('\nConfig options:');
|
|
27
|
-
printWrappedMsg(' --include-dotfolders
|
|
28
|
-
printWrappedMsg(' --include-dotfilles
|
|
27
|
+
printWrappedMsg(' -dd, --include-dotfolders Include dotfolders in file search.');
|
|
28
|
+
printWrappedMsg(' -df, --include-dotfilles Include dotfiles in file search.');
|
|
29
29
|
console.info('\nInfo commands:');
|
|
30
|
-
printWrappedMsg(' -h, --help
|
|
31
|
-
printWrappedMsg(' -v, --version
|
|
30
|
+
printWrappedMsg(' -h, --help Display this help screen.');
|
|
31
|
+
printWrappedMsg(' -v, --version Show version number.');
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
indentation = 23, lines = [], words = msg.match(/\S+|\s+/g);
|
|
36
|
-
|
|
37
|
-
// Split msg into lines of appropriate lengths
|
|
38
|
-
let currentLine = '';
|
|
39
|
-
words.forEach(word => {
|
|
40
|
-
const lineLength = terminalWidth - ( lines.length === 0 ? 0 : indentation );
|
|
41
|
-
if (currentLine.length + word.length > lineLength) { // cap/store it
|
|
42
|
-
lines.push(currentLine); currentLine = ''; }
|
|
43
|
-
currentLine += word;
|
|
44
|
-
});
|
|
45
|
-
lines.push(currentLine); // Push the last line without trimming
|
|
46
|
-
|
|
47
|
-
// Print formatted msg
|
|
48
|
-
lines.forEach((line, index) => {
|
|
49
|
-
if (index === 0) console.info(line); // print 1st line unindented
|
|
50
|
-
else console.info(' '.repeat(indentation) + line); // print subsequent lines indented
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Show version number if -v or --version passed
|
|
55
|
-
} else if (process.argv.some(arg => /^--?v(?:er(?:s(?:ion)?)?)?$/.test(arg))) {
|
|
33
|
+
// Show VERSION number if -v or --version passed
|
|
34
|
+
} else if (process.argv.some(arg => /^--?ve?r?s?i?o?n?$/.test(arg))) {
|
|
56
35
|
console.info('v' + require('./package.json').version);
|
|
57
36
|
|
|
58
|
-
} else { // run
|
|
37
|
+
} else { // run MAIN routine
|
|
59
38
|
|
|
60
39
|
// Init I/O args
|
|
61
40
|
const [inputArg = '', outputArg = ''] = ( // default to empty strings for error-less handling
|
|
@@ -69,7 +48,7 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
69
48
|
if (inputArg && !fs.existsSync(inputPath)) {
|
|
70
49
|
console.error(`\n${br}Error: First arg must be an existing file or directory.`
|
|
71
50
|
+ `\n${ inputPath } does not exist.${nc}`
|
|
72
|
-
+ '\n\nExample valid command: \n>>
|
|
51
|
+
+ '\n\nExample valid command: \n>> minifyjs . output.min.js');
|
|
73
52
|
process.exit(1);
|
|
74
53
|
}
|
|
75
54
|
|
|
@@ -126,3 +105,26 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
126
105
|
console.info(`${ minifiedCnt } file${ minifiedCnt > 1 ? 's' : '' } minified.`);
|
|
127
106
|
} else console.info(`${by}No unminified JavaScript files found.${nc}`);
|
|
128
107
|
}
|
|
108
|
+
|
|
109
|
+
function printWrappedMsg(msg) { // truncates msg, indents 2nd+ lines
|
|
110
|
+
const terminalWidth = process.stdout.columns || 80,
|
|
111
|
+
indentation = 29, lines = [], words = msg.match(/\S+|\s+/g);
|
|
112
|
+
|
|
113
|
+
// Split msg into lines of appropriate lengths
|
|
114
|
+
let currentLine = '';
|
|
115
|
+
words.forEach(word => {
|
|
116
|
+
const lineLength = terminalWidth - ( lines.length === 0 ? 0 : indentation );
|
|
117
|
+
if (currentLine.length + word.length > lineLength) { // cap/store it
|
|
118
|
+
lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
|
|
119
|
+
currentLine = '';
|
|
120
|
+
}
|
|
121
|
+
currentLine += word;
|
|
122
|
+
});
|
|
123
|
+
lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
|
|
124
|
+
|
|
125
|
+
// Print formatted msg
|
|
126
|
+
lines.forEach((line, index) => console.info(
|
|
127
|
+
index === 0 ? line // print 1st line unindented
|
|
128
|
+
: ' '.repeat(indentation) + line // print subsequent lines indented
|
|
129
|
+
));
|
|
130
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamlui/minify.js",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Recursively minify all JavaScript files",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Adam Lui",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"main": "minify.js",
|
|
13
13
|
"bin": {
|
|
14
|
+
"minifyjs": "minify.js",
|
|
14
15
|
"minify-js": "minify.js"
|
|
15
16
|
},
|
|
16
17
|
"scripts": {
|