enetpulse-media-api
v1.3.21
Published
Media handler API.
Downloads
6
Readme
Media - API
Table of Contents
General Information
The API provides various media management features.
- Resizing of images
- Formatting of images
- Formatting of videos
Setup
Before installing the application make sure you have the appropriate version of NodeJS installed. Check the package.json under engines. You can use this guide for nvm to setup multiple NodeJS versions on your machine.
npm install
Startup
This project uses typescript to make the development process more efficient. Therefore when this gets run in production the project has to be build. Normally this gets handled by the release pipelines. If you wish however to build and run the project simulating the release pipeline, use the following commands:
To build the project without running it:
npm run build
To build the project and run it (note server does not restart automatically on code change)
npm start
To run the project in development mode without building it (server restarts automatically on code change)
npm run dev
Note the above commands use tsconfig-paths to leverage the paths property from the tsconfig.json
.
Important DevDependencies
Various dev dependencies are installed in order to improve the development live cycle. Here are some of the most important.
- commitlint/cli is used to enforce conventional commit message formatting. Rules can be found in the link under the package name.
- commit-and-tag-version is used to auto bump versions and create a changelog. Configuration can be found in .versionrc.json. It is meant to be used before a release by running one of the following commands:
For updating the second decimal version (mid tear release)
npm run release
For updating the third decimal version (minor level release)
npm run release:minor
For updating the first decimal version (major release)
npm run release: major
These might be integrated in to the gitlab pipelines.
eslint in combination with prettier are used to make sure the code is formatted and linted. Their true power shines when combined with husky and lint-staged to make sure that no code with linting and style mistakes gets pushed to the repository.
dotenv is used to store environment variables that might change based on the server stage. It also helps with security since it does not get pushed to gitlab.
Developing on the project
Importing functions between folders
In order to avoid long imports when importing between folders and reaching the point where your imports look like this:
import { functionName } from '../../../deeplyNestedParent/deeplyNestedChild/deeplyNestedGrandChild/deeplyNestedFile.ts'
We have leveraged typescripts ability to to declare absolute import paths. All you need to do is declare the shortened path and the folder/file it leads to, in the tsconfig.json under compilerOptions.paths. This will make your imports look like this:
import { ResponseHelper } from '@media-api-helpers'
!!!!NOTE When creating a new file and including it in the tsconfig paths, your IDE wont resolve the path untill you use the imported functions and build the project.
Read more about shortened imports here
Committing changes
As mentioned in the Important DevDependencies, there are several packages that take care of the integrity and maintainability of the codebase. The one that ties them together is husky. After initial install of the dependencies, husky creates a .husky folder, containing scripts ran before and during code commit. In order to add a new script run the following command:
npx husky add .husky/insert-your-commit-stage-here "insert your script here"
The existing scripts are:
pre-commit
npx --no-install lint-staged
runs the code linter trough all staged files. It is recommended to run this script yourself before attempting a commit for easier and faster fixes of linting mistakes.
check the commit message to make sure it is suitable for the automated generation of a changelog.
npx --no-install commitlint --edit