js-comments-eraser 1.1.7 → 1.2.0

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.js ADDED
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ const fs = require("fs");
3
+ const path = require("path");
4
+ function move(src, dest) {
5
+ const srcPath = path.resolve(src);
6
+ const destPath = path.resolve(dest);
7
+ fs.renameSync(srcPath, destPath);
8
+ }
9
+ function removeCommentsFromFile(fileContent) {
10
+ const step1 = fileContent.replace(/(http:\/\/)/gm, "http:--").replace(/(https:\/\/)/gm, "https:--");
11
+ const commentRegex = /\/\/(?!KEEP\b|gm;).*?$|\/\*(?!.*KEEP\b|gm;)[\s\S]*?\*\//gm;
12
+ const commentRegex2 = /\/\/(?!KEEP\b|gm;|g;).*?$|\/\*(?!.*KEEP\b|gm;|g;)[\s\S]*?\*\//gm;
13
+ const step2 = step1.replace(commentRegex2, "");
14
+ const step3 = step2.replace(/(http:--)/gm, "http://").replace(/(https:--)/gm, "https://");
15
+ const step4 = step3;
16
+ return step4;
17
+ }
18
+ function processDirectory(sourceDir2, targetDir2) {
19
+ const HEDEFMEVCUT = fs.existsSync(targetDir2);
20
+ if (!HEDEFMEVCUT) {
21
+ fs.mkdirSync(targetDir2);
22
+ }
23
+ const items = fs.readdirSync(sourceDir2, { withFileTypes: true });
24
+ for (const item of items) {
25
+ const sourcePath = path.join(sourceDir2, item.name);
26
+ const targetPath = path.join(targetDir2, item.name);
27
+ if (item.isDirectory() && (item.name !== "node_modules" && item.name !== "clean_dist")) {
28
+ processDirectory(sourcePath, targetPath);
29
+ } else if (item.isFile() && path.extname(item.name) === ".js" || path.extname(item.name) === ".mjs") {
30
+ const fileContent = fs.readFileSync(sourcePath, "utf8");
31
+ const cleanedContent = removeCommentsFromFile(fileContent);
32
+ if (targetPath && cleanedContent)
33
+ try {
34
+ fs.writeFileSync(targetPath, cleanedContent, "utf8");
35
+ } catch (_writeFileSyncERROR) {
36
+ console.log({ _writeFileSyncERROR });
37
+ }
38
+ else {
39
+ console.log({ targetPath, cleanedContent });
40
+ }
41
+ }
42
+ }
43
+ }
44
+ const args = process.argv.slice(2);
45
+ console.log({ args });
46
+ if (args.length !== 1) {
47
+ console.error("Usage: node [your-js-comments-eraser] <sourceDir>");
48
+ process.exit(1);
49
+ }
50
+ let sourceDir = args[0];
51
+ let targetDir = "clean_dist";
52
+ console.log();
53
+ console.log("***********************");
54
+ processDirectory(sourceDir, targetDir);
55
+ console.log(`"${sourceDir}" klas\xF6r\xFCndeki t\xFCm JavaScript dosyalar\u0131n\u0131n yorum sat\u0131rlar\u0131 silindi ve ayn\u0131 seviyede olu\u015Fturulan "./${targetDir}" klas\xF6r\xFCne kopyaland\u0131.`);
56
+ console.log("***********************");
57
+ const exportet = (user__dirname) => {
58
+ if (true) {
59
+ sourceDir = path.join(user__dirname, targetDir);
60
+ targetDir = path.join(user__dirname, args[0]);
61
+ const finalDestination = path.join(targetDir, path.basename(sourceDir));
62
+ setTimeout(() => {
63
+ move(sourceDir, finalDestination);
64
+ }, 1);
65
+ }
66
+ };
67
+ module.exports.dirname = exportet;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "js-comments-eraser",
3
- "version": "1.1.7",
4
- "main": "index-multi.js",
3
+ "version": "1.2.0",
4
+ "main": "index.js",
5
5
  "scripts": {
6
- "test": "echo \"Error: no test specified\" && exit 1"
6
+ "update-outdated-packages": "npx npm-check-updates -u && npm install"
7
7
  },
