@eljs/create-preset-structure
Version:
Project structure template powered by @eljs/create.
56 lines (50 loc) • 1.32 kB
text/typescript
import { gitCommit } from '@eljs/utils'
import inquirer, { type Answers } from 'inquirer'
import autocomplete from 'inquirer-autocomplete-prompt'
const COMMIT_TYPES: string[] = [
'feat',
'fix',
'docs',
'style',
'refactor',
'chore',
'perf',
'test',
'revert',
'merge',
'sync',
]
main()
.then(() => process.exit(0))
.catch(error => {
console.error(`git commit error: ${error.message}`)
process.exit(1)
})
async function main(): Promise<void> {
const questions = [
{
type: 'autocomplete',
name: 'type',
message:
'Please select commit type(support fuzzy matching and custom input)',
source: function (_: unknown, input: string): Promise<string[]> {
input = input || ''
return new Promise(resolve => {
const fuzzyResult = COMMIT_TYPES.filter(type =>
type.toLowerCase().includes(input.toLowerCase()),
)
resolve(fuzzyResult.length ? fuzzyResult : [input])
})
},
},
{
type: 'input',
name: 'subject',
message: 'Please input the commit subject',
},
]
await inquirer.registerPrompt('autocomplete', autocomplete)
await inquirer.prompt(questions).then(async (answers: Answers) => {
await gitCommit(`${answers.type}: ${answers.subject}`)
})
}