-
-
Save chinhvo/3cae41ecad4a1b2aec5b64c129fb098d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const path = require("path"); | |
function fixFile(filepath) { | |
const contents = fs.readFileSync(filepath, "utf-8"); | |
const matcher = /([0-9]+(?:\.[0-9]+)?)rem/igm; | |
const result = contents.replaceAll(matcher, (substr, size) => { | |
const rem = Number(size); | |
const px = Math.round(rem * 16); | |
console.log(substr, "->", size, "->", px); | |
return px + "px"; | |
}); | |
fs.writeFileSync(filepath, result); | |
} | |
function fixFolder(folder) { | |
const files = fs.readdirSync(folder); | |
for (const file of files) { | |
if (file === "node_modules") { | |
continue; | |
} | |
const abspath = path.join(folder, file); | |
if (file.endsWith(".scss") || file.endsWith(".vue")) { | |
fixFile(abspath); | |
} else if (fs.lstatSync(abspath).isDirectory()) { | |
fixFolder(abspath); | |
} | |
} | |
} | |
fixFolder("."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment