Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI questions to create model with attributes #8

Open
txsoura opened this issue Sep 25, 2021 · 8 comments
Open

Add CLI questions to create model with attributes #8

txsoura opened this issue Sep 25, 2021 · 8 comments
Assignees
Labels
feature New feature or request help wanted Extra attention is needed

Comments

@txsoura
Copy link
Member

txsoura commented Sep 25, 2021

No description provided.

@jlenon7 jlenon7 changed the title add CLI questions to create model with attributes Add CLI questions to create model with attributes Sep 30, 2021
@jlenon7 jlenon7 added feature New feature or request help wanted Extra attention is needed and removed enhancement labels Oct 1, 2021
@meerhamzadev
Copy link

hey, can you explain this a bit more? I'm interested

@jlenon7
Copy link
Contributor

jlenon7 commented Dec 26, 2021

Hey @meerhamzadev, this issue will add some questions to the CLI after choosing a framework to add an attribute to the CRUD.

Example:

Add attribute ? yes/no

-> yes

Attribute name:

-> email

Attribute type:

-> string

Attribute length:

-> 100

Attribute is required ? yes/no

-> yes

Attribute is unique ? yes/no

-> yes

Attribute "email" add successfully!

Add attribute ? yes/no

-> no

// Generate the files...

@meerhamzadev
Copy link

So, I was supposed to provide the interface right? or functionality as well?

@jlenon7
Copy link
Contributor

jlenon7 commented Dec 28, 2021

You can help however you can. Count on me to help you with anything you need, I can help you with functionality and the CLI too.

@jlenon7
Copy link
Contributor

jlenon7 commented Dec 28, 2021

To facilitate this, we can make a brainstorm for what we will need to finalize this issue

  • Add questions
  • Add validations to questions
    • Attribute name and type cannot have spaces
    • Attribute length needs to be only numbers without spaces
  • Save each attribute in an array
  • Add attributes to Models and Validators in back-end templates using a for loop, examples:

Model

// NestJS TypeORM Model example

import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'

export class <%= namePascal %>  {
    @PrimaryGeneratedColumn()
    id: string

    <% for (attribute of attributes) { %>
         @Column({ 
             unique: <%= attribute.unique %>,
             length: <%= attribute.length %>,
             nullable: <%= !attribute.required %>,
          })
         <%= attribute.name %>: <%= attribute.type %>;
    <% } %>

    @CreateDateColumn({ name: 'created_at' })
    createdAt: Date

    @UpdateDateColumn({ name: 'updated_at' })
    updatedAt: Date

    @Column({ name: 'deleted_at' })
    deletedAt?: Date

    @Column({ enum: ['pendent', 'active'] })
    status: string

    /**
     * Relations
     */
}

Validator

// NestJS TypeORM Validator example

import { Injectable } from '@nestjs/common'
import { Validator } from '@secjs/validator'

@Injectable()
export class <%= namePascal %>Validator extends Validator {
  get schema() {
    return {
      <% for (attribute of attributes) { %>
           <%= attribute.name %>: '<%= attribute.required ? 'required' : '' %>|<%= attribute.unique ? 'unique:<%= namePlural %>' : '' %>';
      <% } %>
    }
  }
}

These are just examples, I didn't test it, but I think that should work.

  • Add attributes to ReactJS templates. (For this I think @Henriquecesp can help you)

@meerhamzadev
Copy link

Ok, I would give it a try, this weekend 🙌

@meerhamzadev
Copy link

hey, @jlenon7 how to run CLI locally?

@jlenon7
Copy link
Contributor

jlenon7 commented Jan 16, 2022

Hey @meerhamzadev, sorry about that, I will document how to run locally later.

First install yo globally using npm.

npm install -g yo

Then in the project root, install the dependencies

npm install

Then link the project using npm

npm link

Now every time that you run yo secjs ..., it will use the local project because of npm link.

yo secjs Foo --path=./Bar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants