Skip to content

Commit

Permalink
docs: More changes for contributing
Browse files Browse the repository at this point in the history
  • Loading branch information
zachowj committed Oct 11, 2022
1 parent 9422b63 commit 4711413
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 98 deletions.
74 changes: 3 additions & 71 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,6 @@

When contributing to this repository, please first discuss the change you wish to make via [GitHub Discussions](https://github.com/zachowj/node-red-contrib-home-assistant-websocket/discussions/categories/feature-request).

## Development environment setup

Here are the steps to successfully setup your development environment to contribute to this project

### Setup using the VS Code dev container

This will set up a docker container with all the required tools and dependencies to get started.

1. Go to the [Node-RED Home Assistant](https://github.com/zachowj/node-red-contrib-home-assistant-websocket) repository and fork it.

1. Clone your forked repository to your local machine.

```sh
git clone https://github.com/<GITHUB_USER_NAME>/node-red-contrib-home-assistant-websocket
```

1. Open the project in VS Code.

1. Install the [Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension.

1. Click the green button in the lower-left corner of the window that says "Reopen in Container".

1. Wait for the container to build and start.

1. Open a terminal in VS Code and run `npm run dev` to start the development server.

### Setup locally

1. Go to the [Node-RED Home Assistant](https://github.com/zachowj/node-red-contrib-home-assistant-websocket) repository and fork it.

1. Clone your forked repository to your local machine.

```sh
git clone https://github.com/zachowj/node-red-contrib-home-assistant-websocket
```

1. create an npm link to your forked project. This will also build this project's dependencies.

```sh
cd node-red-contrib-home-assistant-websocket
npm link
```

1. [Install](https://nodered.org/docs/getting-started/local) Node-RED on localhost, assuming we install it on ~/dev directory (you can install it in another location as you wish)

```sh
cd ~/dev/node-red
npm install -g --unsafe-perm node-red
```

1. Install your fork project into local Node-RED using npm link:

```sh
cd ~/dev/node-red
npm link node-red-contrib-home-assistant-websocket
```

1. Starting Node-RED on localhost

```sh
cd ~/dev/node_modules/node-red
npm run dev
```

### Accessing the development server

Node-RED will be running on ports 1880 and 3000. You can access the development server at http://localhost:1880. On port 3000 browser-sync is running and will reload the browser when changes are made to the editor source code.

## Issues and feature requests

You've found a bug in the source code, a mistake in the documentation or maybe you'd like a new feature? Take a look at [GitHub Discussions](https://github.com/zachowj/node-red-contrib-home-assistant-websocket/discussions) to see if it's already being discussed. You can help us by [submitting an issue on GitHub](https://github.com/zachowj/node-red-contrib-home-assistant-websocket/issues). Before you create an issue, make sure to search the issue archive -- your issue may have already been addressed!
Expand All @@ -83,7 +15,7 @@ Please try to create bug reports that are:

**Even better: Submit a pull request with a fix or new feature!**

### How to submit a Pull Request
## How to submit a Pull Request

1. Search our repository for open or closed
[Pull Requests](https://github.com/zachowj/node-red-contrib-home-assistant-websocket/pulls)
Expand All @@ -95,6 +27,6 @@ Please try to create bug reports that are:
5. Push to the branch (`git push origin feat/amazing_feature`)
6. [Open a Pull Request](https://github.com/zachowj/node-red-contrib-home-assistant-websocket/compare?expand=1)

### Testing
## Development environment setup

1. Run `npm run test` to run the tests.
See [Development](https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/development.html).
96 changes: 69 additions & 27 deletions docs/guide/development.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,79 @@
# Development

An environment with Home Assistant/Node Red can be easily spun up using docker and docker-compose along with built in VSCode debug enabled.
Also see [CONTRIBUTING.md](https://github.com/zachowj/node-red-contrib-home-assistant-websocket/blob/main/CONTRIBUTING.md).

1. Clone this repository: `git clone https://github.com/zachowj/node-red-contrib-home-assistant-websocket.git`
2. Install node dependencies as usual: `cd node-red-contrib-home-assistant-websocket && npm`
3. Start the docker dev environment: `npm run dev`
a. _Note: First run will take a bit to download the images ( home-assistants image is over 1gb (yikes!) after that launch is much quicker)_
b. _Note: Also first run load of HomeAssistant web interface seems very slow, but after first time it's also much faster_
4. The `npm run dev` command will leave you with a terminal spitting out logs, `ctrl+c` out of this and it kills all the servers by design, just run `npm run dev` again to pick back up. The following services and ports are launched in the `dev` script
## Environment setup

| service | port mappings | info |
| -------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
| home-assistant | `8123:8123`, `8300:8300` | exposed for local access via browser |
| node-red | `1880:1880`, `9123:9229` | exposed for local access via browser, `9123` is used for debugging. Includes default flow example connected to `home-assistant` |
Here are the steps to successfully setup your development environment to contribute to this project

## Docker Tips
### Setup using the VS Code dev container

1. If you run into environment issues running `npm run dev:clean` should remove all docker data and get you back to a clean state
2. All data will be discarded when the docker container is removed. You can map volumes locally to persist data. Create and copy as directed below then modify `docker-compose.yaml` to map the container directories to the created host dirs below. _See: `./_docker/docker-compose.mapped.yaml` for an example or just use that file to launch manually_
This will set up a docker container with all the required tools and dependencies to get started.

```bash
$ mkdir -p _docker-volumes/home-assistant/config
$ mkdir -p _docker-volumes/node-red/data
$ cp _docker/home-assistant/root-fs/config/* _docker-volumes/home-assistant/config/
$ cp _docker/node-red/root-fs/data/* _docker-volumes/node-red/data
```
1. Go to the [Node-RED Home Assistant](https://github.com/zachowj/node-red-contrib-home-assistant-websocket) repository and fork it.

## Node Debugger via VSCode
1. Clone your forked repository to your local machine.

Optional but it's pretty nice if you have VSCode installed.
```sh
git clone https://github.com/<GITHUB_USER_NAME>/node-red-contrib-home-assistant-websocket
```

- Open the project directory in VSCode
- Go to the debug tab ( or `cmd/ctrl+shift+d`)
- In the debug tab you should see an target for "Attach: Docker", run that guy and you can place debug breakpoints and changes will be reloaded within docker automatically
- Open [http://localhost:8123](http://localhost:8123) for HomeAssistant (password is `password` by default).
- For node-red either open up via the HomeAssistant web link or left hand menu or just open a browser tab to [http://localhost:1880](http://localhost:1880)
1. Open the project in VS Code.

1. Install the [Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension.

1. Click the green button in the lower-left corner of the window that says "Reopen in Container".

1. Wait for the container to build and start.

1. Open a terminal in VS Code and run `npm run dev` to start the development server.

### Setup locally

1. Go to the [Node-RED Home Assistant](https://github.com/zachowj/node-red-contrib-home-assistant-websocket) repository and fork it.

1. Clone your forked repository to your local machine.

```sh
git clone https://github.com/zachowj/node-red-contrib-home-assistant-websocket
```

1. create an npm link to your forked project. This will also build this project's dependencies.

```sh
cd node-red-contrib-home-assistant-websocket
npm link
```

1. [Install](https://nodered.org/docs/getting-started/local) Node-RED on localhost, assuming we install it on ~/dev directory (you can install it in another location as you wish)

```sh
cd ~/dev/node-red
npm install -g --unsafe-perm node-red
```

1. Install your fork project into local Node-RED using npm link:

```sh
cd ~/dev/node-red
npm link node-red-contrib-home-assistant-websocket
```

1. Starting Node-RED on localhost

```sh
cd ~/dev/node_modules/node-red
npm run dev
```

### Accessing

After running `npm run dev` Node-RED will be running on ports 1880 and 3000. You can access the development server at http://localhost:1880 or http://localhost:3000 either port can be used. On port 3000 browser-sync is running and will reload the browser when changes are made to the editor source code.

### Linting

This project uses [ESLint](https://eslint.org/) and [Prettier](https://prettier.io/) to lint and format the code. You can run `npm run lint` to lint the code.

### Testing

1. Run `npm run test` to run the tests.

0 comments on commit 4711413

Please sign in to comment.