• Stars
    star
    888
  • Rank 51,399 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Node Task List: Interactive cli to list and run package.json scripts



ntl


Node Task List

NPM version Build Status Coverage Status License Join the chat at https://gitter.im/ipipeto/Lobby

Interactive cli tool that lists and run package.json scripts.

An iPipeTo workflow


Table of Contents


⬇️ Install

$ npm install -g ntl

🔎 Usage

Navigate to any folder containing a package.json file (usually a Node.js project) that has configured scripts, then just use the ntl command:

ntl

You can also specify a path to a project folder containing a package.json file:

ntl ./my-node-project


demo animation


😍 Features

  • Interactive interface that lists all package.json scripts
  • Select any item in the interactive interface to execute that task
  • Add descriptions to each task that can be shown in the UI
  • Multiple interactive interfaces (menu list, autocomplete fuzzy search)
  • Many options to customize the UI (exclude scripts, amount of items, etc)
  • Easy to repeat last ran script (nt and rerun options)
  • Run multiple tasks
    • Repeat previously set of ran tasks
    • Preserve order of selection
  • Customize rerun cache options

📚 Customize

Custom runner

By default Node Task List tries to use npm to run the configured script tasks. In case you want to use a custom runner (e.g: yarn or pnpm) you can configure ntl to use whatever runner you prefer.

That can be configured system-wide by setting the environment variable in your profile file (.bashrc or .bash_profile for macos). In case you only want to ever use yarn as your node task runner, you should set:

# .bashrc (linux) OR .bash_profile (macos)
export NTL_RUNNER=yarn

Keep in mind environment variables are flexible enough that they can also be set temporarily prior to running a command, so the following would also work:

NTL_RUNNER=yarn ntl

❗ You can also define a runner in a per-project basis using the ntl configuration of your package.json, e.g:

{
  "name": "<project>",
  "version": "1.0.0",
  "ntl": {
    "runner": "yarn"
  }
}

Using task descriptions

📝 You can define descriptions for your tasks in your package.json file by defining a ntl section, e.g:

{
  "name": "<project>",
  "version": "1.0.0",
  "scripts": {
    "build": "make build",
    "coverage": "jest --coverage",
    "test": "jest"
  },
  "ntl": {
    "descriptions": {
      "build": "Builds the project",
      "coverage": "Run test outputing code coverage",
      "test": "Run project's tests"
    }
  }
}

These descriptions will be shown anytime you run ntl.


Displaying task contents

Use the --info or simply -i option in order to display the contents of each script task, like:

$ ntl -i
⬢  Node Task List
? Select a task to run: (Use arrow keys)
❯ generate-manual › maked-man README.md > man/man1/ntl.1
          pretest › eslint cli.js rerun.js test
             test › cross-env NTL_NO_RERUN_CACHE=1 tap

Task contents will also be shown when using the --descriptions option and no description is available for a given item.


Exclude tasks from UI

You can define a list of scripts to be excluded from the interactive menu using the --exclude option:

$ ntl -e coverall tasks
⬢  Node Task List
? Select a task to run: (Use arrow keys)
❯ test
  test:watch

You can also use a wildcard character to exclude multiple scripts:

$ ntl -e "test*"
⬢  Node Task List
? Select a task to run: (Use arrow keys)
❯ coveralls
  tasks

Exclude tasks with missing descriptions

You can also filter out items that doesn't have a description using the --descriptions-only or -o option.


Customize cache

ntl uses a cache system that stores the last ran command for each project in order to make it easier for users to repeat it. Given its importance, the following environment variables are available in order to customize its location and size:

  • NTL_RERUN_CACHE_DIR: Defines a directory to store the cache file
  • NTL_RERUN_CACHE_NAME: Filename to use for the cache
  • NTL_RERUN_CACHE_MAX: Number of items to store in the cache (defaults to 10)
  • NTL_NO_RERUN_CACHE: When defined, avoid the cache system completely

For example, if a given user wanted to store its cache in ~/.ntl/cache location and save up to 100 items in it, they could add the following to their .bashrc (linux) or .bash_profile (macos):

export NTL_RERUN_CACHE_DIR=$HOME
export NTL_RERUN_CACHE_NAME=cache
export NTL_RERUN_CACHE_MAX=100

The cache can also be customized through command line options:

  • --rerun-cache-dir Defines a directory to store the cache file
  • --rerun-cache-name: Filename to use for the cache
  • --no-rerun-cache: Avoids the cache system completely

UI Size

