Add README.md > With Task Runner
This commit is contained in:
parent
c46576d90b
commit
5fe64de8ab
2 changed files with 45 additions and 1 deletions
44
README.md
44
README.md
|
@ -95,6 +95,50 @@ readlineSync.setPrompt('> '.bold.red);
|
||||||
cmd = readlineSync.prompt();
|
cmd = readlineSync.prompt();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## With Task Runner
|
||||||
|
|
||||||
|
If you want to control the flow of task runner (e.g. [Grunt](http://gruntjs.com/)), call readlineSync in a task callback that is called by task runner. Then the flow of tasks is paused and it is controlled by user.
|
||||||
|
|
||||||
|
Example: by using [grunt-task-helper](https://www.npmjs.org/package/grunt-task-helper)
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ grunt
|
||||||
|
Running "fileCopy" task
|
||||||
|
Files already exist:
|
||||||
|
file-a.png
|
||||||
|
file-b.js
|
||||||
|
Overwrite? (y/n) :y
|
||||||
|
file-a.png copied.
|
||||||
|
file-b.js copied.
|
||||||
|
Done.
|
||||||
|
```
|
||||||
|
|
||||||
|
`Gruntfile.js`
|
||||||
|
|
||||||
|
```js
|
||||||
|
grunt.initConfig({
|
||||||
|
taskHelper: {
|
||||||
|
fileCopy: {
|
||||||
|
options: {
|
||||||
|
handlerByTask: function() {
|
||||||
|
// Abort the task if user don't want.
|
||||||
|
return readlineSync.question('Overwrite? (y/n) :')
|
||||||
|
.toLowerCase() === 'y';
|
||||||
|
// Or process.exit()
|
||||||
|
},
|
||||||
|
filesArray: []
|
||||||
|
},
|
||||||
|
...
|
||||||
|
}
|
||||||
|
},
|
||||||
|
copy: {
|
||||||
|
fileCopy: {
|
||||||
|
files: '<%= taskHelper.fileCopy.options.filesArray %>'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## Note
|
## Note
|
||||||
|
|
||||||
### Platforms
|
### Platforms
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "readline-sync",
|
"name": "readline-sync",
|
||||||
"description": "Synchronous Readline",
|
"description": "Synchronous Readline",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"homepage": "https://github.com/anseki/readline-sync",
|
"homepage": "https://github.com/anseki/readline-sync",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "anseki"
|
"name": "anseki"
|
||||||
|
|
Loading…
Reference in a new issue