From e9464aec3bcf8bed5fe0b67c1fce18c49fb8e185 Mon Sep 17 00:00:00 2001 From: Roman Vasilyev Date: Wed, 2 Aug 2023 08:26:49 +0300 Subject: [PATCH] PLA-245 Change file structure for husky hooks Divide the types into separate files. Put the WithGitHooks interface at the top level (git folder). --- src/common/git/husky/add-husky.ts | 2 +- src/common/git/husky/check-cargo-options.ts | 15 +++++++ src/common/git/husky/check-cargo.ts | 2 +- src/common/git/husky/husky-rule.ts | 17 ++++++++ src/common/git/husky/index.ts | 3 +- src/common/git/husky/with-git-hooks.ts | 47 --------------------- src/common/git/index.ts | 1 + src/common/git/with-git-hooks.ts | 17 ++++++++ 8 files changed, 54 insertions(+), 50 deletions(-) create mode 100644 src/common/git/husky/check-cargo-options.ts create mode 100644 src/common/git/husky/husky-rule.ts delete mode 100644 src/common/git/husky/with-git-hooks.ts create mode 100644 src/common/git/with-git-hooks.ts diff --git a/src/common/git/husky/add-husky.ts b/src/common/git/husky/add-husky.ts index e51fa861..6ec4fd11 100644 --- a/src/common/git/husky/add-husky.ts +++ b/src/common/git/husky/add-husky.ts @@ -1,7 +1,7 @@ import type {NodeProject} from 'projen/lib/javascript' +import {WithGitHooks} from '../with-git-hooks' import {checkCargo} from './check-cargo' import {commitMessage} from './commit-message' -import {WithGitHooks} from './with-git-hooks' export const addHusky = (project: NodeProject, options: WithGitHooks): void => { project.addDevDeps('husky') diff --git a/src/common/git/husky/check-cargo-options.ts b/src/common/git/husky/check-cargo-options.ts new file mode 100644 index 00000000..09f3ae9d --- /dev/null +++ b/src/common/git/husky/check-cargo-options.ts @@ -0,0 +1,15 @@ +export interface CheckCargoOptions { + /** + * Perform a code formatting step + * + * @default true + */ + readonly isFormatting?: boolean + + /** + * Path to the cargo + * + * @default '.' + */ + readonly workingDirectory?: string +} diff --git a/src/common/git/husky/check-cargo.ts b/src/common/git/husky/check-cargo.ts index d8bcdff6..3b72ffbe 100644 --- a/src/common/git/husky/check-cargo.ts +++ b/src/common/git/husky/check-cargo.ts @@ -1,8 +1,8 @@ import * as path from 'path' import type {NodeProject} from 'projen/lib/javascript' import {AssetFile} from '../../files/AssetFile' +import type {CheckCargoOptions} from './check-cargo-options' import {destinationFolder, sourceFolder, templateFile, templateString} from './template-path' -import type {CheckCargoOptions} from './with-git-hooks' export const checkCargo = (project: NodeProject, options: CheckCargoOptions) => { const commands: Array = ['cargo check'] diff --git a/src/common/git/husky/husky-rule.ts b/src/common/git/husky/husky-rule.ts new file mode 100644 index 00000000..7e645745 --- /dev/null +++ b/src/common/git/husky/husky-rule.ts @@ -0,0 +1,17 @@ +import type {CheckCargoOptions} from './check-cargo-options' + +export interface HuskyRule { + /** + * Include pre-commit hook with `cargo check` command. + * + * @default undefined + */ + readonly checkCargo?: CheckCargoOptions + + /** + * Include commit message hook. + * + * @default true + */ + readonly commitMsg?: boolean +} diff --git a/src/common/git/husky/index.ts b/src/common/git/husky/index.ts index 11c416ed..af46cf0b 100644 --- a/src/common/git/husky/index.ts +++ b/src/common/git/husky/index.ts @@ -1,2 +1,3 @@ export * from './add-husky' -export * from './with-git-hooks' +export * from './check-cargo-options' +export * from './husky-rule' diff --git a/src/common/git/husky/with-git-hooks.ts b/src/common/git/husky/with-git-hooks.ts deleted file mode 100644 index fd854ec6..00000000 --- a/src/common/git/husky/with-git-hooks.ts +++ /dev/null @@ -1,47 +0,0 @@ -export interface WithGitHooks { - /** - * Include husky for git hook management. - * - * @default false - */ - readonly hasGitHooks?: boolean - - /** - * Include a default git hook that checks commit message. - * - * @default { commitMsg: true } - */ - readonly huskyRules?: HuskyRule -} - -export interface HuskyRule { - /** - * Include pre-commit hook with `cargo check` command. - * - * @default undefined - */ - readonly checkCargo?: CheckCargoOptions - - /** - * Include commit message hook. - * - * @default true - */ - readonly commitMsg?: boolean -} - -export interface CheckCargoOptions { - /** - * Perform a code formatting step - * - * @default true - */ - readonly isFormatting?: boolean - - /** - * Path to the cargo - * - * @default '.' - */ - readonly workingDirectory?: string -} diff --git a/src/common/git/index.ts b/src/common/git/index.ts index ead20a6b..603da509 100644 --- a/src/common/git/index.ts +++ b/src/common/git/index.ts @@ -1,2 +1,3 @@ export * from './gitignore' export * from './husky' +export * from './with-git-hooks' diff --git a/src/common/git/with-git-hooks.ts b/src/common/git/with-git-hooks.ts new file mode 100644 index 00000000..b6975d58 --- /dev/null +++ b/src/common/git/with-git-hooks.ts @@ -0,0 +1,17 @@ +import type {HuskyRule} from './husky' + +export interface WithGitHooks { + /** + * Include husky for git hook management. + * + * @default false + */ + readonly hasGitHooks?: boolean + + /** + * Include a default git hook that checks commit message. + * + * @default { commitMsg: true } + */ + readonly huskyRules?: HuskyRule +}