# Henson Project Preset for MRM

This [mrm](https://github.com/sapegin/mrm) preset enforces henson node.js project template.

## Configuration

- `type`: Type of project, can be 'lib', 'service'
- `webapp`: Type of web app if a web app is included in project, can be 'react', 'ejs'
- `branch`: Release branch, can be 'master' or 'dev'. It must match the beginning of git branch name.
- `excludeBundledDependencies`: List the dependencies (in `node_modules`) which should be excluded from `bundledDependencies`, so that they won't be packed into RPM
- `logFileName`: By default service log file use package name. It can be override by this configuration.
- `targetES`: Which ES standard that Typescript will be compiled to, supported standards are `es5` and `es2017`, by default, `es2017` will be used.

## Tasks

### All

The alias `all` includes all tasks except `validate`.

### Base

Setup project scaffold. Usually it's the first task for a new project.

- Setup project to be updatable with mrm (this tool)
- Setup test framework using `mocha` and `chai`
- Create NPM scipts: `test`, `testall` and `build`
- Create NPM script: `cpd` - Find copy-paste (duplicated) code

### TypeScript

- Setup TypeScript compiler
- Setup linting
- Create NPM script: `build`

### CI

Setup continuous integration.

- Create NPM script: `ci`
- Create NPM script: `npm_publish` - Publish package to NPM repository for project of lib type.

### Dependency

Update project dependencies version to align with product FOSS list and recommendations.
It requires configuration `branch`.

It also updates `package.json` to set all `dependencies` and `optionalDependencies` into `bundledDependencies`, except which are listed in configuration `excludeBundledDependencies`.

### License

Henson CGC license disclaim.

### Docker

Setup standard docker development environment

- Create NPM script: `docker`

### RPM

Build RPM package for project of service type.

- Create NPM script: `rpm` (deprecated by `gitlab:rpm`)

The RPM package contains:

* Compiled JavaScript files and other source files defined in `.npmignore`
* Bundled node modules defined in `bundleDependencies` property in `package.json`
* Non-JS project files under folder `rpm/content/ ` (need to be copied by commands in  `rpm.spec`)

### GitLab

Setup GitLab project CI and configurations. RPM or NPM publish is included in CI pipeline.

- Create NPM script: `gitlab:rpm`

### Document

Setup automatic document generation workflow:

* Generate table of content for markdown
* Generate UML diagram from plantuml source
* Generate API document from Swagger yaml

- Create NPM script: `doc` (`doc:*`)

### Validate

Validate configuration.

## Preset Development

### Check outdated dependencies version

Run `./dev_up.sh` to start node.js docker container.

Inside container, run:

```
yarn install
yarn checkdep master
```

### Test Preset Locally

Since there is no unit test in preset itself, when making modification to preset, you have to verify preset locally with a project before publishing the preset.

The verification requires Node.js environment has been installed on your host, not only Docker env.
And also `mrm` needs to be installed globally:
```
npm install -g mrm
```

### The procedure to verify preset:

1. Change preset version to `dev` in `package.json` of `@henson/mrm-preset`.
2. Pick a project to verify preset, suppose it's on `<rootpath>/projects/helloworld` and the preset is on `<rootpath>/projects/henson-mrm-preset`
3. On bash (not in Docker container), run
   ```
   $ cd <rootpath>/projects/helloworld
   $ mrm all --dir ../henson-mrm-preset
   ```
   Where `../henson-mrm-preset` is the relative path to preset project.
4. Verify target project in Docker dev environment
5. In case preset modified GitLab CI related setting, you needs to push target project to GitLab to see if it works fine.
6. After preset is verified, update its version (from `dev`) and publish.
7. Apply latest preset to test project again by repeat step 3.

### The procedure to verify preset via npx:

npx -p mrm -p @henson/mrm-preset mrm all --preset @henson/mrm-preset --config:branch master --config:type service
