Giter VIP home page Giter VIP logo

stix-generator's Introduction

stix-generator

A module that helps you generate modules and controllers easily using Stix CLI.

Installing

yarn add stix-generator or npm i stix-generator

Setup

import { ModuleManagerConfigInterface } from 'Stix';
import Generator from 'stix-generator';

export const modules: ModuleManagerConfigInterface = [
  ...
  Generator,
];

todo

  • A bunch
  • Copy "templates" directory to dist on build (otherwise the templates will be the transpiled versions)

License

MIT.

stix-generator's People

Contributors

rwoverdijk avatar rawphs avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

rwoverdijk rawphs

stix-generator's Issues

Crud controller

Add option to generate crud controller, including the DbRoute.all route.

Generate relations for entities

Either through patching existing entities or by generating entities that don't exist yet. Or both. Snippet:

class SomeGenerator {
public async generateEntity (output: Output, { name, field }: { name: string, field: string[] }) {
    const fields = Array.isArray(field) ? field : [ field ];
    const { pascalCased, camelCased } = this.generatorService.formatNames(name);

    const relationRegex = /^(?:([\w]+\b)?(\*)?(-|<>|>|<)?(\*)?([\w]+)(?:\.)?(\w+)?)$/g;
    const relationsMap: { [key: string]: string } = {
      '-': 'oneToOne',
      '>': 'manyToOne',
      '<': 'oneToMany',
      '<>': 'manyToMany',
    };

    const relations = fields.map(f => {
      const matches = relationRegex.exec(f);

      return {
        entity: pascalCased,
        relation: relationsMap[matches[3] || '-'],
        property: matches[1] || this.generatorService.formatNames(matches[5]).camelCased,
        owning: !!matches[2] || !matches[4],
        other: {
          property: matches[6] || camelCased,
          entity: matches[5],
          owning: !!matches[4],
        },
      };
    });

    output.addData(relations);
  }
}

Example use:

  • stix generate:entity user user -r profile>Profile.user

generate:action bug

Environment

Node.js: v10.13.0
stix: 4.2.2
stix-generator: 0.1.3

Executed command

$ stix generate:action health health check

Generated code

router.ts

export const router = {
  routes: [
    Route.get('health/check', HealthController, '${action}')
  ],
};

Expected code

export const router = {
  routes: [
    Route.get('/health/check', HealthController, 'check')
  ],
};
  • health/check -> /health/check
  • ${action} -> check

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.