You can increase/reduce the size of the presented UI list using the --size or -s option. In this example we just increased the size of the list to show up to 12 items at once:

$ ntl -s 12
⬢  Node Task List
? Select a task to run:
❯ build
  generate-manual
  hello
  bomdia
  bonjour
  test
  test:dev
  test:ci
  test:integration
  test:unit
  test:e2e
  start

The default size value is 7 items.


🔄 Repeat the last ran task

ntl provides many options to make it easier to rerun the last task, either through having it selected as default option the next time you run the ntl command, or by using one of the following:

  • The ultra convenient way: nt command shorthand 😎 (You should think of nt as: "ok, just run the last node task", in contrast to ntl which should be interpreted as: "ok, give me the node task list again") in case no previous task is available, running nt will behave exactly as ntl
  • Using a --rerun or -r flag, e.g: ntl -r
  • Prepending the NTL_RERUN env variable, e.g: NTL_RERUN=true ntl

demo animation showing how to rerun a script using the nt command shorthand


Ⓜ️ Run multiple tasks

Using the --multiple or -m option, the interface becomes a checkbox-based list that allows you to select multiple tasks and run them in serial.

$ ntl -m
⬢  Node Task List
? Select a task to run:
 ◯ start
 ◉ test
❯◉ test:ci

demo animation showing how to use -m to have a checkbox interface allowing for selection of multiple tasks to be ran in serial

Better yet, combine that with the rerun feature and you can repeat multiple tasks using the nt command.

Run multiple tasks in order of selection

You can run multiple tasks in the order you pick them 😎 Use the --ordered or -O option:

$ ntl -O
⬢  Node Task List
? Select a task to run: (Press <space> to select, <r> to res
et)
 ◯   bar › Test task
 ◯   foo › Test task
❯2 hello › Hello world
 ◯ start › Start the development server
 1  test › Run all tests for the project

⏩ Run in autocomplete or fuzzy search mode

Use --autocomplete or -A option in order to use an interface variation that allows you to type the name of the task instead of browsing through an arrow-based menu. This mode can be very helpful when managing a long list of tasks.

$ ntl -A
⬢  Node Task List
? Select a task to run: t
❯ pretest
  test
  start

demo animation showing how to use -m to have a checkbox interface allowing for selection of multiple tasks to be ran in serial


✅ Tips

ntl as default task

You can define ntl as a dev dependency and one of the tasks of your project, specially start - so whenever someone runs npm start or yarn start they get the convenient ntl interface. Like in the following package.json example:

{
  "name": "<project>",
  "version": "1.0.0",
  "scripts": {
    "start": "ntl"
  },
  "devDependencies": {
    "ntl": "^5.0.0"
  }
}

Exclude scripts

You can also define a task that invokes ntl while excluding other tasks, e.g:

{
  "scripts": {
    "test": "jest --coverage",
    "test:watch": "jest --coverage --watchAll",
    "coveralls": "jest --coverage --coverageReporters=text-lcov | coveralls",
    "tasks": "ntl --exclude coverall tasks"
  }
}

Included command aliases

  • ntl The default command
  • nodetasklist Longhand version in case users have conflicting ntl commands
  • npm-tasklist Legacy longhand version
  • nt Rerun last script shortcut
  • nodetask Rerun last script longhand

ℹ️ Help

Still feel like you could use some --help ?

Usage:
  ntl [<path>]             Build an interactive interface and run any script
  nt [<path>]              Rerun last executed script

Options:
  -a, --all                Includes pre and post scripts on the list   [boolean]
  -A, --autocomplete       Starts in autocomplete mode                 [boolean]
  -D, --debug              Prints to stderr any internal error         [boolean]
  -d, --descriptions       Displays the descriptions of each script    [boolean]
  -o, --descriptions-only  Limits output to scripts with a description [boolean]
  -h, --help               Shows this help message                     [boolean]
  -i, --info               Displays the contents of each script        [boolean]
  -e, --exclude            Excludes specific scripts                     [array]
  -m, --multiple           Allows the selection of multiple items      [boolean]
  -O, --ordered            Selects multiple items in order             [boolean]
  -s, --size               Amount of lines to display at once           [number]
  --rerun-cache-dir        Defines the rerun task cache location        [string]
  --rerun-cache-name       Defines the rerun task cache filename        [string]
  --no-rerun-cache         Never write to or read from cache           [boolean]
  -v, --version            Show version number                         [boolean]
  -r, --rerun              Rerun last executed script                  [boolean]

Visit https://github.com/ruyadorno/ntl for more info

License

MIT © 2020 Ruy Adorno

