Skip to content
Romain Lenzotti edited this page Jun 25, 2020 · 46 revisions

How to create a new Ts.ED package

  • Fork the project + yarn install
  • Create a new directory named mypackage in packages directory.
  • Copy package.json from typeorm and change the name field by @tsed/cron change also the description, keywords, etc... Add contributors field with your name
  • Add your required dependencies in the new package and run yarn install on root
  • Copy tsconfig.compile.json from typeorm
  • Copy Readme and change usage and installation description
  • Add src directory
  • In src add index.ts and create a module file. Example: for typeorm, it's TypeORMModule.ts
  • Export all required class, decorators, service, etc... in the index.js

Note: Decorators can be generated with the cli. Just run the cli inside your packages/mypackage.

Module example

import {Configuration, PlatformApplication, OnDestroy, OnInit} from "@tsed/common";
import {MyService} from "./services/MyService";

@Module({
  imports: [MyService] // prebuild MyService. Use this field to build services before the module.
})
export class MyModule implements OnInit, OnDestroy {
  @Inject()
  app: PlatformApplication;
  
  @Constant("myConfig", {})
  settings: any;

  @Inject()
  myService: MyService;

  async $onInit(): Promise<any> {
    console.log("Init")
  }

  $onDestroy(): Promise<any> | void {
     console.log("Destroy");
  }
}
Clone this wiki locally