Last active
August 29, 2015 14:14
-
-
Save mgrandrath/f4cef28c219dc9df7f58 to your computer and use it in GitHub Desktop.
Lint a list of files with Jake.js
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
"use strict"; | |
var TOUCH_DIR_PREFIX = "generated/lint/"; | |
var path = require("path"); | |
var touchFiles = filesToLint().map(touchFileName); | |
var touchDirs = uniqify(touchFiles.map(path.dirname)); | |
touchDirs.forEach(directory); // this is Jake's `directory` task | |
task("lint", touchDirs.concat(touchFiles)); | |
rule(".lint", sourceFileName, lintRule); | |
function filesToLint() { | |
var javascriptFiles = new jake.FileList(); | |
javascriptFiles.include("src/**/*.js"); | |
// ... more patterns | |
return javascriptFiles.toArray(); | |
} | |
function touchFileName(jsFile) { | |
return TOUCH_DIR_PREFIX + jsFile.replace(/\.js$/, ".lint"); | |
} | |
function sourceFileName(touchFile) { | |
var prefix = new RegExp("^" + TOUCH_DIR_PREFIX); | |
var suffix = new RegExp("\\.lint$"); | |
return touchFile | |
.replace(prefix, "") | |
.replace(suffix, ".js"); | |
} | |
function lintRule() { | |
var fs = require("fs"); | |
if (yourLintFunction(this.source)) { | |
fs.writeFileSync(this.name, "lint ok"); | |
} | |
else { | |
fail("Lint failed"); | |
} | |
} | |
function uniqify(array) { | |
return array.reduce(function (result, value) { | |
return (result.indexOf(value) < 0) ? | |
result.concat(value) : | |
result; | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment