-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathPlugin.js
34 lines (25 loc) · 1.01 KB
/
Plugin.js
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
33
34
const fs = require('fs-extra');
const path = require('path');
class Plugin {
onHandleConfig(ev) {
this._config = ev.data.config;
this._option = ev.data.option || {};
if (!('enable' in this._option)) this._option.enable = true;
if (!this._option.enable) return;
const srcPath = path.resolve(__dirname, 'external-webapi.js');
const outPath = path.resolve(this._config.source, '.external-webapi.js');
fs.copySync(srcPath, outPath);
}
onHandleDocs(ev) {
if (!this._option.enable) return;
const outPath = path.resolve(this._config.source, '.external-webapi.js');
fs.removeSync(outPath);
const name = path.basename(path.resolve(this._config.source)) + '/.external-webapi.js';
for (const doc of ev.data.docs) {
if (doc.kind === 'external' && doc.memberof === name) doc.builtinExternal = true;
}
const docIndex = ev.data.docs.findIndex(doc => doc.kind === 'file' && doc.name === name);
ev.data.docs.splice(docIndex, 1);
}
}
module.exports = new Plugin();