* Add a plugin. * @param {Object} options * @return {Comb}
(options)
| 250 | * @return {Comb} |
| 251 | */ |
| 252 | use(options) { |
| 253 | // Check whether plugin with the same is already used. |
| 254 | let pluginName = options.name; |
| 255 | if (this._pluginAlreadyUsed(pluginName)) { |
| 256 | if (this.verbose) |
| 257 | console.warn(Errors.twoPluginsWithSameName(pluginName)); |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | let plugin = new Plugin(options); |
| 262 | |
| 263 | plugin.syntax.forEach(function(s) { |
| 264 | this.supportedSyntaxes.add(s); |
| 265 | }, this); |
| 266 | |
| 267 | // Sort plugins. |
| 268 | let pluginToRunBefore = plugin.runBefore; |
| 269 | |
| 270 | if (!pluginToRunBefore) { |
| 271 | this.plugins.push(plugin); |
| 272 | } else { |
| 273 | if (this._pluginAlreadyUsed(pluginToRunBefore)) { |
| 274 | let i = this._pluginIndex(pluginToRunBefore); |
| 275 | this.plugins.splice(i, 0, plugin); |
| 276 | } else { |
| 277 | this.plugins.push(plugin); |
| 278 | if (!this.pluginsDependencies[pluginToRunBefore]) |
| 279 | this.pluginsDependencies[pluginToRunBefore] = []; |
| 280 | this.pluginsDependencies[pluginToRunBefore].push(pluginName); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | let dependents = this.pluginsDependencies[pluginName]; |
| 285 | if (!dependents) return this; |
| 286 | |
| 287 | for (let i = 0, l = dependents.length; i < l; i++) { |
| 288 | let name = dependents[i]; |
| 289 | let x = this._pluginIndex(name); |
| 290 | let plugin = this.plugins[x]; |
| 291 | this.plugins.splice(x, 1); |
| 292 | this.plugins.splice(-1, 0, plugin); |
| 293 | } |
| 294 | |
| 295 | // Chaining. |
| 296 | return this; |
| 297 | } |
| 298 | |
| 299 | _getAcceptableFilesFromDirectory(path) { |
| 300 | if (!this._shouldProcess(path)) return; |
no test coverage detected