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-generator

v1.1.3

Published

the CRUD generator plugin for egg

Downloads

8

Readme

egg-generator

image

基于eggjs框架搭建的代码生成器, 目前支持CRUD生成, 生成内容包括

  • 服务端代码: eggjs restful 代码骨架文件 app/controller/api/v1/{name}.js app/model/{name}.js app/service/{name}.js app/router.js // 路由注册代码

  • 后台管理代码: ant design pro (page list, model form, update, delete) 挂历界面

从零开始搭建

快速搭建一个eggjs + egg-sequelize + ant design pro中后台项目并用egg-generator快速生成代码

注意: 数据层目前只支持生成基于Sequelize的代码, 不支持typescript代码生成

第一步: 创建服务端(egg.js)

$ npm i egg-init -g // 安装eggjs官方生成器
$ egg-init project --type=simple // 生成项目
$ cd project // 进入项目目录
$ npm i // 安装依赖

第二步: 创建管理后台(ant design pro)

注意: 后台目录名必须为backend, 且必须在项目根目录下. 例如: project/backend

$ npm i ant-design-pro-cli -g // 安装ant design pro官方生成器
$ pro new // 生成后台, project name输入为: `backend`

注意:以上两部为项目初始搭建, 如果已有的项目中集成可以跳过以上两步. 独立后台项目可以软连接为backend既可. 前提必须按照eggjsant design pro标准目录结构.

第三部: 引入依赖

$ cd .. // 进入项目根目录
$ npm i egg-isequelize egg-async-ivalidator // 引入数据库操作类和数据验证类
$ npm i mysql2 // 如果是msyql数据库需引入mysql2, 其他数据库请查看Sequelize文档
// 编辑 plugin.js, 加入以下代码
exports.sequelize = {
  enable: true,
  package: 'egg-isequelize'
}

exports.validate = {
  enable: true,
  package: 'egg-async-ivalidator',
};

exports.generator = {
  enable: true,
  package: 'egg-generator',
};
// 编辑config.default.js 加入数据库操作源
exports.sequelize = {
  
  // single database
  client: {
    dialect: 'mysql',// support: mysql, mariadb, postgres, mssql
    database: 'test',
    host: 'localhost',
    port: '3306',
    username: 'root',
    password: '',
    hooks: {
      afterDefine(Model) {
        // add paginate method
        require('sequelize-pagination')({
          oneBaseIndex: true,
          pageSize: 20,
        })(Model);
      },
    },
  },
};

开始使用: 快速生成代码

$ cd project && npm run dev // 项目根目录启动服务
$ cd backend && npm start // 启动管理后台

访问 http://127.0.0.1:7001/generator/crud 开始创建