This package provides basics to create a new Hapiness module.
Implementations of Hapiness' route and service are done and related tests too.
- Starter
- Folders
- Files
- Development
- Deployment
- Using your module inside Hapiness application
- Change History
- Maintainers
- License
Download this starter and change hapinessjs/empty-module and @hapiness/empty-module, according your module name and repository, in these files:
package.jsonREADME.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 module 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/unitfolder - Integration tests will be in
test/integrationfolder
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.
See yarn cli documentation to know how to use it.
package.json contains your module definition with name, description, scripts, dependencies, etc.
To install existing or new dependencies use npm or yarn. We advice to use yarn to have the same version that us.
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/module
$ nvm useAll your module's contents must be inside src/module 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
Your main module file must be at the root of src/module folder and named {my-module}.module.ts. Class will be {MyModule}Module.
Module needs to have @HapinessModule({...}) decorator.
Export it with barrels index at the root of src/module.
All services files must be inside src/module/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/module/services.
You can organize services by features and create folders for that. Don't forget to create barrels index for each folder.
If your service needs to be exported by your module to be accessible in the DI of other module, you need to export it with barrels index at the root of src/module and add it inside module metadata's exports array.
All routes files must be inside src/module/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/module/routes.
Example of path for the route to get one user :
$ src/module/routes/user/get/one.route.tsImplementation of the route will be :
@Route({
path: '/user/{id}',
method: 'GET'
})
export class GetOneUserRoute implements OnGet {}All libraries files must be inside src/module/libraries/{my-library} 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/module/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 module 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}.{type}.route.test.ts or {my-library}.library.test.ts.
Classes will be suffixed by Test: {MyModule}ModuleTest, {MyService}ServiceTest, {MethodTypeResource}RouteTest or {MyLibrary}LibraryTest.
To run your tests, just execute:
$ cd path/to/hapiness/module
$ yarn run test
or
$ npm run testCoverage 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/module
$ yarn run build
or
$ npm run buildPackaging will be created inside dist folder. You need to publish only the content of this folder:
$ cd path/to/hapiness/module/dist
$ npm publish (--access public => if scoped package)$ npm install --save @hapiness/core @{your_scope}/{your_module} rxjs
or
$ yarn add @hapiness/core @{your_scope}/{your_module} rxjs"dependencies": {
"@hapiness/core": "^1.5.0",
"@{your_scope}/{your_module}": "^1.0.0",
"rxjs": "^5.5.8"
//...
}
//...import { Hapiness, HapinessModule } from '@hapiness/core';
import { <MyModule>Module } from '@{your_scope}/{your_module}';
@HapinessModule({
version: '1.0.0',
imports: [
<MyModule>Module
]
})
class HapinessModuleApp {}
Hapiness.bootstrap(HapinessModuleApp, [
HttpServerExt.setConfig({ host: '0.0.0.0', port: 4443 })
]);If your module contains route just call specific endpoint to see the result and use service anywhere with dependency injection.
- v1.1.2 (2018-04-03)
- Latest packages' versions.
- v1.1.1 (2017-12-19)
- Latest packages' versions.
- New build process
- Documentation
- v1.1.0 (2017-10-20)
- Latest packages' versions.
- Update tests to match with latest
coreversion. - Project version related to core version.
| Julien Fauville | Antoine Gomez | Sébastien Ritz | Nicolas Jessel |
Copyright (c) 2017 Hapiness Licensed under the MIT license.