From 157665d4f5342fe82cafa15aa508a66f564f9680 Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Wed, 16 Oct 2024 08:19:16 -0500 Subject: [PATCH 01/16] added remove versions file that gets run after build --- services/ui-src/package.json | 2 +- services/ui-src/remove-versions.js | 37 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 services/ui-src/remove-versions.js diff --git a/services/ui-src/package.json b/services/ui-src/package.json index e9cb3cc62..2198670f2 100644 --- a/services/ui-src/package.json +++ b/services/ui-src/package.json @@ -41,7 +41,7 @@ }, "scripts": { "start": "react-scripts start", - "build": "react-scripts build", + "build": "react-scripts build && node remove-version.js", "test": "react-scripts test --unhandled-rejections=strict", "eject": "react-scripts eject" }, diff --git a/services/ui-src/remove-versions.js b/services/ui-src/remove-versions.js new file mode 100644 index 000000000..7457a65e8 --- /dev/null +++ b/services/ui-src/remove-versions.js @@ -0,0 +1,37 @@ +const fs = require('fs'); +const path = require('path'); + +// Define the directory of the build output +const buildDir = path.join(__dirname, 'build', 'static', 'js'); + +// Define the regular expression to match the version pattern +const regex = /\b\d+\.\d+\.\d+\b/g; + +// Function to remove the version from files +const removeVersionFromFiles = (dir) => { + fs.readdir(dir, (err, files) => { + if (err) throw err; + + files.forEach(file => { + const filePath = path.join(dir, file); + + // Check if the file is a JavaScript file + if (file.endsWith('.js')) { + fs.readFile(filePath, 'utf8', (err, data) => { + if (err) throw err; + + // Replace the version pattern + const result = data.replace(regex, ''); + + // Write the modified content back to the file + fs.writeFile(filePath, result, 'utf8', (err) => { + if (err) throw err; + console.log(`Removed version from ${file}`); + }); + }); + } + }); + }); +}; + +removeVersionFromFiles(buildDir); From b62783fc863d7881cb56550647ff15ca029b20dc Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Wed, 16 Oct 2024 10:12:14 -0500 Subject: [PATCH 02/16] added s to match actual file name --- services/ui-src/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ui-src/package.json b/services/ui-src/package.json index 2198670f2..4913b861a 100644 --- a/services/ui-src/package.json +++ b/services/ui-src/package.json @@ -41,7 +41,7 @@ }, "scripts": { "start": "react-scripts start", - "build": "react-scripts build && node remove-version.js", + "build": "react-scripts build && node remove-versions.js", "test": "react-scripts test --unhandled-rejections=strict", "eject": "react-scripts eject" }, From b628d3a2bb1a0eb894f090c71c0b56a61250cfc4 Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Wed, 16 Oct 2024 21:16:57 -0500 Subject: [PATCH 03/16] only strip versions that start with 4, specific to loadash --- services/ui-src/remove-versions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ui-src/remove-versions.js b/services/ui-src/remove-versions.js index 7457a65e8..b0eab29b0 100644 --- a/services/ui-src/remove-versions.js +++ b/services/ui-src/remove-versions.js @@ -5,7 +5,7 @@ const path = require('path'); const buildDir = path.join(__dirname, 'build', 'static', 'js'); // Define the regular expression to match the version pattern -const regex = /\b\d+\.\d+\.\d+\b/g; +const regex = /^4\.\d{1,2}\.\d{1,2}$/; // Function to remove the version from files const removeVersionFromFiles = (dir) => { From 0ee47fbcfe7d45e16f55bb6592453b93fe5d95ee Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Wed, 16 Oct 2024 21:42:24 -0500 Subject: [PATCH 04/16] match occurences not exact string match --- services/ui-src/remove-versions.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/ui-src/remove-versions.js b/services/ui-src/remove-versions.js index b0eab29b0..657f9919e 100644 --- a/services/ui-src/remove-versions.js +++ b/services/ui-src/remove-versions.js @@ -5,7 +5,7 @@ const path = require('path'); const buildDir = path.join(__dirname, 'build', 'static', 'js'); // Define the regular expression to match the version pattern -const regex = /^4\.\d{1,2}\.\d{1,2}$/; +const regex = /4\.\d{1,2}\.\d{1,2}/g; // Added 'g' flag for global matching // Function to remove the version from files const removeVersionFromFiles = (dir) => { @@ -21,7 +21,7 @@ const removeVersionFromFiles = (dir) => { if (err) throw err; // Replace the version pattern - const result = data.replace(regex, ''); + const result = data.replace(regex, ''); // Remove matched versions // Write the modified content back to the file fs.writeFile(filePath, result, 'utf8', (err) => { @@ -34,4 +34,4 @@ const removeVersionFromFiles = (dir) => { }); }; -removeVersionFromFiles(buildDir); +removeVersionFromFiles(buildDir); \ No newline at end of file From cb65bbf0dc07951723c55b68813aa5179059442d Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Wed, 16 Oct 2024 22:08:16 -0500 Subject: [PATCH 05/16] only match 4.17. any number --- services/ui-src/remove-versions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/ui-src/remove-versions.js b/services/ui-src/remove-versions.js index 657f9919e..e584bee83 100644 --- a/services/ui-src/remove-versions.js +++ b/services/ui-src/remove-versions.js @@ -4,8 +4,8 @@ const path = require('path'); // Define the directory of the build output const buildDir = path.join(__dirname, 'build', 'static', 'js'); -// Define the regular expression to match the version pattern -const regex = /4\.\d{1,2}\.\d{1,2}/g; // Added 'g' flag for global matching +// Define the regular expression to match the version pattern 4.17.xx +const regex = /4\.17\.\d{2}/g; // Matches versions like 4.17.01, 4.17.99 // Function to remove the version from files const removeVersionFromFiles = (dir) => { From 78d0f2e3796dab470bf4e75c913cf9791a10fa35 Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Wed, 16 Oct 2024 22:28:32 -0500 Subject: [PATCH 06/16] 4.xx.yy where xx is any number 17 or above --- services/ui-src/remove-versions.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/services/ui-src/remove-versions.js b/services/ui-src/remove-versions.js index e584bee83..f0b842163 100644 --- a/services/ui-src/remove-versions.js +++ b/services/ui-src/remove-versions.js @@ -4,8 +4,9 @@ const path = require('path'); // Define the directory of the build output const buildDir = path.join(__dirname, 'build', 'static', 'js'); -// Define the regular expression to match the version pattern 4.17.xx -const regex = /4\.17\.\d{2}/g; // Matches versions like 4.17.01, 4.17.99 +// Define the regular expression to match the version pattern 4.xx.yy +// where xx is 17 or above and yy is any two-digit number +const regex = /4\.(1[7-9]|[2-9][0-9])\.\d{2}/g; // Matches versions like 4.17.01, 4.25.99 // Function to remove the version from files const removeVersionFromFiles = (dir) => { @@ -34,4 +35,4 @@ const removeVersionFromFiles = (dir) => { }); }; -removeVersionFromFiles(buildDir); \ No newline at end of file +removeVersionFromFiles(buildDir); From a104eac90419e880d48d570098ee4bc033e39df0 Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Thu, 17 Oct 2024 11:19:06 -0500 Subject: [PATCH 07/16] change regex to include any version 4.17 or above --- services/ui-src/remove-versions.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/ui-src/remove-versions.js b/services/ui-src/remove-versions.js index f0b842163..d521776ce 100644 --- a/services/ui-src/remove-versions.js +++ b/services/ui-src/remove-versions.js @@ -4,9 +4,9 @@ const path = require('path'); // Define the directory of the build output const buildDir = path.join(__dirname, 'build', 'static', 'js'); -// Define the regular expression to match the version pattern 4.xx.yy -// where xx is 17 or above and yy is any two-digit number -const regex = /4\.(1[7-9]|[2-9][0-9])\.\d{2}/g; // Matches versions like 4.17.01, 4.25.99 +// Define the regular expression to match the version pattern z.xx.yy +// where if the first z is 4, xx is 17 or above; if z>=5, xx can be anything; +const regex = /(4\.(1[7-9]|[2-9][0-9])|5\.\d{2}|[6-9]\.\d{2})\.\d{2}/g; // Matches versions like 4.17.01, 5.25.99, 7.10.87 // Function to remove the version from files const removeVersionFromFiles = (dir) => { From d1b55f17f32d9c1fffb06cc8a012bf2aeffdc256 Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Fri, 18 Oct 2024 10:58:21 -0500 Subject: [PATCH 08/16] only remove version if it occurs after Bn.VERSION --- services/ui-src/remove-versions.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/ui-src/remove-versions.js b/services/ui-src/remove-versions.js index d521776ce..0f907b828 100644 --- a/services/ui-src/remove-versions.js +++ b/services/ui-src/remove-versions.js @@ -4,9 +4,9 @@ const path = require('path'); // Define the directory of the build output const buildDir = path.join(__dirname, 'build', 'static', 'js'); -// Define the regular expression to match the version pattern z.xx.yy -// where if the first z is 4, xx is 17 or above; if z>=5, xx can be anything; -const regex = /(4\.(1[7-9]|[2-9][0-9])|5\.\d{2}|[6-9]\.\d{2})\.\d{2}/g; // Matches versions like 4.17.01, 5.25.99, 7.10.87 +// Define the regular expression to match the version pattern +// where the match occurs right after Bn.VERSION = " +const regex = /(?<=Bn\.VERSION = ")(4\.(1[7-9]|[2-9][0-9])\.\d{2}|5\.\d{2}\.\d{2}|[6-9]\.\d{2}\.\d{2})/g; // Matches versions like 4.17.01, 5.25.99, 9.10.11 // Function to remove the version from files const removeVersionFromFiles = (dir) => { @@ -21,7 +21,7 @@ const removeVersionFromFiles = (dir) => { fs.readFile(filePath, 'utf8', (err, data) => { if (err) throw err; - // Replace the version pattern + // Replace the version pattern only after Bn.VERSION = " const result = data.replace(regex, ''); // Remove matched versions // Write the modified content back to the file From 79747209e13f0358cf0d8dcbd3e706a695a62a44 Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Fri, 18 Oct 2024 11:26:43 -0500 Subject: [PATCH 09/16] only remove version if it occurs after Bn.VERSION --- services/ui-src/remove-versions.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/services/ui-src/remove-versions.js b/services/ui-src/remove-versions.js index 0f907b828..0f8c73ed4 100644 --- a/services/ui-src/remove-versions.js +++ b/services/ui-src/remove-versions.js @@ -5,8 +5,8 @@ const path = require('path'); const buildDir = path.join(__dirname, 'build', 'static', 'js'); // Define the regular expression to match the version pattern -// where the match occurs right after Bn.VERSION = " -const regex = /(?<=Bn\.VERSION = ")(4\.(1[7-9]|[2-9][0-9])\.\d{2}|5\.\d{2}\.\d{2}|[6-9]\.\d{2}\.\d{2})/g; // Matches versions like 4.17.01, 5.25.99, 9.10.11 +// Specifically targeting the line with Bn.VERSION +const regex = /(Bn\.VERSION = ")(4\.(1[7-9]|[2-9][0-9])\.\d{2}|5\.\d{2}\.\d{2}|[6-9]\.\d{2}\.\d{2})(")/g; // Function to remove the version from files const removeVersionFromFiles = (dir) => { @@ -22,7 +22,7 @@ const removeVersionFromFiles = (dir) => { if (err) throw err; // Replace the version pattern only after Bn.VERSION = " - const result = data.replace(regex, ''); // Remove matched versions + const result = data.replace(regex, '$1"$4'); // Keep the surrounding parts and replace the version // Write the modified content back to the file fs.writeFile(filePath, result, 'utf8', (err) => { @@ -36,3 +36,4 @@ const removeVersionFromFiles = (dir) => { }; removeVersionFromFiles(buildDir); + From 7ba174fa788dd76e3ae666406337f8a160a51bc1 Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Fri, 18 Oct 2024 11:49:21 -0500 Subject: [PATCH 10/16] change to NEW_VERSION instead --- services/ui-src/remove-versions.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/services/ui-src/remove-versions.js b/services/ui-src/remove-versions.js index 0f8c73ed4..ae78cfb0e 100644 --- a/services/ui-src/remove-versions.js +++ b/services/ui-src/remove-versions.js @@ -5,7 +5,7 @@ const path = require('path'); const buildDir = path.join(__dirname, 'build', 'static', 'js'); // Define the regular expression to match the version pattern -// Specifically targeting the line with Bn.VERSION +// specifically targeting the line with Bn.VERSION const regex = /(Bn\.VERSION = ")(4\.(1[7-9]|[2-9][0-9])\.\d{2}|5\.\d{2}\.\d{2}|[6-9]\.\d{2}\.\d{2})(")/g; // Function to remove the version from files @@ -22,7 +22,7 @@ const removeVersionFromFiles = (dir) => { if (err) throw err; // Replace the version pattern only after Bn.VERSION = " - const result = data.replace(regex, '$1"$4'); // Keep the surrounding parts and replace the version + const result = data.replace(regex, '$1"NEW_VERSION"$4'); // Replace version with NEW_VERSION // Write the modified content back to the file fs.writeFile(filePath, result, 'utf8', (err) => { @@ -36,4 +36,3 @@ const removeVersionFromFiles = (dir) => { }; removeVersionFromFiles(buildDir); - From 98720100823ac9a2eef609df46f6811e39e1f631 Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Fri, 18 Oct 2024 12:40:46 -0500 Subject: [PATCH 11/16] try .replace instead --- services/ui-src/remove-versions.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/services/ui-src/remove-versions.js b/services/ui-src/remove-versions.js index ae78cfb0e..81ec8bc64 100644 --- a/services/ui-src/remove-versions.js +++ b/services/ui-src/remove-versions.js @@ -4,10 +4,6 @@ const path = require('path'); // Define the directory of the build output const buildDir = path.join(__dirname, 'build', 'static', 'js'); -// Define the regular expression to match the version pattern -// specifically targeting the line with Bn.VERSION -const regex = /(Bn\.VERSION = ")(4\.(1[7-9]|[2-9][0-9])\.\d{2}|5\.\d{2}\.\d{2}|[6-9]\.\d{2}\.\d{2})(")/g; - // Function to remove the version from files const removeVersionFromFiles = (dir) => { fs.readdir(dir, (err, files) => { @@ -21,8 +17,8 @@ const removeVersionFromFiles = (dir) => { fs.readFile(filePath, 'utf8', (err, data) => { if (err) throw err; - // Replace the version pattern only after Bn.VERSION = " - const result = data.replace(regex, '$1"NEW_VERSION"$4'); // Replace version with NEW_VERSION + // Replace the version pattern only if it matches the Bn.VERSION line + const result = data.replace(/(Bn\.VERSION = ")[0-9]+\.[0-9]+\.[0-9]+(")/, 'BN.VERSION = ""'); // Write the modified content back to the file fs.writeFile(filePath, result, 'utf8', (err) => { @@ -36,3 +32,4 @@ const removeVersionFromFiles = (dir) => { }; removeVersionFromFiles(buildDir); + From e861e4a2f6f7f43b4dfe25c0133b1783faf55067 Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Fri, 18 Oct 2024 13:33:17 -0500 Subject: [PATCH 12/16] try different regex --- services/ui-src/remove-versions.js | 31 +++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/services/ui-src/remove-versions.js b/services/ui-src/remove-versions.js index 81ec8bc64..fa0ab89c6 100644 --- a/services/ui-src/remove-versions.js +++ b/services/ui-src/remove-versions.js @@ -7,7 +7,10 @@ const buildDir = path.join(__dirname, 'build', 'static', 'js'); // Function to remove the version from files const removeVersionFromFiles = (dir) => { fs.readdir(dir, (err, files) => { - if (err) throw err; + if (err) { + console.error("Error reading directory:", err); + return; + } files.forEach(file => { const filePath = path.join(dir, file); @@ -15,15 +18,32 @@ const removeVersionFromFiles = (dir) => { // Check if the file is a JavaScript file if (file.endsWith('.js')) { fs.readFile(filePath, 'utf8', (err, data) => { - if (err) throw err; + if (err) { + console.error("Error reading file:", err); + return; + } + + console.log(`Original content of ${file}:`); + console.log(data); // Log original content // Replace the version pattern only if it matches the Bn.VERSION line - const result = data.replace(/(Bn\.VERSION = ")[0-9]+\.[0-9]+\.[0-9]+(")/, 'BN.VERSION = ""'); + const regex = /(Bn\.VERSION = ")(4\.\d{2}\.\d{2})(")/; + const result = data.replace(regex, '$1NEW_VERSION$3'); + + if (data !== result) { + console.log(`Updated content of ${file}:`); + console.log(result); // Log updated content + } else { + console.log(`No version found in ${file}`); + } // Write the modified content back to the file fs.writeFile(filePath, result, 'utf8', (err) => { - if (err) throw err; - console.log(`Removed version from ${file}`); + if (err) { + console.error("Error writing file:", err); + } else { + console.log(`Version removed from ${file}`); + } }); }); } @@ -33,3 +53,4 @@ const removeVersionFromFiles = (dir) => { removeVersionFromFiles(buildDir); + From fece78a6ca1400e8deb6d79a701918fba9d97867 Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Fri, 18 Oct 2024 13:54:13 -0500 Subject: [PATCH 13/16] try exact string match instead of regex --- services/ui-src/remove-versions.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/services/ui-src/remove-versions.js b/services/ui-src/remove-versions.js index fa0ab89c6..a03db205d 100644 --- a/services/ui-src/remove-versions.js +++ b/services/ui-src/remove-versions.js @@ -26,15 +26,17 @@ const removeVersionFromFiles = (dir) => { console.log(`Original content of ${file}:`); console.log(data); // Log original content - // Replace the version pattern only if it matches the Bn.VERSION line - const regex = /(Bn\.VERSION = ")(4\.\d{2}\.\d{2})(")/; - const result = data.replace(regex, '$1NEW_VERSION$3'); + // Replace the exact version string + const oldVersion = 'Bn.VERSION = "4.17.21"'; + const newVersion = 'Bn.VERSION = "NEW_VERSION"'; // Change this to your desired new version + + const result = data.replace(oldVersion, newVersion); if (data !== result) { console.log(`Updated content of ${file}:`); console.log(result); // Log updated content } else { - console.log(`No version found in ${file}`); + console.log(`No matching version found in ${file}`); } // Write the modified content back to the file @@ -42,7 +44,7 @@ const removeVersionFromFiles = (dir) => { if (err) { console.error("Error writing file:", err); } else { - console.log(`Version removed from ${file}`); + console.log(`Version updated in ${file}`); } }); }); @@ -54,3 +56,4 @@ const removeVersionFromFiles = (dir) => { removeVersionFromFiles(buildDir); + From 2a56acab1edcf3f064b7ed94592ee99b0fac46eb Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Fri, 18 Oct 2024 14:27:18 -0500 Subject: [PATCH 14/16] remove spaces that were causing mismatch --- services/ui-src/remove-versions.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/services/ui-src/remove-versions.js b/services/ui-src/remove-versions.js index a03db205d..a630fbba9 100644 --- a/services/ui-src/remove-versions.js +++ b/services/ui-src/remove-versions.js @@ -26,17 +26,15 @@ const removeVersionFromFiles = (dir) => { console.log(`Original content of ${file}:`); console.log(data); // Log original content - // Replace the exact version string - const oldVersion = 'Bn.VERSION = "4.17.21"'; - const newVersion = 'Bn.VERSION = "NEW_VERSION"'; // Change this to your desired new version - - const result = data.replace(oldVersion, newVersion); + // Replace the version pattern only if it matches the Bn.VERSION line + const regex = /(Bn\.VERSION=")(4\.\d{2}\.\d{2})(")/; + const result = data.replace(regex, 'Bn.VERSION=""'); if (data !== result) { console.log(`Updated content of ${file}:`); console.log(result); // Log updated content } else { - console.log(`No matching version found in ${file}`); + console.log(`No version found in ${file}`); } // Write the modified content back to the file @@ -44,7 +42,7 @@ const removeVersionFromFiles = (dir) => { if (err) { console.error("Error writing file:", err); } else { - console.log(`Version updated in ${file}`); + console.log(`Version removed from ${file}`); } }); }); From 6dc27b46d5530f93d38dc26042f449e17d31ee93 Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Fri, 18 Oct 2024 14:42:56 -0500 Subject: [PATCH 15/16] allow for major version greater then 4 --- services/ui-src/remove-versions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ui-src/remove-versions.js b/services/ui-src/remove-versions.js index a630fbba9..8620349be 100644 --- a/services/ui-src/remove-versions.js +++ b/services/ui-src/remove-versions.js @@ -27,7 +27,7 @@ const removeVersionFromFiles = (dir) => { console.log(data); // Log original content // Replace the version pattern only if it matches the Bn.VERSION line - const regex = /(Bn\.VERSION=")(4\.\d{2}\.\d{2})(")/; + const regex = /(Bn\.VERSION=")([4-9]\.\d{2}\.\d{2})(")/; const result = data.replace(regex, 'Bn.VERSION=""'); if (data !== result) { From 2adbbda90651389eeb097e7ab9586a549f989252 Mon Sep 17 00:00:00 2001 From: Alex Youssefinia Date: Fri, 18 Oct 2024 14:45:37 -0500 Subject: [PATCH 16/16] remove console logs --- services/ui-src/remove-versions.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/services/ui-src/remove-versions.js b/services/ui-src/remove-versions.js index 8620349be..de4ccc778 100644 --- a/services/ui-src/remove-versions.js +++ b/services/ui-src/remove-versions.js @@ -23,20 +23,16 @@ const removeVersionFromFiles = (dir) => { return; } - console.log(`Original content of ${file}:`); - console.log(data); // Log original content - // Replace the version pattern only if it matches the Bn.VERSION line const regex = /(Bn\.VERSION=")([4-9]\.\d{2}\.\d{2})(")/; const result = data.replace(regex, 'Bn.VERSION=""'); if (data !== result) { console.log(`Updated content of ${file}:`); - console.log(result); // Log updated content } else { console.log(`No version found in ${file}`); } - + // Write the modified content back to the file fs.writeFile(filePath, result, 'utf8', (err) => { if (err) {