Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/a-nozeret/prompt-run
🏃 Run commands based on user input, dynamically generating environment variables, arguments, flags
https://github.com/a-nozeret/prompt-run
cli command env environment-variables flags nodejs npm prompt run yarn
Last synced: about 2 months ago
JSON representation
🏃 Run commands based on user input, dynamically generating environment variables, arguments, flags
- Host: GitHub
- URL: https://github.com/a-nozeret/prompt-run
- Owner: a-nozeret
- License: mit
- Created: 2019-07-19T16:05:17.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T04:51:06.000Z (about 2 years ago)
- Last Synced: 2024-10-07T20:48:24.537Z (3 months ago)
- Topics: cli, command, env, environment-variables, flags, nodejs, npm, prompt, run, yarn
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/prompt-run
- Size: 1.46 MB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
🏃 prompt-run
[![NPM](https://img.shields.io/npm/v/prompt-run.svg?logo=npm)](https://www.npmjs.com/package/prompt-run)
[![Travis Build](https://img.shields.io/travis/a-nozeret/prompt-run/master.svg?logo=travis-ci)](https://travis-ci.org/a-nozeret/prompt-run)
[![Codecov Coverage](https://img.shields.io/codecov/c/github/a-nozeret/prompt-run/master.svg?logo=codecov)](https://codecov.io/gh/a-nozeret/prompt-run/)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-airbnb-brightgreen.svg)](https://github.com/airbnb/javascript)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)> Run commands based on user input, dynamically generating environment variables, arguments, flags
## Getting started
```sh
yarn add -D prompt-run
```
```sh
prompt-run [options] [command]
```## API
**Note:** Check the [**Inquirer** documentation](https://github.com/SBoudrias/Inquirer.js#objects) for full details on how to create question objects.### CLI
```
Usage
$ prompt-run [options] [command]Options
--config, -c Path to questions config file
--prefix, -p Prompt scripts with the provided prefix
--dry-run No execution after generating the command
--silent, -s Disable output of generated command
```
### Module
```js
const promptRun = require('prompt-run')promptRun({
command: 'yarn',
options: {},
questions: {
env: [],
args: [],
},
}).then((childProcess) => {})
```#### 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
```js
module.exports = () => ({
env: [
// Question objects
],
args: [
// Question objects
],
})
```
The config is divided into:
+ `env`: Node Environment variables to prompt
+ `args`: Arguments/flags prompted. Anything coming after the base command.##### Questions object
Check the [**Inquirer** documentation](https://github.com/SBoudrias/Inquirer.js#objects) for full details on how to create question objects.## Examples
#### 1. CLI
With a defined config of questions*questions.js*
```js
module.exports = () => ({
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*
```sh
prompt-run -c questions.js yarn start
```
*Example output / command executed*
```sh
$ NODE_ENV=development SECRET_KEY=1234 yarn start --watch --log-level warning
```#### 2. Scripts
As a node module in scripts*dependency-info.js*
```js
const promptRun = require('prompt-run')
const packageJson = require('./package.json')const dependencies = Object.keys(packageJson.dependencies)
const fields = ['description', 'readme', 'version', 'dependencies']promptRun({
command: 'yarn info',
questions: {
args: [
{
type: 'list',
name: 'dependency',
message: 'Select a dependency',
choices: dependencies,
},
{
type: 'list',
name: 'field',
message: 'Select a field to print',
choices: fields,
},
],
},
}).then((childProcess) => {
childProcess.on('close', () => {
console.log('\nFinished with the child process!')
})
})
```
*Run*
```sh
node dependency-info.js
```#### 3. Prefix shortcut
Prompt existing scripts starting with a given prefix*package.json*
```json
{
"scripts": {
"start:dev": "...",
"start:prod": "...",
"start:docker": "..."
}
}
```
*Run*
```sh
prompt-run -p start
```## Development
```sh
yarn
yarn link
...
yarn test --coverage
yarn lint
yarn commit
yarn unlink
```
### Publish / release
```sh
yarn release
git push --follow-tags origin master
```
[Github Action](https://github.com/a-nozeret/prompt-run/blob/master/.github/workflows/npmpublish.yml) will be triggered, publishing the package to NPM### 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](./LICENSE) for more information.