@@ -3,8 +3,14 @@ import type { CAC } from "cac";
3
3
import enquirer from "enquirer" ;
4
4
5
5
import { ACTIVATION , gitCommitScopes , gitCommitTypes } from "@/config" ;
6
- import { execCommand , loadConfigModule , loggerInfo } from "@/helper" ;
7
- import { GitCommitOptions } from "@/types" ;
6
+ import { execCommand } from "@/helper" ;
7
+ import { loggerInfo } from "@/logger" ;
8
+ import {
9
+ CommandsOptions ,
10
+ CommitScope ,
11
+ CommitType ,
12
+ GitCommitOptions ,
13
+ } from "@/types" ;
8
14
9
15
const schema = {
10
16
type : "object" ,
@@ -16,26 +22,12 @@ const schema = {
16
22
required : [ "type" , "scope" , "description" ] ,
17
23
} ;
18
24
19
- const mergeConfig = async ( ) => {
20
- const config = await loadConfigModule ( ) ;
21
- const commands = config && config ?. commands ;
22
- if ( commands && commands . commit ) {
23
- const { gitCommitTypes : types , gitCommitScopes : scopes } = commands . commit ;
24
- return {
25
- types : types && types . length > 0 ? types : gitCommitTypes ,
26
- scopes : scopes && scopes . length > 0 ? scopes : gitCommitScopes ,
27
- } ;
28
- }
29
- return {
30
- types : gitCommitTypes ,
31
- scopes : gitCommitScopes ,
32
- } ;
33
- } ;
34
-
35
- const generateEnquirer = async ( ) : Promise <
25
+ const generateEnquirer = async (
26
+ types : Array < CommitType > ,
27
+ scopes : Array < CommitScope > ,
28
+ ) : Promise <
36
29
Pick < GitCommitOptions , Exclude < keyof GitCommitOptions , "emoji" > >
37
30
> => {
38
- const { types, scopes } = await mergeConfig ( ) ;
39
31
const typesChoices = types . map ( ( { emoji, code, description } ) => {
40
32
const formatCode = `${ code } :` . padEnd ( 20 ) ;
41
33
return {
@@ -116,10 +108,13 @@ export const gitCommit = async (
116
108
) ;
117
109
} ;
118
110
119
- export default function gitCommitInstaller ( cli : CAC ) {
111
+ export default function gitCommitInstaller ( config : CommandsOptions ) {
112
+ const { commit } = config ;
120
113
return {
121
- name : "gitCommitInstaller" ,
122
- setup : ( ) => {
114
+ name : "commit" ,
115
+ describe : "生成 angualr 规范的提交信息" ,
116
+ command : "commit --ask" ,
117
+ setup : ( cli : CAC ) => {
123
118
cli
124
119
. command ( "commit" , "生成 angualr 规范的提交信息" )
125
120
. option ( "-t, --type <type>" , "添加修改类型" )
@@ -128,8 +123,10 @@ export default function gitCommitInstaller(cli: CAC) {
128
123
. option ( "-a, --ask" , "启用询问模式" )
129
124
. action ( async ( options ) => {
130
125
const { type, scope, description, ask } = options ;
126
+ const types = commit ?. gitCommitTypes || gitCommitTypes ;
127
+ const scopes = commit ?. gitCommitScopes || gitCommitScopes ;
131
128
if ( ask ) {
132
- const result = await generateEnquirer ( ) ;
129
+ const result = await generateEnquirer ( types , scopes ) ;
133
130
await gitCommit ( result . type , result . scope , result . description ) ;
134
131
} else {
135
132
await gitCommit ( type , scope , description ) ;
0 commit comments