UNPKG

@sap/cds-dk

Version:

Command line client and development toolkit for the SAP Cloud Application Programming Model

46 lines (41 loc) 1.63 kB
// @ts-check const cds = require('../cds') const Plugin = require('./plugin') const DEBUG = cds.debug('cli|build') module.exports = new (class Plugins { /** @type {Map<string, typeof Plugin>} */ #plugins = new Map() get plugins() { return this.#plugins } constructor() { this.#registerDefaults() } /** * @param {string} id - unique name of the plugin * @param {typeof Plugin | { prototype?: unknown, impl: string, taskDefaults: { src: string } }} plugin - class extending Plugin */ register(id, plugin) { /** * @param {{prototype?: unknown}} plugin * @returns {plugin is typeof Plugin} */ const isNewStylePlugin = plugin => plugin.prototype instanceof Plugin if (!id || !plugin) { throw new Error(`Invalid parameter passed, build plugin id: ${id}`) } if (this.#plugins.has(id)) { throw new Error(`CDS build plugin ${id} already registered`) } if(!isNewStylePlugin(plugin)) { // with cds-dk version 7 the following registration format was supported: // cds.build.register("cov2ap", { impl: "@cap-js-community/odata-v2-adapter/src/build.js", taskDefaults: { src: "srv" } }) throw `The cds build plugin '${id}' is not compatible with this @sap/cds-dk version. Update the npm package '${plugin.impl || id}' to the latest version.` } DEBUG?.(`registering build plugin ${id}`) this.#plugins.set(id, plugin) } #registerDefaults() { this.register('helm', require('./plugins/helm')) } })