-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
64 lines (56 loc) · 1.44 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
const capitalize = (str) => {
return str.charAt(0).toUpperCase() + str.slice(1)
}
const camelCase = (str) => {
return str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase())
}
const categories = ['building-jan', 'research']
/**
* @param {import("plop").NodePlopAPI} plop
*/
module.exports = function main(plop) {
plop.setHelper('capitalize', (text) => {
return capitalize(camelCase(text))
})
plop.load('plop-helper-date')
plop.setGenerator('create-blogpost', {
description: 'Generates a blog post',
prompts: [
{
type: 'list',
name: 'categories',
message: 'what is categories of blog post: ',
choices: categories,
},
{
type: 'input',
name: 'slug',
message: 'Enter slug of blog post: ',
},
{
type: 'input',
name: 'title',
message: 'Enter title of blog post: ',
},
{
type: 'input',
name: 'description',
message: 'The description of blog post: ',
},
],
actions(answers) {
const actions = []
if (!answers) return actions
const { categories, slug, title, description } = answers
actions.push({
type: 'addMany',
templateFiles: 'templates/**',
destination: `./src/pages/post`,
globOptions: { dot: true },
data: { categories, slug, title, description },
abortOnFail: true,
})
return actions
},
})
}