Created
December 24, 2019 09:50
-
-
Save andreiglingeanu/a6a28da8b5e4f8c1c28aa3f7bd5872db to your computer and use it in GitHub Desktop.
This file contains 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
// Make all variables dashed-case | |
// USAGE: | |
// ack -l -- '--\b' | xargs node replace-vars.js | |
const { readFileSync, writeFileSync } = require('fs') | |
const [_, __, ...files] = process.argv | |
console.log(files) | |
const camelCaseToDash = myStr => | |
myStr.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase() | |
files | |
.filter(f => f !== 'LICENSE') | |
.map(file => { | |
const contents = readFileSync(file).toString() | |
const newContents = contents.replace( | |
/--(\w+)/g, | |
(match, p1) => `--${camelCaseToDash(p1)}` | |
) | |
writeFileSync(file, newContents) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment