Created
May 24, 2013 16:53
-
-
Save ForbesLindesay/5644882 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
| var fs = require('fs') | |
| var read = fs.readFileSync | |
| var write = fs.writeFileSync | |
| var readdir = fs.readdirSync | |
| var stat = fs.statSync | |
| var path = require('path') | |
| var join = path.join | |
| var relative = path.relative | |
| processDir(process.cwd()) | |
| function processDir(dir) { | |
| readdir(dir) | |
| .forEach(function (sub) { | |
| var path = join(dir, sub) | |
| if (stat(path).isDirectory()) { | |
| processDir(path) | |
| } else if (/\.jade$/.test(path)) { | |
| processFile(path) | |
| } | |
| }) | |
| } | |
| function processFile(file) { | |
| var src = read(file).toString() | |
| var replacements = 0 | |
| if (/^(\s*style\b.*)$/gm.test(src)) { | |
| src = src.replace(/^(\s*style\b.*)$/gm, function (_, line) { | |
| if (!/\.$/.test(line)) { | |
| replacements++ | |
| return line + '.' | |
| } | |
| }) | |
| } | |
| if (/^(\s*script\b.*)$/gm.test(src)) { | |
| src = src.replace(/^(\s*script\b.*)$/gm, function (_, line) { | |
| if (!/\.$/.test(line) && !/src=/.test(line) && (!/type=/.test(line) || !/type=("|')text\/javascript('|")/.test(line))) { | |
| replacements++ | |
| return line + '.' | |
| } | |
| }) | |
| } | |
| var name = relative(process.cwd(), file) | |
| console.log(name + ' => ' + replacements) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment