js-comments-eraser 1.1.2 → 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.
package/index-multi.js ADDED
@@ -0,0 +1,127 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+
5
+ // const fs = require('fs');
6
+ const fs = require('fs-extra');
7
+
8
+
9
+ // Function to remove comment lines but keep specific ones
10
+ function removeCommentsFromFile(fileContent) {
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
+
15
+ // "KEEP" ve "gm;" etiketlerini koruyan düzenli ifade buda olması lazım //g;
16
+ const commentRegex = /\/\/(?!KEEP\b|gm;).*?$|\/\*(?!.*KEEP\b|gm;)[\s\S]*?\*\//gm;
17
+
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://');
24
+
25
+ const falseIfBlockRegex = /if\s*\(\s*false\s*\)\s*\{[\s\S]*?\}/gm;
26
+ const step4 = step3.replace(falseIfBlockRegex, '');
27
+
28
+ return step4;
29
+ }
30
+
31
+ // Recursive function to process files in a directory
32
+ function processDirectory(sourceDir, targetDir) {
33
+
34
+ const HEDEFMEVCUT = fs.existsSync(targetDir)
35
+
36
+ if (!HEDEFMEVCUT) {
37
+ fs.mkdirSync(targetDir); // Create target directory if not exists
38
+ // console.log(`Target directory: ${targetDir}`, "CREATED");
39
+ }
40
+
41
+ const items = fs.readdirSync(sourceDir, { withFileTypes: true });
42
+ for (const item of items) {
43
+ const sourcePath = path.join(sourceDir, item.name);
44
+ const targetPath = path.join(targetDir, item.name);
45
+ // console.log("TEST(1)",{ sourcePath, targetPath }, {itemisdir:item.isDirectory(),itname:item.name})
46
+
47
+ if (item.isDirectory() && (item.name !== 'node_modules' && item.name !== 'clean_dist')) {
48
+ processDirectory(sourcePath, targetPath);
49
+ } else if (item.isFile() && path.extname(item.name) === '.js') {
50
+
51
+ const fileContent = fs.readFileSync(sourcePath, 'utf8');
52
+ const cleanedContent = removeCommentsFromFile(fileContent);
53
+
54
+ if (targetPath && cleanedContent)
55
+ try {
56
+ fs.writeFileSync(targetPath, cleanedContent, 'utf8');
57
+ // console.log({ targetPath })
58
+ } catch (_writeFileSyncERROR) {
59
+ console.log({ _writeFileSyncERROR })
60
+ }
61
+ else {
62
+ console.log({ targetPath, cleanedContent });
63
+ }
64
+
65
+ // console.log(sourceDir, "\t\t\t->", targetPath);
66
+ }
67
+ }
68
+ // console.log("Bitti", { sourceDir, targetDir })
69
+ }
70
+
71
+ // Get command line arguments
72
+ const args = process.argv.slice(2);
73
+
74
+ // console.log({ args });
75
+
76
+ // if (args.length !== 2) {
77
+ // console.error('Usage: node [your-js-comments-eraser] <sourceDir> <targetDir>');
78
+ // process.exit(1);
79
+ // }
80
+ if (args.length !== 1) {
81
+ console.error('Usage: node [your-js-comments-eraser] <sourceDir>');
82
+ process.exit(1);
83
+ }
84
+
85
+ let sourceDir = args[0]; // basit ifade
86
+ let targetDir = "clean_dist"; // basit ifade
87
+
88
+ console.log()
89
+ console.log("***********************")
90
+ // console.log("Start processing", { sourceDir })
91
+ processDirectory(sourceDir, targetDir);
92
+ 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.`);
93
+ console.log("***********************")
94
+
95
+
96
+ const exportet = (user__dirname) => {
97
+
98
+
99
+ if (true) {
100
+
101
+ sourceDir = path.join(user__dirname, targetDir)//** gerçek/tam ifade */
102
+ targetDir = path.join(user__dirname, args[0])//** gerçek/tam ifade */
103
+
104
+ // console.log({ sourceDir, targetDir, user__dirname });
105
+
106
+ const finalDestination = path.join(targetDir, path.basename(sourceDir));
107
+ // console.log("input params", { sourceDir, targetDir })
108
+ // console.log("move params2", { sourceDir, finalDestination })
109
+
110
+ setTimeout(() => {
111
+
112
+ fs.move(sourceDir, finalDestination, { overwrite: true })
113
+ .then(() => {
114
+ console.log('Successfully moved.');
115
+ })
116
+ .catch(err => {
117
+ console.error('Some things went wrong:', err);
118
+ });
119
+
120
+ }, 1);
121
+
122
+
123
+ }
124
+
125
+ }
126
+
127
+ module.exports.dirname = exportet
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "js-comments-eraser",
3
- "version": "1.1.2",
4
- "main": "index-multi-js-2.js",
3
+ "version": "1.1.4",
4
+ "main": "index-multi.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
7
7
  },
package/readme.md CHANGED
@@ -11,14 +11,14 @@ Komut satırından kullanabilmek için **yorumyok.js** gibi bir dosya açın ve
11
11
 
12
12
 
13
13
  ```
14
- return require('js-comments-eraser')
14
+ return require('js-comments-eraser').dirname(__dirname)
15
15
  ```
16
16
 
17
17
  Daha sonra aşağıdaki gibi komut satırından kullanın.
18
18
 
19
19
  ```
20
20
  $ node yorumyok yorumlu.js yorumsuz.js # 1.0.1
21
- $ node yorumyok <kaynakDir> # 1.1.0
21
+ $ node yorumyok <kaynakDir> # 1.1.3
22
22
  ```
23
23
 
24
24
  [js-comments-eraser](https://github.com/aydincandan/js-comments-eraser/pulls) için önerileriniz dikkate alınacaktır.
@@ -36,14 +36,14 @@ $ npm i js-comments-eraser
36
36
  To use it from the command line, open a file like **nocomments.js** and paste the following into it.
37
37
 
38
38
  ```
39
- return require('js-comments-eraser')
39
+ return require('js-comments-eraser').dirname(__dirname)
40
40
  ```
41
41
 
42
42
  Then use it from the command line as follows.
43
43
 
44
44
  ```
45
45
  $ node nocomments withcomments.js withoutcomments.js # 1.0.1
46
- $ node nocomments <sourceDir> # 1.1.0
46
+ $ node nocomments <sourceDir> # 1.1.3
47
47
 
48
48
  ```
49
49
 
@@ -1,117 +0,0 @@
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
-
30
- // Relative path'ten absolute path'e
31
- sourceDir = path.resolve(sourceDir);
32
- targetDir = path.resolve(targetDir);
33
-
34
-
35
- // const HEDEFMEVCUT = fs.existsSync(args[1])
36
- const HEDEFMEVCUT = fs.existsSync(targetDir)
37
-
38
- // console.log(`Kaynak directory: ${sourceDir}`,`Hedef directory: ${targetDir}`);
39
-
40
- // && path.resolve(sourceDir) === path.resolve(targetDir)
41
- if (!HEDEFMEVCUT) {
42
- // console.warn(`Skipping processing of target directory to avoid infinite loop: ${targetDir}`);
43
- // return;
44
-
45
- // , { recursive: false }
46
- fs.mkdirSync(targetDir); // Create target directory if not exists
47
- console.log(`Target directory: ${targetDir}`, "CREATED");
48
-
49
- }
50
-
51
- const items = fs.readdirSync(sourceDir, { withFileTypes: true });
52
- for (const item of items) {
53
- const sourcePath = path.join(sourceDir, item.name);
54
- const targetPath = path.join(targetDir, item.name);
55
-
56
- if (item.isDirectory()) {
57
- processDirectory(sourcePath, targetPath);
58
- } else if (item.isFile() && path.extname(item.name) === '.js') {
59
-
60
- const fileContent = fs.readFileSync(sourcePath, 'utf8');
61
- const cleanedContent = removeCommentsFromFile(fileContent);
62
-
63
- if (targetPath && cleanedContent)
64
- try {
65
- fs.writeFileSync(targetPath, cleanedContent, 'utf8');
66
- // console.log({ targetPath })
67
- } catch (_writeFileSyncERROR) {
68
- console.log({ _writeFileSyncERROR })
69
- }
70
- else {
71
- console.log({ targetPath, cleanedContent });
72
- }
73
-
74
- // console.log(sourceDir, "\t\t\t->", targetPath);
75
- }
76
- }
77
- }
78
-
79
- // Get command line arguments
80
- const args = process.argv.slice(2);
81
-
82
- // if (args.length !== 2) {
83
- // console.error('Usage: node js-comments-eraser <sourceDir> <targetDir>');
84
- // process.exit(1);
85
- // }
86
- if (args.length !== 1) {
87
- console.error('Usage: node your-js-comments-eraser <sourceDir>');
88
- process.exit(1);
89
- }
90
-
91
- const sourceDir = args[0];
92
- // const targetDir = args[1];
93
- const targetDir = "clean_dist";
94
-
95
- console.log("Start processing")
96
- processDirectory(sourceDir, targetDir);
97
- console.log(`All .js files from ${sourceDir} have been processed and saved to ${sourceDir}/${targetDir}.`);
98
-
99
-
100
-
101
-
102
- const tasinacakKlasor = path.join(__dirname, targetDir); // Taşınacak klasör
103
- const hedefKonum = path.join(__dirname, sourceDir); // Hedef konum
104
-
105
- // console.log(tasinacakKlasor)
106
- // console.log(hedefKonum)
107
-
108
- setTimeout(() => {
109
- fs.move(tasinacakKlasor, hedefKonum, { overwrite: true })
110
- .then(() => {
111
- console.log('Successfully moved.');
112
- })
113
- .catch(err => {
114
- console.error('Some things went wrong:', err);
115
- });
116
-
117
- }, 1000);
@@ -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}.`);
@@ -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