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

node-boiler

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-boiler - npm Package Compare versions

Comparing version 1.1.8 to 1.1.9

106

lib/helpers/fileGenerators.js

@@ -1,63 +0,55 @@

const fs = require('fs');
const contetMaker = require('./contentMaker');
const fs = require("fs");
const contetMaker = require("./contentMaker");
const util = require("util");
const fsWritePromisified = util.promisify(fs.writeFile);
const errorHandler = err => console.log("\x1b[31m", err);
const successHandler = fileName => () =>
console.log("\x1b[32m", `Generated file ${fileName}`);
module.exports = {
//********This function generates all the files for declaring Mongoose Models */
makeModels: function(models) {
return models.map(item =>
fsWritePromisified(`./models/${item}.js`, contetMaker.modelsContent(item))
.then(successHandler(`${item}.js`))
.catch(errorHandler)
);
},
//********This function generates all the files for declaring Mongoose Models */
makeModels: function(model_list){
model_list.map((item, index) => {
const content = contetMaker.modelsContent(item);
fs.writeFile(`./models/${item}.js`, content, (err) => {
if (err) {
console.log("\x1b[31m",err);
}
})
console.log("\x1b[32m",`Generated file ${item}.js`)
})
},
//*********This function generates html views********/
makeViews: function(views) {
return views.map(item =>
fsWritePromisified(`./views/${item}.html`, contetMaker.viewsContent(item))
.then(successHandler(`${item}.html`))
.catch(errorHandler)
);
},
//*********This function generates html views********/
makeViews: function(view_list){
//**********This function generates the code for declaring controllers */
makeControllers: function(controllers) {
return Object.entries(controllers).map(([fileName, methods]) =>
fsWritePromisified(
`./controllers/${fileName}.js`,
contetMaker.controllerContent(methods)
)
.then(successHandler(`${fileName}.js`))
.catch(errorHandler)
);
},
view_list.map((item, index) => {
const content = contetMaker.viewsContent(item);
fs.writeFile(`./views/${item}.html`, content, (err) => {
if (err) {
console.log("\x1b[31m",err);
}
})
console.log("\x1b[32m",`Generated file ${item}.html`)
})
},
//**********This function writes the basic route declaration**********/
//**********This function generates the code for declaring controllers */
makeControllers: function(controller_config){
const controllerFiles = Object.keys(controller_config);
controllerFiles.map((item, index) => {
const content = contetMaker.controllerContent(controller_config[item]);
fs.writeFile(`./controllers/${item}.js`, content, (err) => {
if (err) {
console.log("\x1b[31m",err);
}
})
console.log("\x1b[32m", `Generated file ${item}.js`)
})
},
//**********This function writes the basic route declaration**********/
makeRoutes: function(route_config){
const routeFiles = Object.keys(route_config);
routeFiles.map((item, index) => {
const content = contetMaker.routesContent(route_config[item]);
fs.writeFile(`./routes/${item}.js`, content, err => {
if (err){
console.log("\x1b[31m",err);
}
})
console.log("\x1b[32m", `Generated file ${item}.js`)
})
}
}
makeRoutes: function(routes) {
return Object.entries(routes).map(([fileName, methods]) =>
fsWritePromisified(
`./routes/${fileName}.js`,
contetMaker.routesContent(methods)
)
.then(successHandler(`${fileName}.js`))
.catch(errorHandler)
);
}
};

@@ -1,71 +0,69 @@

const fs = require('fs');
var exec = require('child_process').exec;
const fileGenerators = require('./fileGenerators');
const fs = require("fs");
var exec = require("child_process").exec;
const fileGenerators = require("./fileGenerators");
module.exports = {
//*********A helper function that generates desired folders given an array list */
//*********A helper function that generates desired folders given an array list */
makeFolders: function(array_list) {
const supported = ["models", "views", "controllers", "routes"];
return new Promise((resolve, reject) => {
array_list.map((folder, index) => {
//********* Make the desired directory */
if (supported.indexOf(folder) > -1) {
if (!fs.existsSync(`./${folder}`)) {
fs.mkdirSync(`./${folder}`);
makeFolders : function(array_list){
const supported = ['models','views','controllers','routes'];
return new Promise((resolve, reject) => {
array_list.map((folder, index) => {
//*********Change permissions******/
if (process.platform === "linux") {
exec(`sudo chmod -R 777 ${folder}`, (err, stdout, stderr) => {
if (err) {
reject({ success: false, message: err });
}
//********* Make the desired directory */
if (supported.indexOf(folder) > -1){
if (!fs.existsSync(`./${folder}`)){
fs.mkdirSync(`./${folder}`);
//*********Change permissions******/
if (process.platform === 'linux') {
exec(`sudo chmod -R 777 ${folder}`, (err, stdout, stderr) => {
if (err) {
reject({success: false, message: err});
}
if (stderr) {
reject ({success: false, message: stderr});
}
})
}
console.log("\x1b[32m",`MADE DIRECTORY ./${folder}`);
}
} else {
console.log("\x1b[31m",`NO SUPPORT FOR DIRECTORY ./${folder}`);
reject({success: false, message: "No support for entered directory!"})
if (stderr) {
reject({ success: false, message: stderr });
}
})
});
}
console.log("\x1b[32m", `MADE DIRECTORY ./${folder}`);
}
} else {
console.log("\x1b[31m", `NO SUPPORT FOR DIRECTORY ./${folder}`);
reject({
success: false,
message: "No support for entered directory!"
});
}
});
//*****return promise */
resolve({success: true, message: "Created folders successfully"});
})
},
//*****return promise */
resolve({ success: true, message: "Created folders successfully" });
});
},
//************This helper function generates all the files */
generateFiles: function(json_config){
const folders = Object.keys(json_config);
//************This helper function generates all the files */
generateFiles: function(json_config) {
const folders = Object.keys(json_config);
return new Promise((resolve, reject) => {
folders.map((folder, index) => {
if (folder === 'models') {
fileGenerators.makeModels(json_config.models);
}
else if (folder === 'views') {
fileGenerators.makeViews(json_config.views);
}
else if (folder ==='controllers') {
fileGenerators.makeControllers(json_config.controllers);
}
else if (folder ==='routes') {
fileGenerators.makeRoutes(json_config.routes);
}
})
resolve({success: true, message: "*******GENERATED ALL FILES*******"})
})
const tasks = [];
if (folders.includes("models")) {
tasks.push(...fileGenerators.makeModels(json_config.models));
}
}
if (folders.includes("views")) {
tasks.push(...fileGenerators.makeViews(json_config.views));
}
if (folders.includes("controllers")) {
tasks.push(...fileGenerators.makeControllers(json_config.controllers));
}
if (folders.includes("routes")) {
tasks.push(...fileGenerators.makeRoutes(json_config.routes));
}
return Promise.all(tasks).then(_ => ({
success: true,
message: "*******GENERATED ALL FILES*******"
}));
}
};
{
"name": "node-boiler",
"version": "1.1.8",
"version": "1.1.9",
"description": "Node boiler is a library that automatically writes boiler plate code which otherwise does not come out of the box with node.js. This tool comes in handy while make REST APIs.",

@@ -5,0 +5,0 @@ "main": "index.js",

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