Commit 439cac7e Harvey

no message

1 个父辈 2539f2e0
...@@ -59,17 +59,23 @@ function loadAllJSFiles(dirPaths, options = {}) { ...@@ -59,17 +59,23 @@ function loadAllJSFiles(dirPaths, options = {}) {
}); });
return loadedModules; return loadedModules;
} }
// 使用示例
const modules = loadAllJSFiles(['./build/job'], { const modules = loadAllJSFiles(['./build/job'], {
ignoreNodeModules: true, ignoreNodeModules: true,
filter: (filePath) => !filePath.includes('build/job/index.js') filter: (filePath) => !filePath.includes('build/job/index.js')
}); });
console.log(`=============开始加载任务=============`);
for (const key1 in modules) { for (const key1 in modules) {
var m = modules[key1]; var m = modules[key1];
for (const key2 in m) { for (const key2 in m) {
if (typeof m[key2] === 'function') { if (typeof m[key2] === 'function') {
if (job_handlers.has(key2)) {
console.log(key2 + '已存在');
continue;
}
job_handlers.set(key2, m[key2]); job_handlers.set(key2, m[key2]);
console.log(key2);
} }
} }
} }
console.log(`=============任务加载完毕 共${job_handlers.size}个=============`);
//# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map
\ No newline at end of file \ No newline at end of file
...@@ -69,21 +69,27 @@ function loadAllJSFiles(dirPaths, options: any = {}) { ...@@ -69,21 +69,27 @@ function loadAllJSFiles(dirPaths, options: any = {}) {
return loadedModules; return loadedModules;
} }
// 使用示例
const modules = loadAllJSFiles(['./build/job'], { const modules = loadAllJSFiles(['./build/job'], {
ignoreNodeModules: true, ignoreNodeModules: true,
filter: (filePath) => !filePath.includes('build/job/index.js') filter: (filePath) => !filePath.includes('build/job/index.js')
}); });
console.log(`=============开始加载任务=============`)
for (const key1 in modules) { for (const key1 in modules) {
var m = modules[key1]; var m = modules[key1];
for (const key2 in m) { for (const key2 in m) {
if (typeof m[key2] === 'function') { if (typeof m[key2] === 'function') {
if (job_handlers.has(key2)) {
console.log(key2 + '已存在')
continue;
}
job_handlers.set(key2, m[key2]) job_handlers.set(key2, m[key2])
console.log(key2)
} }
} }
} }
console.log(`=============任务加载完毕 共${job_handlers.size}个=============`)
export { job_handlers } export { job_handlers }
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!