-
Notifications
You must be signed in to change notification settings - Fork 0
/
plopfile.js
88 lines (84 loc) · 2.35 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
/* var fs = require('fs');
function loadCategories(){
var dirPath = 'blogs/';
var result = []; //this is going to contain paths
fs.readdir(__dirname + dirPath, function (err, filesPath) {
if (err) throw err;
result = filesPath.map(function (filePath) {
console.log(dirPath + '/' + filePath)
return dirPath + filePath;
});
});
} */
function replaceAll(string, search, replace) {
return string.split(search).join(replace);
}
function formatDate(date) {
return replaceAll(new Date(date).toISOString().split('T')[0],",","/")
}
module.exports = function (plop) {
const today = new Date(Date.now())
plop.setHelper("formatDate", (date) => formatDate(date))
plop.setHelper("filename", function(date){
return date.replace('-','/').replace('-','')
})
plop.setPrompt('date', require('inquirer-date-prompt'))
// optional welcome message
plop.setWelcomeMessage(
"Welcome to plop! What type of file would you like to generate?"
),
plop.setGenerator("wiki topic",{
description: "Generate a wiki topic",
prompts: [
{
type: "input",
name: "title",
message: "Title of topic:"
}
],
actions: [
{
type: "add",
path: `{{dashCase title}}/README.md`,
templateFile: "plop-templates/blog-post.hbs",
},
]
}),
plop.setGenerator("blog post", {
description: "template for generating blog posts",
prompts: [
{
type: "date",
name: "datetime",
message: "Publish date",
format: { hour: undefined, minute: undefined }
},
{
type: "input",
name: "title",
message: "Title of post:",
},
{
type: "input",
name: "description",
message: "Description of post:",
},
{
type: "list",
name: "category",
message: "Category:",
choices: ["3D Printing", "Programming", "Other"],
filter: function(val) {
return val.toLowerCase()
},
},
],
actions: [
{
type: "add",
path: `blogs/{{dashCase category}}/{{formatDate datetime}}/{{dashCase title}}.md`,
templateFile: "plop-templates/blog-post.hbs",
},
],
})
}