1.1.4 • Published 4 years ago

commands-runner v1.1.4

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

commands-runner

npm npm David GitHub issues

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

YOU MUST READ THIS IMPORT_NOTES

like creating a command to realise something or whatever

if you have issues, miss-understanding, questions or recommendation post an issue here

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:

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
[
  "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

[
  {
    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

{
  "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.stringifyed array

for example:

// 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:

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

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.2

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago