js-comments-eraser 1.1.6 → 1.1.9
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/{index-multi.js → index-multi-move.js} +5 -5
- package/index-multi-rename.js +134 -0
- package/package.json +4 -3
- package/readme.md +2 -2
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
// https://chatgpt.com/share/67758592-d174-8011-be5b-642a87e71019
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
const path = require('path');
|
|
6
|
-
|
|
7
5
|
// const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
8
7
|
const fs = require('fs-extra');
|
|
9
8
|
|
|
10
9
|
|
|
@@ -27,8 +26,9 @@ function removeCommentsFromFile(fileContent) {
|
|
|
27
26
|
.replace(/(http:--)/gm, 'http://')
|
|
28
27
|
.replace(/(https:--)/gm, 'https://');
|
|
29
28
|
|
|
30
|
-
const falseIfBlockRegex = /if\s*\(\s*false\s*\)\s*\{[\s\S]*?\}/gm;
|
|
31
|
-
const step4 = step3
|
|
29
|
+
// const falseIfBlockRegex = /if\s*\(\s*false\s*\)\s*\{[\s\S]*?\}/gm;
|
|
30
|
+
const step4 = step3
|
|
31
|
+
// .replace(falseIfBlockRegex, '');
|
|
32
32
|
|
|
33
33
|
return step4;
|
|
34
34
|
}
|
|
@@ -51,7 +51,7 @@ function processDirectory(sourceDir, targetDir) {
|
|
|
51
51
|
|
|
52
52
|
if (item.isDirectory() && (item.name !== 'node_modules' && item.name !== 'clean_dist')) {
|
|
53
53
|
processDirectory(sourcePath, targetPath);
|
|
54
|
-
} else if (item.isFile() && path.extname(item.name) === '.js') {
|
|
54
|
+
} else if (item.isFile() && path.extname(item.name) === '.js' || path.extname(item.name) === '.mjs') {
|
|
55
55
|
|
|
56
56
|
const fileContent = fs.readFileSync(sourcePath, 'utf8');
|
|
57
57
|
const cleanedContent = removeCommentsFromFile(fileContent);
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
//KEEP: # 1.1.8
|
|
2
|
+
// https://chatgpt.com/share/67758592-d174-8011-be5b-642a87e71019
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
// https://chatgpt.com/share/677aae47-081c-8011-93cb-333cda2cfe22
|
|
9
|
+
function move(src, dest) {
|
|
10
|
+
const srcPath = path.resolve(src);
|
|
11
|
+
const destPath = path.resolve(dest);
|
|
12
|
+
fs.renameSync(srcPath, destPath);
|
|
13
|
+
}
|
|
14
|
+
//move('source.txt', 'destination.txt');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
// Function to remove comment lines but keep specific ones
|
|
19
|
+
function removeCommentsFromFile(fileContent) {
|
|
20
|
+
//KEEP REF: https://chatgpt.com/share/67758592-d174-8011-be5b-642a87e71019
|
|
21
|
+
const step1 = fileContent
|
|
22
|
+
.replace(/(http:\/\/)/gm, 'http:--')
|
|
23
|
+
.replace(/(https:\/\/)/gm, 'https:--'); // ilk yapılan tüm http(s) leri -- ile koruma altına alıyoruz? Nedenki sebebi?
|
|
24
|
+
|
|
25
|
+
// "KEEP" ve "gm;" etiketlerini koruyan düzenli ifade buda olması lazım //g;
|
|
26
|
+
const commentRegex = /\/\/(?!KEEP\b|gm;).*?$|\/\*(?!.*KEEP\b|gm;)[\s\S]*?\*\//gm;
|
|
27
|
+
// //g; da eklendi aşağıda.
|
|
28
|
+
const commentRegex2 = /\/\/(?!KEEP\b|gm;|g;).*?$|\/\*(?!.*KEEP\b|gm;|g;)[\s\S]*?\*\//gm;
|
|
29
|
+
|
|
30
|
+
const step2 = step1
|
|
31
|
+
.replace(commentRegex2, ''); // ikinci yapılan tüm yorum satırları siliniyor iken "KEEP" ve "gm;" ve "g;" etiketleri de korunuyor.
|
|
32
|
+
|
|
33
|
+
const step3 = step2
|
|
34
|
+
.replace(/(http:--)/gm, 'http://')
|
|
35
|
+
.replace(/(https:--)/gm, 'https://');
|
|
36
|
+
|
|
37
|
+
// const falseIfBlockRegex = /if\s*\(\s*false\s*\)\s*\{[\s\S]*?\}/gm;
|
|
38
|
+
const step4 = step3
|
|
39
|
+
// .replace(falseIfBlockRegex, '');
|
|
40
|
+
|
|
41
|
+
return step4;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Recursive function to process files in a directory
|
|
45
|
+
function processDirectory(sourceDir, targetDir) {
|
|
46
|
+
|
|
47
|
+
const HEDEFMEVCUT = fs.existsSync(targetDir)
|
|
48
|
+
|
|
49
|
+
if (!HEDEFMEVCUT) {
|
|
50
|
+
fs.mkdirSync(targetDir); // Create target directory if not exists
|
|
51
|
+
// console.log(`Target directory: ${targetDir}`, "CREATED");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const items = fs.readdirSync(sourceDir, { withFileTypes: true });
|
|
55
|
+
for (const item of items) {
|
|
56
|
+
const sourcePath = path.join(sourceDir, item.name);
|
|
57
|
+
const targetPath = path.join(targetDir, item.name);
|
|
58
|
+
// console.log("TEST(1)",{ sourcePath, targetPath }, {itemisdir:item.isDirectory(),itname:item.name})
|
|
59
|
+
|
|
60
|
+
if (item.isDirectory() && (item.name !== 'node_modules' && item.name !== 'clean_dist')) {
|
|
61
|
+
processDirectory(sourcePath, targetPath);
|
|
62
|
+
} else if (item.isFile() && path.extname(item.name) === '.js' || path.extname(item.name) === '.mjs') {
|
|
63
|
+
|
|
64
|
+
const fileContent = fs.readFileSync(sourcePath, 'utf8');
|
|
65
|
+
const cleanedContent = removeCommentsFromFile(fileContent);
|
|
66
|
+
|
|
67
|
+
if (targetPath && cleanedContent)
|
|
68
|
+
try {
|
|
69
|
+
fs.writeFileSync(targetPath, cleanedContent, 'utf8');
|
|
70
|
+
// console.log({ targetPath })
|
|
71
|
+
} catch (_writeFileSyncERROR) {
|
|
72
|
+
console.log({ _writeFileSyncERROR })
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
console.log({ targetPath, cleanedContent });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// console.log(sourceDir, "\t\t\t->", targetPath);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// console.log("Bitti", { sourceDir, targetDir })
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Get command line arguments
|
|
85
|
+
const args = process.argv.slice(2);
|
|
86
|
+
|
|
87
|
+
// console.log({ args });
|
|
88
|
+
|
|
89
|
+
// if (args.length !== 2) {
|
|
90
|
+
// console.error('Usage: node [your-js-comments-eraser] <sourceDir> <targetDir>');
|
|
91
|
+
// process.exit(1);
|
|
92
|
+
// }
|
|
93
|
+
if (args.length !== 1) {
|
|
94
|
+
console.error('Usage: node [your-js-comments-eraser] <sourceDir>');
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let sourceDir = args[0]; // basit ifade
|
|
99
|
+
let targetDir = "clean_dist"; // basit ifade
|
|
100
|
+
|
|
101
|
+
console.log()
|
|
102
|
+
console.log("***********************")
|
|
103
|
+
// console.log("Start processing", { sourceDir })
|
|
104
|
+
processDirectory(sourceDir, targetDir);
|
|
105
|
+
console.log(`The comment lines of all javascript files in the "${sourceDir}" folder were deleted and copied to the "${targetDir}" folder created in the same folder.`);
|
|
106
|
+
console.log("***********************")
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
const exportet = (user__dirname) => {
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
if (true) {
|
|
113
|
+
|
|
114
|
+
sourceDir = path.join(user__dirname, targetDir)//** gerçek/tam ifade */
|
|
115
|
+
targetDir = path.join(user__dirname, args[0])//** gerçek/tam ifade */
|
|
116
|
+
|
|
117
|
+
// console.log({ sourceDir, targetDir, user__dirname });
|
|
118
|
+
|
|
119
|
+
const finalDestination = path.join(targetDir, path.basename(sourceDir));
|
|
120
|
+
// console.log("input params", { sourceDir, targetDir })
|
|
121
|
+
// console.log("move params2", { sourceDir, finalDestination })
|
|
122
|
+
|
|
123
|
+
setTimeout(() => {
|
|
124
|
+
|
|
125
|
+
move(sourceDir, finalDestination)
|
|
126
|
+
|
|
127
|
+
}, 1);
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
module.exports.dirname = exportet
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-comments-eraser",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"main": "index-multi.js",
|
|
3
|
+
"version": "1.1.9",
|
|
4
|
+
"main": "index-multi-rename.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
7
|
},
|
|
@@ -32,5 +32,6 @@
|
|
|
32
32
|
"description": "It simply clears comments in all javascript files within a folder(in all sub folders[recursively]).",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"fs-extra": "^11.2.0"
|
|
35
|
-
}
|
|
35
|
+
},
|
|
36
|
+
"last_commit": "index-multi-move yerine index-multi-rename kullanilacak."
|
|
36
37
|
}
|
package/readme.md
CHANGED
|
@@ -11,7 +11,7 @@ Komut satırından kullanabilmek için **yorumyok.js** gibi bir dosya açın ve
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
```
|
|
14
|
-
|
|
14
|
+
require('js-comments-eraser').dirname(__dirname)
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
Daha sonra aşağıdaki gibi komut satırından kullanın.
|
|
@@ -37,7 +37,7 @@ $ npm i js-comments-eraser
|
|
|
37
37
|
To use it from the command line, open a file like **nocomments.js** and paste the following into it.
|
|
38
38
|
|
|
39
39
|
```
|
|
40
|
-
|
|
40
|
+
require('js-comments-eraser').dirname(__dirname)
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
Then use it from the command line as follows.
|