# CLI

@mrapi/cli

Used to assist in the construction of standardized mrapiprojects

# install

npm install @mrapi/cli --save-dev
1

# use

@mrapi/cli provides a cli interface for mrapi projects:

npx mrapi -h
1

Help message will be printed:

Usage: run [options] [command]

Options:
  -v, --version       output the version number
  -h, --help          display help for command

Commands:
  generate [options]  Generate prisma schema and nexus types
  help [command]      display help for command
1
2
3
4
5
6
7
8
9

# configuration

The following properties in mrapiConfig will be used:

const { inputSchemaDir, schemaDir, outputDir, managementUrl } = this.mrapiConfig
1

Reference mrapiConfig

# generate

Used to initialize the multi-tenant management instance and generate the prisma client, nexus type, and oas codes required by the DAL.

This command roughly does the following things:

  1. Clear redundant directories or files;
  2. Generate a complete schema.prisma according to the target file;
  3. Initialize the multi-tenant instance, and generate the corresponding prisma client according to schema.prisma;
  4. Generate the corresponding nexus CURD;
  5. Generate the corresponding oas CURD;

# Parameter options

npx mrapi generate -h
1

Help message will be printed:

Usage: run generate [options]

Generate prisma schema and nexus types

Options:
  --env <path>          env filePath (default: "config/.env")
  --name <name>         Schema client name. If the name is "management", Only generate management client.
  --cnt <options>       Generate CNT params. whiteList: disableQueries,disableMutations
  --m <options>         Generate models
  --em <options>        Exclude generate models
  --eqm <options>       Exclude Queries and Mutations
  -h, --help            display help for command
  --provider <options>  Datasource provider list: sqlite,mysql,postgresql.
1
2
3
4
5
6
7
8
9
10
11
12
13

# --name

The file name corresponding to the schema configuration, uniquely identifies the prisma client.

  • Required
  • Type: string
  • Reference Value: "management" or schema configuration file name

Combine mrapiConfig.inputSchemaDir to find the prisma schema configuration entry, Generate schema.prisma export path with mrapiConfig.schemaDir, and generate prisma client address with mrapiConfig.outputDir.`

const inputSchemaPath = path.join(cwd, inputSchemaDir, `${name}.prisma`)
const outputSchemaPath = path.join(cwd, schemaDir, `${name}.prisma`)
const outputPath = path.join(cwd, outputDir, name)
1
2
3

Note: When the value is "management", only the prisma client for multi-tenant management is generated. Avoid the value equal to "schema", because this value will be reserved for the multi-tenant management table configuration file.

# --cnt

Parameters to generate CURD

  • Optional/Not required
  • Type: string(Comma separated)
  • Reference Value: "disableQueries""disableMutations"

"disableQueries" means no queries are generated, and "disableMutations" means no mutations are generated.

# --m

Which models in the configuration file are enabled

  • Optional/Not required
  • Type: string(Comma separated)
  • Undefined means all models are enabled

# --em

Contrary to --m and mutually exclusive, means which models to ignore

  • Optional/Not required
  • Type: string(Comma separated)
  • Undefined means not to ignore any models

# --eqm

Which models ignore both queries and mutations

  • Optional/Not required
  • Type: string(Comma separated)
  • Undefined means all models are enabled

# --provider

The datasource provider of the schema configuration corresponding to --name.

  • Optional/Not required
  • Type: string(Comma separated)
  • Reference Value: mysql, postgresqlsqllite

# example

# General usage, initialize the schema-xxx configuration file
npx mrapi generate --name schema-xxx

# OR

# Only initialize multi-tenant management (prisma/schema.prisma file is required)
npx mrapi generate --name management
1
2
3
4
5
6
7
Last Updated: 9/23/2020, 7:06:33 PM