Skip to content

Commit

Permalink
1.1.5 versiyonu ile javascript içindeki Bazı regex'lerin kendisi tara…
Browse files Browse the repository at this point in the history
…fından bozulması engellendi. BAK: commentRegex2 farkı.
  • Loading branch information
aydincandan committed Jan 5, 2025
1 parent f8a8f30 commit 2312181
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
9 changes: 7 additions & 2 deletions index-multi.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//KEEP: # 1.1.4
// https://chatgpt.com/share/67758592-d174-8011-be5b-642a87e71019
'use strict';

const path = require('path');
Expand All @@ -8,15 +10,18 @@ const fs = require('fs-extra');

// Function to remove comment lines but keep specific ones
function removeCommentsFromFile(fileContent) {
//KEEP REF: https://chatgpt.com/share/67758592-d174-8011-be5b-642a87e71019
const step1 = fileContent
.replace(/(http:\/\/)/gm, 'http:--')
.replace(/(https:\/\/)/gm, 'https:--'); // ilk yapılan tüm http(s) leri -- ile koruma altına alıyoruz? Nedenki sebebi?

// "KEEP" ve "gm;" etiketlerini koruyan düzenli ifade buda olması lazım //g;
const commentRegex = /\/\/(?!KEEP\b|gm;).*?$|\/\*(?!.*KEEP\b|gm;)[\s\S]*?\*\//gm;
const commentRegex = /\/\/(?!KEEP\b|gm;).*?$|\/\*(?!.*KEEP\b|gm;)[\s\S]*?\*\//gm;
// //g; da eklendi aşağıda.
const commentRegex2 = /\/\/(?!KEEP\b|gm;|g;).*?$|\/\*(?!.*KEEP\b|gm;|g;)[\s\S]*?\*\//gm;

const step2 = step1
.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.
.replace(commentRegex2, ''); // ikinci yapılan tüm yorum satırları siliniyor iken "KEEP" ve "gm;" ve "g;" etiketleri de korunuyor.

const step3 = step2
.replace(/(http:--)/gm, 'http://')
Expand Down
2 changes: 1 addition & 1 deletion index-single.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// KEEP: # 1.0.1
//KEEP: # 1.0.1
// https://chatgpt.com/share/67758592-d174-8011-be5b-642a87e71019
const fs = require('fs');

Expand Down
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-comments-eraser",
"version": "1.1.4",
"version": "1.1.5",
"main": "index-multi.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -19,7 +19,15 @@
"cleaner",
"comments"
],
"author": "[email protected]",
"author": "Aydin Candan <[email protected]>",
"repository": {
"type": "git",
"url": "git+https://github.com/aydincandan/js-comments-eraser.git"
},
"bugs": {
"url": "https://github.com/aydincandan/js-comments-eraser/issues"
},
"homepage": "https://github.com/aydincandan/js-comments-eraser#readme",
"license": "ISC",
"description": "It simply clears comments in all javascript files within a folder(in all sub folders[recursively]).",
"dependencies": {
Expand Down

0 comments on commit 2312181

Please sign in to comment.