-
-
Notifications
You must be signed in to change notification settings - Fork 125
/
plopfile.js
143 lines (133 loc) · 4.24 KB
/
plopfile.js
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const lexicon = {
ru: {
label: 'Русский',
choose: 'Выберите язык',
chooseTemplate: 'Выберите шаблон документации',
chooseDocLangs: 'Выберите языковые версии документации',
name: {
label: 'Введите название компонента',
error: {
required: 'Пожалуйста, введите название компонента',
format: 'Имя компонента может содержать только буквы и цифры',
},
},
error: {
required: 'Вам необходимо выбрать хотя бы одну языковую версию',
},
template: {
landing: 'Одностраничная документация',
multi: 'Многостраничная документация',
},
placeholders: {
quickStart: 'Быстрый старт',
events: 'События',
interface: 'Интерфейс',
items: 'Элементы',
categories: 'Категории',
snippets: 'Сниппеты',
pathPrefix: '',
},
},
en: {
label: 'English',
choose: 'Choose language',
chooseTemplate: 'Choose documentation template',
chooseDocLangs: 'Select the language versions of the documentation',
name: {
label: 'Enter the component name',
error: {
required: 'Please, enter the component name',
format: 'Component name can only contain letters and numbers',
},
},
error: {
required: 'You must select at least one language version',
},
template: {
landing: 'Single-page documentation',
multi: 'Multi-page documentation',
},
placeholders: {
quickStart: 'Quick start',
events: 'Events',
interface: 'Interface',
items: 'Items',
categories: 'Categories',
snippets: 'Snippets',
pathPrefix: '/en',
},
},
}
const langKeys = Object.keys(lexicon)
export default function (plop) {
/** @type {import('plop').NodePlopAPI} */
plop.setGenerator('component', {
prompts: [
{
name: 'language',
type: 'list',
message: langKeys.map(lang => lexicon[lang].choose).join(' / '),
choices: langKeys.map(lang => ({ name: lexicon[lang].label, value: lang })),
},
{
name: 'template',
type: 'list',
message: ({ language }) => lexicon[language].chooseTemplate,
choices: ({ language }) => Object.entries(lexicon[language].template).map(([value, name]) => ({ name, value })),
},
{
type: 'input',
name: 'name',
message: ({ language }) => lexicon[language].name.label,
validate: (value, { language }) => {
if (!value) {
return lexicon[language].name.error.required
}
if (!value.match(/^[a-zA-Z0-9]*$/)) {
return lexicon[language].name.error.format
}
return true
},
},
{
type: 'checkbox',
name: 'languages',
message: ({ language }) => lexicon[language].chooseDocLangs,
choices: langKeys.map((value, index) => ({
name: lexicon[value].label,
value,
checked: index === 0,
})),
validate: (value, { language }) => !value.length ? lexicon[language].error.required : true,
loop: true,
},
],
actions: ({ languages, template }) => {
const actions = []
languages.forEach(lang => {
const prefix = lang !== 'ru' ? `${lang}/` : ''
switch (template) {
case 'landing':
actions.push({
type: 'add',
path: `docs/${prefix}components/{{lowerCase name}}.md`,
templateFile: 'plop-templates/landing.md',
abortOnFail: false,
})
break
case 'multi':
actions.push({
type: 'addMany',
templateFiles: '**/*.*',
base: 'plop-templates/multi/',
destination: `docs/${prefix}components/{{lowerCase name}}/`,
data: lexicon[lang].placeholders,
abortOnFail: false,
})
break
}
})
return actions
},
})
}