# @junte/mocker-library

> Library for creating mock files for your projects.

Latest version **0.0.59** (published 2020-09-08) · 0 weekly downloads

## Install

```sh
npm install @junte/mocker-library
pnpm add @junte/mocker-library
yarn add @junte/mocker-library
bun add @junte/mocker-library
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.59 |
| Published | 2020-09-08 |
| First published | 2020-09-08 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 11 |
| Unpacked size | 89.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | junte |

## Links

- npm: https://www.npmjs.com/package/@junte/mocker-library
- npm.io page: https://npm.io/package/@junte/mocker-library

## Dependencies (11)

- [gulp](https://npm.io/package/gulp.md) ~4.0.2
- [tslib](https://npm.io/package/tslib.md) ^1.9.0
- [gulpclass](https://npm.io/package/gulpclass.md) ~0.2.0
- [dummy-json](https://npm.io/package/dummy-json.md) ~2.0.0
- [gulp-debug](https://npm.io/package/gulp-debug.md) ~4.0.0
- [map-stream](https://npm.io/package/map-stream.md) ~0.0.7
- [change-case](https://npm.io/package/change-case.md) ~3.1.0
- [gulp-rename](https://npm.io/package/gulp-rename.md) ~1.4.0
- [gulp-extname](https://npm.io/package/gulp-extname.md) ~0.2.2
- [serialize-ts](https://npm.io/package/serialize-ts.md) ~2.5.4
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ~0.1.13

## Recent versions

- 0.0.59 (latest) — 2020-09-08

## README

# MockerLibrary
Library for creating mock files for your projects.

After setting up and running the library, it will automatically create the HBS(DummyJSON) files from which the conversion to JSON will occur.
##Getting started
####1. Add a dependency to your `package.json`:
```
npm install @junte/mocker-library
```

####2. Add a script in your `package.json`:
```
"scripts": {
   ...
  "mocks": "gulp build --gulpfile node_modules/@junte/mocker-library/gulpfile.js --cwd ."
   ...
}
```

####3. Change a `tsconfig.json`:
```
{
    ...
    compilerOptions: {
        ...
        emitDecoratorMetadata: true,
        ...
    },
    ...
}
```

####4. Config
After the first run mocks script, a config file (mocker.json) will be created in root directory. Set your preferences for the library.

Default config values:
```
{
  outDirProject: './dist/out-tsc',
  modelsDir: './src/models',
  helpersDir: './src/mocks/helpers',
  objectsDir: './src/mocks/objects',
  servicesDir: './src/mocks/services',
  outObjectsJsonDir: './src/mocks/objects',
  outServicesJsonDir: './src/assets/mocks'
}
```
`outDirProject` - this equal to the `outDir` your project (see `tsconfig.json`)

`modelsDir` - directory in which the data models with decorators are placed in them

`helpersDir` - directory with helpers (for dummyjson)

`objectsDir` - directory in which the script will add `*.hbs` (for dummyjson) files generated from models

`servicesDir` - directory in which you will create `*.hbs` files for services 

`outObjectsJsonDir` - directory in which json files created from `*.hbs` files which are in `objectsDir`

`outServicesJsonDir` - directory in which json files created from `*.hbs` files which are in `servicesDir`

#Examples
Model `ObjectLink.ts:`
```
@model()
export class ObjectLink {

  @field({mock: '{{int 1 100}}'})
  id: number;

  @field({mock: '{{presentation}}'})
  presentation: string;
  
}
```

Model `User.ts:`
```
@model()
export class User {

  @field({mock: '{{int 1 100}}'})
  id: number;

  @field({mock: '{{boolean}}'})
  approved: boolean;

  @field({mock: '{{> object_link presentation="John"}}'})
  name: ObjectLink;

  @field({
    name: 'first_name',
    mock: '{{firstName}}'
  })
  firstName: string;

  @field({
    serializer: new ArraySerializer(new ModelSerializer(ObjectLink)),
    mock: '[{{#repeat 1 5}} {{> object_link presentation="Hobby"}} {{/repeat}}]'
  })
  hobby: ObjectLink[];

}
```
at the output we get
`object_link.json:`
```
{
    "id": 77,
    "presentation": "John"
}
```

and `user.json:`

```
{
    "id": 47,
    "approved": false,
    "name": {
        "id": 76,
        "presentation": "John"
    },
    "first_name": "Darrell",
    "hobby": [
        {
            "id": 71,
            "presentation": "Hobby"
        },
        {
            "id": 4,
            "presentation": "Hobby"
        },
        {
            "id": 63,
            "presentation": "Hobby"
        }
      ...
    ]
}
```

---
_Source: https://npm.io/package/@junte/mocker-library · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
