uglify-js-minify-css-allfiles 2.0.0 → 2.0.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 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
- Import the module in your script:
43
+ 1. Basic usage (no Babel):
42
44
 
43
- ```js
44
- import minifyAll from './dist/module.js';
45
+ ```js
46
+ import minifyAll from 'uglify-js-minify-css-allfiles';
45
47
 
46
- /**
47
- * @param {string} minifyFolder - The folder containing files to minify.
48
- * @param {string} [excludeFolder] - The folder to exclude from minification (optional).
49
- */
48
+ await minifyAll('./src/', 'node_modules');
49
+ ```
50
50
 
51
- minifyAll(minifyFolder, excludeFolder);
52
- ```
51
+ 2. Using Babel with default settings:
53
52
 
54
- Execute script:
53
+ ```js
54
+ import minifyAll from 'uglify-js-minify-css-allfiles';
55
55
 
56
- ```js
57
- import minifyAll from 'uglify-js-minify-css-allfiles';
56
+ await minifyAll('./src/', 'node_modules', { useBabel: true });
57
+ ```
58
58
 
59
- // Example 1: Minify all files in '../test/' except those in 'lib' folder
60
- minifyAll('../test/', 'lib');
59
+ 3. Using custom Babel presets:
61
60
 
62
- // Example 2: Use command line arguments
63
- minifyAll(process.argv[2], process.argv[3]);
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
- presets: [
5
- [
6
- '@babel/preset-env',
7
- {
8
- targets: {
9
- esmodules: false, // Target ES2015
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, babelOptions);
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,6 +1,6 @@
1
1
  {
2
2
  "name": "uglify-js-minify-css-allfiles",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
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",
package/test/test.css CHANGED
@@ -1 +1,8 @@
1
- .dragon{width:30px;height:50px}.dragon a{display:block;margin:30px}
1
+ .dragon {
2
+ width: 30px;
3
+ height: 50px;
4
+ }
5
+ .dragon a {
6
+ display: block;
7
+ margin: 30px;
8
+ }
package/test/test.js CHANGED
@@ -1,26 +1,89 @@
1
- class MyPhone {
2
- inst = '';
3
- #brand;
4
- static phoneType = 'smartphone';
5
- static #counter = 0;
6
- constructor(n) {
7
- (this.#brand = n), MyPhone.#counter++;
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
- makeCall(n) {
10
- this.#brand;
19
+
20
+ constructor(initialBalance) {
21
+ this.#balance = initialBalance;
22
+ this.#addTransaction('Initial deposit', initialBalance);
11
23
  }
12
- static getPhoneCount() {
13
- return MyPhone.#counter;
24
+
25
+ // Private method
26
+ #addTransaction(description, amount) {
27
+ this.#transactionHistory.push({ description, amount, date: new Date() });
14
28
  }
15
- get phoneInfo() {
16
- return this.#brand + ' ' + MyPhone.phoneType;
29
+
30
+ // Public method
31
+ deposit(amount) {
32
+ this.#balance += amount;
33
+ this.#addTransaction('Deposit', amount);
17
34
  }
18
- set updateBrand(n) {
19
- this.#brand = n;
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
- let myPhone = new MyPhone('Samsung');
23
- myPhone.makeCall('123-456-7890'),
24
- myPhone.phoneInfo,
25
- (myPhone.updateBrand = 'Apple'),
26
- MyPhone.getPhoneCount();
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
+ })();