esdoc-external-webapi-plugin
Advanced tools
| 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(); |
+4
-4
| { | ||
| "name": "esdoc-external-webapi-plugin", | ||
| "version": "0.0.3", | ||
| "version": "0.0.4", | ||
| "description": "A external Web API plugin for ESDoc", | ||
@@ -23,3 +23,3 @@ "author": "h13i32maru", | ||
| "scripts": { | ||
| "test": "rm -rf ./test/fixture/out && mocha --recursive ./test/src -R spec" | ||
| "test": "rm -rf ./test/out && mocha --require ./test/init.js $(find test/ -regex '.*.test.js$') -R spec" | ||
| }, | ||
@@ -29,3 +29,3 @@ "keywords": [ | ||
| "external", | ||
| "ecmascript", | ||
| "webapi", | ||
| "plugin" | ||
@@ -37,3 +37,3 @@ ], | ||
| ], | ||
| "main": "src/index.js" | ||
| "main": "src/Plugin.js" | ||
| } |
| const fs = require('fs-extra'); | ||
| const path = require('path'); | ||
| class ExternalWebAPIPlugin { | ||
| constructor(config, option = {}) { | ||
| this._config = config; | ||
| this._option = option; | ||
| if (!('enable' in this._option)) this._option.enable = true; | ||
| } | ||
| exec(){ | ||
| 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); | ||
| } | ||
| cleanup(tags){ | ||
| 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 tag of tags) { | ||
| if (tag.kind === 'external' && tag.memberof === name) tag.builtinExternal = true; | ||
| } | ||
| const tagIndex = tags.findIndex(tag => tag.kind === 'file' && tag.name === name); | ||
| tags.splice(tagIndex, 1); | ||
| } | ||
| } | ||
| module.exports = ExternalWebAPIPlugin; | ||
-12
| const ExternalWebAPIPlugin = require('./ExternalWebAPIPlugin'); | ||
| let plugin; | ||
| exports.onHandleConfig = function(ev) { | ||
| plugin = new ExternalWebAPIPlugin(ev.data.config, ev.data.option); | ||
| plugin.exec(); | ||
| }; | ||
| exports.onHandleDocs = function(ev) { | ||
| plugin.cleanup(ev.data.docs); | ||
| }; |
2990
-7.91%4
-20%50
-18.03%