Skip to content

Commit

Permalink
Merge pull request #34 from core-marine-dev/dev
Browse files Browse the repository at this point in the history
Documentation about the project, how to contribute and two templates …
  • Loading branch information
crisconru authored May 21, 2024
2 parents 562e1cb + 691b9a8 commit 854abd2
Show file tree
Hide file tree
Showing 46 changed files with 3,768 additions and 2 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/template-library.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: TODO:

on:
workflow_dispatch:
push:
paths:
- packages/TODO:/**

jobs:
test:
name: 🧪 Test
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- name: 👍 Checkout
uses: actions/checkout@v4

- name: ❇️ Setup node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: 📥 Install Dependencies
run: npm install

- name: 🧑‍🔬 Tests
run: "npm run TODO::test"

publish:
name: 🚀 Publish
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'

steps:
- name: 👍 Checkout
uses: actions/checkout@v4

- name: ❇️ Setup node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'

- name: 📥 Install Dependencies
run: npm install

- name: 🛠️ Build
run: "npm run TODO::build"

- name: 🚀 Publish to npm
run: "npm publish --access public --workspace=@coremarine/TODO:"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
59 changes: 59 additions & 0 deletions .github/workflows/template-nodered.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: TODO:-nodered

on:
workflow_dispatch:
push:
paths:
- packages/TODO:-nodered/**

jobs:
# test:
# name: 🧪 Test
# runs-on: ubuntu-latest

# strategy:
# matrix:
# node-version: [18.x, 20.x]

# steps:
# - name: 👍 Checkout
# uses: actions/checkout@v4

# - name: ❇️ Setup node.js
# uses: actions/setup-node@v4
# with:
# node-version: ${{ matrix.node-version }}
# cache: 'npm'

# - name: 📥 Install Dependencies
# run: npm install

# - name: 🧑‍🔬 Tests
# run: "npm run TODO::nodered:test"

publish:
name: 🚀 Publish
runs-on: ubuntu-latest
# needs: test
if: github.ref == 'refs/heads/main'

steps:
- name: 👍 Checkout
uses: actions/checkout@v4

- name: ❇️ Setup node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'

- name: 📥 Install Dependencies
run: npm install

# - name: 🛠️ Build
# run: "npm run TODO::nodered:build"

- name: 🚀 Publish to npm
run: "npm publish --access public --workspace=@coremarine/TODO:-nodered"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
74 changes: 74 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributing

The whole repository it is an opinionated monorepository:

- [NPM workspaces](https://docs.npmjs.com/cli/using-npm/workspaces) to manage monorepo:
- Flat learning curve
- No depedencies, just npm
- Schema validation to guarantee runtime type checking
- Type validation in TypeScript is only true at devtime not in runtime so it is necessary a schema validator
- Before was [Zod](https://zod.dev/), now is [Valibot](https://valibot.dev/), then who knows
- [ts-standard](https://github.com/standard/ts-standard) as linter + formatter
- No dealing with complicated setup
- [StandardJS](https://standardjs.com/) as code style
- [Vitest](https://vitest.dev/) as test suite
- Faster
- Quite easy to setup
- [tsup](https://tsup.egoist.dev/) as build layer on top of tsc
- Transpile to ESM + CJS
- Quite easy to setup
- Naming has some rules:
- All packages are published with scope `@coremarine`
- The library is called typically as `<manufacturer>-<protocol>` or something like that
- The NodeRED component is called the same as the library with `-nodered` ending
- Example: `@coremarine/nmea-parser` and `@coremarine/nmea-parser-ndoered`

## Create new Component

1. Create well-tested and battle tested TypeScript library.
2. Create a NodeRED wrapper / compoment which uses that library.

### How to create a TypeScript library

1. Copy the `template-library` folder inside packages and paste as a new folder
2. Look for the keyword `TODO:` in your IDE / Editor inside that folder, this is a hint to places you need to setup.
3. Setup npm package -> Modify library `package.json` (`packages/<your-library>/package.json`)
1. `name` to `@coremarine/<your-library>`
2. `description`
3. `homepage`
4. `keywords`
4. Setup npm workspaces -> Add scripts in global / monorepo `package.json`:
1. `lint`
2. `format`
3. `build`
4. `test`
5. `test:coverage`
5. Setup CI/CD (Github Actions)
1. Go to `.github/workflows` folder
2. Copy `template-library.yml` file and paste as a new yml file `<your-library>.yml`
3. Change all TODO:
6. Document your library -> Modify `README.md` (`packages/<your-library>/README.md`)
7. Start with your library by coding in `src` and testing in `tests`

### How to create a NodeRED component

1. Copy the `template-nodered` folder inside packages and paste as a new folder ending with `-nodered` -> `packages/<your-library>-nodered`
2. Look for the keyword `TODO:` in your IDE / Editor inside that folder, this is a hint to places you need to setup.
3. Setup npm package -> Modify library `package.json` (`packages/<your-library>/package.json`)
1. `name` to `@coremarine/<your-library>`
2. `description`
3. `homepage`
4. `keywords`
5. `node-red.nodes.cma-<your-component>`
6. `dependencies.@coremarine/<your-library>`
4. Setup npm workspaces -> Add scripts in global / monorepo `package.json`:
1. `nodered:docker`
2. `nodered:test`
5. Setup CI/CD (Github Actions)
1. Go to `.github/workflows` folder
2. Copy `template-nodered.yml` file and paste as a new yml file `<your-library>-nodered.yml`
3. Change all TODO:
6. Document your library -> Modify `README.md` (`packages/<your-library>-nodered/README.md`)
7. Add component dependencies to package `Dockerfile` file
8. Rename project into package `docker-compose.yml` file
9. Start with your library by coding in `src` and testing in `tests` and seeing results with docker (all files there has a minimal scaffolding to start working on it).
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
# devices
CoreMarine open source devices libraries and Node-RED components
# CoreMarine Devices

This is a collection of the CoreMarine open source JS libraries and its NodeRED component wrappers. It is organised as a NPN Workspaces monorepository.

All devices are inside `packages` folder. Each device usually has two packages:

1. TypeScript library which is transpiled into ESM + CJS modules.
2. NodeRED component which is a wrapper of the CJS library.

<details>
<summary>Devices</summary>
<ul>
<li><a href="packages/nmea-parser/README.md">NMEA parser</a> - <a href="packages/nmea-parser-nodered/README.md">NodeRED component</a></li>
<li><a href="packages/norsub-emru/README.md">Norsub eMRU</a> - <a href="packages/norsub-emru-nodered/README.md">NodeRED component</a></li>
<li><a href="packages/septentrio-sbf/README.md">Septentrio SBF</a> - <a href="packages/septentrio-sbf-nodered/README.md">NodeRED component</a></li>
<li><a href="packages/thelmabiotel-tblive/README.md">Thelmabiotel TB-Live</a> - <a href="packages/thelmabiotel-tblive-nodered/README.md">NodeRED component</a></li>
</ul>
</details>

If you want to contribute take a look on the [CONTRIBUTING](CONTRIBUTING.md) document.
137 changes: 137 additions & 0 deletions packages/template-library/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Custom
.vscode
.idea
.DS_Store
docs
lib

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
21 changes: 21 additions & 0 deletions packages/template-library/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 CoreMarine

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions packages/template-library/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Template Library

![npm (scoped)](https://img.shields.io/npm/v/%40coremarine/TODO:)
[![publish](https://github.com/core-marine-dev/devices/actions/workflows/TODO:.yml/badge.svg)](https://github.com/core-marine-dev/devices/actions/workflows/TODO:.yml)
![npm](https://img.shields.io/npm/dy/%40coremarine/TODO:)

TODO:
Loading

0 comments on commit 854abd2

Please sign in to comment.