Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.
/ quick-start Public archive

Quick start project to create a Hapiness application with all its features

License

Notifications You must be signed in to change notification settings

hapinessjs/quick-start

Repository files navigation

Hapiness

Hapiness Quick Start Project

Quick start project to create a Hapiness application with all its features.

Table of contents

Starter

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.

Back to top

Folders

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.

Back to top

Files

Typescript configuration files

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.

Typescript validation

tslint.json contains all rules for Typescript validation during pretest process.

NPM

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 definition

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.

Back to top

NVM

If you want to use nvm, install node version according .nvmrc file and type:

$ cd path/to/hapiness/application
$ nvm use

Back to top

Development

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.

Modules

If you want to organize your application by modules, you need to follow the guideline of @hapiness/empty-module project.

Services

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.

Routes

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 {}

Libraries

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.

Tests

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.

Back to top

Deployment

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.

Back to top

Change History

  • v1.1.0 (2017-11-20)
    • Latest packages' versions.
    • Documentation.
    • Change packaging process.
  • v1.1.0 (2017-11-14)
    • Create quick-start application.
    • Create tests for each component.
    • Application guideline style.
    • Lettable Observable form RxJS
    • Integration of http-server extension, config library, biim library, logger module, swag module and http module.
    • Documentation

Back to top

Maintainers

tadaweb
Julien Fauville Antoine Gomez Sébastien Ritz Nicolas Jessel

Back to top

License

Copyright (c) 2017 Hapiness Licensed under the MIT license.

Back to top

About

Quick start project to create a Hapiness application with all its features

Resources

License

Stars

Watchers

Forks

Packages

No packages published