clearModules.js
1 const fs = require("fs"); 2 3 const clearModules = (filePath) => { 4 if (fs.existsSync(filePath)) { 5 let fileContent = fs.readFileSync(filePath, "utf8"); 6 fileContent = fileContent.replace(/require\s*\([\s\S]*?\)/, ""); 7 fs.writeFileSync(filePath, fileContent, "utf8"); 8 } else { 9 console.log("File does not exist."); 10 } 11 }; 12 13 clearModules("go.mod"); 14 clearModules("exampleSite/go.mod");