Quick start project to create a Hapiness application with all its features.
Download this starter and change hapinessjs/quick-start
and @hapiness/quick-start
, according your module name and repository, in these files:
package.json
README.md
In README.md
, you need to update the documentation to explain what's your module and what it does.
Delete .travis.yml
if you don't want to have travis-ci integration.
All files for your application will be in src
folder and wrote in Typescript
.
All tests files for your module will be in test
folder and wrote in Typescript
too.
- Unit tests will be in
test/unit
folder - Integration tests will be in
test/integration
folder
All packaging files for your module will be in tools
folder and wrote in Typescript
too.
tsconfig.json
is used for development process and tsconfig.build.json
is used for build process.
In both case, add externals types from @types/{...}
inside compilerOptions.types
array.
tslint.json
contains all rules for Typescript
validation during pretest
process.
yarn.lock
contains fixed packages' versions for all node_modules
used in your module.
Use it to install modules :
$ yarn install
We use bunyan
for logger format output and installation with yarn
failed so we need to use latest npm
version to install all packages.
package.json
contains your module definition with name, description, scripts, dependencies, etc.
To install existing or new dependencies use npm
.
In scripts
part, you have all needed scripts to work. All scripts reference elements in Makefile
.
If you want to use nvm
, install node
version according .nvmrc
file and type:
$ cd path/to/hapiness/application
$ nvm use
All your application's contents must be inside src
folder.
Each folder must have a barrels
index file.
We have a convention name for each files so follow this guideline to be ok with the next hapiness-cli
To have live reload during development, just execute:
$ cd path/to/hapiness/application
$ yarn run dev:watch
or
$ npm run dev:watch
You can organize your application by modules or write services, routes and/or libraries in the root folder of your application.
If you want to organize your application by modules, you need to follow the guideline of @hapiness/empty-module project.
All services files must be inside src/services/{my-service}
folder and named {my-service}.service.ts
. Class will be {MyService}Service
.
Service needs to have @Inject()
decorator and be added inside module metadata
's providers array.
Export it with barrels
index at the root of src/services
.
You can organize services by features and create folders for that. Don't forget to create barrels
index for each folder.
All routes files must be inside src/routes
folder and organize by resources. In each resource folder, you need to create barrels
index and method folder. In each method folder, you need to create barrels
index and type file named {type}.route.ts
. Class will be {MethodTypeResource}Route
.
Route needs to have @Route({...})
decorator and be added inside module metadata
's declarations array.
Export it with barrels
index at the root of src/routes
.
Example of path for the route to get one user :
$ src/routes/user/get/one.route.ts
Implementation of the route will be :
@Route({
path: '/user/{id}',
method: 'GET'
})
export class GetOneUserRoute implements OnGet {}
All libraries files must be inside src/libraries
folder and named {my-library}.library.ts
. Class will be {MyLibrary}Library
.
Library needs to have @Lib()
decorator and be added inside module metadata
's declarations array.
Export it with barrels
index at the root of src/libraries
.
You can organize libraries by features and create folders for that. Don't forget to create barrels
index for each folder.
You must unit test each service, route and library.
Your application and services must be tested with an integration in Hapiness
server application.
Each file name will be suffixed by test
: {my-module}.module.test.ts
, {my-service}.service.test.ts
, {resource}.{method}.route.test.ts
or {my-library}.library.test.ts
.
Classes will be suffixed by Test
: {MyModule}ModuleTest
, {MyService}ServiceTest
, {MethodResource}RouteTest
or {MyLibrary}LibraryTest
.
To run your tests, just execute:
$ cd path/to/hapiness/application
$ yarn run test
or
$ npm run test
Coverage result will be inside ./coverage/lcov-report
folder. Just open the folder in your browser to see the result.
Build your project:
$ cd path/to/hapiness/application
$ yarn run build
or
$ npm run build
Packaging will be created inside dist
folder. You must to publish only the content of this folder.
- v1.1.0 (2017-11-20)
- Latest packages' versions.
- Documentation.
- Change packaging process.
- v1.1.0 (2017-11-14)
Julien Fauville | Antoine Gomez | Sébastien Ritz | Nicolas Jessel |
Copyright (c) 2017 Hapiness Licensed under the MIT license.