-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
99 lines (99 loc) · 3.08 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
/* eslint-disable space-before-function-paren */
/* eslint-env node */
module.exports = (plop) => {
// eslint-disable-next-line prefer-arrow-callback
plop.setHelper('dateNow', function dateNow() {
const now = new Date();
const year = now.getFullYear().toString();
const month = (now.getMonth() + 1).toString().padStart(2, '0');
const day = now.getDate().toString().padStart(2, '0');
return `${year}-${month}-${day}`;
});
plop.setHelper('if_eq', function ifEq(a, b, opts) {
if (a === b) {
// eslint-disable-next-line no-invalid-this
return opts.fn(this);
}
// eslint-disable-next-line no-invalid-this
return opts.inverse(this);
});
plop.setGenerator('blog-post', {
description: 'Creating a new blog post',
prompts: [
{
type: 'input',
name: 'title',
message: 'Blog post title',
},
{
type: 'list',
name: 'language',
message: 'Language',
choices: [
{ name: 'English', value: 'en' },
{ name: 'Romanian', value: 'ro' },
],
default: 0,
},
{
type: 'input',
name: 'description',
message: 'Description',
},
{
type: 'input',
name: 'tags',
message: 'Tags (comma separated list, e.g. food,soup)',
},
{
type: 'input',
name: 'pictureUrl',
message: 'Picture url (e.g. /images/123.jpg)',
},
],
actions: [
{
type: 'add',
path: './src/markdown/{{kebabCase title}}.md',
templateFile: './plop-templates/blog-post-file.hbs',
},
{
type: 'modify',
path: './src/markdown/index.js',
pattern: /^/u, // The start of the file
template:
"import {{camelCase title}} from './{{kebabCase title}}.md';\n",
},
{
type: 'modify',
path: './src/markdown/index.js',
pattern: /(?<=export default \{)/u, // After export default \{
template: "\n '{{kebabCase title}}': {{camelCase title}},",
},
{
type: 'modify',
path: './src/utils/i18n/resources.json',
pattern: /(?<="en":\s\{(?:(?:.|\n)*)"routes":\s\{)/u, // After "en": { "routes": {
templateFile: './plop-templates/i18n-resources-routes-snippet.hbs',
},
{
type: 'modify',
path: './src/utils/i18n/resources.json',
pattern: /(?<="ro":\s\{(?:(?:.|\n)*)"routes":\s\{)/u, // After "ro": { "routes": {
templateFile: './plop-templates/i18n-resources-routes-snippet.hbs',
},
{
type: 'modify',
path: './src/utils/i18n/resources.json',
pattern: /(?<="en":\s\{(?:(?:.|\n)*)"blog-posts":\s\{)/u, // After "en": { "blog-posts": {
templateFile: './plop-templates/i18n-resources-blog-posts-snippet.hbs',
},
{
type: 'modify',
path: './src/utils/i18n/resources.json',
pattern: /(?<="ro":\s\{(?:(?:.|\n)*)"blog-posts":\s\{)/u, // After "ro": { "blog-posts": {
templateFile: './plop-templates/i18n-resources-blog-posts-snippet.hbs',
},
],
});
};