Giter Site home page Giter Site logo

luhaitao0626 / create-crud-template Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 310 KB

This is a cli for creating crud page of an entity, currently support for vue@next sfc template. Code spliting is automatically done.

License: MIT License

JavaScript 55.04% TypeScript 25.55% Vue 19.28% Shell 0.13%

create-crud-template's Introduction

Instruction

This cli used for creating CRUD template of various UI libraries, emelent-plus, ant-design, vant and so on. (Until now, webcrud-cli only support element-plus CRUD template, other template will be available later.) The Main Purpose is to free developers from manually creating entity CRUD files.

How to use?

install globally

1. install

npm install webcrud-cli -g

2. initialize

Instruction: User should run the following commands in the target working directory. For example, in vue project there's a folder named "views". if user want to create a user entity in views folder. And the commonand shall run in this "views" folder.

webcrud-cli init <entity>
  1. This command will create a file named [entity].config.cjs in the current working directory.
  2. Modify the name of [entity].config.cjs to assign a customized name for entity, like assets.config.cjs or products.config.cjs
  3. Modify the config file to make costumized entity configuration. Instructions on options move to "config.cjs" section.

3. create

The following command will create crud template.

webcrud-cli create

If there is only one entity.config.cjs file in current working directory, the cli will immediately create crud template according to this file. However, if there are multiple config.cjs files, the command line will show an interface for user to select the list.

After user select one item, the cli will create a folder named 'entity' then emit template files into it.

Instruction for config.cjs

<entity>.config.cjs structure is as following:

const path = require('path');

const config = {
  type: 'element-plus', // UI type: currently only support element-plus
  output: path.resolve(__dirname), // output, current working directoy
  editable: true, // entity table editable or not
  hasPagination: true, // whether need pagination or not
  fields: { // entity properties, is an object
    name: {
      prop: String, // value type of property
      type: "input", // specify element to show the property value , currently support input, datepicker
      label: "entity", // the label of property, used in table header
      required: true, // whether this property is required
      editable: true, // INSTRUCTION: if you are editing a row, editable will control this field is editable or not.
      query: true, // INSTRUCTION: whether this property is quariable, if you set query as true, it will appear in the search bar.
    },
    age: {
      prop: Number,
      type: "input",
      label: "age",
      required: true,
      editable: true,
      query: true,
    },
    active: {
      prop: Boolean,
      type: "switch",
      label: "active",
      required: false,
      editable: true,
      query: false,
    },
    gender: {
      prop: String,
      type: "input",
      label: "gender",
      required: true,
      editable: false,
      query: false,
    },
    phone: {
      prop: String,
      type: "input",
      label: "phone",
      required: true,
      editable: true,
      query: false,
    },
    email: {
      prop: String,
      type: "input",
      label: "email",
      required: false,
      editable: true,
      query: false,
    },
    address: {
      prop: String,
      type: "input",
      label: "address",
      required: false,
      editable: true,
      query: false,
    },
    birthday: {
      prop: String,
      type: "datepicker",
      label: "birthday",
      required: false,
      editable: true,
      query: false,
    },
  },
  // operations: ["create", "update", "remove", "detail"],
  // dependencies: [
  //   {
  //     name: "store",
  //     isNeed: true,
  //     path: "@/stores",
  //     aliasName: "userStore",
  //     actionTypes: {
  //       isNeed: true,
  //       path: "@/stores/action-types",
  //     },
  //   },
  //   {
  //     name: "router",
  //     isNeed: true,
  //   },
  // ],
};
module.exports = config;

examples

entity view entity view

edit mode edit mode

ineditable field ineditable field

create a new row create a new row

code for users to edit

in crud.ts

// user can replace the api request. place that need to modify is marked as comment of [USER EDIT]
export const getEntitys = async (params: IEntityQuery): Promise<any> => {
    try {
        // [USER EDIT]
        return MockData;
    } catch (e) {
        console.log(e);
        return e
    }
}
export const create = async(entity: IEntity): Promise<any> => {
    // filter unnecessay properties in entity
    let _entity = filterFields(entity, Fields);
    try {
      // [USER EDIT]
        // update api (user defined)
        // const res = await createEntity(_entity)
        // return res
    }
    catch (err) {
        return err
    }
}

export const update = async(entity: IEntity): Promise<any> => {
    // filter unnecessay properties in entity
    let _entity = filterFields(entity, Fields);
    try {
      // [USER EDIT]
        // update api (user defined)
        // const res = await updateEntity(_entity)
        // return res
    }
    catch (err) {
        return err
    }
}
export const remove = async (id: string): Promise<any> => {
    try {
        // remove api (user defined)
        // const res = await updateEntity(id)
        // return res
    }
    catch (err) {
        return err
    }
}

create-crud-template's People

Contributors

lufadao0626 avatar luhaitao0626 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.