@halospv3/hce.shared-config
Version:
Automate commit message quality, changelogs, and CI/CD releases. Exports a semantic-release shareable configuration deserialized from this package's '.releaserc.yml'. Shared resources for .NET projects are also distributed with this package.
113 lines (107 loc) • 6.41 kB
JavaScript
;
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
Object.defineProperty(exports, '__esModule', {
value: true
});
const node_util = require('node:util');
const debug = require('./debug.cjs');
const dotnetHelpers = require('./dotnet/dotnetHelpers.cjs');
const envUtils = require('./envUtils.cjs');
const semanticReleaseConfig = require('./semanticReleaseConfig.cjs');
const setupGitPluginSpec = require('./setupGitPluginSpec.cjs');
/** Semantic-Release Config Factory (dotnet)
* A functional Semantic-Release configuration for dotnet projects
*
* extends {@link baseConfig }
*
* <-- TABLE OF CONTENTS -->
* - evaluateProperties
* - configureDotnetRelease
* - Insert-Edit Plugins
* - Append Plugins
*
*/
/**
* TODO: options/params for inserts/edits. NOT ready for production. Currently, this can only add Git plugin's options if undefined or one or more is missing.
* Insert (`array.splice`) and/or configure plugins.\
* Can be used to...\
* ...load plugin A before plugin B\
* ...edit a plugin's existing configuration
*
* @param config An instance of {@link Options}
* @returns a modified copy of {@link config}
*/
function insertAndEditPlugins(config) {
// const insertAndEditCommands = [];
config.plugins = [...(config.plugins ?? semanticReleaseConfig.defaultPlugins)];
config.plugins = setupGitPluginSpec.setupGitPluginSpec(config.plugins);
return config;
}
/**
* Currently, only configures `@semantic-release/exec` with `prepareCmd: configurePrepareCmd(projectsToPublish, projectsToPackAndPush)` and `publishCmd: configureDotnetNugetPush()`
* @param config
* @param projectsToPublish
* @param projectsToPackAndPush
* @returns config with the specified plugins and plugin options.
*/
function appendPlugins(config, projectsToPublish, projectsToPackAndPush) {
if (config.plugins === undefined) throw new Error('Plugins array was undefined when it should be an array!');
config.plugins.push(
// APPEND this array of [pluginName, pluginConfig] to plugins
// https://github.com/semantic-release/exec#usage
['@semantic-release/exec', {
// 'ZipPublishDir' zips each publish folder to ./publish/*.zip
prepareCmd: dotnetHelpers.configurePrepareCmd(projectsToPublish, projectsToPackAndPush),
publishCmd: dotnetHelpers.configureDotnetNugetPush()
}]);
return config;
}
/**
* Configures {@link baseConfig} with `@semantic-release/exec` to `dotnet` publish, pack, and push.
* @param projectsToPublish An array of dotnet projects' relative paths. If
* empty or unspecified, tries getting projects' semi-colon-separated relative
* paths from the `PROJECTS_TO_PUBLISH` environment variable. If configured as
* recommended, the projects' publish outputs will be zipped to '$PWD/publish'
* for use in the `publish` semantic-release step (typically, GitHub release).
* @param projectsToPackAndPush An array of dotnet projects' relative paths. If
* false, `dotnet pack` and `dotnet nuget push` will be left out of the exec
* commands. If empty or unspecified, tries getting projects'
* semi-colon-separated relative paths from the `PROJECTS_TO_PACK_AND_PUSH`
* environment variable. If configured as recommended, `dotnet pack` will output
* the nupkg/snupk files to `$PWD/publish` where they will be globbed by `dotnet
* nuget push`.
* @returns a semantic-release Options object, based on `@halospv3/hce.shared-config` (our base config), with the `@semantic-release/exec` plugin configured to `dotnet publish`, `pack`, and `push` the specified projects.
*/
function getConfig(projectsToPublish = [], projectsToPackAndPush = []) {
if (debug.enabled) {
console.debug('hce.shared-config:\n' + node_util.inspect(semanticReleaseConfig.baseConfig, false, Infinity, true));
}
const errors = [];
if (projectsToPublish.length === 0) {
const _ = envUtils.getEnvVarValue("PROJECTS_TO_PUBLISH");
if (_ === undefined) errors.push(new Error("projectsToPublish.length must be > 0 or PROJECTS_TO_PUBLISH must be defined and contain at least one path."));else projectsToPublish = _.split(';');
}
if (projectsToPackAndPush !== false && projectsToPackAndPush.length === 0) {
const _ = envUtils.getEnvVarValue("PROJECTS_TO_PACK_AND_PUSH");
if (_ === undefined) errors.push(new Error("projectsToPackAndPush.length must be > 0 or PROJECTS_TO_PACK_AND_PUSH must be defined and contain at least one path."));else projectsToPackAndPush = _.split(';');
}
if (errors.length > 0) {
throw new Error(["getConfig cannot continue. One or more errors occurred.", ...errors.map(v => v.stack)].join('\n'));
}
let config = _objectSpread({}, semanticReleaseConfig.baseConfig);
config = insertAndEditPlugins(config);
if (projectsToPublish) config = appendPlugins(config, projectsToPublish, projectsToPackAndPush);
if (debug.enabled) {
console.debug(`modified plugins array:\n${node_util.inspect(config.plugins, false, Infinity)}`);
}
return config;
}
exports.appendPlugins = appendPlugins;
exports.default = getConfig;
exports.getConfig = getConfig;
exports.insertAndEditPlugins = insertAndEditPlugins;
//# sourceMappingURL=semanticReleaseConfigDotnet.cjs.map