-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from shannonlal/v-0-5-ChainPrompts
V 0 5 chain prompts
- Loading branch information
Showing
11 changed files
with
210 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ node_modules/ | |
test.js | ||
gulpfile.js | ||
npm-debug.log | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Examples | ||
|
||
The following is a selection of example gulp files which can be used for testing | ||
purposes | ||
|
||
## Execute Gulp File | ||
`node_modules/.bin/gulp --gulpfile examples/{sample gulp file} {gulp task}` | ||
|
||
Example: | ||
`node_modules/.bin/gulp --gulpfile examples/list-selection-gulpfile.js getSelection` | ||
|
||
## Gulp Examples | ||
|
||
1. First Choice Selection | ||
`examples/first-choice-selection-gulpfile.js` | ||
|
||
2. List selection which expands the screen | ||
`examples/list-selection-gulpfile.js` | ||
|
||
3. Templating option for messages | ||
`examples/template-replacement-gulpfile.js` | ||
|
||
4. Chain a series of prompts together | ||
`examples/chain-confirm-gulpfile.js` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
var gulp = require( 'gulp' ); | ||
var prompt = require('../index'); | ||
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; | ||
} | ||
}; | ||
|
||
/** | ||
* The following is a sample gulp file for chaining requests. It | ||
* will pass a chaining function to the confirm function and will | ||
* allow the user to chain multiple requests together | ||
* variables | ||
* | ||
*/ | ||
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
var assert = require('assert'); | ||
//Gulp uses vinyl source streams | ||
var source = require('vinyl-source-stream'); | ||
|
||
var proxyrequire = require('proxyquire'); | ||
/** | ||
* The following test spec will verify the operation of the chain prompt function | ||
*/ | ||
describe('gulp chain prompt unit tests', function () { | ||
describe('verify that chain prompt function operates correctly', function () { | ||
|
||
|
||
it('verify that chain prompt does not convert questions to array if already an array', function ( ){ | ||
var prompt = function ( questions ){ | ||
return new Promise( (resolve,reject) => { | ||
resolve('completed prompt'); | ||
}); | ||
}; | ||
|
||
//Mock inquirer to capture response | ||
gulpPrompt = proxyrequire('../index.js', {'inquirer':{ prompt: prompt}}); | ||
let srcStream = source('../README.md'); | ||
let resp = srcStream.pipe( gulpPrompt.confirm( ['options string'] ) ); | ||
resp.write('../test.txt'); | ||
}); | ||
|
||
it('verify that chain function gets called correctly', function ( ){ | ||
var prompt = function ( questions ){ | ||
return new Promise( (resolve,reject) => { | ||
resolve('completed prompt'); | ||
}); | ||
}; | ||
|
||
var chainFunction = function ( opts, resp ){ | ||
console.log('Chain Function called'); | ||
console.log( 'Response', resp); | ||
assert.equal( opts, options ); | ||
}; | ||
let index = 0; | ||
let options = { | ||
type: 'confirm', | ||
name: 'val', | ||
message: 'Test Message?', | ||
default: true, | ||
chainFunction: chainFunction | ||
}; | ||
|
||
|
||
//Mock inquirer to capture response | ||
gulpPrompt = proxyrequire('../index.js', {'inquirer':{ prompt: prompt}}); | ||
let srcStream = source('../README.md'); | ||
|
||
let resp = srcStream.pipe( gulpPrompt.confirm( options ) ); | ||
resp.write('../test.txt'); | ||
}); | ||
}); | ||
}); | ||
|
||
|