-
Notifications
You must be signed in to change notification settings - Fork 1
/
plopfile.ts
72 lines (70 loc) · 2.03 KB
/
plopfile.ts
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
import { NodePlopAPI } from "plop"
const uppercase = (text: string) => text.charAt(0).toUpperCase() + text.slice(1)
export default function (plop: NodePlopAPI) {
// controller generator
plop.setGenerator("page", {
description: "create new page",
prompts: [
{
type: "input",
name: "pagePath",
message: "page path",
},
],
actions: [
{
type: "add",
path: "src/pages/{{pagePath}}.tsx",
templateFile: "templates/page.hbs",
},
{
type: "add",
path: "src/locales/fr/{{pagePath}}.json",
templateFile: "templates/translation.hbs",
},
{
type: "add",
path: "src/locales/en/{{pagePath}}.json",
templateFile: "templates/translation.hbs",
},
{
type: "add",
path: "src/components/images/{{pagePath}}.tsx",
templateFile: "templates/image.hbs",
},
],
})
plop.setHelper("upPath", function (text: string) {
return "../".repeat(text.split("/").length)
})
plop.setHelper("upPathImage", function (text: string) {
return "../".repeat(text.split("/").length + 1)
})
plop.setHelper("getContinent", function (text: string) {
return text.split("/")[0]
})
plop.setHelper("getCountry", function (text: string) {
return text.split("/")[1]
})
plop.setHelper("getId", function (text: string) {
const parts = text.split("/")
return parts[parts.length - 1]
})
plop.setHelper("getComponentImageName", function (text: string) {
const parts = text.split("/")
const unformattedName = parts[parts.length - 1]
const nameParts = unformattedName.split("-")
return nameParts.map(uppercase).join("")
})
// plop.setHelper("getId", function (text: string) {
// problem to load cachedLinks
// const test = "asia/vietnam/southern-vietnam/discover"
// for (const [id, link] of cachedLinks.entries()) {
// if (link.url === test) {
// return id
// }
// }
// return "TODO"
// })
plop.setHelper("uppercase", uppercase)
}