gulp-choose-files
Advanced tools
Comparing version 1.0.0 to 2.0.0
82
index.js
'use strict'; | ||
var through = require('through2'); | ||
var extend = require('extend-shallow'); | ||
var Prompt = require('prompt-checkbox'); | ||
const through = require('through2'); | ||
const { prompt } = require('enquirer'); | ||
module.exports = function(options) { | ||
var opts = extend({key: 'relative', save: false}, options); | ||
var msg = opts.message || 'Which files do you want to write?'; | ||
var paths = []; | ||
var files = {}; | ||
const fileKey = (file, options) => { | ||
if (typeof options.key === 'string') return file[options.key]; | ||
if (typeof options.key === 'function') return options.key(file); | ||
return file.relative; | ||
}; | ||
return through.obj(function(file, enc, next) { | ||
module.exports = options => { | ||
const opts = Object.assign({ key: 'relative' }, options); | ||
const message = opts.message || 'Which files do you want to write?'; | ||
const predefined = [].concat(opts.paths || []); | ||
const choices = []; | ||
const files = {}; | ||
return through.obj((file, enc, next) => { | ||
if (opts.skip) { | ||
@@ -19,23 +25,16 @@ next(null, file); | ||
var key = fileKey(file, opts); | ||
paths.push(key); | ||
files[key] = file; | ||
next(); | ||
}, function(next) { | ||
var stream = this; | ||
if (typeof opts.choices === 'string') { | ||
opts.choices = [opts.choices]; | ||
let key = fileKey(file, opts); | ||
if (predefined.length && predefined.includes(key)) { | ||
next(null, file); | ||
return; | ||
} | ||
if (Array.isArray(opts.choices)) { | ||
opts.choices.forEach(function(filepath) { | ||
stream.push(files[filepath]); | ||
}); | ||
next(); | ||
return; | ||
if (!predefined.length) { | ||
choices.push(key); | ||
files[key] = file; | ||
} | ||
if (paths.length === 0) { | ||
next(); | ||
}, function(next) { | ||
if (!choices.length) { | ||
next(); | ||
@@ -45,32 +44,11 @@ return; | ||
var answers = {}; | ||
var prompt = new Prompt({ | ||
name: 'files', | ||
message: msg, | ||
type: 'checkbox', | ||
choiceObject: true, | ||
radio: true, | ||
choices: paths | ||
}); | ||
prompt.run(answers) | ||
.then(function(answers) { | ||
answers.forEach(function(filepath) { | ||
stream.push(files[filepath]); | ||
}); | ||
prompt({ type: 'multiselect', name: 'paths', message, choices, ...options }) | ||
.then(answers => { | ||
if (answers.paths && answers.paths.length) { | ||
answers.paths.forEach(filename => this.push(files[filename])); | ||
} | ||
next(); | ||
}) | ||
.catch(next); | ||
}); | ||
}; | ||
function fileKey(file, opts) { | ||
if (typeof opts.key === 'string') { | ||
return file[opts.key]; | ||
} | ||
if (typeof opts.key === 'function') { | ||
return opts.key(file); | ||
} | ||
return file.relative; | ||
} |
{ | ||
"name": "gulp-choose-files", | ||
"description": "Gulp plugin that prompts you to choose the files to pass through the stream.", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/generate/gulp-choose-files", | ||
@@ -17,3 +17,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=8" | ||
}, | ||
@@ -24,11 +24,8 @@ "scripts": { | ||
"dependencies": { | ||
"extend-shallow": "^2.0.1", | ||
"prompt-checkbox": "^0.5.0", | ||
"through2": "^2.0.3" | ||
"enquirer": "^2.3.0", | ||
"through2": "^3.0.1" | ||
}, | ||
"devDependencies": { | ||
"assemble": "^0.23.0", | ||
"engine-handlebars": "^0.8.2", | ||
"gulp": "^3.9.1", | ||
"gulp-format-md": "^0.1.12" | ||
"gulp": "^4.0.0", | ||
"gulp-format-md": "^2.0.0" | ||
}, | ||
@@ -67,6 +64,2 @@ "keywords": [ | ||
}, | ||
"reflinks": [ | ||
"verb", | ||
"verb-readme-generator" | ||
], | ||
"lint": { | ||
@@ -73,0 +66,0 @@ "reflinks": true |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
2
7533
44
+ Addedenquirer@^2.3.0
+ Addedansi-colors@4.1.3(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedenquirer@2.4.1(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedthrough2@3.0.2(transitive)
- Removedextend-shallow@^2.0.1
- Removedprompt-checkbox@^0.5.0
- Removed@sellside/emitter@1.2.1(transitive)
- Removedansi-bgblack@0.1.1(transitive)
- Removedansi-bgblue@0.1.1(transitive)
- Removedansi-bgcyan@0.1.1(transitive)
- Removedansi-bggreen@0.1.1(transitive)
- Removedansi-bgmagenta@0.1.1(transitive)
- Removedansi-bgred@0.1.1(transitive)
- Removedansi-bgwhite@0.1.1(transitive)
- Removedansi-bgyellow@0.1.1(transitive)
- Removedansi-black@0.1.1(transitive)
- Removedansi-blue@0.1.1(transitive)
- Removedansi-bold@0.1.1(transitive)
- Removedansi-colors@0.2.0(transitive)
- Removedansi-cyan@0.1.1(transitive)
- Removedansi-dim@0.1.1(transitive)
- Removedansi-gray@0.1.1(transitive)
- Removedansi-green@0.1.1(transitive)
- Removedansi-grey@0.1.1(transitive)
- Removedansi-hidden@0.1.1(transitive)
- Removedansi-inverse@0.1.1(transitive)
- Removedansi-italic@0.1.1(transitive)
- Removedansi-magenta@0.1.1(transitive)
- Removedansi-red@0.1.1(transitive)
- Removedansi-regex@3.0.1(transitive)
- Removedansi-reset@0.1.1(transitive)
- Removedansi-strikethrough@0.1.1(transitive)
- Removedansi-underline@0.1.1(transitive)
- Removedansi-white@0.1.1(transitive)
- Removedansi-wrap@0.1.0(transitive)
- Removedansi-yellow@0.1.1(transitive)
- Removedarr-flatten@1.1.0(transitive)
- Removedarr-union@3.1.0(transitive)
- Removedassign-symbols@1.0.0(transitive)
- Removedbase@0.13.2(transitive)
- Removedcache-base@1.0.1(transitive)
- Removedchoices-separator@0.1.2(transitive)
- Removedclass-utils@0.3.6(transitive)
- Removedcli-width@2.2.1(transitive)
- Removedclone-deep@0.2.4(transitive)
- Removedcollection-visit@1.0.0(transitive)
- Removedcomponent-emitter@1.3.1(transitive)
- Removedcopy-descriptor@0.1.1(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddefine-property@0.2.51.0.0(transitive)
- Removederror-symbol@0.1.0(transitive)
- Removedextend-shallow@2.0.13.0.2(transitive)
- Removedfor-in@0.1.81.0.2(transitive)
- Removedfor-own@0.1.5(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-value@2.0.6(transitive)
- Removedhas-value@0.3.11.0.0(transitive)
- Removedhas-values@0.1.41.0.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinfo-symbol@0.1.0(transitive)
- Removedis-accessor-descriptor@1.0.1(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-data-descriptor@1.0.1(transitive)
- Removedis-descriptor@0.1.71.0.3(transitive)
- Removedis-extendable@0.1.11.0.1(transitive)
- Removedis-fullwidth-code-point@2.0.0(transitive)
- Removedis-number@3.0.0(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedis-windows@1.0.2(transitive)
- Removedisarray@1.0.0(transitive)
- Removedisobject@2.1.03.0.1(transitive)
- Removedkind-of@2.0.13.2.24.0.0(transitive)
- Removedkoalas@1.0.2(transitive)
- Removedlazy-cache@0.2.71.0.42.0.2(transitive)
- Removedlog-ok@0.1.1(transitive)
- Removedlog-utils@0.2.1(transitive)
- Removedmap-visit@1.0.0(transitive)
- Removedmixin-deep@1.3.2(transitive)
- Removedmixin-object@2.0.1(transitive)
- Removedms@2.0.0(transitive)
- Removedmute-stream@0.0.7(transitive)
- Removedobject-copy@0.1.0(transitive)
- Removedobject-visit@1.0.1(transitive)
- Removedpascalcase@0.1.1(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedprompt-base@0.6.2(transitive)
- Removedprompt-checkbox@0.5.1(transitive)
- Removedprompt-choices@1.0.1(transitive)
- Removedprompt-question@1.0.0(transitive)
- Removedradio-symbol@1.0.3(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedreadline-ui@0.1.4(transitive)
- Removedreadline-utils@0.1.6(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedset-getter@0.1.1(transitive)
- Removedset-value@0.4.32.0.1(transitive)
- Removedshallow-clone@0.1.2(transitive)
- Removedsplit-string@3.1.0(transitive)
- Removedstatic-extend@0.1.2(transitive)
- Removedstring-width@2.1.1(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedstrip-ansi@4.0.0(transitive)
- Removedstrip-color@0.1.0(transitive)
- Removedsuccess-symbol@0.1.0(transitive)
- Removedterminal-paginator@0.2.2(transitive)
- Removedthrough2@2.0.5(transitive)
- Removedtime-stamp@1.1.0(transitive)
- Removedto-object-path@0.3.0(transitive)
- Removedtoggle-array@0.1.0(transitive)
- Removedunion-value@1.0.1(transitive)
- Removedunset-value@1.0.0(transitive)
- Removedwarning-symbol@0.1.0(transitive)
- Removedxtend@4.0.2(transitive)
Updatedthrough2@^3.0.1