UNPKG

@halospv3/hce.shared-config

Version:

Automate commit message quality, changelogs, and CI/CD releases. Its `main` entry point is a Semantic Release config. Functions and classes are exposed for customization. An ESLint config, a Commitlint config, and addl. resources for .NET projects are als

36 lines (35 loc) 2.7 kB
//#region src/insertPlugins.ts /** * @param plugins {@link SemanticReleaseOptions.plugins} * @param afterPluginsIDs The `string` IDs of plugins that the {@link insertPluginIDs} must follow. * @param insertPluginIDs The `string` IDs of plugins to insert into a copy of the {@link plugins} array. * @param beforePluginsIDs The `string` IDs of plugins that the {@link insertPluginIDs} must precede. * @returns * A modified copy of {@link plugins} with the given plugins inserted * before {@link beforePluginsIDs} and after {@link afterPluginsIDs}. * * Inserted plugins will be a `[string, {}]` tuple. * @throws {ReferenceError} This should never occur. One or more of the * {@link afterPluginsIDs} had been found in {@link plugins}, but a `.find` call * to get the highest index of the found plugins had returned `undefined` * @throws {AggregateError} One or more error occurred when inserting plugins: `insertPlugin was instructed to insert one or more plugins after [${afterPluginsIDs.map(v => '"' + v + '"').join(', ')}] and before [${beforePluginsIDs.map(v => `"${v}"`).join(', ')}], but ${JSON.stringify(pluginIDs[indexOfLastAfter])} comes after ${JSON.stringify(pluginIDs[index])}!` */ function insertPlugin(plugins, afterPluginsIDs, insertPluginIDs, beforePluginsIDs) { const pluginIDs = plugins.map((v) => typeof v === "string" ? v : v[0]); const indexOfLastAfter = afterPluginsIDs.filter((v) => pluginIDs.includes(v)).map((v) => pluginIDs.indexOf(v)).sort((a, b) => a - b).find((_v, index, object) => index === object.length - 1); if (void 0 === indexOfLastAfter) throw new ReferenceError("An attempt to get the last element of an array returned undefined."); const indicesOfBefore = beforePluginsIDs.filter((v) => pluginIDs.includes(v)).map((v) => pluginIDs.indexOf(v)).sort((a, b) => a - b); const errors = []; for (const index of indicesOfBefore) if (index <= indexOfLastAfter) errors.push(/* @__PURE__ */ new Error(`insertPlugin was instructed to insert one or more plugins after [${afterPluginsIDs.map((v) => "\"" + v + "\"").join(", ")}] and before [${beforePluginsIDs.map((v) => `"${v}"`).join(", ")}], but ${JSON.stringify(pluginIDs[indexOfLastAfter])} comes after ${JSON.stringify(pluginIDs[index])}!`)); if (errors.length > 0) throw new AggregateError(errors, "One or more errors occurred while inserting plugin configs into the Semantic Release config!"); const beforeInsert = plugins.slice(0, indexOfLastAfter + 1); const afterInsert = plugins.slice(indexOfLastAfter + 1, plugins.length + 1); return [ ...beforeInsert, ...insertPluginIDs.map((id) => [id, {}]), ...afterInsert ]; } //#endregion export { insertPlugin }; //# sourceMappingURL=insertPlugins.mjs.map