Last active
August 29, 2015 14:21
-
-
Save nwade/863ef19284b012a7f73f to your computer and use it in GitHub Desktop.
How to get grunt-newer to compile parent jade templates that include modified templates
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
grunt.initConfig({ | |
// ... | |
newer: { | |
options: { | |
override: function (detail, include) { | |
if (detail.task === 'jade') { | |
checkForNewerImports(detail.path, detail.time, include); | |
} else { | |
include(false); | |
} | |
} | |
} | |
}, | |
watch: { | |
jade: { | |
files: ['<%= yeoman.app %>/**/*.jade'], | |
tasks: ['newer:jade'] | |
}, | |
// ... | |
}, | |
// ... | |
}); | |
// ... | |
var fs = require('fs'); | |
var path = require('path'); | |
function checkForNewerImports(jadeFile, mTime, include) { | |
fs.readFile(jadeFile, 'utf8', function (err, data) { | |
var jadeDir = path.dirname(jadeFile), | |
// be careful with this regex - specific to my project's needs - change as needed. | |
regex = /include (.+)/g, | |
shouldInclude = false, | |
match; | |
while ((match = regex.exec(data)) !== null) { | |
var importFile = jadeDir + '/' + match[1] + '.jade'; | |
if (fs.existsSync(importFile)) { | |
var stat = fs.statSync(importFile); | |
if (stat.mtime > mTime) { | |
shouldInclude = true; | |
break; | |
} | |
} | |
} | |
include(shouldInclude); | |
}); | |
} | |
// ... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment