@bfra.me/semantic-release
Version:
Semantic Release shareable configuration and plugins for bfra.me.
141 lines (105 loc) • 3.42 kB
TypeScript
import { BranchSpec } from 'semantic-release';
import { LiteralUnion } from 'type-fest';
type PluginSpec<TSpec extends any[] = any[]> = TSpec extends [infer TName, (infer TConfig)?]
? TName | [TName, TConfig]
: never
interface CommitAnalyzerPluginConfig {
/**
* Preset value.
*/
preset?: string
releaseRules?: {
type: string
scope: string
release: string
}[]
}
type CommitAnalyzerPluginSpec = PluginSpec<
['@semantic-release/commit-analyzer', CommitAnalyzerPluginConfig]
>
interface ReleaseNotesGeneratorPluginConfig {
/**
* Preset value.
*/
preset?: string
}
type ReleaseNotesGeneratorPluginSpec = PluginSpec<
['@semantic-release/release-notes-generator', ReleaseNotesGeneratorPluginConfig]
>
interface NpmPluginConfig {
npmPublish?: boolean
}
type NpmPluginSpec = PluginSpec<['@semantic-release/npm', NpmPluginConfig]>
interface GitHubPluginConfig {
/**
* Some assets
*/
assets?: string
}
type GitHubPluginSpec = PluginSpec<['@semantic-release/github', GitHubPluginConfig]>
interface SemanticReleasePlugins {
'@semantic-release/commit-analyzer': CommitAnalyzerPluginSpec
'@semantic-release/release-notes-generator': ReleaseNotesGeneratorPluginSpec
'@semantic-release/npm': NpmPluginSpec
'@semantic-release/github': GitHubPluginSpec
}
/**
This is a special exported interface for other packages to declare
additional types that should bail out for eslint rules. For example
`semantic-release-license` can declare it like so in its `d.ts`:
```ts
declare module '@bfra-me/semantic-release' {
export interface CustomPluginConfig {
/**
The path to your license path.
\@see [Options](https://github.com/cbhq/semantic-release-license/tree/latest#options)
*\/
'semantic-release-license': {
license: {
path?: string;
}
}
}
}
```
*/
interface CustomPluginConfig {}
type WrapPlugin<T extends {[key: string]: any}> = {
[K in keyof T]: T[K] extends PluginSpec ? T[K] : PluginSpec<[K, T[K]]>
}
type CustomPlugins = WrapPlugin<CustomPluginConfig>
interface KnownPlugins extends CustomPlugins, SemanticReleasePlugins {}
// Extract the TConfig type from a PluginNameAndConfig
type PluginConfig<TSpec extends PluginSpec> = TSpec extends [string, infer TConfig]
? TConfig
: never
type PluginName = LiteralUnion<keyof KnownPlugins, string>
type Plugin<TLookup = PluginName> = TLookup extends keyof KnownPlugins
? PluginSpec<[TLookup, PluginConfig<KnownPlugins[TLookup]>]>
: TLookup extends string
? PluginSpec<[TLookup, {[key: string]: unknown}]>
: PluginSpec<TLookup>
interface CustomExtends {}
type KnownExtends = LiteralUnion<
'@bfra.me/semantic-release' | 'semantic-release-monorepo' | keyof CustomExtends,
string
>
type Extends = KnownExtends | KnownExtends[]
interface SemanticReleaseConfig {
extends?: Extends
branches: readonly BranchSpec[] | BranchSpec
repositoryUrl?: string
tagFormat?: string
plugins?: Plugin[]
dryRun?: boolean
ci?: boolean | undefined
[name: string]: unknown
}
/**
* Define semantic-release global config.
*
* @param config Semantic Release configuration
* @returns Semantic Release configuration
*/
declare function defineConfig(config: SemanticReleaseConfig): SemanticReleaseConfig;
export { type CustomExtends, type Extends, type KnownExtends, type SemanticReleaseConfig, defineConfig };