|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | + |
| 9 | +import * as semver from 'semver'; |
| 10 | + |
| 11 | +import {assertNoErrors, getConfig, NgDevConfig} from '../../utils/config'; |
| 12 | + |
| 13 | +/** Interface describing a built package. */ |
| 14 | +export interface BuiltPackage { |
| 15 | + /** Name of the package. */ |
| 16 | + name: string; |
| 17 | + /** Path to the package output directory. */ |
| 18 | + outputPath: string; |
| 19 | +} |
| 20 | + |
| 21 | +/** Configuration for staging and publishing a release. */ |
| 22 | +export interface ReleaseConfig { |
| 23 | + /** Registry URL used for publishing release packages. Defaults to the NPM registry. */ |
| 24 | + publishRegistry?: string; |
| 25 | + /** List of NPM packages that are published as part of this project. */ |
| 26 | + npmPackages: string[]; |
| 27 | + /** Builds release packages and returns a list of paths pointing to the output. */ |
| 28 | + buildPackages: () => Promise<BuiltPackage[]|null>; |
| 29 | + /** Generates the release notes from the most recent tag to `HEAD`. */ |
| 30 | + generateReleaseNotesForHead: (outputPath: string) => Promise<void>; |
| 31 | + /** |
| 32 | + * Gets a pattern for extracting the release notes of the a given version. |
| 33 | + * @returns A pattern matching the notes for a given version (including the header). |
| 34 | + */ |
| 35 | + // TODO: Remove this in favor of a canonical changelog format across the Angular organization. |
| 36 | + extractReleaseNotesPattern?: (version: semver.SemVer) => RegExp; |
| 37 | +} |
| 38 | + |
| 39 | +/** Configuration for releases in the dev-infra configuration. */ |
| 40 | +export type DevInfraReleaseConfig = NgDevConfig<{release: ReleaseConfig}>; |
| 41 | + |
| 42 | +/** Retrieve and validate the config as `ReleaseConfig`. */ |
| 43 | +export function getReleaseConfig(config: Partial<DevInfraReleaseConfig> = getConfig()): |
| 44 | + ReleaseConfig { |
| 45 | + // List of errors encountered validating the config. |
| 46 | + const errors: string[] = []; |
| 47 | + |
| 48 | + if (config.release === undefined) { |
| 49 | + errors.push(`No configuration defined for "release"`); |
| 50 | + } |
| 51 | + if (config.release?.npmPackages === undefined) { |
| 52 | + errors.push(`No "npmPackages" configured for releasing.`); |
| 53 | + } |
| 54 | + if (config.release?.buildPackages === undefined) { |
| 55 | + errors.push(`No "buildPackages" function configured for releasing.`); |
| 56 | + } |
| 57 | + if (config.release?.generateReleaseNotesForHead === undefined) { |
| 58 | + errors.push(`No "generateReleaseNotesForHead" function configured for releasing.`); |
| 59 | + } |
| 60 | + |
| 61 | + assertNoErrors(errors); |
| 62 | + return config.release!; |
| 63 | +} |
0 commit comments