npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

egg-template-helper

v1.0.3

Published

egg template helper

Downloads

9

Readme

egg-template-helper

Setup an egg project

install egg-init globally

  npm i egg-init -g

setup a TypeScript based project

npx egg-init --type=ts projectName
cd projectName && npm i
npm run dev

setup a JavaScript based project

egg-init --type simple projectName
cd projectName && npm i
npm run dev

For further details, please refer to https://github.com/eggjs/egg-init

Install

  npm install egg-template-helper -g

or

  yarn global add egg-template-helper

Usage

$ eth -h

  Usage: eth [commands] [options]

  Options:
    -v, --version            output the version number
    -h, --help               output usage information

  Commands:

    new [name] [options]     新建egg文件
    delete [name] [options]  删除egg文件
    rename [name] [options]  重命名egg文件

eth new

create files by the [name] and a specified type.

New Options

| name | type | description | | --- | --- | --- | | category | string | new file category | | test | boolean | whether append test for controller / service / model |

Available category

  • default: will create controller, service and model.
  • controller: will create a controller.
  • service: will create a service.
  • model: will create a model, the model depends on mongoose.

create controller / service / model

  eth new user --category default

or

  eth new user -c default

Actually the [name] parameter is a path relative to app/controller / app/service / app/model

In this example, it will create app/controller/user.ts, app/model/user.ts, app/service/user.ts.

create a sub directory controller / service / model

  eth new permission/role --category default

or

  eth new permission/role -c default

It will create app/controller/permission/role.ts, app/model/permission/role.ts, app/service/permission/role.ts.

eth delete

delete files associated with the [name]

  eth delete user

It will delete app/controller/user.ts, app/model/user.ts, app/service/user.ts.

eth rename

Rename Options

| name | type | description | | --- | --- | --- | | newPath | string | new path |

rename files associated with the [name]

  eth rename user -n masterUser

or

  eth rename user -newPath masterUser

It will rename app/controller/user.ts, app/model/user.ts, app/service/user.ts to app/controller/masterUser.ts, app/model/masterUser.ts, app/service/masterUser.ts

It will also change the file content!!!

Once user renamed to masterUser, the app/controller/masterUser.ts content is changed.

import { Controller } from 'egg'

/**
 * MasterUser Controller
 *
 * @export
 * @class MasterUserController
 * @extends {Controller}
 */
export default class MasterUserController extends Controller {
}

Customizations

You can setup your own templates.

eth.config.json

create an eth.config.json file under the project root.

| name | type | default | description | | --- | --- | --- | --- | | ext | string | ".ts" | file extenision, you can specify ext to ".js" if you use JavaScript to develop egg project | | templateDir | string | "" | custom template path, relative to the project root | | execEts | boolean | true | execute egg-ts-helper after command executed. It will take effect when ext is ".ts" | | renameContent | boolean | true | rewrite file content when executing rename command | | customData | object | {} | pass custom data to custom template when executing new command |

Example

Let's customize a template and inject an author name by setting customData.

eth.config.json

{
  "ext": ".ts",
  "templateDir": "template",
  "execEts": true,
  "renameContent": false,
  "customData": {
    "Author": "Dada"
  }
}

directory structure

egg-showcase
  ├── node_modules
  └── app
      ├── controller
      ├── model
      ├── service
      └── router.ts
  ├── template                          template directory
  |   ├── controller.test.tpl           controller test template
  |   ├── controller.tpl                controller template
  |   ├── model.tpl                     model template
  |   ├── service.test.tpl              service testtemplate
  └── └── service.tpl                   service template

template/comtroller.tpl

import { Controller } from 'egg'

/**
 * <%=pascalCaseName%> Controller
 * 
 * @author <%=Author%>
 * @export
 * @class <%=pascalCaseName%>Controller
 * @extends {Controller}
 */
export default class <%=pascalCaseName%>Controller extends Controller {
}

There are four built in variables: name, pascalCaseName, testName, modelTestRootRelative

execute new command

  eth new user -c default

The content in app/controller/user.ts will like this:

import { Controller } from 'egg'

/**
 * User Controller
 *
 * @author Dada
 * @export
 * @class UserController
 * @extends {Controller}
 */
export default class UserController extends Controller {
}