Skip to content

Commit

Permalink
build: Move gulp to use pnpm and local .node-red directory
Browse files Browse the repository at this point in the history
  • Loading branch information
zachowj committed Aug 22, 2024
1 parent 0669088 commit 104f76d
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ coverage
dist/
docs/.vuepress/.cache
docs/.vuepress/.temp
.node-red
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npm test
pnpm test
4 changes: 2 additions & 2 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
npm run lint
npm run test
pnpm run lint
pnpm run test
72 changes: 43 additions & 29 deletions docs/guide/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,49 +26,63 @@ This method sets up a Docker container with all required tools and dependencies.

6. Wait for the container to build and start.

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

### Local Setup

1. Fork the [Node-RED Home Assistant repository](https://github.com/zachowj/node-red-contrib-home-assistant-websocket).
1. **Fork the Repository:**

2. Clone your forked repository:
- Begin by forking the [Node-RED Home Assistant repository](https://github.com/zachowj/node-red-contrib-home-assistant-websocket) to your GitHub account.

```sh
git clone https://github.com/<GITHUB_USER_NAME>/node-red-contrib-home-assistant-websocket
```
1. **Clone Your Forked Repository:**

3. Navigate to the project directory and create an npm link, which also builds the project's dependencies:
- Clone the forked repository to your local machine:

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

4. [Install Node-RED](https://nodered.org/docs/getting-started/local) locally. This example assumes installation in the `~/dev` directory:
1. **Navigate to the Project Directory:**

```sh
cd ~/dev/node-red
npm install -g --unsafe-perm node-red
```
- Change to the project’s root directory:

5. Link your forked project to the local Node-RED installation:
```bash
cd node-red-contrib-home-assistant-websocket
```

```sh
cd ~/dev/node-red
npm link node-red-contrib-home-assistant-websocket
```
1. **Setup the Environment:**

6. Start Node-RED:
- You can either run the setup script or manually configure the environment:

```sh
cd ~/dev/node_modules/node-red
npm run dev
```
**Option A: Run the Setup Script**

- Execute the provided setup script to automate the environment configuration:

```bash
./scripts/setup.sh
```

**Option B: Manual Setup**

- Alternatively, you can manually create a `.node-red` directory and link `pnpm`:

```bash
mkdir .node-red
corepack enable && corepack enable pnpm
pnpm link --dir .node-red
```

1. **Start Node-RED:**

- Launch Node-RED in development mode:

```bash
pnpm dev
```

### Accessing the Development Server

After running `npm run dev`, Node-RED will be available on ports 1880 and 3000. Access the development server at:
After running `pnpm dev`, Node-RED will be available on ports 1880 and 3000. Access the development server at:

- [http://localhost:1880](http://localhost:1880)
- [http://localhost:3000](http://localhost:3000)
Expand All @@ -80,13 +94,13 @@ Port 3000 includes browser-sync, which will automatically reload the browser whe
This project uses [ESLint](https://eslint.org/) and [Prettier](https://prettier.io/) for code linting and formatting. Run the following command to lint the code:

```sh
npm run lint
pnpm lint
```

### Testing

To run the tests, use:

```sh
npm run test
pnpm test
```
11 changes: 7 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,14 @@ task(
// nodemon and browser-sync code modified from
// https://github.com/connio/node-red-contrib-connio/blob/master/gulpfile.js
function runNodemonAndBrowserSync(done) {
const argv = require('yargs').argv;
const dir = argv.dir;

nodemonInstance = nodemon(`
nodemon
--ignore **/*
--exec node-red -u ~/.node-red
`);
nodemon
--ignore **/*
--exec node-red -u ${dir ?? process.env.NODE_RED_DEV_DIR ?? '.node-red'}
`);

nodemon
.once('start', () => {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"engines": {
"node": ">=14.0.0"
},
"packageManager": "[email protected]",
"scripts": {
"build": "gulp build",
"coverage": "nyc --reporter=lcov pnpm run test",
Expand Down Expand Up @@ -153,7 +154,8 @@
"typescript": "5.5.4",
"vinyl-source-stream": "2.0.0",
"vue": "^3.4.38",
"vuepress": "2.0.0-rc.15"
"vuepress": "2.0.0-rc.15",
"yargs": "^17.7.2"
},
"lint-staged": {
"*.{js,ts}": [
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# setup pnpm
echo "Setting up pnpm"
corepack enable && corepack enable npm

# set an environment variable from first argument if it exists or use default value
NR_DIR=${1:-.node-red}

# create directory if it doesn't exist
if [ ! -d "$NR_DIR" ]; then
echo "Creating directory $NR_DIR"
mkdir -p $NR_DIR
fi

# copy files from .devcontainer/nodered to the directory
echo "Copying files from .devcontainer/nodered to $NR_DIR"
cp -r .devcontainer/nodered/* $NR_DIR

# link pnpm
echo "Linking pnpm"
pnpm link --dir $NR_DIR

0 comments on commit 104f76d

Please sign in to comment.