From a0192d238b47318f91fd1a9e3ee9309f8b8bc6fa Mon Sep 17 00:00:00 2001 From: rahul <10168946+raxhvl@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:53:07 +0530 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20Assistive=20scripts=20for=20con?= =?UTF-8?q?tributors=20(#13)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨ Powerup: Assitive script to upgrade solidty version * ✨ Rebrand: Assistive script for soledge rebranding (#11). * 🥢: messaging --------- Co-authored-by: rahul --- package.json | 4 ++ scripts/config.js | 11 +++++ scripts/io.js | 109 +++++++++++++++++++++++++++++++++++++++++++++ scripts/powerup.js | 53 ++++++++++++++++++++++ scripts/rebrand.js | 63 ++++++++++++++++++++++++++ 5 files changed, 240 insertions(+) create mode 100644 scripts/config.js create mode 100644 scripts/io.js create mode 100644 scripts/powerup.js create mode 100644 scripts/rebrand.js diff --git a/package.json b/package.json index acb129b..7cca55d 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,10 @@ "license": "MIT", "version": "0.0.5", "description": "Edgelord Solidity snippets.", + "scripts": { + "powerup": "node scripts/powerup.js", + "rebrand": "node scripts/rebrand.js" + }, "files": [ "src/**/*.sol" ], diff --git a/scripts/config.js b/scripts/config.js new file mode 100644 index 0000000..9e74d89 --- /dev/null +++ b/scripts/config.js @@ -0,0 +1,11 @@ +/*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ +/* CONFIGS */ +/*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ + +const LATEST_SOLIDITY_VERSION = "0.8.24"; +const SRC_DIR = "src"; + +module.exports = { + LATEST_SOLIDITY_VERSION, + SRC_DIR, +}; diff --git a/scripts/io.js b/scripts/io.js new file mode 100644 index 0000000..fe71541 --- /dev/null +++ b/scripts/io.js @@ -0,0 +1,109 @@ +const fs = require("fs"); +const path = require("path"); +const { SRC_DIR } = require("./config"); +/*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ +/* I/O Helpers */ +/*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ + +/** + * Recursively retrieves a list of Solidity files within a given directory. + * + * @param {string} directory - The root directory to search for Solidity files. Defaults to SRC_DIR. + * @param {string[]} fileList - An optional array to accumulate file paths (used for recursion). + * @returns {string[]} An array of Solidity file paths. + */ +function getSolidityFiles(directory = SRC_DIR, fileList = []) { + const files = fs.readdirSync(directory); + + files.forEach((file) => { + const filePath = path.join(directory, file); + + if (fs.statSync(filePath).isDirectory()) { + getSolidityFiles(filePath, fileList); + } else if (file.endsWith(".sol")) { + fileList.push(filePath); + } + }); + return fileList; +} + +/** + * Shows the updates to be applied as a table. + * + * @param {Update[]} updates - An array of update objects containing scope, file paths, pattern, and patch. + */ +async function showUpdates(updates) { + console.log(`${updates.length} update(s) can be automatically applied:`); + + // Friendly table heading. + updates = updates.map((update) => ({ + "Update type": update.scope, + File: update.file, + "Current value": truncate(update.from), + "Proposed change": truncate(update.to), + })); + + // Increasing index so it starts from 1 instead of 0. + updates = updates.reduce((acc, u, i) => { + acc[i + 1] = u; + return acc; + }, {}); + + console.table(updates); +} + +/** + * Prompts the user for confirmation with a yes/no question. + * + * @param {string} prompt - The question to ask the user. + * @returns {Promise} A Promise that resolves to true if the user confirms, false otherwise. + */ +async function getUserConfirmation(prompt) { + const rl = require("readline").createInterface({ + input: process.stdin, + output: process.stdout, + }); + + const answer = await new Promise((resolve) => { + rl.question(`${prompt} (y/n): `, resolve); + }); + rl.close(); + return answer.toLowerCase() === "y"; +} + +/** + * Applies updates to specified files. + * + * @param {Update[]} updates - An array of update objects containing scope, file paths, pattern, and patch. + */ +function applyUpdates(updates) { + updates.forEach((update) => { + let content = fs.readFileSync(update.file, "utf-8"); + // The update query may contain reserved regex characters + // that needs to be escaped to be considered literally. + let inputString = update.from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); + content = content.replace(new RegExp(inputString, "g"), update.to); + fs.writeFileSync(update.file, content, "utf-8"); + }); + console.log( + `🎉 ${updates.length} update(s) applied.\n👀 Please verify before committing to git.` + ); +} +/** + * Adds ellipis to text beyond a defined length. + * + * @param {string} Text the text to truncate. + * @returns {string} The truncated text. + */ +function truncate(text) { + let length = 30; + if (text.length <= length) return text; + return text.substr(0, 30) + "\u2026"; +} + +module.exports = { + getSolidityFiles, + showUpdates, + getUserConfirmation, + applyUpdates, +}; diff --git a/scripts/powerup.js b/scripts/powerup.js new file mode 100644 index 0000000..5bf3b5a --- /dev/null +++ b/scripts/powerup.js @@ -0,0 +1,53 @@ +const fs = require("fs"); +const { LATEST_SOLIDITY_VERSION } = require("./config"); +const { + getSolidityFiles, + showUpdates, + getUserConfirmation, + applyUpdates, +} = require("./io"); + +/** + * Powerup: Updates solidity version to `LATEST_SOLIDITY_VERSION`. + */ +async function powerup() { + const updates = []; + + for (let filePath of getSolidityFiles()) { + const oldVersion = getSolidityVersion(filePath); + if (!oldVersion) { + console.log(`Could not determine Solidity version in ${filePath}`); + continue; + } + + if (oldVersion != LATEST_SOLIDITY_VERSION) { + updates.push({ + scope: "Solidity version", + file: filePath, + from: oldVersion, + to: LATEST_SOLIDITY_VERSION, + }); + } + } + + if (updates.length > 0) { + showUpdates(updates); + const confirmation = await getUserConfirmation( + "Do you want to upgrade these file(s) to the latest Solidity version?" + ); + if (confirmation) applyUpdates(updates); + } else { + console.log( + `🎉 All files are already on the latest Solidity version (${LATEST_SOLIDITY_VERSION})!` + ); + } +} + +function getSolidityVersion(filePath) { + const content = fs.readFileSync(filePath, "utf-8"); + const versionMatch = content.match(/pragma solidity (\^)?(\d+\.\d+\.\d+);/); + + return versionMatch ? versionMatch[2] : null; +} + +powerup(); diff --git a/scripts/rebrand.js b/scripts/rebrand.js new file mode 100644 index 0000000..2d2a931 --- /dev/null +++ b/scripts/rebrand.js @@ -0,0 +1,63 @@ +const fs = require("fs"); +const { + getSolidityFiles, + showUpdates, + getUserConfirmation, + applyUpdates, +} = require("./io"); + +/** + * Rebrand: Migrate branding from solady to soledge. + * Currently, only comments are being rebranded. + */ +async function rebrand() { + const updates = []; + const COMMENT_MAPPING = [ + { + from: "/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/", + to: "/*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/", + }, + { + from: "/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/", + to: "/*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/", + }, + ]; + + for (let filePath of getSolidityFiles()) { + for (let patch of COMMENT_MAPPING) { + if (fileContainsPattern(filePath, patch.from)) { + updates.push({ + scope: "soledge branding", + file: filePath, + from: patch.from, + to: patch.to, + }); + } + } + } + + if (updates.length > 0) { + showUpdates(updates); + const confirmation = await getUserConfirmation( + "Confirm applying the proposed branding updates?" + ); + if (confirmation) applyUpdates(updates); + } else { + console.log(`🎉 All files already adheres to soledge branding guidelines.`); + } +} + +function fileContainsPattern(filePath, pattern) { + const content = fs.readFileSync(filePath, "utf-8"); + + // Escape regex special characters from pattern + pattern = pattern.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); + + // Use the escaped pattern in the regex match + const regex = new RegExp(pattern); + + // Check if the content matches the pattern + return regex.test(content); +} + +rebrand(); From d5980e9eb5fca360041cbd8732982cc6bdad1df9 Mon Sep 17 00:00:00 2001 From: atarpara Date: Wed, 7 Feb 2024 11:04:20 +0530 Subject: [PATCH 2/4] =?UTF-8?q?=E2=99=BB=20Refactor/Cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/config.js | 11 --- scripts/io.js | 109 ---------------------- scripts/ladytoedge.js | 209 ++++++++++++++++++++++++++++++++++++++++++ scripts/powerup.js | 53 ----------- scripts/rebrand.js | 63 ------------- 5 files changed, 209 insertions(+), 236 deletions(-) delete mode 100644 scripts/config.js delete mode 100644 scripts/io.js create mode 100644 scripts/ladytoedge.js delete mode 100644 scripts/powerup.js delete mode 100644 scripts/rebrand.js diff --git a/scripts/config.js b/scripts/config.js deleted file mode 100644 index 9e74d89..0000000 --- a/scripts/config.js +++ /dev/null @@ -1,11 +0,0 @@ -/*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ -/* CONFIGS */ -/*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ - -const LATEST_SOLIDITY_VERSION = "0.8.24"; -const SRC_DIR = "src"; - -module.exports = { - LATEST_SOLIDITY_VERSION, - SRC_DIR, -}; diff --git a/scripts/io.js b/scripts/io.js deleted file mode 100644 index fe71541..0000000 --- a/scripts/io.js +++ /dev/null @@ -1,109 +0,0 @@ -const fs = require("fs"); -const path = require("path"); -const { SRC_DIR } = require("./config"); -/*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ -/* I/O Helpers */ -/*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ - -/** - * Recursively retrieves a list of Solidity files within a given directory. - * - * @param {string} directory - The root directory to search for Solidity files. Defaults to SRC_DIR. - * @param {string[]} fileList - An optional array to accumulate file paths (used for recursion). - * @returns {string[]} An array of Solidity file paths. - */ -function getSolidityFiles(directory = SRC_DIR, fileList = []) { - const files = fs.readdirSync(directory); - - files.forEach((file) => { - const filePath = path.join(directory, file); - - if (fs.statSync(filePath).isDirectory()) { - getSolidityFiles(filePath, fileList); - } else if (file.endsWith(".sol")) { - fileList.push(filePath); - } - }); - return fileList; -} - -/** - * Shows the updates to be applied as a table. - * - * @param {Update[]} updates - An array of update objects containing scope, file paths, pattern, and patch. - */ -async function showUpdates(updates) { - console.log(`${updates.length} update(s) can be automatically applied:`); - - // Friendly table heading. - updates = updates.map((update) => ({ - "Update type": update.scope, - File: update.file, - "Current value": truncate(update.from), - "Proposed change": truncate(update.to), - })); - - // Increasing index so it starts from 1 instead of 0. - updates = updates.reduce((acc, u, i) => { - acc[i + 1] = u; - return acc; - }, {}); - - console.table(updates); -} - -/** - * Prompts the user for confirmation with a yes/no question. - * - * @param {string} prompt - The question to ask the user. - * @returns {Promise} A Promise that resolves to true if the user confirms, false otherwise. - */ -async function getUserConfirmation(prompt) { - const rl = require("readline").createInterface({ - input: process.stdin, - output: process.stdout, - }); - - const answer = await new Promise((resolve) => { - rl.question(`${prompt} (y/n): `, resolve); - }); - rl.close(); - return answer.toLowerCase() === "y"; -} - -/** - * Applies updates to specified files. - * - * @param {Update[]} updates - An array of update objects containing scope, file paths, pattern, and patch. - */ -function applyUpdates(updates) { - updates.forEach((update) => { - let content = fs.readFileSync(update.file, "utf-8"); - // The update query may contain reserved regex characters - // that needs to be escaped to be considered literally. - let inputString = update.from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); - content = content.replace(new RegExp(inputString, "g"), update.to); - fs.writeFileSync(update.file, content, "utf-8"); - }); - console.log( - `🎉 ${updates.length} update(s) applied.\n👀 Please verify before committing to git.` - ); -} -/** - * Adds ellipis to text beyond a defined length. - * - * @param {string} Text the text to truncate. - * @returns {string} The truncated text. - */ -function truncate(text) { - let length = 30; - if (text.length <= length) return text; - return text.substr(0, 30) + "\u2026"; -} - -module.exports = { - getSolidityFiles, - showUpdates, - getUserConfirmation, - applyUpdates, -}; diff --git a/scripts/ladytoedge.js b/scripts/ladytoedge.js new file mode 100644 index 0000000..087e1c4 --- /dev/null +++ b/scripts/ladytoedge.js @@ -0,0 +1,209 @@ +const fs = require("fs"); +const path = require("path"); + +/* Configurations */ +let LATEST_SOLIDITY_VERSION = "0.8.24"; +const SRC_DIR = "src"; + +/* I/O Helpers */ +function getSolidityFiles(directory = SRC_DIR, fileList = []) { + const files = fs.readdirSync(directory); + + files.forEach((file) => { + const filePath = path.join(directory, file); + + if (fs.statSync(filePath).isDirectory()) { + getSolidityFiles(filePath, fileList); + } else if (file.endsWith(".sol")) { + fileList.push(filePath); + } + }); + return fileList; +} + +function showUpdates(updates) { + console.log(`${updates.length} update(s) can be automatically applied:`); + console.table(updates); +} + +function getUserConfirmation(prompt) { + const rl = require("readline").createInterface({ + input: process.stdin, + output: process.stdout, + }); + + return new Promise((resolve) => { + rl.question(`${prompt} (y/n): `, (answer) => { + rl.close(); + resolve(answer.toLowerCase() === "y"); + }); + }); +} + +function applyUpdates(updates) { + updates.forEach((update) => { + let content = fs.readFileSync(update.file, "utf-8"); + let inputString = update.from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); + content = content.replace(new RegExp(inputString, "g"), update.to); + fs.writeFileSync(update.file, content, "utf-8"); + }); + console.log( + `🎉 ${updates.length} update(s) applied.\n👀 Please verify before committing to git.` + ); +} + +function getSolidityVersion(filePath) { + const content = fs.readFileSync(filePath, "utf-8"); + const versionMatch = content.match(/pragma solidity (\^)?(\d+\.\d+\.\d+);/); + return versionMatch ? versionMatch[2] : null; +} + +// migrating solidity version +async function powerup(fileOrDir = SRC_DIR, subCommand, version) { + if (subCommand === "--solc") { + updateSolcVersion(version); + } + const updates = []; + let solidityFiles = []; + + if (fs.lstatSync(fileOrDir).isDirectory()) { + solidityFiles = getSolidityFiles(fileOrDir); + } + else { + if (fileOrDir.endsWith(".sol")) { + solidityFiles.push(fileOrDir); + } else { + console.error("Please provide a valid Solidity file or directory."); + return; + } + } + + + for (const filePath of solidityFiles) { + const oldVersion = getSolidityVersion(filePath); + if (!oldVersion) { + console.log(`Could not determine Solidity version in ${filePath}`); + continue; + } + + if (oldVersion != LATEST_SOLIDITY_VERSION) { + updates.push({ + scope: "Solidity version", + file: filePath, + from: oldVersion, + to: LATEST_SOLIDITY_VERSION, + }); + } + } + + if (updates.length > 0) { + showUpdates(updates); + const confirmation = await getUserConfirmation( + "Do you want to upgrade these file(s) to the latest Solidity version?" + ); + if (confirmation) applyUpdates(updates); + } else { + console.log( + `🎉 All files are already on the latest Solidity version (${LATEST_SOLIDITY_VERSION})!` + ); + } +} + +// migrating solady brand to soledge +async function rebrand(fileOrDir = SRC_DIR) { + const updates = []; + const COMMENT_MAPPING = [ + { + from: "/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/", + to: "/*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/", + }, + { + from: "/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/", + to: "/*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/", + }, + ]; + + + let solidityFiles = []; + + if (fs.lstatSync(fileOrDir).isDirectory()) { + solidityFiles = getSolidityFiles(fileOrDir); + } else { + if (fileOrDir.endsWith(".sol")) { + solidityFiles.push(fileOrDir); + } else { + console.error("Please provide a valid Solidity file or directory."); + return; + } + } + + if (solidityFiles.length === 0) { + console.error("No Solidity files found in the specified directory."); + return; + } + + for (let filePath of solidityFiles) { + for (let patch of COMMENT_MAPPING) { + if (fileContainsPattern(filePath, patch.from)) { + updates.push({ + scope: "soledge branding", + file: filePath, + from: patch.from, + to: patch.to, + }); + } + } + } + + if (updates.length > 0) { + showUpdates(updates); + const confirmation = await getUserConfirmation( + "Confirm applying the proposed branding updates?" + ); + if (confirmation) applyUpdates(updates); + } else { + console.log( + `🎉 All files already adhere to soledge branding guidelines.` + ); + } + + function fileContainsPattern(filePath, pattern) { + const content = fs.readFileSync(filePath, "utf-8"); + + // Escape regex special characters from pattern + pattern = pattern.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); + + // Use the escaped pattern in the regex match + const regex = new RegExp(pattern); + + // Check if the content matches the pattern + return regex.test(content); + } + +} + +function updateSolcVersion(version) { + LATEST_SOLIDITY_VERSION = version; +} + +const args = process.argv.slice(2); +const command = args[0]; +const fileOrDir = args[1]; +const subCommand = args[2]; +const version = args[3]; + +if (command === "--powerup") { + powerup(fileOrDir, subCommand, version); +} +else if (command === "--rebrand") { + rebrand(fileOrDir); +} +else { + console.error("Invalid command.\n"); + console.log("Usage: node ladytoedge.js "); + console.log("Available commands:"); + console.log("--rebrand "); + console.log("--powerup --solc "); + process.exit(1); + +} diff --git a/scripts/powerup.js b/scripts/powerup.js deleted file mode 100644 index 5bf3b5a..0000000 --- a/scripts/powerup.js +++ /dev/null @@ -1,53 +0,0 @@ -const fs = require("fs"); -const { LATEST_SOLIDITY_VERSION } = require("./config"); -const { - getSolidityFiles, - showUpdates, - getUserConfirmation, - applyUpdates, -} = require("./io"); - -/** - * Powerup: Updates solidity version to `LATEST_SOLIDITY_VERSION`. - */ -async function powerup() { - const updates = []; - - for (let filePath of getSolidityFiles()) { - const oldVersion = getSolidityVersion(filePath); - if (!oldVersion) { - console.log(`Could not determine Solidity version in ${filePath}`); - continue; - } - - if (oldVersion != LATEST_SOLIDITY_VERSION) { - updates.push({ - scope: "Solidity version", - file: filePath, - from: oldVersion, - to: LATEST_SOLIDITY_VERSION, - }); - } - } - - if (updates.length > 0) { - showUpdates(updates); - const confirmation = await getUserConfirmation( - "Do you want to upgrade these file(s) to the latest Solidity version?" - ); - if (confirmation) applyUpdates(updates); - } else { - console.log( - `🎉 All files are already on the latest Solidity version (${LATEST_SOLIDITY_VERSION})!` - ); - } -} - -function getSolidityVersion(filePath) { - const content = fs.readFileSync(filePath, "utf-8"); - const versionMatch = content.match(/pragma solidity (\^)?(\d+\.\d+\.\d+);/); - - return versionMatch ? versionMatch[2] : null; -} - -powerup(); diff --git a/scripts/rebrand.js b/scripts/rebrand.js deleted file mode 100644 index 2d2a931..0000000 --- a/scripts/rebrand.js +++ /dev/null @@ -1,63 +0,0 @@ -const fs = require("fs"); -const { - getSolidityFiles, - showUpdates, - getUserConfirmation, - applyUpdates, -} = require("./io"); - -/** - * Rebrand: Migrate branding from solady to soledge. - * Currently, only comments are being rebranded. - */ -async function rebrand() { - const updates = []; - const COMMENT_MAPPING = [ - { - from: "/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/", - to: "/*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/", - }, - { - from: "/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/", - to: "/*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/", - }, - ]; - - for (let filePath of getSolidityFiles()) { - for (let patch of COMMENT_MAPPING) { - if (fileContainsPattern(filePath, patch.from)) { - updates.push({ - scope: "soledge branding", - file: filePath, - from: patch.from, - to: patch.to, - }); - } - } - } - - if (updates.length > 0) { - showUpdates(updates); - const confirmation = await getUserConfirmation( - "Confirm applying the proposed branding updates?" - ); - if (confirmation) applyUpdates(updates); - } else { - console.log(`🎉 All files already adheres to soledge branding guidelines.`); - } -} - -function fileContainsPattern(filePath, pattern) { - const content = fs.readFileSync(filePath, "utf-8"); - - // Escape regex special characters from pattern - pattern = pattern.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); - - // Use the escaped pattern in the regex match - const regex = new RegExp(pattern); - - // Check if the content matches the pattern - return regex.test(content); -} - -rebrand(); From 7e5ae7ba534d0f0e2aabd6189a05403c5b453a78 Mon Sep 17 00:00:00 2001 From: atarpara Date: Wed, 7 Feb 2024 11:05:40 +0530 Subject: [PATCH 3/4] =?UTF-8?q?=E2=99=BB=20Cleanup=20package.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 package.json diff --git a/package.json b/package.json deleted file mode 100644 index 7cca55d..0000000 --- a/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "soledge", - "license": "MIT", - "version": "0.0.5", - "description": "Edgelord Solidity snippets.", - "scripts": { - "powerup": "node scripts/powerup.js", - "rebrand": "node scripts/rebrand.js" - }, - "files": [ - "src/**/*.sol" - ], - "repository": { - "type": "git", - "url": "git+https://github.com/vectorized/soledge.git" - } -} From b322e9735e7f0bdca1e83910542f7c40f9283039 Mon Sep 17 00:00:00 2001 From: atarpara Date: Wed, 7 Feb 2024 11:11:57 +0530 Subject: [PATCH 4/4] =?UTF-8?q?=E2=99=BB=20Update=20Script=20Uses?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ladytoedge.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/scripts/ladytoedge.js b/scripts/ladytoedge.js index 087e1c4..69c4cf8 100644 --- a/scripts/ladytoedge.js +++ b/scripts/ladytoedge.js @@ -169,17 +169,17 @@ async function rebrand(fileOrDir = SRC_DIR) { function fileContainsPattern(filePath, pattern) { const content = fs.readFileSync(filePath, "utf-8"); - + // Escape regex special characters from pattern pattern = pattern.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); - + // Use the escaped pattern in the regex match const regex = new RegExp(pattern); - + // Check if the content matches the pattern return regex.test(content); - } - + } + } function updateSolcVersion(version) { @@ -199,11 +199,10 @@ else if (command === "--rebrand") { rebrand(fileOrDir); } else { - console.error("Invalid command.\n"); - console.log("Usage: node ladytoedge.js "); + console.error("Invalid command."); + console.log("Usage: node script.js "); console.log("Available commands:"); - console.log("--rebrand "); - console.log("--powerup --solc "); + console.log("--rebrand (default: src/"); + console.log("--powerup (default: src/) --solc (default: 0.8.24)"); process.exit(1); - }