Developing
This article outlines how to get Dashy running in a development environment, and outlines the basics of the architecture. If you're adding new features, you may want to check out the Development Guides docs, for tutorials covering basic tasks.
- Setting up the Development Environment
- Git Strategy
- Resources for Beginners
- App Info
- Code Style Guide
- Application Structure
- Development Tools
- Misc / Notes
Setting up the Dev Environmentโ
Prerequisitesโ
You will need either the latest or LTS version of Node.js to build and serve the application and Git to easily fetch the code, and push any changes. If you plan on running or deploying the container, you'll also need Docker. To avoid any unexpected issues, ensure you've got at least NPM V 7.5 or Yarn 1.22 (you may find NVM helpful for switching/ managing versions).
Running the Projectโ
- Get Code:
git clone https://github.com/Lissy93/dashy.git - Navigate into the directory:
cd dashy - Install dependencies:
yarn - Start dev server:
yarn dev
Dashy should now be being served on http://localhost:8080/. Hot reload is enabled, so making changes to any of the files will trigger them to be rebuilt and the page refreshed.
Project Commandsโ
Basicsโ
yarn build- Builds the production bundle into./dist. The Vite dev/runtime server servesuser-data/conf.ymlon each request, so a rebuild is only needed when source code or assets change, not when config changesyarn start- Starts the Node server, which serves the built site from./distand the live config fromuser-data/. Runyarn buildfirst
Developmentโ
yarn dev- Starts the development server with hot reloadingyarn lint- Lints code to ensure it follows a consistent, neat styleyarn test- Runs tests, and outputs results
Utils and Checksโ
yarn validate-config- If you have quite a long configuration file, you may wish to check that it's all good to go, before deploying the app. This can be done withyarn validate-configordocker exec -it [container-id] yarn validate-config. Your config file needs to be in/user-data/conf.yml(or within your Docker container at/app/user-data/conf.yml). This will first check that your YAML is valid, and then validates it against Dashy's schema.yarn health-check- Checks that the application is up and running on it's specified port, and outputs current status and response times. Useful for integrating into your monitoring service, if you need to maintain high system availability
Alternate Start Commandsโ
yarn build && yarn start- Builds the app, then starts the production Node server. Use this for a manual production-style run on bare metal. With Vite,conf.ymlis served fromuser-data/at runtime, so config changes only require a page refreshyarn pm2-start- Starts the Node server using PM2, a process manager for Node.js applications, that helps them stay alive. PM2 has some built-in basic monitoring features, and an optional management solution. If you are running the app on bare metal, it is recommended to use this start command
Notesโ
- If you are using NPM, replace
yarnwithnpm run - If you are using Docker, precede each command with
docker exec -it [container-id]. Container ID can be found by runningdocker ps
Environmental Variablesโ
All environmental variables are optional. Currently there are not many environmental variables used, as most of the user preferences are stored under appConfig in the conf.yml file.
You can set variables either in your environment, or using the .env file.
NODE_ENV- Current environment, can be either development, production or testPORT- The port to expose the running application onHOST- The host that Dashy is running on, domain or IPBASE_URL- The default base path for serving up static assetsVITE_APP_DOMAIN- Usually the same as BASE_URL, but accessible in frontendINTEGRITY- Should enable SRI for build script and link resourcesIS_DOCKER- Computed automatically on build. Indicates if running in containerVITE_APP_VERSION- Again, set automatically using package.json during build timeBACKUP_DIR- Directory for conf.yml backupsDISABLE_CONFIG_BACKUPS- Set to 'true' to skip the pre-save backup step (useful on read-only filesystems or where permissions don't allow it)
Environment Modesโ
You can set the environment using the NODE_ENV variable. By default, the correct environment should be selected based on the script you run to start the app. The following environments are supported: production, development and test. For more info, see Vite Env Variables and Modes.
Git Strategyโ
Git Flowโ
Like most Git repos, we are following the Github Flow standard.
- Create a branch (or fork if you don'd have write access)
- Code some awesome stuff ๐งโ๐ป
- Add, commit and push your changes to your branch/ fork
- Head over to GitHub and create a Pull Request
- Fill in the required sections in the template, and hit submit
- Follow up with any reviews on your code
- Merge ๐
Git Branch Namingโ
The format of your branch name should be something similar to: [TYPE]/[TICKET]_[TITLE]
For example, FEATURE/420_Awesome-feature or FIX/690_login-server-error
Commit Emojisโ
Using a single emoji at the start of each commit message, to indicate the type task, makes the commit ledger easier to understand, plus it looks cool.
- ๐จ
:art:- Improve structure / format of the code. - โก๏ธ
:zap:- Improve performance. - ๐ฅ
:fire:- Remove code or files. - ๐
:bug:- Fix a bug. - ๐๏ธ
:ambulance:- Critical hotfix - โจ
:sparkles:- Introduce new features. - ๐
:memo:- Add or update documentation. - ๐
:rocket:- Deploy stuff. - ๐
:lipstick:- Add or update the UI and style files. - ๐
:tada:- Begin a project. - โ
:white_check_mark:- Add, update, or pass tests. - ๐๏ธ
:lock:- Fix security issues. - ๐
:bookmark:- Make a Release or Version tag. - ๐จ
:rotating_light:- Fix compiler / linter warnings. - ๐ง
:construction:- Work in progress. - โฌ๏ธ
:arrow_up:- Upgrade dependencies. - ๐ท
:construction_worker:- Add or update CI build system. - โป๏ธ
:recycle:- Refactor code. - ๐ฉน
:adhesive_bandage:- Simple fix for a non-critical issue. - ๐ง
:wrench:- Add or update configuration files. - ๐ฑ
:bento:- Add or update assets. - ๐๏ธ
:card_file_box:- Perform database schema related changes. - โ๏ธ
:pencil2:- Fix typos. - ๐
:globe_with_meridians:- Internationalization and translations.
For a full list of options, see gitmoji.dev
PR Guidelinesโ
Once you've made your changes, and pushed them to your fork or branch, you're ready to open a pull request!
For a pull request to be merged, it must:
- Must be backwards compatible
- The build, lint and tests (run by GH actions) must pass
- There must not be any merge conflicts
When you submit your PR, include the required info, by filling out the PR template. Including:
- A brief description of your changes
- The issue, ticket or discussion number (if applicable)
- For UI relate updates include a screenshot
- If any dependencies were added, explain why it was needed, state the cost associated, and confirm it does not introduce any security issues
- Finally, check the checkboxes, to confirm that the standards are met, and hit submit!
Resources for Beginnersโ
New to Web Development? Glad you're here! Dashy is a pretty simple app, so it should make a good candidate for your first PR. Presuming that you already have a basic knowledge of JavaScript, the following articles should point you in the right direction for getting up to speed with the technologies used in this project:
- Open Source for Beginners
- Introduction to Vue.js
- Vue.js Walkthrough
- ES6 Features
- Definitive guide to SCSS
- Complete beginners guide to Docker
- Docker Classroom - Interactive Tutorials
- Quick start TypeScript guide
- Complete TypeScript tutorial series
- Using TypeScript with Vue.js
- Git cheat sheet
- Basics of using NPM
As well as Node, Git and Docker- you'll also need an IDE (e.g. VS Code or Vim) and a terminal (Windows users may find WSL more convenient).
App Infoโ
Style Guideโ
Linting is done using ESLint, and using the Vue.js Styleguide, which is very similar to the AirBnB Styleguide. You can run yarn lint to report and fix issues. While the dev server is running, issues will be reported to the console automatically, and any lint errors will trigger the build to fail. Note that all lint checks must pass before any PR can be merged. Linting is also run as a git pre-commit hook
The most significant things to note are:
- Indentation should be done with two spaces
- Strings should use single quotes
- All statements must end in a semi-colon
- The final element in all objects must be preceded with a comma
- Maximum line length is 100
- There must be exactly one blank line between sections, before function names, and at the end of the file
- With conditionals, put else on the same line as your if block's closing brace
- All multiline blocks must use braces
- Avoid console statements in the frontend
Styleguides:
- Vue: Vue styleguide
- JavaScript: github.com/airbnb/javascript
Application Structureโ
Files in the Root: ./โ
โฎ
โโโ package.json # Project meta-data, dependencies and paths to scripts
โโโ src/ # Project front-end source code
โโโ server.js # A Node.js server to serve up the /dist directory
โโโ services/ # All server-side endpoints and utilities
โโโ vite.config.mjs # Vite (build tool) configuration
โโโ Dockerfile # The blueprint for building the Docker container
โโโ docker-compose.yml # A Docker run command
โโโ .env # Location for any environmental variables
โโโ yarn.lock # Auto-generated list of current packages and version numbers
โโโ docs/ # Markdown documentation
โโโ README.md # Readme, basic info for getting started
โโโ LICENSE # License for use
โฏ
Frontend Source: ./src/โ
./src
โโโ App.vue # Vue.js starting file