mirror of
https://github.com/bobwen-dev/react-templates
synced 2025-04-12 00:56:39 +02:00
check for stale files
This commit is contained in:
parent
1ed5eb873e
commit
80d9a901fc
@ -263,6 +263,13 @@ function convertFile(source, target) {
|
||||
// console.log('invalid file, only handle html files');
|
||||
// return;// only handle html files
|
||||
// }
|
||||
var util = require('./util');
|
||||
|
||||
if (!util.isStale(source, target)) {
|
||||
console.log('target file ' + target + ' is up to date, skipping');
|
||||
// return;
|
||||
}
|
||||
|
||||
var html = fs.readFileSync(source).toString();
|
||||
if (!html.match(/\<\!doctype jsx/i)) {
|
||||
throw new Error('invalid file, missing header');
|
||||
|
21
src/util.js
Normal file
21
src/util.js
Normal file
@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
/**
|
||||
* @param {string} source
|
||||
* @param {string} target
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isStale(source, target) {
|
||||
if (!fs.existsSync(target)) {
|
||||
return true;
|
||||
}
|
||||
var sourceTime = fs.statSync(source).mtime;
|
||||
var targetTime = fs.statSync(target).mtime;
|
||||
return sourceTime.getTime() > targetTime.getTime();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isStale: isStale
|
||||
};
|
@ -56,3 +56,21 @@ test('html tests', function (t) {
|
||||
|
||||
});
|
||||
|
||||
test('util.isStale', function (t) {
|
||||
t.plan(2);
|
||||
var a = path.join(dataPath, 'a.tmp');
|
||||
var b = path.join(dataPath, 'b.tmp');
|
||||
|
||||
var mtime1 = new Date(1995, 11, 17, 3, 24, 0);
|
||||
fs.utimesSync(a, mtime1, mtime1);
|
||||
|
||||
var mtime2 = new Date(1995, 11, 17, 3, 24, 1);
|
||||
fs.utimesSync(b, mtime2, mtime2);
|
||||
|
||||
var util = require('../../src/util');
|
||||
var actual = util.isStale(a, b);
|
||||
t.equal(actual, false);
|
||||
actual = util.isStale(b, a);
|
||||
t.equal(actual, true);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user