uglify-js-minify-css-allfiles 2.0.0 → 2.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.
- package/README.md +48 -17
- package/demo.js +14 -12
- package/dist/module.js +29 -1
- package/logs/summary.log +16 -0
- package/package.json +5 -4
- package/test/test.css +8 -1
- package/test/test.js +83 -20
package/README.md
CHANGED
|
@@ -25,6 +25,8 @@ You can easily minify all files in a specific folder, with the option to exclude
|
|
|
25
25
|
|
|
26
26
|
- [Installation](#installation)
|
|
27
27
|
- [Usage](#usage)
|
|
28
|
+
- [Parameters](#parameters)
|
|
29
|
+
- [BabelOptions](#babeloptions)
|
|
28
30
|
- [Changelog](#changelog)
|
|
29
31
|
- [License](#license)
|
|
30
32
|
|
|
@@ -38,30 +40,59 @@ $ npm i uglify-js-minify-css-allfiles
|
|
|
38
40
|
|
|
39
41
|
## Usage
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
1. Basic usage (no Babel):
|
|
42
44
|
|
|
43
|
-
```js
|
|
44
|
-
import minifyAll from '
|
|
45
|
+
```js
|
|
46
|
+
import minifyAll from 'uglify-js-minify-css-allfiles';
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* @param {string} [excludeFolder] - The folder to exclude from minification (optional).
|
|
49
|
-
*/
|
|
48
|
+
await minifyAll('./src/', 'node_modules');
|
|
49
|
+
```
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
```
|
|
51
|
+
2. Using Babel with default settings:
|
|
53
52
|
|
|
54
|
-
|
|
53
|
+
```js
|
|
54
|
+
import minifyAll from 'uglify-js-minify-css-allfiles';
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
await minifyAll('./src/', 'node_modules', { useBabel: true });
|
|
57
|
+
```
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
minifyAll('../test/', 'lib');
|
|
59
|
+
3. Using custom Babel presets:
|
|
61
60
|
|
|
62
|
-
|
|
63
|
-
minifyAll
|
|
64
|
-
|
|
61
|
+
```js
|
|
62
|
+
import minifyAll from 'uglify-js-minify-css-allfiles';
|
|
63
|
+
|
|
64
|
+
await minifyAll('./src/', 'node_modules', {
|
|
65
|
+
presets: [
|
|
66
|
+
[
|
|
67
|
+
'@babel/preset-env',
|
|
68
|
+
{
|
|
69
|
+
targets: {
|
|
70
|
+
esmodules: false, // Target ES2015
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
],
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Parameters
|
|
79
|
+
|
|
80
|
+
The `minifyAll` function accepts the following parameters:
|
|
81
|
+
|
|
82
|
+
| Parameter | Type | Default | Description |
|
|
83
|
+
| --------------- | -------------- | ------- | -------------------------------------------------------------------------------------------- |
|
|
84
|
+
| `contentPath` | string | - | The path to the directory containing the files to be minified. This is a required parameter. |
|
|
85
|
+
| `excludeFolder` | string | `''` | The name of a folder to exclude from minification. Leave empty to include all folders. |
|
|
86
|
+
| `babelOptions` | object or null | `null` | An object containing Babel options or a flag to use default Babel settings. |
|
|
87
|
+
|
|
88
|
+
## BabelOptions
|
|
89
|
+
|
|
90
|
+
The `babelOptions` parameter can have the following properties:
|
|
91
|
+
|
|
92
|
+
| Property | Type | Default | Description |
|
|
93
|
+
| ---------- | ------- | ------- | --------------------------------------------------------------------------------------------- |
|
|
94
|
+
| `useBabel` | boolean | `false` | If set to `true`, enables Babel transformation with default presets targeting ES2015. |
|
|
95
|
+
| `presets` | array | - | Custom Babel presets to use for transformation. If provided, overrides the `useBabel` option. |
|
|
65
96
|
|
|
66
97
|
## Changelog
|
|
67
98
|
|
package/demo.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import minifyAll from './dist/module.js';
|
|
2
2
|
|
|
3
|
-
minifyAll('./test/', 'lib', {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
minifyAll('./test/', 'lib', { useBabel: true });
|
|
4
|
+
|
|
5
|
+
// minifyAll('./test/', 'lib', {
|
|
6
|
+
// presets: [
|
|
7
|
+
// [
|
|
8
|
+
// '@babel/preset-env',
|
|
9
|
+
// {
|
|
10
|
+
// targets: {
|
|
11
|
+
// esmodules: false, // Target ES2015
|
|
12
|
+
// },
|
|
13
|
+
// },
|
|
14
|
+
// ],
|
|
15
|
+
// ],
|
|
16
|
+
// });
|
|
15
17
|
// console.log(process.argv.slice(2)[0], process.argv.slice(2)[1]);
|
|
16
18
|
// minifyAll(process.argv.slice(2)[0], process.argv.slice(2)[1]);
|
package/dist/module.js
CHANGED
|
@@ -60,6 +60,33 @@ async function processFile(filePath, logger, babelOptions = null) {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Resolves Babel options based on the provided configuration.
|
|
65
|
+
*
|
|
66
|
+
* @param {Object|null} options - The Babel options object or null.
|
|
67
|
+
* @returns {Object|null} The resolved Babel options or null if no valid options are provided.
|
|
68
|
+
*/
|
|
69
|
+
function resolveBabelOptions(options) {
|
|
70
|
+
if (!options) return null;
|
|
71
|
+
|
|
72
|
+
if (options.useBabel) {
|
|
73
|
+
return {
|
|
74
|
+
presets: [
|
|
75
|
+
[
|
|
76
|
+
'@babel/preset-env',
|
|
77
|
+
{
|
|
78
|
+
targets: {
|
|
79
|
+
esmodules: false, // Target ES2015
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return options.presets ? options : null;
|
|
88
|
+
}
|
|
89
|
+
|
|
63
90
|
/**
|
|
64
91
|
* Minifies all JavaScript and CSS files in the specified directory and its subdirectories.
|
|
65
92
|
*
|
|
@@ -101,10 +128,11 @@ export default async function minifyAll(contentPath, excludeFolder = '', babelOp
|
|
|
101
128
|
await logger.initialize();
|
|
102
129
|
|
|
103
130
|
const rootDir = contentPath || '';
|
|
131
|
+
const finalBabelOptions = resolveBabelOptions(babelOptions);
|
|
104
132
|
|
|
105
133
|
await getAllFiles(rootDir, async (filePath) => {
|
|
106
134
|
if (excludeFolder && filePath.includes(excludeFolder)) return;
|
|
107
|
-
await processFile(filePath, logger,
|
|
135
|
+
await processFile(filePath, logger, finalBabelOptions);
|
|
108
136
|
});
|
|
109
137
|
|
|
110
138
|
await logger.summarize();
|
package/logs/summary.log
CHANGED
|
@@ -94,3 +94,19 @@ Files with errors: 0
|
|
|
94
94
|
Error files:
|
|
95
95
|
|
|
96
96
|
==================================================
|
|
97
|
+
|
|
98
|
+
=============== Processing Summary ===============
|
|
99
|
+
Time: 08/20/2024, 10:34:11
|
|
100
|
+
Total files processed: 0
|
|
101
|
+
Files with errors: 0
|
|
102
|
+
Error files:
|
|
103
|
+
|
|
104
|
+
==================================================
|
|
105
|
+
|
|
106
|
+
=============== Processing Summary ===============
|
|
107
|
+
Time: 08/20/2024, 10:38:29
|
|
108
|
+
Total files processed: 0
|
|
109
|
+
Files with errors: 0
|
|
110
|
+
Error files:
|
|
111
|
+
|
|
112
|
+
==================================================
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uglify-js-minify-css-allfiles",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "you will be able to minify all files as same file names which is js or css",
|
|
5
5
|
"main": "minify.js",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./minify.js"
|
|
9
|
+
},
|
|
7
10
|
"scripts": {
|
|
8
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
12
|
},
|
|
@@ -40,9 +43,7 @@
|
|
|
40
43
|
"dependencies": {
|
|
41
44
|
"clean-css": "^4.2.4",
|
|
42
45
|
"uglify-js": "^3.19.2",
|
|
43
|
-
"uglify-js-es6": "^2.8.9"
|
|
44
|
-
},
|
|
45
|
-
"devDependencies": {
|
|
46
|
+
"uglify-js-es6": "^2.8.9",
|
|
46
47
|
"@babel/core": "^7.25.2",
|
|
47
48
|
"@babel/preset-env": "^7.25.3"
|
|
48
49
|
}
|
package/test/test.css
CHANGED
package/test/test.js
CHANGED
|
@@ -1,26 +1,89 @@
|
|
|
1
|
-
class
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
class ModernBank {
|
|
2
|
+
// Private fields
|
|
3
|
+
#balance = 0;
|
|
4
|
+
#transactionHistory = [];
|
|
5
|
+
|
|
6
|
+
// Public field
|
|
7
|
+
accountType = 'Checking';
|
|
8
|
+
|
|
9
|
+
// Static private field
|
|
10
|
+
static #bankName = 'Modern JS Bank';
|
|
11
|
+
|
|
12
|
+
// Static public field
|
|
13
|
+
static exchangeRate = 1.2;
|
|
14
|
+
|
|
15
|
+
// Static initialization block
|
|
16
|
+
static {
|
|
17
|
+
console.log(`${this.#bankName} is initializing...`);
|
|
8
18
|
}
|
|
9
|
-
|
|
10
|
-
|
|
19
|
+
|
|
20
|
+
constructor(initialBalance) {
|
|
21
|
+
this.#balance = initialBalance;
|
|
22
|
+
this.#addTransaction('Initial deposit', initialBalance);
|
|
11
23
|
}
|
|
12
|
-
|
|
13
|
-
|
|
24
|
+
|
|
25
|
+
// Private method
|
|
26
|
+
#addTransaction(description, amount) {
|
|
27
|
+
this.#transactionHistory.push({ description, amount, date: new Date() });
|
|
14
28
|
}
|
|
15
|
-
|
|
16
|
-
|
|
29
|
+
|
|
30
|
+
// Public method
|
|
31
|
+
deposit(amount) {
|
|
32
|
+
this.#balance += amount;
|
|
33
|
+
this.#addTransaction('Deposit', amount);
|
|
17
34
|
}
|
|
18
|
-
|
|
19
|
-
|
|
35
|
+
|
|
36
|
+
// Public method with optional chaining and nullish coalescing
|
|
37
|
+
withdraw(amount, { fee, description } = {}) {
|
|
38
|
+
const totalAmount = amount + (fee ?? 0);
|
|
39
|
+
if (this.#balance >= totalAmount) {
|
|
40
|
+
this.#balance -= totalAmount;
|
|
41
|
+
this.#addTransaction(description?.trim() || 'Withdrawal', -amount);
|
|
42
|
+
if (fee) this.#addTransaction('Withdrawal fee', -fee);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Getter
|
|
49
|
+
get balance() {
|
|
50
|
+
return this.#balance;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Static method
|
|
54
|
+
static convertCurrency(amount) {
|
|
55
|
+
return amount * this.exchangeRate;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Async method
|
|
59
|
+
async getTransactionHistory() {
|
|
60
|
+
// Simulating an async operation
|
|
61
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
62
|
+
return this.#transactionHistory;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Method using the logical assignment operator
|
|
66
|
+
updateAccountType(newType) {
|
|
67
|
+
this.accountType ||= newType;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// toString method using template literals
|
|
71
|
+
toString() {
|
|
72
|
+
return `ModernBank account (${this.accountType}) - Balance: $${this.#balance}`;
|
|
20
73
|
}
|
|
21
74
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
75
|
+
|
|
76
|
+
// Usage example
|
|
77
|
+
(async () => {
|
|
78
|
+
const account = new ModernBank(1000);
|
|
79
|
+
account.deposit(500);
|
|
80
|
+
account.withdraw(200, { fee: 5, description: 'ATM withdrawal ' });
|
|
81
|
+
account.updateAccountType('Savings');
|
|
82
|
+
|
|
83
|
+
console.log(account.toString());
|
|
84
|
+
console.log(`Balance: $${account.balance}`);
|
|
85
|
+
console.log(`$100 in foreign currency: $${ModernBank.convertCurrency(100)}`);
|
|
86
|
+
|
|
87
|
+
const history = await account.getTransactionHistory();
|
|
88
|
+
console.log('Transaction History:', history);
|
|
89
|
+
})();
|