UNPKG

kns-cli

Version:

kns cli for hapi.js and sequelize.js

52 lines (43 loc) 2.13 kB
var Path = require("path"); var Promise = require("bluebird"); var mkdirp = Promise.promisifyAll(require("mkdirp")); var templatehelper = require("./templatehelper"); module.exports = function (dstPath, pluginName) { var filename = ""; if (pluginName.indexOf(".js") == -1) { filename = pluginName + ".js"; } var content = { filename: pluginName, routefile: pluginName + "_" + "routes.js", model: pluginName.toLocaleLowerCase(), Model: pluginName[0].toLocaleUpperCase() + pluginName.slice(1), controller: pluginName[0].toLocaleUpperCase() + pluginName.slice(1) + "Controller", controllershortname: pluginName[0].toLocaleUpperCase() + pluginName.slice(1), dependency: "kns-floppy" }; var srcPath = Path.join(__dirname, "../templates/plugin/plugin_dependency_template.js"); var routeFilePath = Path.join(__dirname, "../templates/plugin/route_template.js"); var controllerFilePath = Path.join(__dirname, "../templates/plugin/controller_template.js"); var modelFilePath = Path.join(__dirname, "../templates/plugin/model_template.js"); dstPath = Path.join(dstPath, pluginName); createFolders([ Path.join(dstPath + "/controller"), Path.join(dstPath + "/model"), Path.join(dstPath + "/view") ]).then(function () { return templatehelper(srcPath, dstPath, filename, content).then(function () { templatehelper(routeFilePath, dstPath, pluginName + "_" + "routes.js", content).then(function() { templatehelper(controllerFilePath, Path.join(dstPath, "/controller"), "_" + pluginName[0].toLocaleUpperCase() + pluginName.slice(1) + "Controller.js", content).then(function() { templatehelper(modelFilePath, Path.join(dstPath, "/model"), "_" + pluginName.toLocaleLowerCase() + ".js", content).then(function() { }); }); }); }); }); }; function createFolders(folderPaths) { return Promise.map(folderPaths, function (folderpath) { return mkdirp.mkdirpAsync(folderpath); }); }