Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gutil

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gutil

GUtil

  • 1.0.0
  • npm
  • Socket score

Version published
Weekly downloads
4.5K
decreased by-22.96%
Maintainers
1
Weekly downloads
 
Created
Source

gen-js-utils

Javascript generator utils

Quick start

create the working directory :

mkdir gen-js-test
cd gen-js-test

install gen-js :

npm install gen-js

create templates and generated directory :

mkdir templates
mkdir generated

create a template file : "bean.ejs"

create the main javascript file : "main.js"

var Generator = require('gen-js');
var by = require("../lib/util/by");

var generator = new Generator();
generator.config = config;
generator.generate({

    }, {

    });

Documentation

Create generation project

  1. Create a new directory
  2. Go to this directory
  3. Download "gen-js" with npm :
npm install gen-js
  1. Create the directory for templates
mkdir templates
  1. Create the directory for generated files
mkdir generated

You now have these directories :

[root]
  |-- node_modules
  |   |-- gen-js
  |-- templates
  |-- generated

Main configuration

{
    inDir:"templates",
    outDir:"generated",
    packageBase:"org.demo"
}

, with :

  • inDir : relative path to the templates directory
  • outDir : relative path to the output directory where the files are generated
  • packageBase : project root package

Template definition

{
    id:"bean_template",
    inFile:"java/bean.ejs",
    outDir:"src/main/java",
    outFile:"XXX.java",
    generatedName:"XXX",
    generatedPackage:"PPP.domain"
}

, with :

  • id : template identifier
  • inFile : template file
  • outDir : generated directory
  • outFile : generated file
  • generatedName : generated entity name
    • XXX : replace by the entity name : the first letter is capitalized
    • xxx : replace by the entity name : the first letter is uncapitalized
  • generatedPackage : generated entity package
    • XXX : replace by the entity name : the first letter is capitalized
    • xxx : replace by the entity name : the first letter is uncapitalized
    • PPP : replace by the project root package from the main configuration

Entity definition

The entity is an object with any data you want.

You defined the necessary attributes and values for your templates.

For example, we can define a sample entity "author" with the stereotype "bean" :

{
    "name": "author",
    "stereotypes":["bean","document"],
    "attributes":[
        {"name":"id", "type":"Long", "sqlName":"ID", "sqlType":"INT", "size":"10", "isPrimaryKey":"true", "nbMin":"1", "nbMax":"1"},
        {"name":"firstname", "type":"String", "sqlName":"FIRSTNAME", "sqlType":"VARCHAR", "size":"10", "isPrimaryKey":"false", "nbMin":"1", "nbMax":"1"},
        {"name":"lastname", "type":"String", "sqlName":"LASTNAME", "sqlType":"VARCHAR", "size":"10", "isPrimaryKey":"false", "nbMin":"1", "nbMax":"1"}
    ]
}

Gen-js generator

Import the main class : Generator

var Generator = require('gen-js');

Create a new instance of Generator :

var generator = new Generator();

Define the main configuration in the Generator :

generator.config = {
    inDir:"templates",
    outDir:"generated",
    packageBase:"org.demo"
};

Define and inject all your templates and entities of your model even if they have not to be generated.

All entities and templates are required to make links between entities and generated entities during the generation.

For that, declare the entities array and the templates array in the Generator :

// array of entities
generator.entities = [
    {
        "name": "author",
        "stereotypes":["bean","document"],
        "attributes":[
          {"name":"id", "type":"Long", "sqlName":"ID", "sqlType":"INT", "size":"10", "isPrimaryKey":"true", "nbMin":"1", "nbMax":"1"},
          {"name":"firstname", "type":"String", "sqlName":"FIRSTNAME", "sqlType":"VARCHAR", "size":"10", "isPrimaryKey":"false", "nbMin":"1", "nbMax":"1"},
          {"name":"lastname", "type":"String", "sqlName":"LASTNAME", "sqlType":"VARCHAR", "size":"10", "isPrimaryKey":"false", "nbMin":"1", "nbMax":"1"}
        ]
    }
    ,
    ...
];
// array of templates
generator.templates = [
    {
        id:"bean_template",
        inFile:"java/bean.ejs",
        outDir:"src/main/java",
        outFile:"XXX.java",
        generatedName:"XXX",
        generatedPackage:"PPP.domain"
    }
    ,
    ...
];

Call the generate method to make generation :

generator.generate(entities[0], templates[0]);

You can use the 'by' utility method to make simple selection of objects in an array :

generator.generate(by(entities,'stereotypes','bean'), by(templates,'id','bean_template'));

The utility method 'by' located in the directory 'lib/util' of 'gen-js'.

FAQs

Package last updated on 13 Apr 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc