Calls the importTransforms hook on addons. @private @method _importAddonTransforms
()
| 477 | @method _importAddonTransforms |
| 478 | */ |
| 479 | _importAddonTransforms() { |
| 480 | this.project.addons.forEach((addon) => { |
| 481 | if (this.shouldIncludeAddon(addon)) { |
| 482 | if (addon.importTransforms) { |
| 483 | let transforms = addon.importTransforms(); |
| 484 | |
| 485 | if (!transforms) { |
| 486 | throw new Error(`Addon "${addon.name}" did not return a transform map from importTransforms function`); |
| 487 | } |
| 488 | |
| 489 | Object.keys(transforms).forEach((transformName) => { |
| 490 | let transformConfig = { |
| 491 | files: [], |
| 492 | options: {}, |
| 493 | }; |
| 494 | |
| 495 | // store the transform info |
| 496 | if (typeof transforms[transformName] === 'object') { |
| 497 | transformConfig['callback'] = transforms[transformName].transform; |
| 498 | transformConfig['processOptions'] = transforms[transformName].processOptions; |
| 499 | } else if (typeof transforms[transformName] === 'function') { |
| 500 | transformConfig['callback'] = transforms[transformName]; |
| 501 | transformConfig['processOptions'] = (assetPath, entry, options) => options; |
| 502 | } else { |
| 503 | throw new Error( |
| 504 | `Addon "${addon.name}" did not return a callback function correctly for transform "${transformName}".` |
| 505 | ); |
| 506 | } |
| 507 | |
| 508 | if (this._customTransformsMap.has(transformName)) { |
| 509 | // there is already a transform with a same name, therefore we warn the user |
| 510 | this.project.ui.writeWarnLine( |
| 511 | `Addon "${addon.name}" is defining a transform name: ${transformName} that is already being defined. Using transform from addon: "${addon.name}".` |
| 512 | ); |
| 513 | } |
| 514 | |
| 515 | this._customTransformsMap.set(transformName, transformConfig); |
| 516 | }); |
| 517 | } |
| 518 | } |
| 519 | }); |
| 520 | } |
| 521 | |
| 522 | /** |
| 523 | Loads and initializes addons for this project. |
no test coverage detected