pax_global_header00006660000000000000000000000064131025122060014502gustar00rootroot0000000000000052 comment=f5ca0904624690e765fa3d350add96bb3aa24126 gulp-changed-3.1.0/000077500000000000000000000000001310251220600140415ustar00rootroot00000000000000gulp-changed-3.1.0/.editorconfig000066400000000000000000000002761310251220600165230ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [{package.json,*.yml}] indent_style = space indent_size = 2 gulp-changed-3.1.0/.gitattributes000066400000000000000000000000351310251220600167320ustar00rootroot00000000000000* text=auto *.js text eol=lf gulp-changed-3.1.0/.gitignore000066400000000000000000000000151310251220600160250ustar00rootroot00000000000000node_modules gulp-changed-3.1.0/.travis.yml000066400000000000000000000000671310251220600161550ustar00rootroot00000000000000sudo: false language: node_js node_js: - '6' - '4' gulp-changed-3.1.0/fixture/000077500000000000000000000000001310251220600155275ustar00rootroot00000000000000gulp-changed-3.1.0/fixture/different.ext/000077500000000000000000000000001310251220600202745ustar00rootroot00000000000000gulp-changed-3.1.0/fixture/different.ext/src/000077500000000000000000000000001310251220600210635ustar00rootroot00000000000000gulp-changed-3.1.0/fixture/different.ext/src/a.typescript000066400000000000000000000000011310251220600234220ustar00rootroot00000000000000agulp-changed-3.1.0/fixture/different.ext/src/b.typescript000066400000000000000000000000011310251220600234230ustar00rootroot00000000000000bgulp-changed-3.1.0/fixture/different.ext/trg/000077500000000000000000000000001310251220600210705ustar00rootroot00000000000000gulp-changed-3.1.0/fixture/different.ext/trg/a.coffee000066400000000000000000000000011310251220600224500ustar00rootroot00000000000000agulp-changed-3.1.0/fixture/different.ext/trg/b.coffee000066400000000000000000000000021310251220600224520ustar00rootroot00000000000000b!gulp-changed-3.1.0/fixture/different.transformPath/000077500000000000000000000000001310251220600223245ustar00rootroot00000000000000gulp-changed-3.1.0/fixture/different.transformPath/src/000077500000000000000000000000001310251220600231135ustar00rootroot00000000000000gulp-changed-3.1.0/fixture/different.transformPath/src/a000066400000000000000000000000021310251220600232460ustar00rootroot00000000000000a gulp-changed-3.1.0/fixture/different.transformPath/src/b000066400000000000000000000000021310251220600232470ustar00rootroot00000000000000b gulp-changed-3.1.0/fixture/different.transformPath/trg/000077500000000000000000000000001310251220600231205ustar00rootroot00000000000000gulp-changed-3.1.0/fixture/different.transformPath/trg/c/000077500000000000000000000000001310251220600233425ustar00rootroot00000000000000gulp-changed-3.1.0/fixture/different.transformPath/trg/c/a000066400000000000000000000000021310251220600234750ustar00rootroot00000000000000a gulp-changed-3.1.0/fixture/different.transformPath/trg/c/b000066400000000000000000000000031310251220600234770ustar00rootroot00000000000000b! gulp-changed-3.1.0/fixture/different/000077500000000000000000000000001310251220600174755ustar00rootroot00000000000000gulp-changed-3.1.0/fixture/different/src/000077500000000000000000000000001310251220600202645ustar00rootroot00000000000000gulp-changed-3.1.0/fixture/different/src/a000066400000000000000000000000011310251220600204160ustar00rootroot00000000000000agulp-changed-3.1.0/fixture/different/src/b000066400000000000000000000000011310251220600204170ustar00rootroot00000000000000bgulp-changed-3.1.0/fixture/different/trg/000077500000000000000000000000001310251220600202715ustar00rootroot00000000000000gulp-changed-3.1.0/fixture/different/trg/a000066400000000000000000000000011310251220600204230ustar00rootroot00000000000000agulp-changed-3.1.0/fixture/different/trg/b000066400000000000000000000000021310251220600204250ustar00rootroot00000000000000b!gulp-changed-3.1.0/fixture/identical/000077500000000000000000000000001310251220600174635ustar00rootroot00000000000000gulp-changed-3.1.0/fixture/identical/src/000077500000000000000000000000001310251220600202525ustar00rootroot00000000000000gulp-changed-3.1.0/fixture/identical/src/a000066400000000000000000000000011310251220600204040ustar00rootroot00000000000000agulp-changed-3.1.0/fixture/identical/src/b000066400000000000000000000000011310251220600204050ustar00rootroot00000000000000bgulp-changed-3.1.0/fixture/identical/trg/000077500000000000000000000000001310251220600202575ustar00rootroot00000000000000gulp-changed-3.1.0/fixture/identical/trg/a000066400000000000000000000000011310251220600204110ustar00rootroot00000000000000agulp-changed-3.1.0/fixture/identical/trg/b000066400000000000000000000000011310251220600204120ustar00rootroot00000000000000bgulp-changed-3.1.0/index.js000066400000000000000000000043431310251220600155120ustar00rootroot00000000000000'use strict'; const fs = require('fs'); const path = require('path'); const gutil = require('gulp-util'); const through = require('through2'); const pify = require('pify'); const readFile = pify(fs.readFile); const stat = pify(fs.stat); // Ignore missing file error function fsOperationFailed(stream, sourceFile, err) { if (err.code !== 'ENOENT') { stream.emit('error', new gutil.PluginError('gulp-changed', err, { fileName: sourceFile.path })); } stream.push(sourceFile); } // Only push through files changed more recently than the destination files function compareLastModifiedTime(stream, sourceFile, targetPath) { return stat(targetPath) .then(targetStat => { if (sourceFile.stat && sourceFile.stat.mtime > targetStat.mtime) { stream.push(sourceFile); } }); } // Only push through files with different contents than the destination files function compareContents(stream, sourceFile, targetPath) { return readFile(targetPath) .then(targetData => { if (sourceFile.isNull() || !sourceFile.contents.equals(targetData)) { stream.push(sourceFile); } }); } module.exports = (dest, opts) => { opts = Object.assign({ cwd: process.cwd(), hasChanged: compareLastModifiedTime }, opts); if (!dest) { throw new gutil.PluginError('gulp-changed', '`dest` required'); } if (opts.transformPath !== undefined && typeof opts.transformPath !== 'function') { throw new gutil.PluginError('gulp-changed', '`opts.transformPath` needs to be a function'); } return through.obj(function (file, enc, cb) { const dest2 = typeof dest === 'function' ? dest(file) : dest; let newPath = path.resolve(opts.cwd, dest2, file.relative); if (opts.extension) { newPath = gutil.replaceExtension(newPath, opts.extension); } if (opts.transformPath) { newPath = opts.transformPath(newPath); if (typeof newPath !== 'string') { throw new gutil.PluginError('gulp-changed', '`opts.transformPath` needs to return a string'); } } opts .hasChanged(this, file, newPath) .catch(err => fsOperationFailed(this, file, err)) .then(() => cb()); }); }; module.exports.compareLastModifiedTime = compareLastModifiedTime; module.exports.compareContents = compareContents; module.exports.compareSha1Digest = compareContents; gulp-changed-3.1.0/license000066400000000000000000000021371310251220600154110ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. gulp-changed-3.1.0/package.json000066400000000000000000000021441310251220600163300ustar00rootroot00000000000000{ "name": "gulp-changed", "version": "3.1.0", "description": "Only pass through changed files", "license": "MIT", "repository": "sindresorhus/gulp-changed", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "contributors": [ { "name": "Alex Gorbatchev", "url": "github.com/alexgorbatchev" }, { "name": "Bo-Yi Wu", "url": "github.com/appleboy" }, { "name": "Milan Gardian", "url": "github.com/milang" } ], "engines": { "node": ">=4" }, "scripts": { "test": "xo && mocha" }, "files": [ "index.js" ], "keywords": [ "gulpplugin", "file", "files", "changed", "newer", "modified", "modification", "updated", "time", "mtime", "stat", "cache", "cached", "passthrough" ], "dependencies": { "gulp-util": "^3.0.0", "pify": "^2.3.0", "through2": "^2.0.0" }, "devDependencies": { "del": "^2.2.2", "get-stream": "^3.0.0", "gulp": "^3.0.0", "mocha": "^3.2.0", "xo": "*" } } gulp-changed-3.1.0/readme.md000066400000000000000000000072061310251220600156250ustar00rootroot00000000000000# gulp-changed [![Build Status](https://travis-ci.org/sindresorhus/gulp-changed.svg?branch=master)](https://travis-ci.org/sindresorhus/gulp-changed) > Only pass through changed files No more wasting precious time on processing unchanged files. By default it's only able to detect whether files in the stream changed. If you require something more advanced like knowing if imports/dependencies changed, create a custom comparator, or use [another plugin](https://github.com/gulpjs/gulp#incremental-builds). ---

