Skip to content

Commit 063615a

Browse files
authored
Merge pull request #73 from nelsonpecora/master
added ctime option w/ tests, docs
2 parents 94c93ea + 04ffa69 commit 063615a

File tree

3 files changed

+283
-38
lines changed

3 files changed

+283
-38
lines changed

index.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ function Newer(options) {
6969
*/
7070
this._map = options.map;
7171

72+
/**
73+
* Key for the timestamp in files' stats object
74+
* @type {string}
75+
*/
76+
this._timestamp = options.ctime ? 'ctime' : 'mtime';
77+
7278
/**
7379
* Promise for the dest file/directory stats.
7480
* @type {[type]}
@@ -104,6 +110,7 @@ function Newer(options) {
104110

105111
if (options.extra) {
106112
var extraFiles = [];
113+
var timestamp = this._timestamp;
107114
for (var i = 0; i < options.extra.length; ++i) {
108115
extraFiles.push(Q.nfcall(glob, options.extra[i]));
109116
}
@@ -125,7 +132,7 @@ function Newer(options) {
125132
// We get all the file stats here; find the *latest* modification.
126133
var latestStat = resolvedStats[0];
127134
for (var j = 1; j < resolvedStats.length; ++j) {
128-
if (resolvedStats[j].mtime > latestStat.mtime) {
135+
if (resolvedStats[j][timestamp] > latestStat[timestamp]) {
129136
latestStat = resolvedStats[j];
130137
}
131138
}
@@ -194,10 +201,15 @@ Newer.prototype._transform = function(srcFile, encoding, done) {
194201
}
195202
})
196203
.spread(function(destFileStats, extraFileStats) {
197-
var newer = !destFileStats || srcFile.stat.mtime > destFileStats.mtime;
204+
var timestamp = self._timestamp;
205+
var newer =
206+
!destFileStats || srcFile.stat[timestamp] > destFileStats[timestamp];
198207
// If *any* extra file is newer than a destination file, then ALL
199208
// are newer.
200-
if (extraFileStats && extraFileStats.mtime > destFileStats.mtime) {
209+
if (
210+
extraFileStats &&
211+
extraFileStats[timestamp] > destFileStats[timestamp]
212+
) {
201213
newer = true;
202214
}
203215
if (self._all) {

readme.md

+3
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,14 @@ gulp.task('concat', function() {
7171
* **options.ext** - `string` Source files will be matched to destination files with the provided extension (e.g. '.css').
7272
* **options.map** - `function` Map relative source paths to relative destination paths (e.g. `function(relativePath) { return relativePath + '.bak'; }`)
7373
* **options.extra** - `string` or `array` An extra file, file glob, or list of extra files and/or globs, to check for updated time stamp(s). If any of these files are newer than the destination files, then all source files will be passed into the stream.
74+
* **options.ctime** - `boolean` Source files will be matched to destination files based on `ctime` rather than `mtime`.
7475

7576
Create a [transform stream](http://nodejs.org/api/stream.html#stream_class_stream_transform_1) that passes through files whose modification time is more recent than the corresponding destination file's modification time.
7677

7778
If `dest` is a directory path, the `newer` stream will check for files in the destination directory with the same relative path as source files. Source files that have been modified more recently than the resolved destination file will be passed through. If the `dest` directory or resolved destination file does not exist, all source files will be passed through.
7879

7980
If `dest` is a file path, the `newer` stream will pass through *all* files if *any one* of them has been modified more recently than the destination file. If the `dest` file does not exist, all source files will be passed through.
8081

82+
By default, the `newer` stream will check files' *modification time*, or `mtime`, which updates when the file contents are changed. If `ctime` is `true`, files' *change time* will be checked instead, which updates when file contents or attributes like the file name or permissions have changed.
83+
8184
[![Current Status](https://secure.travis-ci.org/tschaub/gulp-newer.png?branch=master)](https://travis-ci.org/tschaub/gulp-newer)

0 commit comments

Comments
 (0)