Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Typescript type for config (closes #1052) #1055

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Put only the options to override in a configuration file. Here is a list of file
configuration in the root of the project:

- `.release-it.json`
- `.release-it.ts`
- `.release-it.js` (or `.cjs`; export the configuration object: `module.exports = {}`)
- `.release-it.yaml` (or `.yml`)
- `.release-it.toml`
Expand Down Expand Up @@ -42,6 +43,26 @@ The configuration can also be stored in a `release-it` property in `package.json
}
```

Typescript config files are supported, providing typing hints to the config:

```ts
import type { Config } from 'release-it';

export default {
git: {
commit: true,
tag: true,
push: true
},
github: {
release: true
},
npm: {
publish: true
}
} satisfies Config;
```

Or, use YAML in `.release-it.yml`:

```yaml
Expand Down
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const searchPlaces = [
'package.json',
'.release-it.json',
'.release-it.js',
'.release-it.ts',
'.release-it.cjs',
'.release-it.yaml',
'.release-it.yml',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"lib",
"test"
],
"types": "./types/index.d.ts",
"scripts": {
"knip": "knip",
"lint": "eslint lib test",
Expand Down
183 changes: 183 additions & 0 deletions types/config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
import { Hooks } from './hooks';

export interface Config {
hooks?: Hooks;

plugins?: Record<string, Record<string, any>>;

git?: {
/** @default "git log --pretty=format:\"* %s (%h)\" ${from}...${to}" */
changelog?: string;

/** @default true */
requireCleanWorkingDir?: boolean;

/** @default false */
requireBranch?: boolean;

/** @default true */
requireUpstream?: boolean;

/** @default false */
requireCommits?: boolean;

/** @default true */
requireCommitsFail?: boolean;

/** @default "" */
commitsPath?: string;

/** @default false */
addUntrackedFiles?: boolean;

/** @default true */
commit?: boolean;

/** @default "Release ${version}" */
commitMessage?: string;

commitArgs?: Array<any>;

/** @default true */
tag?: boolean;

/** @default null */
tagExclude?: any;

/** @default null */
tagName?: any;

/** @default null */
tagMatch?: any;

/** @default false */
getLatestTagFromAllRefs?: boolean;

/** @default "Release ${version}" */
tagAnnotation?: string;

tagArgs?: Array<any>;

/** @default true */
push?: boolean;

/** @default ["--follow-tags"] */
pushArgs?: Array<string>;

/** @default "" */
pushRepo?: string;
};

npm?: {
/** @default true */
publish?: boolean;

/** @default "." */
publishPath?: string;

publishArgs?: Array<any>;

/** @default null */
tag?: any;

/** @default null */
otp?: any;

/** @default false */
ignoreVersion?: boolean;

/** @default false */
allowSameVersion?: boolean;

versionArgs?: Array<any>;

/** @default false */
skipChecks?: boolean;

/** @default 10 */
timeout?: number;
};

github?: {
/** @default false */
release?: boolean;

/** @default "Release ${version}" */
releaseName?: string;

/** @default null */
releaseNotes?: any;

/** @default false */
autoGenerate?: boolean;

/** @default false */
preRelease?: boolean;

/** @default false */
draft?: boolean;

/** @default "GITHUB_TOKEN" */
tokenRef?: string;

/** @default null */
assets?: any;

/** @default null */
host?: any;

/** @default 0 */
timeout?: number;

/** @default null */
proxy?: any;

/** @default false */
skipChecks?: boolean;

/** @default false */
web?: boolean;

comments?: {
/** @default false */
submit?: boolean;

/** @default ":rocket?: _This issue has been resolved in v${version}. See [${releaseName}](${releaseUrl}) for release notes._" */
issue?: string;

/** @default ":rocket?: _This pull request is included in v${version}. See [${releaseName}](${releaseUrl}) for release notes._" */
pr?: string;
};
};

gitlab?: {
/** @default false */
release?: boolean;

/** @default "Release ${version}" */
releaseName?: string;

/** @default null */
releaseNotes?: any;

milestones?: Array<any>;

/** @default "GITLAB_TOKEN" */
tokenRef?: string;

/** @default "Private-Token" */
tokenHeader?: string;

/** @default null */
certificateAuthorityFile?: any;

/** @default null */
assets?: any;

/** @default null */
origin?: any;

/** @default false */
skipChecks?: boolean;
};
}
47 changes: 47 additions & 0 deletions types/hooks.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export type HookPrefix = 'before' | 'after';
export type InternalPlugin = 'version' | 'git' | 'npm' | 'github' | 'gitlab';
export type HookName = 'init' | 'bump' | 'release';

export type Hooks = {
['before:init']?: string | string[];
['before:bump']?: string | string[];
['before:release']?: string | string[];
['after:init']?: string | string[];
['after:bump']?: string | string[];
['after:release']?: string | string[];

['before:version:init']?: string | string[];
['before:version:bump']?: string | string[];
['before:version:release']?: string | string[];
['after:version:init']?: string | string[];
['after:version:bump']?: string | string[];
['after:version:release']?: string | string[];

['before:git:init']?: string | string[];
['before:git:bump']?: string | string[];
['before:git:release']?: string | string[];
['after:git:init']?: string | string[];
['after:git:bump']?: string | string[];
['after:git:release']?: string | string[];

['before:npm:init']?: string | string[];
['before:npm:bump']?: string | string[];
['before:npm:release']?: string | string[];
['after:npm:init']?: string | string[];
['after:npm:bump']?: string | string[];
['after:npm:release']?: string | string[];

['before:github:init']?: string | string[];
['before:github:bump']?: string | string[];
['before:github:release']?: string | string[];
['after:github:init']?: string | string[];
['after:github:bump']?: string | string[];
['after:github:release']?: string | string[];

['before:gitlab:init']?: string | string[];
['before:gitlab:bump']?: string | string[];
['before:gitlab:release']?: string | string[];
['after:gitlab:init']?: string | string[];
['after:gitlab:bump']?: string | string[];
['after:gitlab:release']?: string | string[];
};
3 changes: 3 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'release-it';

export type { Config } from './config.d';