├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .verb.md ├── LICENSE ├── README.md ├── assemblefile.js ├── example.gif ├── fixtures ├── a.hbs ├── a.txt ├── b.hbs ├── b.txt ├── c.hbs └── c.txt ├── gulpfile.js ├── index.js └── package.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 12 | trim_trailing_whitespace = false 13 | insert_final_newline = false -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "modules": true, 4 | "experimentalObjectRestSpread": true 5 | }, 6 | 7 | "env": { 8 | "browser": false, 9 | "es6": true, 10 | "node": true, 11 | "mocha": true 12 | }, 13 | 14 | "globals": { 15 | "document": false, 16 | "navigator": false, 17 | "window": false 18 | }, 19 | 20 | "rules": { 21 | "accessor-pairs": 2, 22 | "arrow-spacing": [2, { "before": true, "after": true }], 23 | "block-spacing": [2, "always"], 24 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 25 | "comma-dangle": [2, "never"], 26 | "comma-spacing": [2, { "before": false, "after": true }], 27 | "comma-style": [2, "last"], 28 | "constructor-super": 2, 29 | "curly": [2, "multi-line"], 30 | "dot-location": [2, "property"], 31 | "eol-last": 2, 32 | "eqeqeq": [2, "allow-null"], 33 | "generator-star-spacing": [2, { "before": true, "after": true }], 34 | "handle-callback-err": [2, "^(err|error)$" ], 35 | "indent": [2, 2, { "SwitchCase": 1 }], 36 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 37 | "keyword-spacing": [2, { "before": true, "after": true }], 38 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 39 | "new-parens": 2, 40 | "no-array-constructor": 2, 41 | "no-caller": 2, 42 | "no-class-assign": 2, 43 | "no-cond-assign": 2, 44 | "no-const-assign": 2, 45 | "no-control-regex": 2, 46 | "no-debugger": 2, 47 | "no-delete-var": 2, 48 | "no-dupe-args": 2, 49 | "no-dupe-class-members": 2, 50 | "no-dupe-keys": 2, 51 | "no-duplicate-case": 2, 52 | "no-empty-character-class": 2, 53 | "no-eval": 2, 54 | "no-ex-assign": 2, 55 | "no-extend-native": 2, 56 | "no-extra-bind": 2, 57 | "no-extra-boolean-cast": 2, 58 | "no-extra-parens": [2, "functions"], 59 | "no-fallthrough": 2, 60 | "no-floating-decimal": 2, 61 | "no-func-assign": 2, 62 | "no-implied-eval": 2, 63 | "no-inner-declarations": [2, "functions"], 64 | "no-invalid-regexp": 2, 65 | "no-irregular-whitespace": 2, 66 | "no-iterator": 2, 67 | "no-label-var": 2, 68 | "no-labels": 2, 69 | "no-lone-blocks": 2, 70 | "no-mixed-spaces-and-tabs": 2, 71 | "no-multi-spaces": 2, 72 | "no-multi-str": 2, 73 | "no-multiple-empty-lines": [2, { "max": 1 }], 74 | "no-native-reassign": 0, 75 | "no-negated-in-lhs": 2, 76 | "no-new": 2, 77 | "no-new-func": 2, 78 | "no-new-object": 2, 79 | "no-new-require": 2, 80 | "no-new-wrappers": 2, 81 | "no-obj-calls": 2, 82 | "no-octal": 2, 83 | "no-octal-escape": 2, 84 | "no-proto": 0, 85 | "no-redeclare": 2, 86 | "no-regex-spaces": 2, 87 | "no-return-assign": 2, 88 | "no-self-compare": 2, 89 | "no-sequences": 2, 90 | "no-shadow-restricted-names": 2, 91 | "no-spaced-func": 2, 92 | "no-sparse-arrays": 2, 93 | "no-this-before-super": 2, 94 | "no-throw-literal": 2, 95 | "no-trailing-spaces": 0, 96 | "no-undef": 2, 97 | "no-undef-init": 2, 98 | "no-unexpected-multiline": 2, 99 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 100 | "no-unreachable": 2, 101 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 102 | "no-useless-call": 0, 103 | "no-with": 2, 104 | "one-var": [0, { "initialized": "never" }], 105 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 106 | "padded-blocks": [0, "never"], 107 | "quotes": [2, "single", "avoid-escape"], 108 | "radix": 2, 109 | "semi": [2, "always"], 110 | "semi-spacing": [2, { "before": false, "after": true }], 111 | "space-before-blocks": [2, "always"], 112 | "space-before-function-paren": [2, "never"], 113 | "space-in-parens": [2, "never"], 114 | "space-infix-ops": 2, 115 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 116 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 117 | "use-isnan": 2, 118 | "valid-typeof": 2, 119 | "wrap-iife": [2, "any"], 120 | "yoda": [2, "never"] 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | *.sublime-* 4 | 5 | # test related, or directories generated by tests 6 | test/actual 7 | actual 8 | coverage 9 | .nyc* 10 | 11 | # npm 12 | node_modules 13 | npm-debug.log 14 | 15 | # yarn 16 | yarn.lock 17 | yarn-error.log 18 | 19 | # misc 20 | _gh_pages 21 | _draft 22 | _drafts 23 | bower_components 24 | vendor 25 | temp 26 | tmp 27 | TODO.md 28 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | ![gulp choose files example](example.gif) 2 | 3 | ## Usage 4 | 5 | ```js 6 | var gulp = require('gulp'); 7 | var choose = require('{%= name %}'); 8 | 9 | gulp.task('default', function() { 10 | return gulp.src('fixtures/*.*') 11 | .pipe(choose()) 12 | .pipe(gulp.dest('actual')); 13 | }); 14 | ``` 15 | 16 | ## options.key 17 | 18 | **Type**: `string` 19 | 20 | **Default**: `relative` 21 | 22 | Specify the [vinyl][] `file` property to use when displaying file names in the choices array. 23 | 24 | **Examples** 25 | 26 | Given the file path `/dev/fixtures/foo.txt` (depending on cwd and `file.base`), here is what you would get: 27 | 28 | ```js 29 | choose({key: 'path'}); 30 | //=> '/dev/fixtures/foo.txt' 31 | choose({key: 'relative'}); 32 | //=> 'fixtures/foo.txt' 33 | choose({key: 'basename'}); 34 | //=> 'foo.txt' 35 | choose({key: 'stem'}); 36 | //=> 'foo' 37 | ``` 38 | 39 | ## options.choices 40 | 41 | If you need to be able to automatically skip the prompt, you can pass a string or array with your "choices" to `options.choices`. 42 | 43 | The following will only write `a.txt`: 44 | 45 | ```js 46 | gulp.task('default', function() { 47 | return gulp.src('fixtures/*.txt') 48 | .pipe(choose({choices: ['a.txt']})) 49 | .pipe(gulp.dest('actual')); 50 | }); 51 | ``` 52 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2017, Jon Schlinkert 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gulp-choose-files [![NPM version](https://img.shields.io/npm/v/gulp-choose-files.svg?style=flat)](https://www.npmjs.com/package/gulp-choose-files) [![NPM monthly downloads](https://img.shields.io/npm/dm/gulp-choose-files.svg?style=flat)](https://npmjs.org/package/gulp-choose-files) [![NPM total downloads](https://img.shields.io/npm/dt/gulp-choose-files.svg?style=flat)](https://npmjs.org/package/gulp-choose-files) 2 | 3 | > Gulp plugin that prompts you to choose the files to pass through the stream. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | ```sh 10 | $ npm install --save gulp-choose-files 11 | ``` 12 | 13 | Install with [yarn](https://yarnpkg.com): 14 | 15 | ```sh 16 | $ yarn add gulp-choose-files 17 | ``` 18 | 19 | ![gulp choose files example](example.gif) 20 | 21 | ## Usage 22 | 23 | ```js 24 | var gulp = require('gulp'); 25 | var choose = require('gulp-choose-files'); 26 | 27 | gulp.task('default', function() { 28 | return gulp.src('fixtures/*.*') 29 | .pipe(choose()) 30 | .pipe(gulp.dest('actual')); 31 | }); 32 | ``` 33 | 34 | ## options.key 35 | 36 | **Type**: `string` 37 | 38 | **Default**: `relative` 39 | 40 | Specify the [vinyl](https://github.com/gulpjs/vinyl) `file` property to use when displaying file names in the choices array. 41 | 42 | **Examples** 43 | 44 | Given the file path `/dev/fixtures/foo.txt` (depending on cwd and `file.base`), here is what you would get: 45 | 46 | ```js 47 | choose({key: 'path'}); 48 | //=> '/dev/fixtures/foo.txt' 49 | choose({key: 'relative'}); 50 | //=> 'fixtures/foo.txt' 51 | choose({key: 'basename'}); 52 | //=> 'foo.txt' 53 | choose({key: 'stem'}); 54 | //=> 'foo' 55 | ``` 56 | 57 | ## options.choices 58 | 59 | If you need to be able to automatically skip the prompt, you can pass a string or array with your "choices" to `options.choices`. 60 | 61 | The following will only write `a.txt`: 62 | 63 | ```js 64 | gulp.task('default', function() { 65 | return gulp.src('fixtures/*.txt') 66 | .pipe(choose({choices: ['a.txt']})) 67 | .pipe(gulp.dest('actual')); 68 | }); 69 | ``` 70 | 71 | ## About 72 | 73 | ### Related projects 74 | 75 | * [gulp-choose-file](https://www.npmjs.com/package/gulp-choose-file): Gulp plugin that prompts you to choose a file to pass through the stream. | [homepage](https://github.com/pointnet/gulp-choose-file "Gulp plugin that prompts you to choose a file to pass through the stream.") 76 | * [gulp-condense](https://www.npmjs.com/package/gulp-condense): Remove extra newlines in a string. | [homepage](https://github.com/jonschlinkert/gulp-condense "Remove extra newlines in a string.") 77 | * [gulp-extname](https://www.npmjs.com/package/gulp-extname): gulp plugin to dynamically rewrite dest extensions based on src extensions. | [homepage](https://github.com/jonschlinkert/gulp-extname "gulp plugin to dynamically rewrite dest extensions based on src extensions.") 78 | * [gulp-htmlmin](https://www.npmjs.com/package/gulp-htmlmin): gulp plugin to minify HTML. | [homepage](https://github.com/jonschlinkert/gulp-htmlmin#readme "gulp plugin to minify HTML.") 79 | 80 | ### Contributing 81 | 82 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 83 | 84 | ### Building docs 85 | 86 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ 87 | 88 | To generate the readme, run the following command: 89 | 90 | ```sh 91 | $ npm install -g verbose/verb#dev verb-generate-readme && verb 92 | ``` 93 | 94 | ### Running tests 95 | 96 | Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: 97 | 98 | ```sh 99 | $ npm install && npm test 100 | ``` 101 | 102 | ### Author 103 | 104 | **Jon Schlinkert** 105 | 106 | * [github/jonschlinkert](https://github.com/jonschlinkert) 107 | * [twitter/jonschlinkert](https://twitter.com/jonschlinkert) 108 | 109 | ### License 110 | 111 | Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). 112 | Released under the [MIT License](LICENSE). 113 | 114 | *** 115 | 116 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on April 28, 2017._ -------------------------------------------------------------------------------- /assemblefile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var choose = require('./'); 4 | var assemble = require('assemble'); 5 | var app = assemble(); 6 | 7 | /** 8 | * Basic 9 | */ 10 | 11 | app.task('default', function() { 12 | return app.src('fixtures/*.*') 13 | .pipe(choose()) 14 | .pipe(app.dest('actual')); 15 | }); 16 | 17 | /** 18 | * Render templates 19 | */ 20 | 21 | app.task('render', function() { 22 | app.engine('hbs', require('engine-handlebars')); 23 | app.data({title: 'Assemble'}); 24 | 25 | return app.src('fixtures/*.*') 26 | .pipe(choose()) 27 | .pipe(app.renderFile('hbs')) 28 | .pipe(app.dest('actual')); 29 | }); 30 | 31 | /** 32 | * Choose files loaded from a collection (instead of fs) 33 | */ 34 | 35 | app.task('pages', function() { 36 | app.pages('foo', {content: 'this is foo'}); 37 | app.pages('bar', {content: 'this is bar'}); 38 | app.pages('baz', {content: 'this is baz'}); 39 | return app.toStream('pages') 40 | .pipe(choose()) 41 | .pipe(app.dest('actual')); 42 | }); 43 | 44 | /** 45 | * Expose the instance 46 | */ 47 | 48 | module.exports = app; 49 | -------------------------------------------------------------------------------- /example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/generate/gulp-choose-files/fdbfd35616c9de76c905a9f3f25aef23a24c8e61/example.gif -------------------------------------------------------------------------------- /fixtures/a.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | title: AAA 3 | --- 4 | This is {{title}}! -------------------------------------------------------------------------------- /fixtures/a.txt: -------------------------------------------------------------------------------- 1 | This is AAA! -------------------------------------------------------------------------------- /fixtures/b.hbs: -------------------------------------------------------------------------------- 1 | --- 2 | title: BBB 3 | --- 4 | This is {{title}}! -------------------------------------------------------------------------------- /fixtures/b.txt: -------------------------------------------------------------------------------- 1 | This is BBB! -------------------------------------------------------------------------------- /fixtures/c.hbs: -------------------------------------------------------------------------------- 1 | This is {{title}}! -------------------------------------------------------------------------------- /fixtures/c.txt: -------------------------------------------------------------------------------- 1 | This is CCC! -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var gulp = require('gulp'); 4 | var choose = require('./'); 5 | 6 | gulp.task('default', function() { 7 | return gulp.src('fixtures/*.txt') 8 | .pipe(choose({choices: ['a.txt']})) 9 | .pipe(gulp.dest('actual')); 10 | }); 11 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var through = require('through2'); 4 | var extend = require('extend-shallow'); 5 | var Prompt = require('prompt-checkbox'); 6 | 7 | module.exports = function(options) { 8 | var opts = extend({key: 'relative', save: false}, options); 9 | var msg = opts.message || 'Which files do you want to write?'; 10 | var paths = []; 11 | var files = {}; 12 | 13 | return through.obj(function(file, enc, next) { 14 | if (opts.skip) { 15 | next(null, file); 16 | return; 17 | } 18 | 19 | var key = fileKey(file, opts); 20 | paths.push(key); 21 | files[key] = file; 22 | 23 | next(); 24 | }, function(next) { 25 | var stream = this; 26 | 27 | if (typeof opts.choices === 'string') { 28 | opts.choices = [opts.choices]; 29 | } 30 | 31 | if (Array.isArray(opts.choices)) { 32 | opts.choices.forEach(function(filepath) { 33 | stream.push(files[filepath]); 34 | }); 35 | next(); 36 | return; 37 | } 38 | 39 | if (paths.length === 0) { 40 | next(); 41 | return; 42 | } 43 | 44 | var answers = {}; 45 | var prompt = new Prompt({ 46 | name: 'files', 47 | message: msg, 48 | type: 'checkbox', 49 | choiceObject: true, 50 | radio: true, 51 | choices: paths 52 | }); 53 | 54 | prompt.run(answers) 55 | .then(function(answers) { 56 | answers.forEach(function(filepath) { 57 | stream.push(files[filepath]); 58 | }); 59 | next(); 60 | }) 61 | .catch(next); 62 | 63 | }); 64 | }; 65 | 66 | function fileKey(file, opts) { 67 | if (typeof opts.key === 'string') { 68 | return file[opts.key]; 69 | } 70 | if (typeof opts.key === 'function') { 71 | return opts.key(file); 72 | } 73 | return file.relative; 74 | } 75 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-choose-files", 3 | "description": "Gulp plugin that prompts you to choose the files to pass through the stream.", 4 | "version": "1.0.0", 5 | "homepage": "https://github.com/generate/gulp-choose-files", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "repository": "generate/gulp-choose-files", 8 | "bugs": { 9 | "url": "https://github.com/generate/gulp-choose-files/issues" 10 | }, 11 | "license": "MIT", 12 | "files": [ 13 | "index.js" 14 | ], 15 | "main": "index.js", 16 | "engines": { 17 | "node": ">=0.10.0" 18 | }, 19 | "scripts": { 20 | "test": "mocha" 21 | }, 22 | "dependencies": { 23 | "extend-shallow": "^2.0.1", 24 | "prompt-checkbox": "^0.5.0", 25 | "through2": "^2.0.3" 26 | }, 27 | "devDependencies": { 28 | "assemble": "^0.23.0", 29 | "engine-handlebars": "^0.8.2", 30 | "gulp": "^3.9.1", 31 | "gulp-format-md": "^0.1.12" 32 | }, 33 | "keywords": [ 34 | "ask", 35 | "choose", 36 | "conditional", 37 | "files", 38 | "fs", 39 | "gulp", 40 | "gulpplugin", 41 | "pick", 42 | "plugin", 43 | "prompt", 44 | "question", 45 | "render", 46 | "write" 47 | ], 48 | "verb": { 49 | "toc": false, 50 | "layout": "default", 51 | "tasks": [ 52 | "readme" 53 | ], 54 | "plugins": [ 55 | "gulp-format-md" 56 | ], 57 | "related": { 58 | "list": [ 59 | "gulp-choose-file", 60 | "gulp-condense", 61 | "gulp-extname", 62 | "gulp-htmlmin" 63 | ] 64 | }, 65 | "reflinks": [ 66 | "verb", 67 | "verb-readme-generator" 68 | ], 69 | "lint": { 70 | "reflinks": true 71 | } 72 | } 73 | } 74 | --------------------------------------------------------------------------------