Created
January 23, 2021 13:48
-
-
Save tobspr/fe87d9be048d695e357e85b67a8b7ee8 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