
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
grunt-prompt
Advanced tools
Add interactive console prompts to your Gruntfile such as lists, checkboxes, text input with filtering, and password fields.
Add interactive UI to your Gruntfile such as lists, checkboxes, text input with filtering, and password fields, all on the command line.
Grunt-prompt
's UI is powered by the amazing Inquirer, a project created by Simon Boudrias.
This plugin requires Grunt ~0.4.1
npm install grunt-prompt --save-dev
One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-prompt');
In your project's Gruntfile, add a section named prompt
to the data object passed into grunt.initConfig()
.
grunt-prompt
is a multi-task. This means you can create multiple prompts.
grunt.initConfig({
prompt: {
target: {
options: {
questions: [
{
config: 'config.name', // arbitray name or config for any other grunt task
type: '<question type>', // list, checkbox, confirm, input, password
message: 'Question to ask the user',
default: 'value', // default value if nothing is entered
choices: 'Array|Function(answers)',
validate: Function(value), // return true if valid, error message if invalid
filter: Function(value), // modify the answer
when: Function(answers) // only ask this question when this function returns true
}
]
}
},
},
})
Type: String
required
This is used for three things:
config: 'jshint.allFiles.reporter'
answers
object: if (answers['jshint.allFiles.reporter'] === 'custom') {...
grunt.config
: grunt.config('jshint.allFiles.reporter')
Type: String
required
Type of question to ask:
list
: use arrow keys to pick one choice. Returns a string.checkbox
: use arrow keys and space bar to pick multiple items. Returns an array.confirm
: Yes/no. Returns a boolean.input
: Free text input. Returns a string.password
: Masked input. Returns a string.Here's an example of each type:
The documentation for Inquiry has more details about type as well as additional typess.
Type: String
required
Question to ask the user.
Hint: keep it short, users hate to read.
Type: String
/Array
/Boolean
depending on question type
optional
Default value used when the user just bangs Enter.
For question types 'list' and 'checkbox'
: Type: array of hashes
name
The label that is displayed in the UI.value
optional Value returned. When not used the name is used instead.checked
optional Choosed the option by default. Only for checkbox.choices: [
{ name: 'jshint', checked: true },
{ name: 'jslint' },
{ name: 'eslint' },
{ name: 'I like to live dangerously', value: 'none' }
]
Type: function(value)
optional
Return true
if it is valid (true true
, not a truthy value).
Return string
message if it is not valid.
Type: function(value)
optional
Use a modified version of the input for the answer. Useful for stripping extra characters, converting strings to integers.
Type: function(answers)
optional
Choose when this question is asked. Perfect for asking questions based on the results of previous questions.
You can also modify how tasks will work by changing options for other tasks.
You do not need to write code to do this, it's all in the config
var.
Here we will let the user choose what Mocha reporter to use.
config:
prompt: {
mochacli: {
options: {
questions: [
{
config: 'mochacli.options.reporter'
type: 'list'
message: 'Which Mocha reporter would you like to use?',
default: 'spec'
choices: ['dot', 'spec', 'nyan', 'TAP', 'landing', 'list',
'progress', 'json', 'JSONconv', 'HTMLconv', 'min', 'doc']
}
]
}
}
}
and create a shortcut:
grunt.registerTask('test',
[
'prompt:mochacli',
'mochacli'
]);
And run it:
$ grunt test
This config
value is accessible to all other grunt
tasks via grunt.config('<config name>')
.
If you had this:
config: 'validation'
Then later on in your custom task can access it like this:
var validation = grunt.config('validation');
This is an example of how grunt-prompt
for something like grunt-bump which makes it easy to
update your project's version in the package.json
, bower.json
, and git tag
.
prompt: {
bump: {
options: {
questions: [
{
config: 'bump.increment',
type: 'list',
message: 'Bump version from ' + '<%= pkg.version %>'.cyan + ' to:',
choices: [
{
value: 'build',
name: 'Build: '.yellow + (currentVersion + '-?').yellow +
' Unstable, betas, and release candidates.'
},
{
value: 'patch',
name: 'Patch: '.yellow + semver.inc(currentVersion, 'patch').yellow +
' Backwards-compatible bug fixes.'
},
{
value: 'minor',
name: 'Minor: '.yellow + semver.inc(currentVersion, 'minor').yellow +
' Add functionality in a backwards-compatible manner.'
},
{
value: 'major',
name: 'Major: '.yellow + semver.inc(currentVersion, 'major').yellow +
' Incompatible API changes.'
},
{
value: 'custom',
name: 'Custom: ?.?.?'.yellow +
' Specify version...'
}
]
},
{
config: 'bump.version',
type: 'input',
message: 'What specific version would you like',
when: function (answers) {
return answers['bump.increment'] === 'custom';
},
validate: function (value) {
var valid = semver.valid(value) && true;
return valid || 'Must be a valid semver, such as 1.2.3-rc1. See ' +
'http://semver.org/'.blue.underline + ' for more details.';
}
},
{
config: 'bump.files',
type: 'checkbox',
message: 'What should get the new version:',
choices: [
{
value: 'package',
name: 'package.json' +
(!grunt.file.isFile('package.json') ? ' file not found, will create one'.grey : ''),
checked: grunt.file.isFile('package.json')
},
{
value: 'bower',
name: 'bower.json' +
(!grunt.file.isFile('bower.json') ? ' file not found, will create one'.grey : ''),
checked: grunt.file.isFile('bower.json')
},
{
value: 'git',
name: 'git tag',
checked: grunt.file.isDir('.git')
}
]
}
]
}
}
}
FAQs
Interactive prompt for your Grunt config using console checkboxes, text input with filtering, password fields.
The npm package grunt-prompt receives a total of 6,019 weekly downloads. As such, grunt-prompt popularity was classified as popular.
We found that grunt-prompt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.