-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplopfile.mjs
More file actions
80 lines (74 loc) · 2.03 KB
/
plopfile.mjs
File metadata and controls
80 lines (74 loc) · 2.03 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import fs from 'node:fs'
import path from 'node:path'
import chalk from 'chalk'
import hbs_helpers from 'handlebars-helpers'
const iconsList = fs
.readdirSync(path.join(process.cwd(), 'src/icons'))
.map((item) => item.substring(0, item.lastIndexOf('.')) || item)
export default (
/** @type {import('plop').NodePlopAPI} */
plop
) => {
const helpers = hbs_helpers()
for (const prop in helpers) {
if (!prop.toLowerCase().includes('case')) {
plop.setHelper(prop, helpers[prop])
}
}
plop.setGenerator('icon', {
description: '📦 generate a new Icon',
prompts: [
{
type: 'input',
name: 'name',
message: 'What would you like to call your icon?',
validate: (icon) => {
if (icon === '') {
return chalk.red('⛔ Icon name cannot be empty')
}
if (iconsList.includes(icon)) {
return chalk.red('⛔ Already exists')
}
return true
},
},
{
type: 'confirm',
name: 'hasFilledProp',
message: `Will this icon have the ${chalk.blue('filled')} prop?`,
},
{
type: 'confirm',
name: 'hasDisableProp',
message: `Will this icon have the ${chalk.yellowBright('disabled')} prop?`,
},
{
type: 'confirm',
name: 'hasCustomProps',
message: `Will it have other ${chalk.greenBright('custom')} props?`,
},
{
type: 'number',
name: 'variantsCount',
message: 'How many variants are you expecting for this icon?',
},
],
actions() {
const currentActions = [
{
type: 'add',
path: 'src/icons/{{ properCase name }}.tsx',
templateFile: 'generators/Icon.tsx.hbs',
},
{
type: 'append',
path: 'src/index.ts',
pattern: /(\/{3} @PLOP_EXPORTS)/g,
template:
"export { {{ properCase name }} } from './icons/{{ properCase name }}'",
},
]
return currentActions
},
})
}