1.1.0 • Published 1 year ago

node-ray-cli v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

node-ray-cli


Overview

This npm package provides a ray script that lets you control Spatie's Ray app from the command line. It allows you to easily debug your CLI scripts.

Installation

Install the package normally with npm:

npm install node-ray-cli

...install it globally to be able to access it from any script/directory:

npm install -g node-ray-cli

...or run it without installing using npx:

npx node-ray-cli --help

Usage

ray <command name> <args, ...>

If no command name is specified, send is assumed.

image

When calling commands that send modifiable payloads, the payload uuid is sent to stdout if the --show-uuid option flag is provided. For example, you may modify the color of a payload after it has been sent by using the color command:

ray 'hello world' --show-uuid # writes "ae625128-ed3a-2b92-1a3f-2e0ebf7a2ad1" to stdout
ray color ae625128-ed3a-2b92-1a3f-2e0ebf7a2ad1 green

...or remove the payload from Ray entirely:

ray 'hello world' --show-uuid # writes "ae625128-ed3a-2b92-1a3f-2e0ebf7a2ad1" to stdout
ray remove ae625128-ed3a-2b92-1a3f-2e0ebf7a2ad1

Some other usage examples:

ray 'hello world' --blue
ray pause
ray html '<em>hello world</em>'
ray file message.txt

Disabling node-ray-cli

The ray command can be disabled by setting the NODE_RAY_DISABLED environment variable to "1":

export NODE_RAY_DISABLED="1"

Available option flags

There are several option flags that can be used with any command:

FlagDescription
--hideDisplay the payload as collapsed by default
--if=valueDon't send the payload if value is "false", 0, or "no"
--largeDisplay large text
--show-uuidWrite the payload uuid to stdout
--smallDisplay small text
--blueDisplay the payload as blue
--grayDisplay the payload as gray
--greenDisplay the payload as green
--orangeDisplay the payload as orange
--purpleDisplay the payload as purple
--redDisplay the payload as red

Command reference

CommandDescription
clearClear the current screen
clear-allClear the current and all previous screens
color <uuid> <color>Change the color of a payload that has already been sent
confettiDisplay confetti in Ray!
file <filename>Show the contents of filename
hide-appHide the Ray app
html <content>Display rendered html
image <location>Display an image from a URL or file
json <content>Display formatted JSON
notify <message>Display a desktop notification
pausePause code execution
remove <uuid>Remove a payload
send <payload>Send a payload to Ray
show-appShow the Ray app
size <uuid> <size>Change the text size of a payload that has already been sent (sizes are 'large' or 'small')
text <data>Display a text string with whitespace preserved
xml <data>Display formatted XML

Example Bash Script

#!/bin/bash

RAYUUID=$(ray "arg count: $#" --show-uuid)
ray color $RAYUUID blue

if [ $# -eq 0 ]; then
    echo "no filename provided"
    exit 1
fi

FILENAME="$1"

ray "$FILENAME"
ray file "$FILENAME" --purple --small --hide
ray show-app

if [ ! -e "$FILENAME" ]; then
    ray send "file missing: $FILENAME" --red
    exit 1
fi

ray pause

cat "$FILENAME" | wc -l

Development Setup

npm install
npm run build:dev
node dist/index.js --help

Testing

node-ray-cli uses Jest for unit tests. To run the test suite:

npm run test


Code Coverage


Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.