🏃 prompt-run
Run commands based on user input, dynamically generating environment variables, arguments, flags
Getting started
yarn add -D prompt-run
prompt-run [options] [command]
API
Note: Check the Inquirer documentation for full details on how to create question objects.
CLI
Usage
$ prompt-run [options] [command]
Options
--config, -c <filename> Path to questions config file
--prefix, -p <prefix> Prompt scripts with the provided prefix
--dry-run No execution after generating the command
--silent, -s Disable output of generated command
Module
const promptRun =
Command
The base used to run along the generated command.
Default: yarn
(or npm run
if your project doesn't contain a yarn.lock
file)
It can be anything which is not needed to prompt.
Options
Name | Type | Default | Description |
---|---|---|---|
config | string | "prompt-run.js" | Path to questions config file |
prefix | string | undefined | Prompt existing scripts starting with the given prefix |
dryRun | boolean | false | No execution after generating the command |
silent | boolean | false | Disable output of the generated command |
Questions
Questions config file
module env: // Question objects args: // Question objects
The config is divided into:
env
: Node Environment variables to promptargs
: Arguments/flags prompted. Anything coming after the base command.
Questions object
Check the Inquirer documentation for full details on how to create question objects.
Examples
1. CLI
With a defined config of questions
questions.js
module env: type: 'list' name: 'NODE_ENV' choices: 'production' 'development' name: 'SECRET_KEY' args: type: 'confirm' name: '--watch' default: false name: '--log-level' type: 'list' choices: 'error' 'warning'
Run
prompt-run -c questions.js yarn start
Example output / command executed
$ NODE_ENV=development SECRET_KEY=1234 yarn start --watch --log-level warning
2. Scripts
As a node module in scripts
dependency-info.js
const promptRun = const packageJson = const dependencies = Objectconst fields = 'description' 'readme' 'version' 'dependencies'
Run
node dependency-info.js
3. Prefix shortcut
Prompt existing scripts starting with a given prefix
package.json
Run
prompt-run -p start
Development
yarnyarn link...yarn test --coverageyarn lintyarn commityarn unlink
Publish / release
Github Action auto-publishing for each commit pushed to master.
Todo list
- Bugs:
- Inquirer errors do not appear directly in CLI mode
- Configs should consist in promptRun Object argument
- feature:
$ prompt-run -env NODE_ENV yarn start
shortcut for question
License
Licensed under the MIT License, Copyright © 2019-present Antoine Nozeret.
See LICENSE for more information.