batch-import
Advanced tools
Comparing version 3.1.0 to 3.1.1
37
index.js
@@ -23,3 +23,3 @@ 'use strict'; | ||
var subPath = fs.readdirSync($path) | ||
} catch (err) { | ||
} catch (error) { | ||
// 找不到目录时停止递归 | ||
@@ -44,3 +44,3 @@ return | ||
// 文件类型 | ||
// js类型 | ||
if (index > 0) { | ||
@@ -52,5 +52,5 @@ | ||
try { | ||
container[filename] = require(filePath) | ||
} catch (err) { | ||
throw err | ||
var result = require(filePath) | ||
} catch (error) { | ||
throw error | ||
} | ||
@@ -60,3 +60,5 @@ | ||
if (option.import) { | ||
container[filename] = option.import.call(this.container, filename, container[filename]) | ||
container[filename] = option.import.call(container, filename, result) | ||
} else { | ||
container[filename] = result | ||
} | ||
@@ -66,9 +68,17 @@ | ||
// 目录类型 | ||
// 目录或其它类型 | ||
else { | ||
// 跳过.DS_Store隐藏属性文件 | ||
if (itemPath === ".DS_Store") continue | ||
container[itemPath] = {} | ||
if (itemPath === ".DS_Store") { | ||
continue | ||
} | ||
if (!container[itemPath]) { | ||
container[itemPath] = {} | ||
} | ||
let directoryPath = path.join($path, itemPath) | ||
this.recursion(directoryPath, option, container[itemPath]) | ||
} | ||
@@ -82,2 +92,3 @@ | ||
/** | ||
@@ -97,6 +108,11 @@ * | ||
for (let name in options) { | ||
if (!container[name]) { | ||
container[name] = {} | ||
} | ||
let option = options[name] | ||
container[name] = {} | ||
let directoryPath = path.join(cwd, option.path) | ||
parser.recursion(directoryPath, option, container[name]) | ||
// 导入完毕后的处理函数 | ||
@@ -106,2 +122,3 @@ if (option.complete) { | ||
} | ||
} | ||
@@ -108,0 +125,0 @@ |
{ | ||
"name": "batch-import", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "批量加载node.js模块、目录,并转换为对应的JS对象", | ||
@@ -9,4 +9,7 @@ "main": "index.js", | ||
"scripts": { | ||
"dev": "nodemon test.js" | ||
"dev": "jtf" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"author": "", | ||
@@ -22,2 +25,2 @@ "license": "ISC", | ||
"homepage": "https://github.com/xiangle/batch-import#readme" | ||
} | ||
} |
@@ -21,9 +21,9 @@ # batch-import | ||
* `path` *String* - 指定模块加载目录(必填) | ||
* `path` *String* - 指定模块加载递归目录(必填) | ||
* `contain` *Array* - 仅加载指定模块,不能与exclude同时使用(可选) | ||
* `contain` *Array* - 仅加载指定模块或目录,不能与exclude同时使用(可选) | ||
* `exclude` *Array* - 排除指定模块,不能与contain同时使用(可选) | ||
* `exclude` *Array* - 排除指定模块或目录,不能与contain同时使用(可选) | ||
* `import(filename, data)` *Function* - 模块导出数据处理函数,this指向根容器。用于数据检验、预处理等操作(可选) | ||
* `import(filename, data)` *Function* - 模块导出数据处理函数,this指向当前层级容器。用于数据检验、预处理等操作(可选) | ||
@@ -30,0 +30,0 @@ * `filename` *String* - 当前文件名称,不含后缀 |
5915
4
86