0.0.59 • Published 4 years ago

@junte/mocker-library v0.0.59

Weekly downloads
1
License
-
Repository
-
Last release
4 years ago

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

4 years ago

0.0.58

4 years ago

0.0.57

4 years ago

0.0.56

4 years ago

0.0.55

4 years ago

0.0.54

4 years ago

0.0.53

4 years ago

0.0.52

4 years ago

0.0.51

4 years ago

0.0.50

4 years ago

0.0.49

4 years ago

0.0.48

4 years ago

0.0.47

4 years ago

0.0.46

4 years ago

0.0.45

4 years ago

0.0.44

4 years ago

0.0.43

4 years ago

0.0.42

4 years ago

0.0.41

4 years ago

0.0.40

4 years ago

0.0.39

4 years ago

0.0.37

4 years ago

0.0.36

4 years ago

0.0.35

4 years ago

0.0.34

4 years ago

0.0.33

4 years ago

0.0.32

4 years ago

0.0.31

4 years ago

0.0.30

4 years ago

0.0.29

4 years ago

0.0.28

4 years ago

0.0.27

4 years ago

0.0.26

4 years ago

0.0.25

4 years ago

0.0.24

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago