Create nodes using Typescript, Vue and Vite

Continuing from this other thread: Write nodes using Typescript + Vue 3 + JSON Schemas for runtime validations

You can now develop nodes using Typescript and build them with Vite. This will soon be released as a standalone package, but you can preview it here today.

I built a core library that unlocks a modern API for authoring nodes with class-based definitions and JSON Schema. Take a look

IONode


ConfigNode

Todayโ€™s my birthday, but Iโ€™m the one giving something back. :wrapped_gift:
I hope this resonates with anyone building a product on top of Node-RED.

6 Likes

Great Stuff and a really nice API for creating nodes - well done!

I think there is a learning for all of us developing for NR: the current method of creating node packages doesn't fly with the users of NR.

Encapsulating functionality into smaller units is currently possible either using a) sub-flows or b) extended JS code in function nodes, c) using node packages or d) extending NR itself.

Of those, the only two available for users of NR are sub-flows and function nodes. But both are limited and not as broad as creating a node package or extending NR.

Clarification: "users" of NR are those that create "flows as code" and don't, themselves, create code using JS. Hence these "users" are not able to create their own node packages.

Your work is aimed at developers of NR packages who are capable of coding JS or using third-party editors to create code. Users of NR aren't necessarily able to do that. For these "users", their editor is the NR frontend, VScode or Emacs or Vi or NotePad are developer tools unknown to them.

So I would suggest that using this as a basis for a frontend components inside NR would be a good next step. Especially as you have removed the need to know how the HTML templates work - which is great.

I've tried doing this with the NodeDev package but it's definitely not perfect. One thing is does allow is importing of existing node packages that then can be modified inside NR and then can be reinstalled into NR - thus "users" can begin learning how to develop node packages for NR inside NR, no third-party editor required.

1 Like

Happy birthday. Have a great day

1 Like

This is how easy the setup with vite is

If you need custom runtime settings, just create a file named node-red.settings.ts in the root of your project. IT IS FULLY TYPED!

To start the dev server with the latest node-red runtime, run pnpm vite

If you need a different version, configure nodeRedLauncherOptions.runtime.version with the version you need. For example,


If you need different runtime settings for different environments, configure nodeRedLauncherOptions.runtime.settingsFilepath with the path to a different settings.ts file. When this property isn't set, the plugin tries to use settings located at ./node-red.settings.ts

To build your production distro, run pnpm build.

By default, the following 3 files/dir are always copied to dist:

  • LICENSE
  • README.md
  • examples

Your license is also added to the begining of your index.html

The package.json in the dist folder is automatically generated containing only the dependencies that were actually used by the server-side code. Client-side dependencies are bundled with your distro, and properly broken into smaller chunks.

Soon this plugin and the core library will be packaged. At the moment imports will be @allanoricil/nrg/core and @allanoricil/nrg/vite. However, If the node-red core team (@knolleary, @dceejay, @hardillb)review and let me publish these under the @node-red namespace, then imports will be @node-red/nrg/core and @node-red/nrg/vite, which would look way more professional.

This is the directory structure of an nrg project

.
โ”œโ”€โ”€ client/
โ”‚   โ”œโ”€โ”€ assets
โ”‚   โ”œโ”€โ”€ components
โ”‚   โ”œโ”€โ”€ icons
โ”‚   โ”œโ”€โ”€ nodes
โ”‚   โ”œโ”€โ”€ public
โ”‚   โ””โ”€โ”€ index.ts
โ”œโ”€โ”€ server/
โ”‚   โ”œโ”€โ”€ nodes
โ”‚   โ”œโ”€โ”€ schemas
โ”‚   โ””โ”€โ”€ index.ts
โ”œโ”€โ”€ locales/
โ”‚   โ”œโ”€โ”€ docs/
โ”‚   โ”‚   โ””โ”€โ”€ {node-type}/
โ”‚   โ”‚       โ””โ”€โ”€ {en-US|pt-BR|...}.{md|html}
โ”‚   โ””โ”€โ”€ labels/
โ”‚       โ””โ”€โ”€ {node-type}/
โ”‚           โ””โ”€โ”€ {en-US|pt-BR|...}.json
โ”œโ”€โ”€ examples/
โ”‚   โ””โ”€โ”€ 01-example.json
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ node-red.settings.ts
โ””โ”€โ”€ vite.config.ts
2 Likes