More Repositories

1

ipt

Interactive Pipe To: The Node.js cli interactive workflow
JavaScript
843
star
2

simple-slider

🎠 The 1kb JavaScript Carousel
JavaScript
601
star
3

snapstub

Copy API endpoints to your fs and run a local server using them
JavaScript
255
star
4

dom-i18n

Provides a very basic HTML multilingual support using JavaScript
JavaScript
139
star
5

grunt-menu

Useful menu interface for listing/executing your configured tasks
JavaScript
79
star
6

installme-osx

My personal script to setup a new OSX
Shell
60
star
7

git-bc

Git plugin to interactively list branches and checkout
JavaScript
60
star
8

generator-umd

An Yeoman Generator to create a basic UMD structure
JavaScript
28
star
9

console-faker

Get some file content to be printed out on console while you type anything on your keyboard.
JavaScript
26
star
10

preact-jest-snapshot-test-boilerplate

🚀 Test Preact components using Jest snapshots
JavaScript
23
star
11

mitro-cli

Manage your Mitro passwords from a command line interface.
JavaScript
22
star
12

telegram-pi-bot

A python-telegram-bot setup to run on Raspberry pi
Python
22
star
13

polymer-simple-slider

A Polymer element providing a simple slider functionality
HTML
22
star
14

jest-serializer-html-string

A better Jest snapshot serializer for plain html strings
JavaScript
17
star
15

prettierme

Fastest way to run prettier for a single file. Fork of https://github.com/ruyadorno/eslintme
Shell
15
star
16

angular-simple-slider

An AngularJS directive providing a simple slider functionality
JavaScript
15
star
17

checkbower

Validates your bower.json files
JavaScript
13
star
18

itrash

Interactively selects files to delete from current folder in the cli
JavaScript
13
star
19

git-iadd

Git plugin that allows you to interactively select which files to add to stage (git add)
JavaScript
12
star
20

dotfiles

Shell
11
star
21

mail-sender

A simple python script to send an html email using smtplib
Python
10
star
22

clean-dir

Command line util to clean a directory
JavaScript
9
star
23

request-hash

Generate a hash from an express Request or http.IncomingMessage
JavaScript
8
star
24

path-complete-extname

path.extname implementation adapted to also include multiple dots extensions.
JavaScript
8
star
25

eslintme

The fastest way to eslint a single file
Shell
7
star
26

extract-path

Extract a valid file system path from a string
JavaScript
7
star
27

lru-cache-fs

Extends lru-cache to add file system support
JavaScript
6
star
28

estimate

Application to help time estimation for digital agencies.
Python
5
star
29

js-signals-factory

A small factory implementation for js-signals.
JavaScript
5
star
30

git-pr

Interactive checkout PRs using the GitHub cli
Shell
4
star
31

git-ishow

Git plugin that lets you interactively select a stashed item to show
JavaScript
4
star
32

tlr

Quick spawn a tiny-lr server
JavaScript
4
star
33

nextjs-api-fetch-example

A simple example using fetched API data to render components
JavaScript
4
star
34

simple-output

Output messages to stdout/stderr
JavaScript
4
star
35

extend-grunt-plugin

Helper method to easily extend an already existing grunt task.
JavaScript
4
star
36

create-100-workshop

The road to 100% test coverage workshop
JavaScript
3
star
37

npx-utils

👾 Manages packages in the npx-space
JavaScript
3
star
38

simple-data-structures

🌅 Basic data structures with tons of tests and helper functions
Python
2
star
39

cli-all-the-things

Talk at ForwardJS 2020
JavaScript
2
star
40

npm-community-landing-page

HTML
2
star
41

outdated

Shortcut to interactively update an outdated dep using npm + ipt
Shell
1
star
42

redact

Small cli util that redacts path refs from stdin
JavaScript
1
star
43

stubborn-server-hash-loader

Loader plugin for stubborn-server
JavaScript
1
star
44

ruyadorno.github.io

HTML
1
star
45

mitro-js

Mirror of the API to access Mitro server side from node applications.
JavaScript
1
star
46

vim-change-indent

Vim plugin to convert the indent sizes in a file.
Vim Script
1
star
47

ruyadorno

1
star
48

generator-jsmontreal

A test generator to be presented at js-montreal 02/10 meetup
JavaScript
1
star
49

checkgituser

Checks a folder to find .git/config files without an [user] field declared
Python
1
star
50

the-one-with-test-coverage

Demo repo for my test coverage talk from JS Montreal 10/2019
JavaScript
1
star