# commands-runner

> a cli tool to run a bunch of commands command

Latest version **1.1.4** (published 2020-04-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install commands-runner
pnpm add commands-runner
yarn add commands-runner
bun add commands-runner
```

Provides the commands `cmr`, `commands-runner`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2020-04-08 |
| First published | 2019-11-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 11 |
| Unpacked size | 54.5 KB |
| Known vulnerabilities | 0 (+7 in 1 direct dependencies) |
| Install scripts | yes |
| Author | ali_ahmed |
| Maintainers | ali_ahmed |
| Keywords | cli, commands, cmr.json, cmr, commands-runner, typescript |

## Links

- npm: https://www.npmjs.com/package/commands-runner
- Repository: https://github.com/AliBasicCoder/commands-runner
- npm.io page: https://npm.io/package/commands-runner

## Dependencies (11)

- [chalk](https://npm.io/package/chalk.md) ^3.0.0
- [delete](https://npm.io/package/delete.md) ^1.1.0
- [adm-zip](https://npm.io/package/adm-zip.md) ^0.4.13
- [shortid](https://npm.io/package/shortid.md) ^2.2.15
- [inquirer](https://npm.io/package/inquirer.md) ^7.0.0
- [make-dir](https://npm.io/package/make-dir.md) ^3.0.0
- [spinnies](https://npm.io/package/spinnies.md) ^0.5.0
- [@zeit/ncc](https://npm.io/package/@zeit/ncc.md) ^0.20.5
- [commander](https://npm.io/package/commander.md) ^5.0.0
- [autocomplete](https://npm.io/package/autocomplete.md) 0.0.1
- [cli-spinners](https://npm.io/package/cli-spinners.md) ^2.2.0

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.1.4 (latest) — 2020-04-08
- 1.0.8 (dev) — 2019-11-23
- 1.1.3 — 2019-11-27
- 1.1.2 — 2019-11-26
- 1.1.1 — 2019-11-25
- 1.1.0 — 2019-11-24
- 1.0.9 — 2019-11-23
- 1.0.7 — 2019-11-23
- 1.0.6 — 2019-11-22
- 1.0.5 — 2019-11-22
- 1.0.4 — 2019-11-22
- 1.0.3 — 2019-11-22
- 1.0.2 — 2019-11-22
- 1.0.1 — 2019-11-21
- 1.0.0 — 2019-11-21

## README

# commands-runner

[![npm](https://img.shields.io/npm/v/commands-runner)](https://www.npmjs.com/package/commands-runner)
[![npm](https://img.shields.io/npm/dm/commands-runner)](https://www.npmjs.com/package/commands-runner)
[![David](https://img.shields.io/david/AliBasicCoder/commands-runner)](https://david-dm.org/AliBasicCoder/commands-runner)
[![GitHub issues](https://img.shields.io/github/issues/AliBasicCoder/commands-runner)](https://github.com/AliBasicCoder/commands-runner/issues)

commands-runner is a cli tool to run commands
that can be used to any thing

YOU MUST READ THIS [IMPORT_NOTES](#important-Notes)

like creating a command to realise something or whatever

if you have issues, miss-understanding, questions or recommendation post an issue [here](https://github.com/AliBasicCoder/commands-runner/issues)

# installation

via npm:

```
npm i -g commands-runner
```

NOTE: don't install this module with yarn

# how to use

first create a file with you commandName followed
by `.cmr.json`

`.cmr.json` files should follow the `Commands`
type bellow:

```ts
interface Option {
  title: string; // the title of the option (required)
  // NOTE: you must provide one of this properties
  script?: string; // the node file you want to run (optional)
  template?: string; // the template zip file you want to extract (optional)
  commands?: commandItem[]; // the commands you want to run (optional)
}
interface AskItem {
  ask: string; // the question
  multiple?: boolean; // if you want to make the user able to choose multiple items
  options: Option[]; // the options
}
interface TemplateItem {
  template: string; // the template zip file you want to extract (required)
}
interface ScriptItem {
  script: string; // the script you want to run (required)
  scriptName: string; // ignore this
}
type commandItem = string | ScriptItem | TemplateItem | AskItem;

type Commands = commandItem | commandItem[];
```

example 1:

making a command that do the following

1. creating a git repo
2. making some template
3. running a file called `foo.js`

```js
[
  "git init", // running git init
  {
    template: "./template.zip", // extracting a file called template.zip
  },
  {
    script: "./print_hello_world.js", // running print_hello_world.js
  },
];
```

NOTE: the file name should include the extension (.cmr.json)

1. run `commands-runner add $fileName`
2. run `commands-runner start $fileName`

and it will run the commands as needed

example 2: for providing a list for the user to choose what to do

```js
[
  {
    ask: "choose something from the following", // the qeustion you want to ask
    multiple: true, // if true make the user able to choose multiple options
    options: [
      // the options
      {
        title: "extract the template", // the title of the option
        template: "./template.zip", // to extract a template
      },
      {
        title: "run a file",
        script: "foo.js", // to run a js file
      },
      {
        title: "run some commands",
        commands: [
          // to run some commands
          "echo hello world",
          { script: "bar.js" },
          // ...
        ],
      },
    ],
  },
];
```

example 3:
for using `value` option

```js
{
  "ask": "what's the type of sandwich you want?", // the question
  "multiple": true, // if you want to make the user able to use multiple options
  "options": [ // the options
    {
      "title": "hot dog", // the title of the option
      "value": "hot dog" // the value of it
    },
    {
      "title": "cheese burger",
      "value": "cheese burger"
    },
    {
      "title": "chicken burger",
      "value": "cheese burger"
    }
  ],
  "script": "./script.js" // the script you want to run after user choses options
}
```

when a user a select an option it will be passed in to the script as process arguments

if you use multiple it will be a `JSON.stringify`ed array

for example:

```js
// script.js
console.log(process.argv[2]); // will console log the value of  option user selected
```

# important-Notes

1. the script name of any of the commands should include the extension (.cmr.json)

2. when you use a script it get bundled so you probably won't be able to use any resources except json files (this might change in future versions)

3. any template or script name changes to a random hash

# cli

you can use `commands-runner` or `cmr`
to run this commands

## start

```
start <script>
```

starts a script you already installed

## add

```
add <script>
```

adds a script of commands for you to be able to use

## delete

```
delete <script>
```

delete a script from the installed script

## overwrite

```
overwrite <scriptToOverWrite> <script>
```

overwrite an installed script

## config

```
config
```

a command to run the configuration file with VSCode

the config file should follow the type `Config` below:

```ts
import { Spinner, SpinnerName } from "cli-spinners";

interface Config {
  "spinner-options": {
    spinner: SpinnerName | Spinner;
    color: string;
    indent: number;
    indentBeforeOutput: number;
    succeedColor: string;
    failColor: string;
  };
  "install-path": string; // the installation path
}
```

### install-path

the path you want to install your script

the default is your home directory + "/commands-runner"

### spinner-options

the spinner options

#### spinner

the spinner you want to choose for example: `dots` or ``runner`

@default `dots`

#### color

the color of the spinner while it's running

it could be any valid chalk color

@default `cyan`

#### indent

indent the spinner with a given number of spaces

@default `0`

#### indentBeforeOutput

indent the output of the command or script you're running
with a given number of spaces

@default `3`

#### succeedColor

the color of the spinner when it's done successfully

@default `green`

#### failColor

the color of the spinner when it fails

@default `red`

# License

MIT License

Copyright (c) 2019 AliBasicCoder

---
_Source: https://npm.io/package/commands-runner · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
