js-comments-eraser 1.0.1 → 1.1.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/index-multi-js-2.js +114 -0
- package/index-multi-js-keep-2.js +63 -0
- package/index-multi-js-keep.js +63 -0
- package/index-multi-js.js +63 -0
- package/{index.js → index-single-js.js} +2 -0
- package/package.json +20 -4
- package/readme.md +10 -4
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const fs = require('fs-extra');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// Function to remove comment lines but keep specific ones
|
|
8
|
+
function removeCommentsFromFile(fileContent) {
|
|
9
|
+
const commentRegex1 = /(http:\/\/)/gm;
|
|
10
|
+
const commentRegex2 = /(https:\/\/)/gm;
|
|
11
|
+
const step1 = fileContent.replace(commentRegex1, 'http:--').replace(commentRegex2, 'https:--');
|
|
12
|
+
|
|
13
|
+
// "KEEP" ve "gm;" etiketlerini koruyan düzenli ifade
|
|
14
|
+
const commentRegex = /\/\/(?!KEEP\b|gm;).*?$|\/\*(?!.*KEEP\b|gm;)[\s\S]*?\*\//gm;
|
|
15
|
+
const step2 = step1.replace(commentRegex, '');
|
|
16
|
+
|
|
17
|
+
const commentRegex1n = /(http:--)/gm;
|
|
18
|
+
const commentRegex2n = /(https:--)/gm;
|
|
19
|
+
const step3 = step2.replace(commentRegex1n, 'http://').replace(commentRegex2n, 'https://');
|
|
20
|
+
|
|
21
|
+
const falseIfBlockRegex = /if\s*\(\s*false\s*\)\s*\{[\s\S]*?\}/gm;
|
|
22
|
+
const step4 = step3.replace(falseIfBlockRegex, '');
|
|
23
|
+
|
|
24
|
+
return step4;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Recursive function to process files in a directory
|
|
28
|
+
function processDirectory(sourceDir, targetDir) {
|
|
29
|
+
// const sourceDir = args[0];
|
|
30
|
+
// const targetDir = args[1];
|
|
31
|
+
|
|
32
|
+
// const HEDEFMEVCUT = fs.existsSync(args[1])
|
|
33
|
+
const HEDEFMEVCUT = fs.existsSync(targetDir)
|
|
34
|
+
|
|
35
|
+
// console.log(`Kaynak directory: ${sourceDir}`,`Hedef directory: ${targetDir}`);
|
|
36
|
+
|
|
37
|
+
// && path.resolve(sourceDir) === path.resolve(targetDir)
|
|
38
|
+
if (!HEDEFMEVCUT) {
|
|
39
|
+
// console.warn(`Skipping processing of target directory to avoid infinite loop: ${targetDir}`);
|
|
40
|
+
// return;
|
|
41
|
+
|
|
42
|
+
// , { recursive: false }
|
|
43
|
+
fs.mkdirSync(targetDir); // Create target directory if not exists
|
|
44
|
+
console.log(`Target directory: ${targetDir}`, "CREATED");
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const items = fs.readdirSync(sourceDir, { withFileTypes: true });
|
|
49
|
+
for (const item of items) {
|
|
50
|
+
const sourcePath = path.join(sourceDir, item.name);
|
|
51
|
+
const targetPath = path.join(targetDir, item.name);
|
|
52
|
+
|
|
53
|
+
if (item.isDirectory()) {
|
|
54
|
+
processDirectory(sourcePath, targetPath);
|
|
55
|
+
} else if (item.isFile() && path.extname(item.name) === '.js') {
|
|
56
|
+
|
|
57
|
+
const fileContent = fs.readFileSync(sourcePath, 'utf8');
|
|
58
|
+
const cleanedContent = removeCommentsFromFile(fileContent);
|
|
59
|
+
|
|
60
|
+
if (targetPath && cleanedContent)
|
|
61
|
+
try {
|
|
62
|
+
fs.writeFileSync(targetPath, cleanedContent, 'utf8');
|
|
63
|
+
// console.log({ targetPath })
|
|
64
|
+
} catch (_writeFileSyncERROR) {
|
|
65
|
+
console.log({ _writeFileSyncERROR })
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
console.log({ targetPath, cleanedContent });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// console.log(sourceDir, "\t\t\t->", targetPath);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Get command line arguments
|
|
77
|
+
const args = process.argv.slice(2);
|
|
78
|
+
|
|
79
|
+
// if (args.length !== 2) {
|
|
80
|
+
// console.error('Usage: node js-comments-eraser <sourceDir> <targetDir>');
|
|
81
|
+
// process.exit(1);
|
|
82
|
+
// }
|
|
83
|
+
if (args.length !== 1) {
|
|
84
|
+
console.error('Usage: node your-js-comments-eraser <sourceDir>');
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const sourceDir = args[0];
|
|
89
|
+
// const targetDir = args[1];
|
|
90
|
+
const targetDir = "clean_dist";
|
|
91
|
+
|
|
92
|
+
console.log("Start processing")
|
|
93
|
+
processDirectory(sourceDir, targetDir);
|
|
94
|
+
console.log(`All .js files from ${sourceDir} have been processed and saved to ${sourceDir}/${targetDir}.`);
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
const tasinacakKlasor = path.join(__dirname, targetDir); // Taşınacak klasör
|
|
100
|
+
const hedefKonum = path.join(__dirname, sourceDir); // Hedef konum
|
|
101
|
+
|
|
102
|
+
// console.log(tasinacakKlasor)
|
|
103
|
+
// console.log(hedefKonum)
|
|
104
|
+
|
|
105
|
+
setTimeout(() => {
|
|
106
|
+
fs.move(tasinacakKlasor, hedefKonum, { overwrite: true })
|
|
107
|
+
.then(() => {
|
|
108
|
+
console.log('Successfully moved.');
|
|
109
|
+
})
|
|
110
|
+
.catch(err => {
|
|
111
|
+
console.error('Some things went wrong:', err);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
}, 1000);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// https://chatgpt.com/share/67758592-d174-8011-be5b-642a87e71019
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
// Function to remove comment lines but keep specific ones
|
|
6
|
+
function removeCommentsFromFile(fileContent) {
|
|
7
|
+
const commentRegex1 = /(http:\/\/)/gm;
|
|
8
|
+
const commentRegex2 = /(https:\/\/)/gm;
|
|
9
|
+
const step1 = fileContent.replace(commentRegex1, 'http:--').replace(commentRegex2, 'https:--');
|
|
10
|
+
|
|
11
|
+
// "KEEP" ve "gm;" etiketlerini koruyan düzenli ifade
|
|
12
|
+
const commentRegex = /\/\/(?!KEEP\b|gm;).*?$|\/\*(?!.*KEEP\b|gm;)[\s\S]*?\*\//gm;
|
|
13
|
+
const step2 = step1.replace(commentRegex, '');
|
|
14
|
+
|
|
15
|
+
const commentRegex1n = /(http:--)/gm;
|
|
16
|
+
const commentRegex2n = /(https:--)/gm;
|
|
17
|
+
const step3 = step2.replace(commentRegex1n, 'http://').replace(commentRegex2n, 'https://');
|
|
18
|
+
|
|
19
|
+
const falseIfBlockRegex = /if\s*\(\s*false\s*\)\s*\{[\s\S]*?\}/gm;
|
|
20
|
+
const step4 = step3.replace(falseIfBlockRegex, '');
|
|
21
|
+
|
|
22
|
+
return step4;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Recursive function to process files in a directory
|
|
26
|
+
function processDirectory(sourceDir, targetDir) {
|
|
27
|
+
if (fs.existsSync(targetDir) && path.resolve(sourceDir) === path.resolve(targetDir)) {
|
|
28
|
+
console.warn(`Skipping processing of target directory to avoid infinite loop: ${targetDir}`);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fs.mkdirSync(targetDir, { recursive: true }); // Create target directory if not exists
|
|
33
|
+
|
|
34
|
+
const items = fs.readdirSync(sourceDir, { withFileTypes: true });
|
|
35
|
+
for (const item of items) {
|
|
36
|
+
const sourcePath = path.join(sourceDir, item.name);
|
|
37
|
+
const targetPath = path.join(targetDir, item.name);
|
|
38
|
+
|
|
39
|
+
if (item.isDirectory()) {
|
|
40
|
+
processDirectory(sourcePath, targetPath); // Recurse into subdirectory
|
|
41
|
+
} else if (item.isFile() && path.extname(item.name) === '.js') {
|
|
42
|
+
const fileContent = fs.readFileSync(sourcePath, 'utf8');
|
|
43
|
+
const cleanedContent = removeCommentsFromFile(fileContent);
|
|
44
|
+
fs.writeFileSync(targetPath, cleanedContent, 'utf8');
|
|
45
|
+
console.log(`Processed: ${sourcePath} -> ${targetPath}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Get command line arguments
|
|
51
|
+
const args = process.argv.slice(2);
|
|
52
|
+
|
|
53
|
+
if (args.length !== 2) {
|
|
54
|
+
console.error('Usage: node js-comments-eraser <sourceDir> <targetDir>');
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const sourceDir = args[0];
|
|
59
|
+
const targetDir = args[1];
|
|
60
|
+
|
|
61
|
+
// Start processing
|
|
62
|
+
processDirectory(sourceDir, targetDir);
|
|
63
|
+
console.log(`All .js files from ${sourceDir} have been processed and saved to ${targetDir}.`);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// https://chatgpt.com/share/67758592-d174-8011-be5b-642a87e71019
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
// Function to remove comment lines but keep specific ones
|
|
6
|
+
function removeCommentsFromFile(fileContent) {
|
|
7
|
+
const commentRegex1 = /(http:\/\/)/gm;
|
|
8
|
+
const commentRegex2 = /(https:\/\/)/gm;
|
|
9
|
+
const step1 = fileContent.replace(commentRegex1, 'http:--').replace(commentRegex2, 'https:--');
|
|
10
|
+
|
|
11
|
+
// Yalnızca "KEEP" etiketi olmayan yorumları kaldır
|
|
12
|
+
const commentRegex = /\/\/(?!KEEP\b).*?$|\/\*(?!.*KEEP\b)[\s\S]*?\*\//gm;
|
|
13
|
+
const step2 = step1.replace(commentRegex, '');
|
|
14
|
+
|
|
15
|
+
const commentRegex1n = /(http:--)/gm;
|
|
16
|
+
const commentRegex2n = /(https:--)/gm;
|
|
17
|
+
const step3 = step2.replace(commentRegex1n, 'http://').replace(commentRegex2n, 'https://');
|
|
18
|
+
|
|
19
|
+
const falseIfBlockRegex = /if\s*\(\s*false\s*\)\s*\{[\s\S]*?\}/gm;
|
|
20
|
+
const step4 = step3.replace(falseIfBlockRegex, '');
|
|
21
|
+
|
|
22
|
+
return step4;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Recursive function to process files in a directory
|
|
26
|
+
function processDirectory(sourceDir, targetDir) {
|
|
27
|
+
if (fs.existsSync(targetDir) && path.resolve(sourceDir) === path.resolve(targetDir)) {
|
|
28
|
+
console.warn(`Skipping processing of target directory to avoid infinite loop: ${targetDir}`);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fs.mkdirSync(targetDir, { recursive: true }); // Create target directory if not exists
|
|
33
|
+
|
|
34
|
+
const items = fs.readdirSync(sourceDir, { withFileTypes: true });
|
|
35
|
+
for (const item of items) {
|
|
36
|
+
const sourcePath = path.join(sourceDir, item.name);
|
|
37
|
+
const targetPath = path.join(targetDir, item.name);
|
|
38
|
+
|
|
39
|
+
if (item.isDirectory()) {
|
|
40
|
+
processDirectory(sourcePath, targetPath); // Recurse into subdirectory
|
|
41
|
+
} else if (item.isFile() && path.extname(item.name) === '.js') {
|
|
42
|
+
const fileContent = fs.readFileSync(sourcePath, 'utf8');
|
|
43
|
+
const cleanedContent = removeCommentsFromFile(fileContent);
|
|
44
|
+
fs.writeFileSync(targetPath, cleanedContent, 'utf8');
|
|
45
|
+
console.log(`Processed: ${sourcePath} -> ${targetPath}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Get command line arguments
|
|
51
|
+
const args = process.argv.slice(2);
|
|
52
|
+
|
|
53
|
+
if (args.length !== 2) {
|
|
54
|
+
console.error('Usage: node js-comments-eraser <sourceDir> <targetDir>');
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const sourceDir = args[0];
|
|
59
|
+
const targetDir = args[1];
|
|
60
|
+
|
|
61
|
+
// Start processing
|
|
62
|
+
processDirectory(sourceDir, targetDir);
|
|
63
|
+
console.log(`All .js files from ${sourceDir} have been processed and saved to ${targetDir}.`);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// KEEP: # 1.0.2
|
|
2
|
+
// https://chatgpt.com/share/67758592-d174-8011-be5b-642a87e71019
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
// Function to remove comment lines
|
|
7
|
+
function removeCommentsFromFile(fileContent) {
|
|
8
|
+
const commentRegex1 = /(http:\/\/)/gm;
|
|
9
|
+
const commentRegex2 = /(https:\/\/)/gm;
|
|
10
|
+
const step1 = fileContent.replace(commentRegex1, 'http:--').replace(commentRegex2, 'https:--');
|
|
11
|
+
|
|
12
|
+
const commentRegex = /\/\/(?!gm;).*?$|\/\*[\s\S]*?\*\//gm;
|
|
13
|
+
const step2 = step1.replace(commentRegex, '');
|
|
14
|
+
|
|
15
|
+
const commentRegex1n = /(http:--)/gm;
|
|
16
|
+
const commentRegex2n = /(https:--)/gm;
|
|
17
|
+
const step3 = step2.replace(commentRegex1n, 'http://').replace(commentRegex2n, 'https://');
|
|
18
|
+
|
|
19
|
+
const falseIfBlockRegex = /if\s*\(\s*false\s*\)\s*\{[\s\S]*?\}/gm;
|
|
20
|
+
const step4 = step3.replace(falseIfBlockRegex, '');
|
|
21
|
+
|
|
22
|
+
return step4;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Recursive function to process files in a directory
|
|
26
|
+
function processDirectory(sourceDir, targetDir) {
|
|
27
|
+
if (fs.existsSync(targetDir) && path.resolve(sourceDir) === path.resolve(targetDir)) {
|
|
28
|
+
console.warn(`Skipping processing of target directory to avoid infinite loop: ${targetDir}`);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fs.mkdirSync(targetDir, { recursive: true }); // Create target directory if not exists
|
|
33
|
+
|
|
34
|
+
const items = fs.readdirSync(sourceDir, { withFileTypes: true });
|
|
35
|
+
for (const item of items) {
|
|
36
|
+
const sourcePath = path.join(sourceDir, item.name);
|
|
37
|
+
const targetPath = path.join(targetDir, item.name);
|
|
38
|
+
|
|
39
|
+
if (item.isDirectory()) {
|
|
40
|
+
processDirectory(sourcePath, targetPath); // Recurse into subdirectory
|
|
41
|
+
} else if (item.isFile() && path.extname(item.name) === '.js') {
|
|
42
|
+
const fileContent = fs.readFileSync(sourcePath, 'utf8');
|
|
43
|
+
const cleanedContent = removeCommentsFromFile(fileContent);
|
|
44
|
+
fs.writeFileSync(targetPath, cleanedContent, 'utf8');
|
|
45
|
+
console.log(`Processed: ${sourcePath} -> ${targetPath}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Get command line arguments
|
|
51
|
+
const args = process.argv.slice(2);
|
|
52
|
+
|
|
53
|
+
if (args.length !== 2) {
|
|
54
|
+
console.error('Usage: node js-comments-eraser <sourceDir> <targetDir>');
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const sourceDir = args[0];
|
|
59
|
+
const targetDir = args[1];
|
|
60
|
+
|
|
61
|
+
// Start processing
|
|
62
|
+
processDirectory(sourceDir, targetDir);
|
|
63
|
+
console.log(`All .js files from ${sourceDir} have been processed and saved to ${targetDir}.`);
|
package/package.json
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-comments-eraser",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"main": "index.js",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"main": "index-multi-js-2.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
7
|
},
|
|
8
|
-
"keywords": [
|
|
8
|
+
"keywords": [
|
|
9
|
+
"node",
|
|
10
|
+
"js",
|
|
11
|
+
"javascript",
|
|
12
|
+
"delete",
|
|
13
|
+
"scrape",
|
|
14
|
+
"comment",
|
|
15
|
+
"remove",
|
|
16
|
+
"eraser",
|
|
17
|
+
"server",
|
|
18
|
+
"client",
|
|
19
|
+
"cleaner",
|
|
20
|
+
"comments"
|
|
21
|
+
],
|
|
9
22
|
"author": "aydincandan@gmail.com",
|
|
10
23
|
"license": "ISC",
|
|
11
|
-
"description": "clears comments
|
|
24
|
+
"description": "It simply clears comments in all javascript files within a folder(in all sub folders[recursively]).",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"fs-extra": "^11.2.0"
|
|
27
|
+
}
|
|
12
28
|
}
|
package/readme.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
|
|
2
|
+
# DONT USE 1.1.0 version Some things went wrong
|
|
3
|
+
|
|
1
4
|
## Türkçe
|
|
2
5
|
|
|
3
6
|
Projenize dahil etmek için aşağıdaki gibi yapın.
|
|
@@ -10,13 +13,14 @@ Komut satırından kullanabilmek için **yorumyok.js** gibi bir dosya açın ve
|
|
|
10
13
|
|
|
11
14
|
|
|
12
15
|
```
|
|
13
|
-
return
|
|
16
|
+
return require('js-comments-eraser')
|
|
14
17
|
```
|
|
15
18
|
|
|
16
19
|
Daha sonra aşağıdaki gibi komut satırından kullanın.
|
|
17
20
|
|
|
18
21
|
```
|
|
19
|
-
$ node yorumyok yorumlu.js yorumsuz.js
|
|
22
|
+
$ node yorumyok yorumlu.js yorumsuz.js # 1.0.1
|
|
23
|
+
$ node yorumyok <kaynakDir> # 1.1.0
|
|
20
24
|
```
|
|
21
25
|
|
|
22
26
|
[js-comments-eraser](https://github.com/aydincandan/js-comments-eraser/pulls) için önerileriniz dikkate alınacaktır.
|
|
@@ -34,13 +38,15 @@ $ npm i js-comments-eraser
|
|
|
34
38
|
To use it from the command line, open a file like **nocomments.js** and paste the following into it.
|
|
35
39
|
|
|
36
40
|
```
|
|
37
|
-
return
|
|
41
|
+
return require('js-comments-eraser')
|
|
38
42
|
```
|
|
39
43
|
|
|
40
44
|
Then use it from the command line as follows.
|
|
41
45
|
|
|
42
46
|
```
|
|
43
|
-
$ node nocomments withcomments.js withoutcomments.js
|
|
47
|
+
$ node nocomments withcomments.js withoutcomments.js # 1.0.1
|
|
48
|
+
$ node nocomments <sourceDir> # 1.1.0
|
|
49
|
+
|
|
44
50
|
```
|
|
45
51
|
|
|
46
52
|
Your suggestions for [js-comments-eraser](https://github.com/aydincandan/js-comments-eraser/pulls) will be taken into consideration.
|