8
8
  "keywords": [
9
9
  "node",
@@ -31,6 +31,7 @@
31
31
  "license": "ISC",
32
32
  "description": "It simply clears comments in all javascript files within a folder(in all sub folders[recursively]).",
33
33
  "dependencies": {
34
- "fs-extra": "^11.2.0"
35
- }
34
+ "fs-extra": "^11.3.4"
35
+ },
36
+ "last_commit": "index-multi-rename yerine jscommentseraser kullanilacak."
36
37
  }
package/LICENSE DELETED
@@ -1,24 +0,0 @@
1
- This is free and unencumbered software released into the public domain.
2
-
3
- Anyone is free to copy, modify, publish, use, compile, sell, or
4
- distribute this software, either in source code form or as a compiled
5
- binary, for any purpose, commercial or non-commercial, and by any
6
- means.
7
-
8
- In jurisdictions that recognize copyright laws, the author or authors
9
- of this software dedicate any and all copyright interest in the
10
- software to the public domain. We make this dedication for the benefit
11
- of the public at large and to the detriment of our heirs and
12
- successors. We intend this dedication to be an overt act of
13
- relinquishment in perpetuity of all present and future rights to this
14
- software under copyright law.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
- OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
- OTHER DEALINGS IN THE SOFTWARE.
23
-
24
- For more information, please refer to <https://unlicense.org>
package/index-multi.js DELETED
@@ -1,133 +0,0 @@
1
- //KEEP: # 1.1.4
2
- // https://chatgpt.com/share/67758592-d174-8011-be5b-642a87e71019
3
- 'use strict';
4
-
5
- const path = require('path');
6
-
7
- // const fs = require('fs');
8
- const fs = require('fs-extra');
9
-
10
-
11
- // Function to remove comment lines but keep specific ones
12
- function removeCommentsFromFile(fileContent) {
13
- //KEEP REF: https://chatgpt.com/share/67758592-d174-8011-be5b-642a87e71019
14
- const step1 = fileContent
15
- .replace(/(http:\/\/)/gm, 'http:--')
16
- .replace(/(https:\/\/)/gm, 'https:--'); // ilk yapılan tüm http(s) leri -- ile koruma altına alıyoruz? Nedenki sebebi?
17
-
18
- // "KEEP" ve "gm;" etiketlerini koruyan düzenli ifade buda olması lazım //g;
19
- const commentRegex = /\/\/(?!KEEP\b|gm;).*?$|\/\*(?!.*KEEP\b|gm;)[\s\S]*?\*\//gm;
20
- // //g; da eklendi aşağıda.
21
- const commentRegex2 = /\/\/(?!KEEP\b|gm;|g;).*?$|\/\*(?!.*KEEP\b|gm;|g;)[\s\S]*?\*\//gm;
22
-
23
- const step2 = step1
24
- .replace(commentRegex2, ''); // ikinci yapılan tüm yorum satırları siliniyor iken "KEEP" ve "gm;" ve "g;" etiketleri de korunuyor.
25
-
26
- const step3 = step2
27
- .replace(/(http:--)/gm, 'http://')
28
- .replace(/(https:--)/gm, 'https://');
29
-
30
- // const falseIfBlockRegex = /if\s*\(\s*false\s*\)\s*\{[\s\S]*?\}/gm;
31
- const step4 = step3
32
- // .replace(falseIfBlockRegex, '');
33
-
34
- return step4;
35
- }
36
-
37
- // Recursive function to process files in a directory
38
- function processDirectory(sourceDir, targetDir) {
39
-
40
- const HEDEFMEVCUT = fs.existsSync(targetDir)
41
-
42
- if (!HEDEFMEVCUT) {
43
- fs.mkdirSync(targetDir); // Create target directory if not exists
44
- // console.log(`Target directory: ${targetDir}`, "CREATED");
45
- }
46
-
47
- const items = fs.readdirSync(sourceDir, { withFileTypes: true });
48
- for (const item of items) {
49
- const sourcePath = path.join(sourceDir, item.name);
50
- const targetPath = path.join(targetDir, item.name);
51
- // console.log("TEST(1)",{ sourcePath, targetPath }, {itemisdir:item.isDirectory(),itname:item.name})
52
-
53
- if (item.isDirectory() && (item.name !== 'node_modules' && item.name !== 'clean_dist')) {
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
- // console.log("Bitti", { sourceDir, targetDir })
75
- }
76
-
77
- // Get command line arguments
78
- const args = process.argv.slice(2);
79
-
80
- // console.log({ args });
81
-
82
- // if (args.length !== 2) {
83
- // console.error('Usage: node [your-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
- let sourceDir = args[0]; // basit ifade
92
- let targetDir = "clean_dist"; // basit ifade
93
-
94
- console.log()
95
- console.log("***********************")
96
- // console.log("Start processing", { sourceDir })
97
- processDirectory(sourceDir, targetDir);
98
- 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.`);
99
- console.log("***********************")
100
-
101
-
102
- const exportet = (user__dirname) => {
103
-
104
-
105
- if (true) {
106
-
107
- sourceDir = path.join(user__dirname, targetDir)//** gerçek/tam ifade */
108
- targetDir = path.join(user__dirname, args[0])//** gerçek/tam ifade */
109
-
110
- // console.log({ sourceDir, targetDir, user__dirname });
111
-
112
- const finalDestination = path.join(targetDir, path.basename(sourceDir));
113
- // console.log("input params", { sourceDir, targetDir })
114
- // console.log("move params2", { sourceDir, finalDestination })
115
-
116
- setTimeout(() => {
117
-
118
- fs.move(sourceDir, finalDestination, { overwrite: true })
119
- .then(() => {
120
- console.log('Successfully moved.');
121
- })
122
- .catch(err => {
123
- console.error('Some things went wrong:', err);
124
- });
125
-
126
- }, 1);
127
-
128
-
129
- }
130
-
131
- }
132
-
133
- module.exports.dirname = exportet
package/index-single.js DELETED
@@ -1,53 +0,0 @@
1
- //KEEP: # 1.0.1
2
- // https://chatgpt.com/share/67758592-d174-8011-be5b-642a87e71019
3
- const fs = require('fs');
4
-
5
- // Function to remove comment lines
6
- function removeCommentsFromFile(fileContent) {
7
-
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
- // Get command line arguments
26
- const args = process.argv.slice(2);
27
-
28
- if (args.length !== 2) {
29
- console.error('Usage: node nocomments <source.js> <target.js>');
30
- process.exit(1);
31
- }
32
-
33
- const sourceFile = args[0];
34
- const targetFile = args[1];
35
-
36
- // Read source file and clear comments
37
- fs.readFile(sourceFile, 'utf8', (err, data) => {
38
- if (err) {
39
- console.error(`Could not read source file: ${sourceFile}`, err);
40
- process.exit(1);
41
- }
42
-
43
- const cleanedContent = removeCommentsFromFile(data);
44
-
45
- // Write cleaned content to destination file
46
- fs.writeFile(targetFile, cleanedContent, 'utf8', err => {
47
- if (err) {
48
- console.error(`Could not write target file: ${targetFile}`, err);
49
- process.exit(1);
50
- }
51
- console.log(`Comments were cleaned up and saved to ${targetFile}.`);
52
- });
53
- });
package/readme.md DELETED
@@ -1,51 +0,0 @@
1
-
2
- ## Türkçe
3
-
4
- Projenize dahil etmek için aşağıdaki gibi yapın.
5
-
6
- ```
7
- $ npm i js-comments-eraser
8
- ```
9
-
10
- Komut satırından kullanabilmek için **yorumyok.js** gibi bir dosya açın ve içine aşağıdakini yapıştırın.
11
-
12
-
13
- ```
14
- return require('js-comments-eraser').dirname(__dirname)
15
- ```
16
-
17
- Daha sonra aşağıdaki gibi komut satırından kullanın.
18
-
19
- ```
20
- $ node yorumyok yorumlu.js yorumsuz.js # 1.0.1
21
- $ node yorumyok <kaynakDir> # >= 1.1.3
22
-
23
- ```
24
-
25
- [js-comments-eraser](https://github.com/aydincandan/js-comments-eraser/pulls) için önerileriniz dikkate alınacaktır.
26
-
27
-
28
-
29
- ## English
30
-
31
- To include it in your project, do the following.
32
-
33
- ```
34
- $ npm i js-comments-eraser
35
- ```
36
-
37
- To use it from the command line, open a file like **nocomments.js** and paste the following into it.
38
-
39
- ```
40
- return require('js-comments-eraser').dirname(__dirname)
41
- ```
42
-
43
- Then use it from the command line as follows.
44
-
45
- ```
46
- $ node nocomments withcomments.js withoutcomments.js # 1.0.1
47
- $ node nocomments <sourceDir> # >= 1.1.3
48
-
49
- ```
50
-
51
- Your suggestions for [js-comments-eraser](https://github.com/aydincandan/js-comments-eraser/pulls) will be taken into consideration.