mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Simplified checkUpToDate() and added getLastModified()
This commit is contained in:
parent
2843f29c81
commit
e49d0f31cb
@ -30,6 +30,7 @@ var ElementNode = require('./ElementNode');
|
||||
var TextNode = require('./TextNode');
|
||||
var TagHandlerNode = require('../taglibs/core/TagHandlerNode');
|
||||
var raptorModulesResolver = require('raptor-modules/resolver');
|
||||
var fs = require('fs');
|
||||
|
||||
function TemplateCompiler(path, options) {
|
||||
this.dirname = nodePath.dirname(path);
|
||||
@ -239,13 +240,37 @@ TemplateCompiler.prototype = {
|
||||
return new TextNode(text, escapeXml);
|
||||
},
|
||||
|
||||
checkUpToDate: function(sourceFile, targetFile) {
|
||||
getLastModified: function() {
|
||||
var sourceFile = this.path;
|
||||
|
||||
var statSource = fs.statSync(sourceFile);
|
||||
|
||||
var lastModifiedTime = statSource.mtime.getTime();
|
||||
|
||||
var taglibFiles = this.taglibs.getInputFiles();
|
||||
var len = taglibFiles.length;
|
||||
for (var i=0; i<len; i++) {
|
||||
var taglibFileStat;
|
||||
var taglibFile = taglibFiles[i];
|
||||
|
||||
try {
|
||||
taglibFileStat = fs.statSync(taglibFile);
|
||||
} catch(e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lastModifiedTime = Math.max(lastModifiedTime, taglibFileStat.mtime.getTime());
|
||||
}
|
||||
|
||||
return lastModifiedTime;
|
||||
},
|
||||
|
||||
checkUpToDate: function(targetFile) {
|
||||
if (this.options.checkUpToDate === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
var sourceFile = this.path;
|
||||
|
||||
var statTarget;
|
||||
|
||||
|
||||
@ -84,6 +84,16 @@ extend(exports, {
|
||||
});
|
||||
},
|
||||
|
||||
getLastModified: function(path, options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = null;
|
||||
}
|
||||
|
||||
var compiler = this.createCompiler(path, options);
|
||||
callback(null, compiler.getLastModified());
|
||||
},
|
||||
|
||||
Node: require('./Node'),
|
||||
ElementNode: require('./ElementNode'),
|
||||
TextNode: require('./TextNode'),
|
||||
|
||||
@ -24,7 +24,7 @@ module.exports = function load(templatePath) {
|
||||
|
||||
var targetFile = templatePath + '.js';
|
||||
var compiler = raptorTemplatesCompiler.createCompiler(templatePath);
|
||||
var isUpToDate = compiler.checkUpToDate(templatePath, targetFile);
|
||||
var isUpToDate = compiler.checkUpToDate(targetFile);
|
||||
if (isUpToDate) {
|
||||
return require(targetFile);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user