1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47#!/usr/bin/env node
import pc from 'picocolors'
import boxen from 'boxen'
import inquirer from 'inquirer'
import * as emoji from 'node-emoji'
import { kebabCase, pascalCase, kongponentSrcPath, createComponentFiles } from './utils/index.js'
import fs from 'fs'
const questions = [
{
type: 'input',
name: 'name',
message: 'What is the kebab-case name of the new Kongponent?',
filter: async (input: string): Promise<string> => kebabCase(input).replace(/[^a-z-]/gi, ''),
validate: async (input: string) => {
if (!input.startsWith('k-')) {
return 'The name of a Kongponent should start with \'k-\''
} else if (input.includes('--')) {
return 'The name should not include a double-dash \'--\''
} else if (input.endsWith('-')) {
return 'The name should not end with a dash.'
} else if (fs.existsSync(kongponentSrcPath(input))) {
// Kongponent already exists
return `Error: ${pascalCase(input)} already exists`
}
return true
},
},
]
const createKongponent = async (): Promise<void> => {
console.clear()
console.log(boxen(pc.cyan(pc.bold(`${emoji.get('sparkles')} Create a new Kongponent ${emoji.get('sparkles')}`)), { margin: 1, padding: 2 }))
const answers = await inquirer.prompt(questions)
// Insert an empty after answering the questions
console.log('')
// Create src/component files
await createComponentFiles(answers.name)
}
createKongponent()