1.0.1 • Published 2 years ago

nodemon-remote v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Nodemon-Remote

Drop-in replacement for nodemon with HTTP remote control and support for custom commands.

How to use it

Installation

npm install --save nodemon-remote
# or
npx nodemon-remote <nodemon cli arguments>

Create a config: .remoterc.js

module.exports = {
  port: 2020,
  access_key: "MY_SECRET_ACCESS_KEY",
  commands: {
    // Custom commands (arguments are always escaped)
    checkout: { cmd: "git checkout '${branch}'" },
    fetch: { cmd: "git fetch --all" },
    // Define multiple commands
    pullAndInstall: {
      cmd: [
        "git pull origin '${branch}'"
        "npm ci"
      ]
    },
  },
};

Send custom remote command

curl -X POST \
  http://<endpoint>:2020/
  --header "Authorization: BEARER <MY_SECRET_ACCESS_KEY>" \
  --data '{ "cmd": "checkout", "branch": "main" }'

Send nodemon restart command

curl -X POST \
  http://<endpoint>:2020/
  --header "Authorization: BEARER <MY_SECRET_ACCESS_KEY>" \
  --data '{ "cmd": "nodemon:restart" }'

Available build-in commands:

  • nodemon:restart: Restart nodemon
  • nodemon:reset: Resets all settings

Github Webhook Integration

Trigger commands based on a configurable label.

Example: Any PR that has the "preview" label assigned and that code is pushed to will get checked out in the remote container.

module.exports = {
  // ...
  webhook: {
    label: "preview",
    // Commands will run, if a PR with the label above is modified
    cmd: [
      "git fetch --all",
      "git checkout '${ref}'",
      "npm ci",
      "nodemon:restart",
    ],
  },
};
  1. Got to webhook settings (https://github.com/<org>/<project>/settings/hooks/new)

  2. Enter payload URL:

http://<endpoint>:2020/webhook
  1. Select application/json and enter secret

npm.io

  1. Select Let me select individual events.

  2. Enable Pull requests only

npm.io

  1. Hit Add Webhook

  2. Assign label configured in config.webhook.label (e.g. "preview") to PR