UNPKG

motion

Version:

motion - moving development forward

78 lines (77 loc) 9.68 kB
{ "_args": [ [ "gulp-if@https://registry.npmjs.org/gulp-if/-/gulp-if-2.0.0.tgz", "/Users/nw/flint/packages/flint" ] ], "_from": "gulp-if@2.0.0", "_id": "gulp-if@2.0.0", "_inCache": true, "_location": "/gulp-if", "_phantomChildren": {}, "_requested": { "name": "gulp-if", "raw": "gulp-if@https://registry.npmjs.org/gulp-if/-/gulp-if-2.0.0.tgz", "rawSpec": "https://registry.npmjs.org/gulp-if/-/gulp-if-2.0.0.tgz", "scope": null, "spec": "https://registry.npmjs.org/gulp-if/-/gulp-if-2.0.0.tgz", "type": "remote" }, "_requiredBy": [ "/" ], "_resolved": "https://registry.npmjs.org/gulp-if/-/gulp-if-2.0.0.tgz", "_shasum": "5d5f6a7f74b45ba8ed78039ac177b3f1f730cd2b", "_shrinkwrap": null, "_spec": "gulp-if@https://registry.npmjs.org/gulp-if/-/gulp-if-2.0.0.tgz", "_where": "/Users/nw/flint/packages/flint", "author": { "name": "Rob Richardson", "url": "http://robrich.org/" }, "bugs": { "url": "https://github.com/robrich/gulp-if/issues" }, "dependencies": { "gulp-match": "^1.0.0", "ternary-stream": "^2.0.0", "through2": "^2.0.0" }, "description": "Conditionally run a task", "devDependencies": { "end-of-stream": "^1.1.0", "graceful-fs": "^4.1.2", "jshint": "^2.8.0", "mkdirp": "^0.5.1", "mocha": "^2.3.3", "rimraf": "^2.4.3", "should": "^7.1.0", "stream-exhaust": "^1.0.1", "vinyl-fs": "^2.1.1" }, "engines": { "node": ">= 0.10.0" }, "homepage": "https://github.com/robrich/gulp-if", "keywords": [ "conditional", "gulpplugin", "if", "ternary" ], "license": "MIT", "main": "./index.js", "name": "gulp-if", "optionalDependencies": {}, "readme": "gulp-if ![status](https://secure.travis-ci.org/robrich/gulp-if.png?branch=master)\r\n=======\r\n\r\nA ternary gulp plugin: conditionally control the flow of vinyl objects.\r\n\r\n**Note**: Badly behaved plugins can often get worse when used with gulp-if. Typically the fix is not in gulp-if.\r\n\r\n**Note**: Works great with [lazypipe](https://github.com/OverZealous/lazypipe), see below\r\n\r\n## Usage\r\n\r\n1: Conditionally filter content\r\n\r\n**Condition**\r\n\r\n![][condition]\r\n\r\n```javascript\r\nvar gulpif = require('gulp-if');\r\nvar uglify = require('gulp-uglify');\r\n\r\nvar condition = true; // TODO: add business logic\r\n\r\ngulp.task('task', function() {\r\n gulp.src('./src/*.js')\r\n .pipe(gulpif(condition, uglify()))\r\n .pipe(gulp.dest('./dist/'));\r\n});\r\n```\r\nOnly uglify the content if the condition is true, but send all the files to the dist folder\r\n\r\n\r\n2: Ternary filter\r\n\r\n**Ternary**\r\n\r\n![][ternary]\r\n\r\n```javascript\r\nvar gulpif = require('gulp-if');\r\nvar uglify = require('gulp-uglify');\r\nvar beautify = require('gulp-beautify');\r\n\r\nvar condition = function (file) {\r\n // TODO: add business logic\r\n return true;\r\n}\r\n\r\ngulp.task('task', function() {\r\n gulp.src('./src/*.js')\r\n .pipe(gulpif(condition, uglify(), beautify()))\r\n .pipe(gulp.dest('./dist/'));\r\n});\r\n```\r\n\r\nIf condition returns true, uglify else beautify, then send everything to the dist folder\r\n\r\n\r\n3: Remove things from the stream\r\n\r\n**Remove from here on**\r\n\r\n![][exclude]\r\n\r\n```javascript\r\nvar gulpIgnore = require('gulp-ignore');\r\nvar uglify = require('gulp-uglify');\r\nvar jshint = require('gulp-jshint');\r\n\r\nvar condition = './gulpfile.js';\r\n\r\ngulp.task('task', function() {\r\n gulp.src('./*.js')\r\n .pipe(jshint())\r\n .pipe(gulpIgnore.exclude(condition))\r\n .pipe(uglify())\r\n .pipe(gulp.dest('./dist/'));\r\n});\r\n```\r\n\r\nRun JSHint on everything, remove gulpfile from the stream, then uglify and write everything else.\r\n\r\n\r\n4: Exclude things from the stream\r\n\r\n**Exclude things from entering the stream**\r\n\r\n![][glob]\r\n\r\n```javascript\r\nvar uglify = require('gulp-uglify');\r\n\r\ngulp.task('task', function() {\r\n gulp.src(['./*.js', '!./node_modules/**'])\r\n .pipe(uglify())\r\n .pipe(gulp.dest('./dist/'));\r\n});\r\n```\r\n\r\nGrab all JavaScript files that aren't in the node_modules folder, uglify them, and write them.\r\nThis is fastest because nothing in node_modules ever leaves `gulp.src()`\r\n\r\n\r\n## works great with [lazypipe](https://github.com/OverZealous/lazypipe)\r\n\r\nLazypipe creates a function that initializes the pipe chain on use. This allows you to create a chain of events inside the gulp-if condition. This scenario will run jshint analysis and reporter only if the linting flag is true.\r\n\r\n```js\r\nvar gulpif = require('gulp-if');\r\nvar jshint = require('gulp-jshint');\r\nvar uglify = require('gulp-uglify');\r\n\r\nvar linting = false;\r\nvar compressing = false;\r\n\r\nvar jshintChannel = lazypipe()\r\n // adding a pipeline step\r\n .pipe(jshint) // notice the stream function has not been called!\r\n .pipe(jshint.reporter)\r\n // adding a step with an argument\r\n .pipe(jshint.reporter, 'fail');\r\n\r\ngulp.task('scripts', function () {\r\n return gulp.src(paths.scripts.src)\r\n .pipe(gulpif(linting, jshintChannel()))\r\n .pipe(gulpif(compressing, uglify()))\r\n .pipe(gulp.dest(paths.scripts.dest));\r\n});\r\n```\r\n[source](https://github.com/spenceralger/gulp-jshint/issues/38#issuecomment-40423932)\r\n\r\n## works great inside [lazypipe](https://github.com/OverZealous/lazypipe)\r\n\r\nLazypipe assumes that all function parameters are static, gulp-if arguments need to be instantiated inside each lazypipe. This difference can be easily solved by passing a function on the lazypipe step\r\n\r\n```js\r\nvar gulpif = require('gulp-if');\r\nvar jshint = require('gulp-jshint');\r\nvar uglify = require('gulp-uglify');\r\n\r\nvar compressing = false;\r\n\r\nvar jsChannel = lazypipe()\r\n // adding a pipeline step\r\n .pipe(jshint) // notice the stream function has not been called!\r\n .pipe(jshint.reporter)\r\n // adding a step with an argument\r\n .pipe(jshint.reporter, 'fail')\r\n // you can't say: .pipe(gulpif, compressing, uglify)\r\n // because uglify needs to be instantiated separately in each lazypipe instance\r\n // you can say this instead:\r\n .pipe(function () {\r\n return gulpif(compressing, uglify());\r\n });\r\n // why does this work? lazypipe calls the function, passing in the no arguments to it,\r\n // it instantiates a new gulp-if pipe and returns it to lazypipe.\r\n\r\ngulp.task('scripts', function () {\r\n return gulp.src(paths.scripts.src)\r\n .pipe(jsChannel())\r\n .pipe(gulp.dest(paths.scripts.dest));\r\n});\r\n```\r\n\r\n[source](https://github.com/robrich/gulp-if/issues/32)\r\n\r\n## gulp-if API\r\n\r\n### gulpif(condition, stream [, elseStream, [, minimatchOptions]])\r\n\r\ngulp-if will pipe data to `stream` whenever `condition` is truthy.\r\n\r\nIf `condition` is falsey and `elseStream` is passed, data will pipe to `elseStream`\r\n\r\nAfter data is piped to `stream` or `elseStream` or neither, data is piped down-stream.\r\n\r\n#### Parameters\r\n\r\n##### condition\r\n\r\nType: `boolean` or [`stat`](http://nodejs.org/api/fs.html#fs_class_fs_stats) object or `function` that takes in a vinyl file and returns a boolean or `RegularExpression` that works on the `file.path`\r\n\r\nThe condition parameter is any of the conditions supported by [gulp-match](https://github.com/robrich/gulp-match). The `file.path` is passed into `gulp-match`.\r\n\r\nIf a function is given, then the function is passed a vinyl `file`. The function should return a `boolean`.\r\n\r\n##### stream\r\n\r\nStream for gulp-if to pipe data into when condition is truthy.\r\n\r\n##### elseStream\r\n\r\nOptional, Stream for gulp-if to pipe data into when condition is falsey.\r\n\r\n##### minimatchOptions\r\n\r\nOptional, if it's a glob condition, these options are passed to [https://github.com/isaacs/minimatch](minimatch).\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\n(MIT License)\r\n\r\nCopyright (c) 2014 [Richardson & Sons, LLC](http://richardsonandsons.com/)\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining\r\na copy of this software and associated documentation files (the\r\n\"Software\"), to deal in the Software without restriction, including\r\nwithout limitation the rights to use, copy, modify, merge, publish,\r\ndistribute, sublicense, and/or sell copies of the Software, and to\r\npermit persons to whom the Software is furnished to do so, subject to\r\nthe following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be\r\nincluded in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\r\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n\r\n[condition]: https://rawgithub.com/robrich/gulp-if/master/img/condition.svg\r\n[ternary]: https://rawgithub.com/robrich/gulp-if/master/img/ternary.svg\r\n[exclude]: https://rawgithub.com/robrich/gulp-if/master/img/exclude.svg\r\n[glob]: https://rawgithub.com/robrich/gulp-if/master/img/glob.svg\r\n", "readmeFilename": "README.md", "repository": { "type": "git", "url": "git://github.com/robrich/gulp-if.git" }, "scripts": { "test": "mocha && jshint ." }, "version": "2.0.0" }