Giter VIP home page Giter VIP logo

pubnub-cli's Introduction

BLOCKS CLI

Fork of the origina PubNub CLI

For this fork, I refactored how the path for the block.json file path is selected. In the original cli, the file name is hardcoded with var blockFile = workingDir + options.file + 'block.json'; on line 61 and var fullPath = workingDir + options.file + eh.file; on line 1241. That doesn't really work with multiple block files and environments, if I want to share the same function Javascript file in multiple cloned blocks for development & production environments for example. I don't want to have them in the same block because restarting the block for dev would also restart it for prod. I fixed the path so that you can give a full filepath for the cli, for example pubnub-cli push -f /dev.block.json. This wouldn't work with the original cli and I would have to write pubnub-cli push -f /dev. and that would work for restarting the function, but would fail when pushing because the path gets messed up.

Install

npm install -g pubnub-cli

Help

node pubnub-cli -h

Usage

Usage:
  pubnub-cli [OPTIONS] <command> [ARGS]

Options:
  -b, --block NUMBER     Block ID
  -k, --key NUMBER       Subscribe Key ID
  -f, --file PATH        A block file
  -m, --email STRING     Email
  -n, --insert INSERT    Insert Mode. Create new blocks and skip prompts.
  -a, --account NUMBER   Account ID
  -p, --password STRING  Password
      --debug            Show debug information
  -h, --help             Display help and usage details

Commands:
  init, log, login, logout, pull, push, start, stop, watch, test
  • Init - Download the remote PubNub function and event handlers locally
  • Log - Log the event handler output to console
  • Login - Authorize with PubNub and write session to disk
  • Logout - Remove local session from disk
  • Pull - Download remote event handlers and overwrite file
  • Push - Upload remote event handlers and overwrite
  • Start - Start the remote PubNub Function
  • Stop - Stop the remote PubNub Funciton
  • Watch - Watch the local directory and push event handlers when changes are detected
  • Test - Run event handler unit tests

Login

Authorizes this computer with PubNub API.

Input:

pubnub-cli login

Output:

pubnub-cli login
? PubNub Email: [email protected]
? PubNub Password: *************
Logging In... Done!
OK: ---------------------------------------
OK: Logged In!
OK: Deluxe!
OK: ---------------------------------------

Creates a file ~/.pubnub-cli with PubNub session properties:

{
  "created": 1463775328,
  "expires": 1467587119,
  "modified": 1464995119,
  "role": "user",
  "status": 1,
  "storage": "{}",
  "token": "38583023-a36a-4a03-97f6-c838bd9f7aab",
  "user": {},
  "user_id": 198072,
  "user_roles": {}
}

This file is used for every request thereafter.

Init

Writes a block.json file. Use selects key and block (or creates a new block). Block information is pulled from server and persisted into file.

Note the -f specifies the directory of the future block.json file. See "Pull" below for more info on block.json.

Input:

pubnub-cli init

Output:

INFO: Reading session from /Users/ian/.pubnub-cli
OK: Working as [email protected]
OK: Which app are you working on?
? Select a key eon-demos
OK: Which block are you working on?
? Select a block Email Sendgrid Block
OK: ---------------------------------------
OK: New block.json written to disk.
OK: Deluxe!
OK: ---------------------------------------
OK: Use this handy command next time:
OK: node pubnub-cli init -b 853 -k 145183

Pull

Pulls block information from server and writes to block.json.

Input

pubnub-cli pull

Output

INFO: Reading session from /Users/ian/.pubnub-cli
OK: Working as [email protected]
OK: Working on block Email Sendgrid Block
OK: ---------------------------------------
OK: Local block.json updated with remote data.
OK: Deluxe!
OK: ---------------------------------------
OK: Use this handy command next time:
OK: node pubnub-cli pull -b 853 -k 145183

Block.json looks like:

{
  "_key_id": 145183,
  "_id": 40,
  "name": "name this block",
  "description": "describe this block",
  "event_handlers": [
    {
      "_id": 69,
      "name": "Wohoo!",
      "event": "js-before-publish",
      "channels": "input"
    },
    {
      "_id": 107,
      "name": "kjklhlkjh",
      "event": "js-before-publish",
      "channels": "input"
    }
  ]
}

The properties _key_id and _id represent the key id and block id respectively. These should not be modified.

Push

Updates server with information provided in block.json. Upload code by specifying a file within the event handler object. See below for example.

Input

pubnub-cli push

Output

OK: Working as [email protected]
OK: Working on block Email Sendgrid Block
OK: ---------------------------------------
OK: Block pushed
OK: Deluxe!
OK: ---------------------------------------
OK: Use this handy command next time:
OK: node pubnub-cli push -b 853 -k 145183

Sample block.json for uploading event handlers directly:

{
  "_key_id": 145183,
  "_id": 40,
  "name": "name this block",
  "description": "describe this block",
  "event_handlers": [
    {
      "_id": 69,
      "name": "a handler",
      "event": "js-before-publish",
      "channels": "input",
      "file": "/after-presence/sample_handler.js"
    },
    {
      "_id": 107,
      "name": "a handler",
      "event": "js-before-publish",
      "channels": "input",
      "file": "/before-publish/sample_handler.js"
    },
    {
      "_id": 118,
      "name": "a handler",
      "event": "js-after-publish",
      "channels": "input",
      "file": "/after-publish/sample_handler.js"
    }
  ]
}

Start

Starts running a block.

Input

pubnub-cli start

Output

OK: Working as [email protected]
OK: Working on block Email Sendgrid Block
OK: Sending start command
Starting Block...
OK: ---------------------------------------
OK: Block started
OK: Deluxe!
OK: ---------------------------------------

Stop

Stops a running block.

Input

pubnub-cli stop

Output

NFO: Reading session from /Users/ian/.pubnub-cli
OK: Working as [email protected]
OK: Working on block Email Sendgrid Block
OK: ---------------------------------------
OK: Block stopped
OK: Deluxe!
OK: ---------------------------------------

Test

Runs unit tests for the event handlers with pubnub-functions-mock package in the local environment.

pubnub-cli test

Output

OK: Working with prod environment at https://admin.pubnub.com
OK: Working on block CICD Example

  #eventhandler
    ✓ creates event handler of type Function

  1 passing (9ms)

  #endpoint
    ✓ creates endpoint event handler of type Function

  1 passing (9ms)

OK: ---------------------------------------
OK: Unit tests completed.
OK: Deluxe!
OK: ---------------------------------------

pubnub-cli's People

Watchers

James Cloos avatar Otto Kivikärki avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.