
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Javascript generator utils
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({ }, { });
npm install gen-js
mkdir templates
mkdir generated
You now have these directories :
[root] |-- node_modules | |-- gen-js |-- templates |-- generated
{ inDir:"templates", outDir:"generated", packageBase:"org.demo" }
, with :
{ id:"bean_template", inFile:"java/bean.ejs", outDir:"src/main/java", outFile:"XXX.java", generatedName:"XXX", generatedPackage:"PPP.domain" }
, with :
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"} ] }
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
GUtil
The npm package gutil receives a total of 4,745 weekly downloads. As such, gutil popularity was classified as popular.
We found that gutil demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.