Skip to content

Commit b2eb28d

Browse files
committed
chore: plopjs
1 parent 5c7255d commit b2eb28d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

template/plopfile.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,53 @@ module.exports = (plop) => {
4747
},
4848
],
4949
});
50+
51+
plop.setGenerator('screen', {
52+
description: 'Create a common screen',
53+
// User input prompts provided as arguments to the template
54+
prompts: [
55+
{
56+
// Raw text input
57+
type: 'input',
58+
// Variable name for this input
59+
name: 'name',
60+
// Prompt to display on command line
61+
message: 'What is your common screen name?',
62+
},
63+
],
64+
actions: [
65+
{
66+
// Action type 'append' injects a template into an existing file
67+
type: 'append',
68+
path: 'src/screens/index.ts',
69+
// Pattern tells plop where in the file to inject the template
70+
pattern: `/* PLOP_INJECT_SCREEN */`,
71+
template: `{{pascalCase name}}: { component: {{pascalCase name}}Screen },`,
72+
},
73+
{
74+
// Action type 'append' injects a template into an existing file
75+
type: 'append',
76+
path: 'src/screens/index.ts',
77+
// Pattern tells plop where in the file to inject the template
78+
pattern: `/* PLOP_INJECT_IMPORT */`,
79+
template: `import {{pascalCase name}}Screen from 'screens/{{pascalCase name}}';`,
80+
},
81+
{
82+
// Action type 'append' injects a template into an existing file
83+
type: 'append',
84+
path: 'src/screens/index.ts',
85+
// Pattern tells plop where in the file to inject the template
86+
pattern: `/* PLOP_INJECT_TYPE */`,
87+
template: `{{pascalCase name}}: undefined;`,
88+
},
89+
{
90+
// Add a new file
91+
type: 'add',
92+
// Path for the new file
93+
path: 'src/screens/{{pascalCase name}}.tsx',
94+
// Handlebars template used to generate content of new file
95+
templateFile: 'plop-templates/CommonScreen.js.hbs',
96+
},
97+
],
98+
});
5099
};

0 commit comments

Comments
 (0)