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"
}
...
]
}