-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·1 lines (1 loc) · 1.55 KB
/
index.js
1
"use strict";require("shelljs/global");const path=require("path"),fs=require("fs");const{test:test}=require("shelljs");const Logger=require("./classes/Logger");const projectConfPath=`${__dirname}/../../config.json`;module.exports=async function(config={}){let logger=new Logger;if(typeof config["doLogging"]!="undefined"){global["DO_TOOL_LOGGING"]=config["doLogging"]=="true"||config["doLogging"]==true||config["doLogging"]==1}else global["DO_TOOL_LOGGING"]=false;if(typeof config["doLoggingExtraSpacing"]!="undefined"){global["DO_LOGGING_EXTRA_SPACING"]=config["doLoggingExtraSpacing"]=="true"||config["doLoggingExtraSpacing"]==true||config["doLoggingExtraSpacing"]==1}else global["DO_LOGGING_EXTRA_SPACING"]=false;if(!test("-f",projectConfPath)){let fileCont=fs.readFileSync(__dirname+"/tpls/project.conf.tpl").toString();fileCont.to(projectConfPath)}let appRoot=path.dirname(require.main.filename),cmdRoot,ignoreRoutes=[];if(!config["cmdRoot"]){cmdRoot=`${appRoot}/cmds`;if(!fs.existsSync(cmdRoot)){if(DO_TOOL_LOGGING)logger.critical(`Default path doesn't exist. Please provide a "cmdRoot" option in the init function or create the folder: ${cmdRoot}`)}}else{if(/^\.\//.test(config["cmdRoot"])){config["cmdRoot"]=config["cmdRoot"].replace(/^\.\//,`${appRoot}/`)}cmdRoot=`${appRoot.replace(/\/$/,"")}/${config["cmdRoot"]}`}if(typeof config["ignoreRoutes"]!="undefined"&&Array.isArray(config["ignoreRoutes"])){ignoreRoutes=config["ignoreRoutes"]}else ignoreRoutes=[];await require("./run")(cmdRoot,ignoreRoutes,projectConfPath,logger,config.cmdRoot||"cmds",config.init||undefined)};