batch-import
Advanced tools
Comparing version 3.0.0 to 3.1.0
23
index.js
@@ -30,2 +30,13 @@ 'use strict'; | ||
// 目录、模块路径过滤 | ||
if (option.contain) { | ||
if (option.contain.indexOf(itemPath) === -1) { | ||
continue | ||
} | ||
} else if (option.exclude) { | ||
if (option.exclude.indexOf(itemPath) > -1) { | ||
continue | ||
} | ||
} | ||
let index = itemPath.indexOf('.js') | ||
@@ -36,14 +47,2 @@ | ||
// 模块路径过滤 | ||
if (option.contain) { | ||
if (option.contain.indexOf(itemPath) === -1) { | ||
return | ||
} | ||
} else if (option.exclude) { | ||
if (option.exclude.indexOf(itemPath) === 1) { | ||
return | ||
} | ||
} | ||
let filename = itemPath.slice(0, index) | ||
@@ -50,0 +49,0 @@ let filePath = path.join($path, itemPath) |
{ | ||
"name": "batch-import", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "批量加载node.js模块、目录,并转换为对应的JS对象", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,31 +17,25 @@ # batch-import | ||
### batchImport(container, container) | ||
### batchImport(options, container) | ||
* `options.path` *String* - 指定模块加载目录(必填) | ||
* `options` *Object* | ||
* `options.contain` *Array* - 仅加载指定模块,不能与exclude同时使用(可选) | ||
* `path` *String* - 指定模块加载目录(必填) | ||
* `options.exclude` *Array* - 排除指定模块,不能与contain同时使用(可选) | ||
* `contain` *Array* - 仅加载指定模块,不能与exclude同时使用(可选) | ||
* `options.import` *Function* - 模块导出数据处理函数,用于数据检验、预处理等操作(可选) | ||
* `exclude` *Array* - 排除指定模块,不能与contain同时使用(可选) | ||
* `options.complete` *Function* - 同一个配置项下的所有模块导出完成后的数据处理函数,用于数据检验、预处理等操作(可选) | ||
* `import(filename, data)` *Function* - 模块导出数据处理函数,this指向根容器。用于数据检验、预处理等操作(可选) | ||
* `container` *Object* - 将模块导出结果保存到已存在的指定容器中(可选) | ||
* `filename` *String* - 当前文件名称,不含后缀 | ||
* `data` * - 模块导出数据 | ||
#### options.import([filename],[data]) | ||
* `complete(data)` *Function* - 同一个配置项下的所有模块导出完成后的数据处理函数,this指向根容器。用于数据检验、预处理等操作(可选) | ||
> this指向根容器 | ||
* `data` *Object* - 所有子集模块导出数据集合 | ||
* `filename` *String* - 当前文件名称,不含后缀 | ||
* `container` *Object* - 可选,将模块导出结果保存到指定容器中 | ||
* `data` * - 模块导出数据 | ||
#### options.import([data]) | ||
> this指向根容器 | ||
* `data` *Object* - 所有子集模块导出数据集合 | ||
### 示例 | ||
@@ -48,0 +42,0 @@ |
@@ -15,3 +15,2 @@ "use strict" | ||
complete(data) { | ||
// 对extend进行扁平化处理,缩短访问路径 | ||
for (let name in data) { | ||
@@ -18,0 +17,0 @@ this[name] = data[name] |
7078
141
87