1.2.0 • Published 5 years ago

prysma v1.2.0

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

Prysma

Build Status npm version Renovate enabled code style: prettier semantic-release

NodeJS Light Management Service

Installing

Prerequisites

  • Nodejs v10.15.3 or greater is required. Check by running node -v
  • A Running MQTT broker (default location is localhost:1883. See Configuration section to change)

Install globally with Yarn or NPM

yarn:

yarn global add prysma
prysma

npm:

npm install -g prysma
prysma

Notes:

  • The default database is a sqlite database created at ~/.prysma/prysma.db
  • The default MQTT Broker host used by prysma is localhost:1883
  • These can be changed in the configuration (see Configuration section below)

Developing

Built With

Prerequisites

  • Nodejs v10.15.3 or greater is required. (Check by running node -v)
  • Yarn (Check by running yarn -v)
  • Docker (Check by running docker -v) (Used for tests and running an MQTT broker locally)
  • Docker-compose (Check by running docker-compose -v) (Used for tests and running an MQTT broker locally)

Setting up Dev

git clone https://github.com/Rooknj/prysma.git
cd prysma
yarn install

Run Prysma locally

Using environment configuration (specified in .env file) or default configuration options

Note: run docker-compose up to start local services (or just use yarn start --local)

yarn start

With an automatically started MQTT broker running on localhost:1883 (Note: This requires docker and docker-compose to be installed)

yarn start --local

With an MQTT broker running at prysma.local:1883

yarn start --remote

Testing

Tests are written using Jest

Run tests on watch mode:

yarn test

Run tests with coverage:

yarn test --coverage

Run tests once:

yarn test --no-watch

Building

Compile Typescript (outputs to /dist)

yarn build

Compile Typescript and generate an executable using zeit/pkg (executable located in /build)

yarn build --createExecutable

Deploying

Deployments happen automatically using Semantic-Release based off of commit messages

Build and publish Docker Image

Note: This docker image stores the database in the /data directory. Create a volume on it to persist data across container starts

yarn docker:build -t <tagName>
yarn docker:publish -t <tagName>

Clean temporary Files

yarn clean

Commit Messages

Commit messages must follow Conventional Commits

Example Messages

  • chore(docs): updated Readme
  • refactor: renamed LedStrip to Light
  • fix(LightMessenger): fixed a bug where an incorrect message format was being used
  • feat: Added ability to assign lights to different rooms
  • BREAKING CHANGE: Removed deprecated functions

CI will fail if you do not use the correct commit format. Local messages are linted using Commitlint

Commitizen support coming soon

Configuration

Prysma is configurable using environment variables

Default Configuration

  • PORT=80 (or 4001 if NODE_ENV=development)
  • MQTT_HOST=localhost
  • MQTT_PORT=1883
  • MQTT_USERNAME=""
  • MQTT_PASSWORD=""
  • MQTT_RECONNECT_PERIOD=5000
  • TYPEORM_CONNECTION=sqlite
  • TYPEORM_DATABASE=home directory/.prysma/prysma.db (or projectRoot/.prysma/prysma.db if NODE_ENV=development)
  • TYPEORM_SYNCHRONIZE=true
  • TYPEORM_LOGGING=false

Overriding default configuration with environment variables

  1. Duplicate .env.template and rename to .env
  2. Fill in the desired configuration options
  3. Note: For overriding TypeORM configurations, make sure you include all required fields for the database you choose to use

Other configuration variables

View available configuration environment variables in .env.template.

Versioning

We use SemVer 2.0.0 for versioning. To see available versions, check out the releases page

Style Guide

Linting

Linting is managed by ESLint

Run yarn lint to check all files

Currently we are extending eslint:recommended, @typescript-eslint/recommended, airbnb-base, eslint-comments/recommended, and jest/recommended

Full config is located in .eslintrc.js

Note: The linter is ran during CI and the build will fail if there are any errors. Currently we are not automatically fixing linting errors so you will have to make sure the linter passes manually

Code Style

Code style is managed by Prettier code style: prettier

All default prettier styles are enabled except for the overrides located in .prettierrc.js

Prettier is automatically ran on staged files every commit using Husky and Lint-Staged

You can run prettier manually on every file through the command yarn reformat or you can set up prettier to run inside your IDE/Editor

License

This project is licensed under the terms of the MIT license.