⚛ Learn React in just a couple of afternoons with this awesome React course by Wes Bos

--- ## Install ``` $ npm install --save-dev gulp-changed ``` ## Usage ```js const gulp = require('gulp'); const changed = require('gulp-changed'); const ngAnnotate = require('gulp-ng-annotate'); // Just as an example const SRC = 'src/*.js'; const DEST = 'dist'; gulp.task('default', () => gulp.src(SRC) .pipe(changed(DEST)) // `ngAnnotate` will only get the files that // changed since the last time it was run .pipe(ngAnnotate()) .pipe(gulp.dest(DEST)) ); ``` ## API ### changed(destination, [options]) #### destination Type: `string` `Function` Destination directory. Same as you put into `gulp.dest()`. This is needed to be able to compare the current files with the destination files. Can also be a function returning a destination directory path. #### options Type: `Object` ##### cwd Type: `string`
Default: `process.cwd()` Working directory the folder is relative to. ##### extension Type: `string` Extension of the destination files. Useful if it differs from the original, like in the example below: ```js gulp.task('jade', () => gulp.src('src/**/*.jade') .pipe(changed('app', {extension: '.html'})) .pipe(jade()) .pipe(gulp.dest('app')) ); ``` ##### hasChanged Type: `Function`
Default: `changed.compareLastModifiedTime` Function that determines whether the source file is different from the destination file. ###### Built-in comparators - `changed.compareLastModifiedTime` - `changed.compareContents` - `changed.compareSha1Digest` (Deprecated) ###### Example ```js gulp.task('jade', () => gulp.src('src/**/*.jade') .pipe(changed('app', {hasChanged: changed.compareContent})) .pipe(jade()) .pipe(gulp.dest('app')) ); ``` You can also supply a custom comparator function which will receive the following arguments and should return `Promise`. - `stream` *([transform object stream](https://github.com/rvagg/through2#transformfunction))* - Should be used to queue `sourceFile` if it passes some comparison - `sourceFile` *([Vinyl file object](https://github.com/wearefractal/vinyl#file))* - `destPath` *(string)* - Destination for `sourceFile` as an absolute path ##### transformPath Type: `Function` Function to transform the path to the destination file. Should return the absolute path to the (renamed) destination file. Useful if you rename your file later on, like in the below example: ```js gulp.task('marked', () => gulp.src('src/content/about.md') .pipe(changed('dist', {transformPath: newPath => path.join(path.dirname(newPath), path.basename(newPath, '.md'), 'index.html')})) .pipe(marked()) .pipe(rename(newPath => path.join(path.dirname(newPath), path.basename(newPath, '.md'), 'index.html')))) .pipe(gulp.dest('dist')) ); ``` ## In-place change monitoring If you're looking to process source files in-place without any build output (formatting, linting, etc), have a look at [gulp-changed-in-place](https://github.com/alexgorbatchev/gulp-changed-in-place). ## License MIT © [Sindre Sorhus](https://sindresorhus.com) gulp-changed-3.1.0/test.js000066400000000000000000000071731310251220600153660ustar00rootroot00000000000000'use strict'; /* eslint-env mocha */ const fs = require('fs'); const path = require('path'); const assert = require('assert'); const gulp = require('gulp'); const gutil = require('gulp-util'); const del = require('del'); const getStream = require('get-stream'); const changed = require('.'); function test(dest, opts) { let desc = 'should only pass through changed files'; let extension = '.js'; if (opts && opts.extension) { desc += ' using extension ' + opts.extension; extension = opts.extension; } else if (/^\//.test(dest)) { desc += ' with a absolute path'; } else { desc += ' using file extension'; } it(desc, cb => { const stream = changed(dest, opts); const files = []; if (typeof dest === 'function') { dest = 'tmp'; } try { fs.mkdirSync(dest); fs.writeFileSync(path.join(dest, `foo${extension}`), ''); } catch (err) {} stream.on('data', file => { files.push(file); fs.writeFileSync(path.join(dest, file.relative), file); }); stream.on('end', () => { assert.equal(files.length, 1); assert.equal(files[0].relative, 'bar.js'); del.sync(dest); cb(); }); stream.write(new gutil.File({ cwd: __dirname, base: __dirname, path: 'foo.js', contents: Buffer.from(''), stat: { mtime: fs.statSync(path.join(dest, 'foo' + extension)) } })); stream.write(new gutil.File({ base: __dirname, path: 'bar.js', contents: Buffer.from(''), stat: { mtime: new Date() } })); stream.end(); }); } describe('compareLastModifiedTime', () => { describe('using relative dest', () => { test('tmp'); test('tmp', {extension: '.coffee'}); }); describe('using absolute dest', () => { const absTmp = path.resolve(__dirname, 'tmp'); test(absTmp); test(absTmp, {extension: '.coffee'}); }); describe('dest can be a function', () => { test(() => 'tmp'); }); }); describe('compareContents', () => { it('should not pass any files through in identical directories', () => { const stream = gulp.src('fixture/identical/src/*') .pipe(changed('fixture/identical/trg', {hasChanged: changed.compareContents})); return getStream.array(stream).then(files => { assert.equal(files.length, 0); }); }); it('should only pass through changed files using file extension', () => { const stream = gulp.src('fixture/different/src/*') .pipe(changed('fixture/different/trg', {hasChanged: changed.compareContents})); return getStream.array(stream).then(files => { assert.equal(files.length, 1); assert.equal(path.basename(files[0].path), 'b'); }); }); it('should only pass through changed files using transformPath', () => { const stream = gulp.src('fixture/different.transformPath/src/*') .pipe(changed('fixture/different.transformPath/trg', { hasChanged: changed.compareContents, transformPath: newPath => { const pathParsed = path.parse(newPath); return path.join(pathParsed.dir, 'c', pathParsed.base); } })); return getStream.array(stream).then(files => { assert.equal(files.length, 1); assert.equal(path.basename(files[0].path), 'b'); }); }); it('should only pass through changed files using extension .coffee', () => { const stream = gulp.src('fixture/different.ext/src/*') .pipe(changed('fixture/different.ext/trg', { hasChanged: changed.compareContents, extension: '.coffee' })); return getStream.array(stream).then(files => { assert.equal(files.length, 1); assert.equal(path.basename(files[0].path), 'b.typescript'); }); }); }); describe('compareSha1Digest', () => { it('should be an alias for compareContents', () => { assert.equal(changed.compareContents, changed.compareSha1Digest); }); });