egg-controller
Advanced tools
Comparing version 0.1.3 to 0.1.4
45
app.js
@@ -6,23 +6,32 @@ "use strict"; | ||
const register_1 = require("./lib/register"); | ||
function autoLoadDir(dirPath) { | ||
if (!fs.existsSync(dirPath)) | ||
return; | ||
fs.readdirSync(dirPath) | ||
.forEach(dirName => { | ||
const fullPath = path.join(dirPath, dirName); | ||
const stat = fs.statSync(fullPath); | ||
if (stat.isDirectory()) { | ||
this.autoLoadDir(fullPath); | ||
} | ||
else if (stat.isFile()) { | ||
const ext = path.parse(dirName).ext; | ||
if (ext === '.js' || (ext === '.ts' && dirName.indexOf('.d.ts') < 0)) { | ||
require(fullPath); | ||
} | ||
} | ||
}); | ||
} | ||
exports.default = (app) => { | ||
const config = app.config.controller; | ||
if (config.autoLoad) { | ||
function autoLoadDir(dirPath) { | ||
if (!fs.existsSync(dirPath)) | ||
return; | ||
fs.readdirSync(dirPath) | ||
.forEach(dirName => { | ||
const fullPath = path.join(dirPath, dirName); | ||
const stat = fs.statSync(fullPath); | ||
if (stat.isDirectory()) { | ||
this.autoLoadDir(fullPath); | ||
} | ||
else if (stat.isFile()) { | ||
const parsedPath = path.parse(dirName); | ||
if (parsedPath.ext === '.ts' && dirName.indexOf('.d.ts') < 0) { | ||
const jsPath = path.join(dirPath, parsedPath.name, '.js'); | ||
if (fs.existsSync(jsPath)) { | ||
app.loader.loadFile(jsPath); | ||
} | ||
else { | ||
app.loader.loadFile(fullPath); | ||
} | ||
} | ||
if (parsedPath.ext === '.js') { | ||
app.loader.loadFile(fullPath); | ||
} | ||
} | ||
}); | ||
} | ||
[].concat(config.dir).forEach(dir => { | ||
@@ -29,0 +38,0 @@ autoLoadDir(dir); |
{ | ||
"name": "egg-controller", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "controller for egg.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
35936
836
3