js-comments-eraser 1.1.3 → 1.1.4
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.
|
@@ -8,17 +8,19 @@ const fs = require('fs-extra');
|
|
|
8
8
|
|
|
9
9
|
// Function to remove comment lines but keep specific ones
|
|
10
10
|
function removeCommentsFromFile(fileContent) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const step1 = fileContent
|
|
12
|
+
.replace(/(http:\/\/)/gm, 'http:--')
|
|
13
|
+
.replace(/(https:\/\/)/gm, 'https:--'); // ilk yapılan tüm http(s) leri -- ile koruma altına alıyoruz? Nedenki sebebi?
|
|
14
14
|
|
|
15
|
-
// "KEEP" ve "gm;" etiketlerini koruyan düzenli ifade
|
|
15
|
+
// "KEEP" ve "gm;" etiketlerini koruyan düzenli ifade buda olması lazım //g;
|
|
16
16
|
const commentRegex = /\/\/(?!KEEP\b|gm;).*?$|\/\*(?!.*KEEP\b|gm;)[\s\S]*?\*\//gm;
|
|
17
|
-
const step2 = step1.replace(commentRegex, '');
|
|
18
17
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const step2 = step1
|
|
19
|
+
.replace(/\/\/(?!KEEP\b|gm;).*?$|\/\*(?!.*KEEP\b|gm;)[\s\S]*?\*\//gm, ''); // ikinci yapılan tüm yorum satırları siliniyor iken "KEEP" ve "gm;" etiketleri de korunuyor.
|
|
20
|
+
|
|
21
|
+
const step3 = step2
|
|
22
|
+
.replace(/(http:--)/gm, 'http://')
|
|
23
|
+
.replace(/(https:--)/gm, 'https://');
|
|
22
24
|
|
|
23
25
|
const falseIfBlockRegex = /if\s*\(\s*false\s*\)\s*\{[\s\S]*?\}/gm;
|
|
24
26
|
const step4 = step3.replace(falseIfBlockRegex, '');
|
|
@@ -40,9 +42,9 @@ function processDirectory(sourceDir, targetDir) {
|
|
|
40
42
|
for (const item of items) {
|
|
41
43
|
const sourcePath = path.join(sourceDir, item.name);
|
|
42
44
|
const targetPath = path.join(targetDir, item.name);
|
|
43
|
-
// console.log({ sourcePath, targetPath })
|
|
45
|
+
// console.log("TEST(1)",{ sourcePath, targetPath }, {itemisdir:item.isDirectory(),itname:item.name})
|
|
44
46
|
|
|
45
|
-
if (item.isDirectory()) {
|
|
47
|
+
if (item.isDirectory() && (item.name !== 'node_modules' && item.name !== 'clean_dist')) {
|
|
46
48
|
processDirectory(sourcePath, targetPath);
|
|
47
49
|
} else if (item.isFile() && path.extname(item.name) === '.js') {
|
|
48
50
|
|
package/package.json
CHANGED
package/index-multi-js-keep-2.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
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}.`);
|
package/index-multi-js-keep.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
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}.`);
|
package/index-multi-js.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
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}.`);
|
|
File without changes
|