Skip to content

Latest commit

History

History
152 lines (114 loc) 路 3.25 KB

code-generation.md

File metadata and controls

152 lines (114 loc) 路 3.25 KB

Code Generation

You are reading the documentation for version 2 of FoalTS. Instructions for upgrading to this version are available here. The old documentation can be found here.

Create a project

foal createapp my-app

Create a new directory with all the required files to get started.

If you specify the flag --mongodb, the CLI will generate a new project using MongoDB instead of SQLite.

If you specify the flag --yaml, the new project will use YAML format for its configuration files. You can find more information here.

Create a controller

foal g controller <name>

Create a new controller in ./src/app/controllers, in ./controllers or in the current directory depending on which folders are found.

Example

foal g controller auth
foal g controller api/product

Output

src/
 '- app/
  '- controllers/
   |- api/
   | |- product.controller.ts
   | '- index.ts
   |- auth.controller.ts
   '- index.ts

The --register flag

foal g controller <name> --register

If you wish to automatically create a new route attached to this controller, you can use the --register flag to do so.

Example

foal g controller api --register
foal g controller api/product --register

Output

src/
 '- app/
  |- controllers/
  | |- api/
  | | |- product.controller.ts
  | | '- index.ts
  | |- api.controller.ts
  | '- index.ts
  '- app.controller.ts

app.controller.ts

export class AppController {
  subControllers = [
    controller('/api', ApiController)
  ]
}

api.controller.ts

export class ApiController {
  subControllers = [
    controller('/product', ProductController)
  ]
}

Create an entity (simple model)

foal g entity <name>

Create a new entity in ./src/app/entities, in ./entities or in the current directory depending on which folders are found.

Create REST API

foal g rest-api <name>

Create a new controller and a new entity to build a basic REST API. Depending on which directories are found, they will be generated in src/app/{entities}|{controllers}/, {entities}|{controllers}/ or in the current directory.

If you are in the root directory and you want to automatically register the controller within the app controller you can add the --register flag.

foal g rest-api <name> --register

See the page REST Blueprints for more details.

Create a hook

foal g hook <name>

Create a new hook in ./src/app/hooks, in ./hooks or in the current directory depending on which folders are found.

Create a script

foal g script <name>

Create a new shell script in src/scripts regardless of where you run the command.

Create a service

foal g service <name>

Create a new service in ./src/app/services, in ./services or in the current directory depending on which folders are found.

Example

foal g service auth
foal g service apis/github

Output

src/
 '- app/
  '- services/
   |- apis/
   | '- github.service.ts
   | '- index.ts
   |- auth.service.ts
   '- index.ts