-
-
Notifications
You must be signed in to change notification settings - Fork 204
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: Convert gitmoji commands & flags to ts #1277
base: master
Are you sure you want to change the base?
Changes from 10 commits
a1fe032
e0f62c1
3951b15
505ba4e
c914eac
df51a8b
00775d9
199f15d
bc1b231
f9ea3df
1bc9714
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,19 +1,35 @@ | ||||||||||
// @flow | ||||||||||
import COMMIT_MODES from '@constants/commit' | ||||||||||
import { CommitModes } from '@constants/commit' | ||||||||||
import FLAGS from '@constants/flags' | ||||||||||
|
||||||||||
const isSupportedCommand = (command: ?string, options: Object): boolean => { | ||||||||||
return Object.keys(options).includes(command) | ||||||||||
type Options = { | ||||||||||
[key: string]: object | ||||||||||
} | ||||||||||
|
||||||||||
Comment on lines
+4
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually no, would probably be better if you imported options from |
||||||||||
type Cli = { | ||||||||||
flags: Record<string, object> | ||||||||||
input: string[] | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||||||||||
showHelp(): void | ||||||||||
} | ||||||||||
|
||||||||||
const isSupportedCommand = ( | ||||||||||
command: string | undefined, | ||||||||||
options: Options | ||||||||||
): boolean => { | ||||||||||
return command !== undefined && Object.keys(options).includes(command) | ||||||||||
} | ||||||||||
|
||||||||||
type CommandType = 'flag' | 'command' | ||||||||||
|
||||||||||
type CommandResult = { | ||||||||||
type: CommandType | ||||||||||
command: string | null | ||||||||||
} | ||||||||||
|
||||||||||
const determineCommand = ( | ||||||||||
flags: Object, | ||||||||||
flags: Options, | ||||||||||
input: string[], | ||||||||||
options: Object | ||||||||||
): { | ||||||||||
type: 'flag' | 'command', | ||||||||||
command: ?string | ||||||||||
} => { | ||||||||||
options: Options | ||||||||||
): CommandResult => { | ||||||||||
const command = Object.keys(flags) | ||||||||||
.map((flag) => flags[flag] && flag) | ||||||||||
.find((flag) => options[flag]) | ||||||||||
|
@@ -25,22 +41,30 @@ const determineCommand = ( | |||||||||
} | ||||||||||
: { | ||||||||||
type: 'command', | ||||||||||
command: input[0] | ||||||||||
command: input[0] || null | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
type CommandOptions = { | ||||||||||
message?: string | ||||||||||
mode?: CommitModes | ||||||||||
scope?: string | ||||||||||
title?: string | ||||||||||
query?: string[] | ||||||||||
} | ||||||||||
|
||||||||||
const getOptionsForCommand = ( | ||||||||||
command: ?string, | ||||||||||
flags: Object, | ||||||||||
command: string | null, | ||||||||||
flags: Options, | ||||||||||
input: string[], | ||||||||||
type: 'flag' | 'command' | ||||||||||
): ?Object => { | ||||||||||
type: CommandType | ||||||||||
): CommandOptions | null => { | ||||||||||
switch (command) { | ||||||||||
case FLAGS.COMMIT: | ||||||||||
case FLAGS.HOOK: | ||||||||||
return { | ||||||||||
message: flags['message'], | ||||||||||
mode: command === FLAGS.HOOK ? COMMIT_MODES.HOOK : COMMIT_MODES.CLIENT, | ||||||||||
mode: command === FLAGS.HOOK ? CommitModes.HOOK : CommitModes.CLIENT, | ||||||||||
scope: flags['scope'], | ||||||||||
title: flags['title'] | ||||||||||
} | ||||||||||
|
@@ -53,7 +77,7 @@ const getOptionsForCommand = ( | |||||||||
return null | ||||||||||
} | ||||||||||
|
||||||||||
const findGitmojiCommand = (cli: any, options: Object): void => { | ||||||||||
const findGitmojiCommand = (cli: Cli, options: Options): void => { | ||||||||||
const { command, type } = determineCommand(cli.flags, cli.input, options) | ||||||||||
|
||||||||||
if (!command || !isSupportedCommand(command, options)) { | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You apparently changed the import but you didn't include the actual enum change