Socket
Socket
Sign inDemoInstall

egg-ts-helper

Package Overview
Dependencies
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-ts-helper

egg typescript helper


Version published
Weekly downloads
19K
increased by2.32%
Maintainers
1
Weekly downloads
 
Created
Source

egg-ts-helper

NPM version Build Status Appveyor status Coverage Status

A simple tool for generating declaration files in egg application. Injecting controller,proxy,service and extend to egg by Declaration Merging

Install

npm i egg-ts-helper -g

or

yarn global add egg-ts-helper

QuickStart

Open your egg application, executing the command

$ ets

-w flag can auto recreated d.ts while file changed

$ ets -w

Usage

$ ets -h

Usage: ets [options]
Options:
   -h, --help               usage
   -v, --version            show version
   -w, --watch              watch file change
   -c, --cwd [path]         egg application base dir (default: process.cwd)
   -C, --config [path]      configuration file, The argument can be a file path to a valid JSON/JS configuration file.(default: {cwd}/tshelper.js)
   -f, --framework [name]   egg framework(default: egg)
   -s, --silent             disabled log
   -i, --ignore [dir]       ignore watchDirs, your can ignore multiple dirs with comma like: -i controller,service
   -e, --enabled [dir]      enabled watchDirs, your can use multiple dirs with comma like: -e proxy,other
   -E, --extra [json]       extra config, value type was a json string

Options

nametypedefaultdescription
cwdstringprocess.cwdegg application base dir
frameworkstringeggegg framework
typingsstring{cwd}/typingstypings dir
caseStylestringloweregg case style(lower,upper,camel)
watchbooleanfalsewatch file change or not
execAtInitbooleanfalseexecute d.ts generation while instance was created
configFilestring{cwd}/tshelper.jsconfigure file path
watchDirsobjectgenerator configuration

egg-ts-helper would watching app/extend,app/controller,app/service by default. The dts would recreated when the files under these folders was changed.

you can disabled some folders by -i flag.

$ ets -i extend,controller

or configure in the config file

// {cwd}/tshelper.js

module.exports = {
  watchDirs: {
    extend: false,
    controller: false,
  }
}

or configure in package.json

// {cwd}/package.json

{
  "egg": {
    "framework": "egg",
    "tsHelper": {
      "watchDirs": {
        "extend": false
      }
    }
  }
}

Register

You can use register to start egg-ts-helper before starting egg application.

$ node -r egg-ts-helper/register index.js

Demo

see https://github.com/whxaxes/egg-boilerplate-d-ts

It works in these directories : app/controller, app/service, app/proxy, app/extend.

Controller

(service, proxy are the same)

ts

// app/controller/home.ts
import { Controller } from 'egg';

export default class HomeController extends Controller {
  public async index() {
    this.ctx.body = 'ok';
  }
}

typings

// app/typings/app/controller/index.d.ts
import Home from '../../../app/controller/home';

declare module 'egg' {
  interface IController {
    home: Home;
  }
}
Extend

ts

// app/extend/context.ts
export default {
  doSomething() {
    console.info('do something');
  }
};

typings

// app/typings/app/controller/index.d.ts
import ExtendObject from '../../../app/extend/context';

declare module 'egg' {
  interface Context {
    doSomething: typeof ExtendObject.doSomething;
  }
}

Keywords

FAQs

Package last updated on 27 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc