npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prompt-run

v1.4.5

Published

Run commands based on user input, dynamically generating environment variables, arguments, flags

Downloads

11

Readme

NPM Travis Build Codecov Coverage JavaScript Style Guide Commitizen friendly

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 = 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
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 for full details on how to create question objects.

Examples

1. CLI

With a defined config of questions

questions.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

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 = 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

node dependency-info.js

3. Prefix shortcut

Prompt existing scripts starting with a given prefix

package.json

{
  "scripts": {
    "start:dev": "...",
    "start:prod": "...",
    "start:docker": "..."
  }
}

Run

prompt-run -p start

Development

yarn
yarn link
...
yarn test --coverage
yarn lint
yarn commit
yarn 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.