{"id":18389558,"url":"https://github.com/anseki/grunt-confirm","last_synced_at":"2025-04-07T02:34:29.395Z","repository":{"id":20857832,"uuid":"24144603","full_name":"anseki/grunt-confirm","owner":"anseki","description":"Abort or continue the flow of tasks according to an answer (with or without Enter key) to the specified question. The flow of tasks is paused, until the user responds and the next behavior is found by specified options.","archived":false,"fork":false,"pushed_at":"2022-08-19T03:10:01.000Z","size":27,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T11:44:55.265Z","etag":null,"topics":["abort","confirm","continue","flow","grunt","grunt-plugins","gruntplugin","javascript","pause","prompt","question","wait"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anseki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-17T12:53:39.000Z","updated_at":"2022-08-19T03:10:04.000Z","dependencies_parsed_at":"2022-08-30T11:30:18.902Z","dependency_job_id":null,"html_url":"https://github.com/anseki/grunt-confirm","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anseki%2Fgrunt-confirm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anseki%2Fgrunt-confirm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anseki%2Fgrunt-confirm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anseki%2Fgrunt-confirm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anseki","download_url":"https://codeload.github.com/anseki/grunt-confirm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247583473,"owners_count":20962038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abort","confirm","continue","flow","grunt","grunt-plugins","gruntplugin","javascript","pause","prompt","question","wait"],"created_at":"2024-11-06T01:43:44.123Z","updated_at":"2025-04-07T02:34:24.386Z","avatar_url":"https://github.com/anseki.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# grunt-confirm\n\n[![npm](https://img.shields.io/npm/v/grunt-confirm.svg)](https://www.npmjs.com/package/grunt-confirm) [![GitHub issues](https://img.shields.io/github/issues/anseki/grunt-confirm.svg)](https://github.com/anseki/grunt-confirm/issues) [![David](https://img.shields.io/david/anseki/grunt-confirm.svg)](package.json) [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\nAbort or continue the flow of tasks according to an answer (with or without Enter key) to the specified question. The flow of tasks is paused, until the user responds and the next behavior is found by specified options.\n\n![sample](cl_01.png)\n\n![sample](cl_02.png)\n\n## Getting Started\n\nThis plugin requires Grunt `~0.4.1`\n\nIf you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:\n\n```shell\nnpm install grunt-confirm --save-dev\n```\n\nOnce the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:\n\n```js\ngrunt.loadNpmTasks('grunt-confirm');\n```\n\n## The \"confirm\" task\n\nIn your project's Gruntfile, add a section named `confirm` to the data object passed into `grunt.initConfig()` (see [Configuring tasks](http://gruntjs.com/configuring-tasks)).\n\n### Options\n\n#### `question`\n\n*Type:* string, function or `undefined`\n\nDisplay a specified string or a returned string by a specified function to the user.  \nIf the function returns a *falsy*, this task is finished immediately. And the flow of tasks is continued.\n\nThe function is passed a `files` argument. That is the standard Grunt `files` components (see [Files](http://gruntjs.com/configuring-tasks#files)).  \nThe function can make the question text by using it.\n\nIf this option is not specified when `'_key'` is specified to the [`input`](#input) option and the [`proceed`](#proceed) option is not specified (i.e. you want to let the flow of tasks just pause), a message `'Continue... (Hit any key)'` is displayed.\n\nFor example:\n\n`Gruntfile.js`\n\n```js\ngrunt.initConfig({\n  confirm: {\n    build: {\n      options: {\n        // Static text.\n        question: 'This processing requires about 10 minutes. Continue?',\n        input: '_key:y'\n      }\n    }\n  },\n  // Other tasks...\n});\n```\n\n```js\ngrunt.initConfig({\n  confirm: {\n    deploy: {\n      src: '\u003c%= copy.deploy.src %\u003e', // refer to another task\n      options: {\n        question: function(files) {\n          var count = 0;\n          files.forEach(function(f) { count += f.src.length; });\n          return !count ? false : // No file. And do nothing.\n            count + ' files are copied at next task. Are you sure?';\n        },\n        input: '_key:y'\n      }\n    }\n  },\n  copy: {\n    deploy: {\n      expand: true,\n      cwd: 'src/',\n      src: '**/*.html',\n      dest: 'public_html/'\n    }\n  }\n});\n```\n\n#### `input`\n\n*Type:* string or `undefined`\n\nAccept the user's input that is specified type.\n\n* If it is not specified (i.e. `undefined`), accept a **text** (with an Enter key), and let the [`proceed`](#proceed) option decide whether to continue the flow of tasks.\n* If a comma-separated string like `'text1,text2'` is specified, accept a **text** (with an Enter key), and continue the flow of tasks when the input text was found in that comma-separated string, otherwise abort it.\n* If `'_key'` is specified, get a pressed **key** (without an Enter key), and let the [`proceed`](#proceed) option decide whether to continue the flow of tasks.\n* If a string `'_key:charlist'` is specified, get a pressed **key** (without an Enter key), and continue the flow of tasks when the pressed key was found in that `charlist`, otherwise abort it. The `charlist` is a string that includes characters as the keys. For example, if `'_key:abc'` is specified, continue the flow of tasks when the `A`, `B` or `C` key is pressed.\n\nThe string comparisons are case-insensitive (i.e. `a` equals `A`).\n\n#### `proceed`\n\n*Type:* function, boolean or `undefined`\n\nDecide whether to continue the flow of tasks when the [`input`](#input) option is not specified (i.e. `undefined`) or `'_key'` is specified to it.\n\nIf a function is specified, call the function, and continue the flow of tasks when that returns a *truthy*, otherwise abort it.  \nThe function is passed an `answer` and a `files` arguments. The `answer` is a string that was input by the user, or a single character as a pressed key by the user. The `files` is the standard Grunt `files` components (see [Files](http://gruntjs.com/configuring-tasks#files)).  \nThe function can determine to abort or continue by using those.\n\nIf `false` is specified, the flow of tasks is aborted immediately. And the remaining tasks will not run.  \nOtherwise the flow of tasks is continued. That is, when any text was input or any key was pressed, it is continued. It is just paused until it.\n\nFor example:\n\n`Gruntfile.js`\n\n```js\ngrunt.initConfig({\n  confirm: {\n    pack: {\n      src: '\u003c%= another.pack.src %\u003e', // refer to another task\n      options: {\n        question: 'How many files are required?',\n        proceed: function(answer, files) {\n          var count = 0;\n          files.forEach(function(f) { count += f.src.length; });\n          if (count \u003c +answer) {\n            grunt.log.writeln('There are only ' + count + ' files.');\n            return false;\n          } else {\n            return true;\n          }\n        }\n      }\n    }\n  },\n  // Other tasks...\n});\n```\n\n```js\ngrunt.initConfig({\n  confirm: {\n    build: {\n      options: {\n        question: 'Do you want to build? :',\n        input: '_key:y' // Continue the flow if `Y` key is pressed.\n      }\n    }\n  },\n  // Other tasks...\n});\n```\n\n```js\ngrunt.initConfig({\n  confirm: {\n    // Show something. Pause until any key is pressed.\n    showMessage: {options: {input: '_key'}}\n  },\n  // Other tasks...\n});\n```\n\n## See Also\n\nIf you want to more process, consider [grunt-task-helper](https://github.com/anseki/grunt-task-helper) and [readlineSync](https://github.com/anseki/readline-sync).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanseki%2Fgrunt-confirm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanseki%2Fgrunt-confirm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanseki%2Fgrunt-confirm/lists"}