pax_global_header00006660000000000000000000000064132217306410014511gustar00rootroot0000000000000052 comment=df7582f848aba597b9e821dbb8507ddd208178d7 gulp-changed-3.2.0/000077500000000000000000000000001322173064100140515ustar00rootroot00000000000000gulp-changed-3.2.0/.editorconfig000066400000000000000000000002571322173064100165320ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 gulp-changed-3.2.0/.gitattributes000066400000000000000000000000351322173064100167420ustar00rootroot00000000000000* text=auto *.js text eol=lf gulp-changed-3.2.0/.gitignore000066400000000000000000000000271322173064100160400ustar00rootroot00000000000000node_modules yarn.lock gulp-changed-3.2.0/.npmrc000066400000000000000000000000231322173064100151640ustar00rootroot00000000000000package-lock=false gulp-changed-3.2.0/.travis.yml000066400000000000000000000000631322173064100161610ustar00rootroot00000000000000language: node_js node_js: - '8' - '6' - '4' gulp-changed-3.2.0/fixture/000077500000000000000000000000001322173064100155375ustar00rootroot00000000000000gulp-changed-3.2.0/fixture/different.ext/000077500000000000000000000000001322173064100203045ustar00rootroot00000000000000gulp-changed-3.2.0/fixture/different.ext/src/000077500000000000000000000000001322173064100210735ustar00rootroot00000000000000gulp-changed-3.2.0/fixture/different.ext/src/a.typescript000066400000000000000000000000011322173064100234320ustar00rootroot00000000000000agulp-changed-3.2.0/fixture/different.ext/src/b.typescript000066400000000000000000000000011322173064100234330ustar00rootroot00000000000000bgulp-changed-3.2.0/fixture/different.ext/trg/000077500000000000000000000000001322173064100211005ustar00rootroot00000000000000gulp-changed-3.2.0/fixture/different.ext/trg/a.coffee000066400000000000000000000000011322173064100224600ustar00rootroot00000000000000agulp-changed-3.2.0/fixture/different.ext/trg/b.coffee000066400000000000000000000000021322173064100224620ustar00rootroot00000000000000b!gulp-changed-3.2.0/fixture/different.transformPath/000077500000000000000000000000001322173064100223345ustar00rootroot00000000000000gulp-changed-3.2.0/fixture/different.transformPath/src/000077500000000000000000000000001322173064100231235ustar00rootroot00000000000000gulp-changed-3.2.0/fixture/different.transformPath/src/a000066400000000000000000000000021322173064100232560ustar00rootroot00000000000000a gulp-changed-3.2.0/fixture/different.transformPath/src/b000066400000000000000000000000021322173064100232570ustar00rootroot00000000000000b gulp-changed-3.2.0/fixture/different.transformPath/trg/000077500000000000000000000000001322173064100231305ustar00rootroot00000000000000gulp-changed-3.2.0/fixture/different.transformPath/trg/c/000077500000000000000000000000001322173064100233525ustar00rootroot00000000000000gulp-changed-3.2.0/fixture/different.transformPath/trg/c/a000066400000000000000000000000021322173064100235050ustar00rootroot00000000000000a gulp-changed-3.2.0/fixture/different.transformPath/trg/c/b000066400000000000000000000000031322173064100235070ustar00rootroot00000000000000b! gulp-changed-3.2.0/fixture/different/000077500000000000000000000000001322173064100175055ustar00rootroot00000000000000gulp-changed-3.2.0/fixture/different/src/000077500000000000000000000000001322173064100202745ustar00rootroot00000000000000gulp-changed-3.2.0/fixture/different/src/a000066400000000000000000000000011322173064100204260ustar00rootroot00000000000000agulp-changed-3.2.0/fixture/different/src/b000066400000000000000000000000011322173064100204270ustar00rootroot00000000000000bgulp-changed-3.2.0/fixture/different/trg/000077500000000000000000000000001322173064100203015ustar00rootroot00000000000000gulp-changed-3.2.0/fixture/different/trg/a000066400000000000000000000000011322173064100204330ustar00rootroot00000000000000agulp-changed-3.2.0/fixture/different/trg/b000066400000000000000000000000021322173064100204350ustar00rootroot00000000000000b!gulp-changed-3.2.0/fixture/identical/000077500000000000000000000000001322173064100174735ustar00rootroot00000000000000gulp-changed-3.2.0/fixture/identical/src/000077500000000000000000000000001322173064100202625ustar00rootroot00000000000000gulp-changed-3.2.0/fixture/identical/src/a000066400000000000000000000000011322173064100204140ustar00rootroot00000000000000agulp-changed-3.2.0/fixture/identical/src/b000066400000000000000000000000011322173064100204150ustar00rootroot00000000000000bgulp-changed-3.2.0/fixture/identical/trg/000077500000000000000000000000001322173064100202675ustar00rootroot00000000000000gulp-changed-3.2.0/fixture/identical/trg/a000066400000000000000000000000011322173064100204210ustar00rootroot00000000000000agulp-changed-3.2.0/fixture/identical/trg/b000066400000000000000000000000011322173064100204220ustar00rootroot00000000000000bgulp-changed-3.2.0/index.js000066400000000000000000000043631322173064100155240ustar00rootroot00000000000000'use strict'; const fs = require('fs'); const path = require('path'); const replaceExt = require('replace-ext'); const PluginError = require('plugin-error'); 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 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 PluginError('gulp-changed', '`dest` required'); } if (opts.transformPath !== undefined && typeof opts.transformPath !== 'function') { throw new 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 = replaceExt(newPath, opts.extension); } if (opts.transformPath) { newPath = opts.transformPath(newPath); if (typeof newPath !== 'string') { throw new 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.2.0/license000066400000000000000000000021251322173064100154160ustar00rootroot00000000000000MIT License 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.2.0/package.json000066400000000000000000000017551322173064100163470ustar00rootroot00000000000000{ "name": "gulp-changed", "version": "3.2.0", "description": "Only pass through changed files", "license": "MIT", "repository": "sindresorhus/gulp-changed", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=4" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "gulpplugin", "file", "files", "changed", "newer", "modified", "modification", "updated", "time", "mtime", "stat", "cache", "cached", "passthrough" ], "dependencies": { "make-dir": "^1.1.0", "pify": "^3.0.0", "plugin-error": "^0.1.2", "replace-ext": "^1.0.0", "through2": "^2.0.0", "touch": "^3.1.0" }, "devDependencies": { "ava": "*", "chalk": "^2.3.0", "del": "^3.0.0", "figures": "^2.0.0", "get-stream": "^3.0.0", "gulp": "^3.0.0", "vinyl": "^2.1.0", "xo": "*" } } gulp-changed-3.2.0/readme.md000066400000000000000000000070641322173064100156370ustar00rootroot00000000000000# 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). ## Install ``` $ npm install --save-dev gulp-changed ``` *Support this module by buying this excellent [Node.js course](https://LearnNode.com/friend/AWESOME).* ## 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.compareContents})) .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.2.0/test.js000066400000000000000000000073131322173064100153720ustar00rootroot00000000000000import path from 'path'; import fs from 'fs'; import touch from 'touch'; import makeDir from 'make-dir'; import test from 'ava'; import gulp from 'gulp'; import Vinyl from 'vinyl'; import del from 'del'; import getStream from 'get-stream'; import figures from 'figures'; import chalk from 'chalk'; import changed from '.'; const pointer = chalk.gray.dim(figures.pointerSmall); const macro = (t, opts) => { return new Promise(async resolve => { let dest = opts.dest; const extension = opts.extension || '.js'; const stream = changed(dest, opts); const files = []; if (typeof dest === 'function') { dest = dest(); } await makeDir(dest); await touch(path.join(dest, `foo${extension}`)); stream.on('data', file => { files.push(file); fs.writeFileSync(path.join(dest, file.relative), file); }); stream.on('end', () => { t.is(files.length, 1); t.is(files[0].relative, 'bar.js'); del.sync(dest); return resolve(); }); stream.write(new Vinyl({ cwd: __dirname, base: __dirname, path: 'foo.js', contents: Buffer.from(''), stat: { mtime: fs.statSync(path.join(dest, 'foo' + extension)) } })); stream.write(new Vinyl({ base: __dirname, path: 'bar.js', contents: Buffer.from(''), stat: { mtime: new Date() } })); stream.end(); }); }; macro.title = (providedTitle, opts) => { let desc = 'should only pass through changed files'; if (opts && opts.extension) { desc += ' using extension ' + opts.extension; } else if (opts.absolute) { desc += ' with a absolute path'; } else { desc += ' using file extension'; } return [providedTitle, desc].join(` ${pointer} `); }; test.serial(`compareLastModifiedTime ${pointer} using relative dest`, macro, {dest: 'tmp', absolute: true}); test.serial(`compareLastModifiedTime ${pointer} using relative dest`, macro, {dest: 'tmp', absolute: true, extension: '.coffee'}); test.serial(`compareLastModifiedTime ${pointer} dest can be a function`, macro, {dest: () => 'tmp'}); test(`compareContents ${pointer} should not pass any files through in identical directories`, async t => { const stream = gulp.src('fixture/identical/src/*') .pipe(changed('fixture/identical/trg', {hasChanged: changed.compareContents})); const files = await getStream.array(stream); t.is(files.length, 0); }); test(`compareContents ${pointer} should only pass through changed files using file extension`, async t => { const stream = gulp.src('fixture/different/src/*') .pipe(changed('fixture/different/trg', {hasChanged: changed.compareContents})); const files = await getStream.array(stream); t.is(files.length, 1); t.is(path.basename(files[0].path), 'b'); }); test(`compareContents ${pointer} should only pass through changed files using transformPath`, async t => { 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); } })); const files = await getStream.array(stream); t.is(files.length, 1); t.is(path.basename(files[0].path), 'b'); }); test(`compareContents ${pointer} should only pass through changed files using extension .coffee`, async t => { const stream = gulp.src('fixture/different.ext/src/*') .pipe(changed('fixture/different.ext/trg', { hasChanged: changed.compareContents, extension: '.coffee' })); const files = await getStream.array(stream); t.is(files.length, 1); t.is(path.basename(files[0].path), 'b.typescript'); }); test(`compareSha1Digest ${pointer} should be an alias for compareContents`, t => { t.is(changed.compareContents, changed.compareSha1Digest); });