Add interactive console prompts to gulp(evacuated from NSA/Microsoft Github)

anonymous 9d4732a049 Merge https://notabug.org/makenotabuggreatagain/gulp-prompt il y a 5 ans
examples a357b15a57 Check in first implementation il y a 6 ans
test ce3aa0915a Check in fix for Chain Prompt Unit Tests il y a 6 ans
.gitignore 3de852ddf3 Check in latset git ignore il y a 7 ans
.travis.yml 647a3e5488 add travis and update codestyle il y a 7 ans
CHANGELOG.md 06e8480186 Merge branch 'master' into v-1-1-0-PromptChaining il y a 6 ans
LICENSE c58c34cc0f aha found author il y a 5 ans
README.md 2aedfe1ed9 update contact info il y a 5 ans
eslintrc.json 40662416eb Cleaned up code and added ES Lint il y a 7 ans
index.js 06e8480186 Merge branch 'master' into v-1-1-0-PromptChaining il y a 6 ans
package.json f749a5350b Lock event-stream package to avoid compromised flatmap-stream il y a 6 ans
yarn.lock f749a5350b Lock event-stream package to avoid compromised flatmap-stream il y a 6 ans

README.md

Gulp prompt

If you are interested in getting involved please send us an e-mail or open an issue.

Add interaction to gulp tasks.

.confirm([options])

Options:

  • message - Message to be displayed
  • default - Default response if none is provided

This method will allow the pipe to continue if the user input is true, otherwise, it will be terminated.

Default usage:


gulp.src('test.js')
	.pipe(prompt.confirm())
	.pipe(gulp.dest('dest'));

If a string is provided to the options, it will be set as the message:


gulp.src('test.js')
	.pipe(prompt.confirm('Are you ready for Gulp?'))
	.pipe(gulp.dest('dest'));

Example when using options:


gulp.src('test.js')
	.pipe(prompt.confirm({
		message: 'Continue?',
		default: true
	}))
	.pipe(gulp.dest('dest'));

.prompt(questions, callback)

This is a clean pass-through function for gulp to utilize the full Inquirer.js Library, please refer to them for documentation on corresponding parameters.

Please note that all types are avaiable, not just the examples below.

Example Input:


gulp.src('test.js')
	.pipe(prompt.prompt({
		type: 'input',
		name: 'task',
		message: 'Which task would you like to run?'
	}, function(res){
		//value is in res.task (the name option gives the key)
	}));

Example Checkbox:


gulp.src('test.js')
	.pipe(prompt.prompt({
		type: 'checkbox',
		name: 'bump',
		message: 'What type of bump would you like to do?',
		choices: ['patch', 'minor', 'major']
	}, function(res){
		//value is in res.bump (as an array)
	}));

Example Password:


gulp.src('test.js')
	.pipe(prompt.prompt({
		type: 'password',
		name: 'pass',
		message: 'Please enter your password'
	}, function(res){
		//value is in res.pass
	}));

Example Multiple:


gulp.src('test.js')
	.pipe(prompt.prompt([{
		type: 'input',
		name: 'first',
		message: 'First question?'
	},
	{
		type: 'input',
		name: 'second',
		message: 'Second question?'
	}], function(res){
		//value is in res.first and res.second
	}));

Example Validation:


gulp.src('test.js')
	.pipe(prompt.prompt({
		type: 'password',
		name: 'pass',
		message: 'Please enter your password',
		validate: function(pass){

			if(pass !== '123456'){
				return false;
			}

			return true;
		}
	}, function(res){
		//value is in res.pass
	}));

Example List Selection: Note: see sample file


    gulp.src( './package.json' )
        .pipe( prompt.prompt({
            type:'list',
            name:'env',
            message:'Please enter selection?',
            choices: ['a','b','c','d','e','f', 'g', 'h'],
            pageSize:'3'
        }, (res) => {
            console.log('Result', res);
        }) );

Example Templating: This was a fix to the issue #8 (https://github.com/Freyskeyd/gulp-prompt/issues/8) Note: see sample file


    return gulp.src( './package.json' )
        .pipe( prompt.confirm({
            type:'input',
            name:'env',
            message:'Hello <%= user %>, please enter selection?',
            templateOptions:{ 'user': 'fred' }
        }, (res) => {
            console.log('Result', res);
        }) );

Example Chaining Prompts: This was a fix to the issue #35 (https://github.com/Freyskeyd/gulp-prompt/issues/35) This was a fix to the issue #34 (https://github.com/Freyskeyd/gulp-prompt/issues/34) Note: see sample file


	var index =0;

	var chainFunction = function ( options, resp ){
		console.log( 'Here is the selection ', resp);
		if( index <= 3){
			options.message = `Hello this is iteration ${index}`;
			index++;
			return options;
		}else{
			return;
		}
	};

	gulp.task( 'chainConfirm',  () => {
		return gulp.src( '../package.json' )
			.pipe( prompt.confirm({
				type:'input',
				name:'env',
				message:'Hello First interation, please enter selection?',
				chainFunction:chainFunction
			}, (res) => {
				console.log('Result', res);
			}) );
	});

This was a fix to the issue #60 (https://github.com/Freyskeyd/gulp-prompt/issues/60) Note: see sample file


	var index =0;

	var chainFunction = function ( options, resp ){
		console.log( 'Here is the selection ', resp);
		if( index <= 3){
			options.message = `Hello this is iteration ${index}`;
			index++;
			return options;
		}else{
			return;
		}
	};

	gulp.task( 'chainConfirm',  () => {
		return gulp.src( '../package.json' )
			.pipe( prompt.prompt({
				type:'input',
				name:'env',
				message:'Hello First interation, please enter selection?',
				chainFunction:chainFunction
			}, (res) => {
				console.log('Result', res);
			}) );
	});