Last active
March 17, 2016 15:04
-
-
Save BorisChumichev/92fefc18a379fa2fe202 to your computer and use it in GitHub Desktop.
Inserts colons to stylus code
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
var fs = require('fs') | |
, filesToCorrect = process.argv.length - 2 | |
, addColonsToFile = function (pathToFile) { | |
try { | |
var code = fs.readFileSync(pathToFile).toString() | |
, stringsToReplace = code.match(/^\s*(?!for)([a-z-]*)\b\s+[^:=]/gm) | |
} catch(e) { | |
console.log('error while reading: ' + pathToFile) | |
} | |
if (stringsToReplace === null) return | |
stringsToReplace.forEach(function(stringToReplace) { | |
var newString = stringToReplace.replace(/^\s*([a-z-]*)\b/, | |
stringToReplace.match(/^\s*[a-z-]*\b/) + ':' ) | |
code = code.replace(stringToReplace, newString) | |
}) | |
fs.writeFileSync(pathToFile, code) | |
console.log('completed: ' + pathToFile + ', with ' + stringsToReplace.length +' rows affected') | |
} | |
if (filesToCorrect !== 0) | |
while(filesToCorrect--) | |
addColonsToFile(process.argv[filesToCorrect + 2]) |
I would recommend replacing the stringsToReplace regex with /^\s*(?!for)([a-z-]*)\b[ \t]+[^:=\n]/gm
to account for tag selectors such as
a
font-size 1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run tool:
node insert-colons-to-my-styl-please.js ./*.styl