1.0.0 • Published 6 years ago

scarface v1.0.0

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

generator-scarface NPM version Build Status Dependency Status

Scaffolding with steroids

Scarface is a node module which purpose is to make developers life easier by using templates to generate full projects

The idea of scarface is to be totally language-agnostic, so you can create your own template, by using EJS templates sintax

My motivation for creating that initially was to be productive in my own projects but I decided to extend to the community

Unfortunatelly I have my full time job, so be aware that the intention of the project is to grow with the help of the community

By default, it comes with aspnetcore template which will generate a project for an API using:

  • AspNetCore 2.0
  • EntityFramework 2.0 with Postgres (can be easily changed to SQL Server)
  • Swagger interface

Installation

First, install generator-scarface using npm (we assume you have pre-installed node.js).

npm install -g scarface

Or you can clone the full project from Github

git clone https://github.com/bruno-bert/generator-scarface.git

And then, in directory of cloned project, type:

npm install

Usage

Create a directory to your application:

mkDir appTest
cd appTest

Then, inside the directory, create a schema.json file containing all configuration of your application. Please refer to the section How to Configure Json file

Then, in your terminal, type:

scarface -t [templateName]
scarface -t [templateName] -d [true/false] -i [true/false] -o [outputDirectory]
  t:  Name of template to be used (REQUIRED)
  d:  Flag that turns on/off debug messages
  o:  Output directory to generate project
  i:  Flag that turns on/off install of dependencies [This depends on implementation in template]

If you cloned the full project, you can use it by typing:

node scarface-cli.js -t [templateName]

How to use the aspnetcore template

By default, scarface comes with template aspnetcore, so as pre-requisite for this project to work you need to have the ASPNETCORE 2.0 installed.

Then you can type:

scarface -t aspnetcore

At the end of proccess you will have full project created in your current folder. This specific template creates 2 folders: app and test

Type:

cd app

Then:

dotnet restore && dotnet run

Your API should be running and server listening to port 5000 In your browser, access the url http://localhost:5000/swagger

Attention: This tool do not create the database for you. So, if you do not have the database created, you can do that easily by using the Entity Framework cli tool

dotnet ef migrations add %RANDOM%
dotnet ef database update

How to Configure Json file

Full Documentation to be created

Example:

The example below shows how to create a Json file that will generate a project based in your template

The tags in json will be used in the template selected

{
  "$schema": "http://json-schema.org/draft-06/schema",

  "info": {
    "title": "My API",
    "description": "API used to connect to Sysmine database layer",
    "author": "Bruno Bertoni de Paula",
    
    "contact": {
      "email": "bruno.bert.jj@gmail.com"   
    }

  },

 
      
  "appconfig": {
    "name": "MyApi",

    "dbConnection": {
      "client": "postgres",
      "host": "localhost",
      "database": "testdb",
      "port": "5432",
      "pooling": "true",
      "userId" : "postgres",
      "password" : "icwsig@78"
    },

 
   
    "template": "aspnetcore"
    

  },

  
  "appmodel": {
    "type": "object",
    "properties": {

      "clientes": {
        "type": "array",
        "items": { "$ref": "#/definitions/cliente" }
       }

    },

    "definitions": {

        "Cliente": {
            "type": "object",
            "required": ["id","doc_cliente","nome_cliente"],
            "properties": {
              
           
            "doc_cliente": {           
                "type": "string"
            },
            "nome_cliente": {          
                "type": "string"
            },
            "descricao_cliente": {           
                "type": "string"
            },
            "flag_status": {           
                "type": "string"
            }
          
            },
"additionalProperties": { "tableName": "cliente" }
          },

      "Empresa": {

        "type": "object",
        "properties": {
         
        "cliente_id": {
            "type": "int"
        },
 

      
       
        "nome_empresa": {           
            "type": "string"
        },
        "descricao_empresa": {          
            "type": "string"
        },
        "descricao_empresa_do": {           
            "type": "string"
        },
        "flag_status": {           
            "type": "string"
        }
       



        },
"additionalProperties": { "tableName": "empresa" }

      }

     
    }
  }
}

How to create your own templates

Full Documentation to be created

License

MIT © Bruno de Paula