diff --git a/README.md b/README.md index 029bb21..ebd6478 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,50 @@ readlineSync.setPrompt('> '.bold.red); 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 ### Platforms diff --git a/package.json b/package.json index 2a4591b..a6e1ddc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "readline-sync", "description": "Synchronous Readline", - "version": "0.4.6", + "version": "0.4.7", "homepage": "https://github.com/anseki/readline-sync", "author": { "name": "anseki"