NodeJS Light Management Service
- 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)
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)
- 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)
git clone https://github.com/Rooknj/prysma.git
cd prysma
yarn install
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
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
Compile Typescript (outputs to /dist)
yarn build
Compile Typescript and generate an executable using zeit/pkg (executable located in /build)
yarn build --createExecutable
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>
yarn clean
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
Prysma is configurable using environment variables
- 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
- Duplicate .env.template and rename to .env
- Fill in the desired configuration options
- Note: For overriding TypeORM configurations, make sure you include all required fields for the database you choose to use
View available configuration environment variables in .env.template.
We use SemVer 2.0.0 for versioning. To see available versions, check out the releases page
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 is managed by 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
This project is licensed under the terms of the MIT license.