-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.js
More file actions
32 lines (29 loc) · 922 Bytes
/
agent.js
File metadata and controls
32 lines (29 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require('fs');
const path = require('path');
const { ContextLoader } = require('ys-loader');
module.exports = (app, configs = {}) => {
const cwd = app.options.baseDir;
const cache = {};
const cacheDir = path.resolve(cwd, 'app/cache');
if (!fs.existsSync(cacheDir)) {
throw new Error('找不到缓存文件夹:' + cacheDir);
}
app.on('beforeLoadFiles', loader => loader.cache = [cacheDir]);
app.on('serverWillStart', server => {
const loader = server.loader;
const loadCount = new ContextLoader({
directory: loader.cache,
target: app,
inject: server,
property: 'cache',
runtime(Class, ctx) {
return class transformClassModule extends Class {
constructor(mysql, redis) {
super(ctx, mysql, redis, configs.name);
}
}
}
}).load();
if (!loader.isPro && loadCount) loader.log('cache');
});
}