-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.mjs
103 lines (103 loc) · 3.73 KB
/
plopfile.mjs
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
100
101
102
103
export default function (plop) {
// create your generators here
plop.setGenerator('matcher', {
description: 'create a new matcher',
prompts: [
// {
// choices: ['Component'],
// message: 'Type of Matcher',
// name: 'matcherType',
// type: 'list',
// },
{
message: 'Component Name',
name: 'componentName',
type: 'input',
validate: val => val.length > 0 || 'Component name is required',
},
],
actions: [
{
type: 'add',
path: 'docs/css/{{lowerCase componentName}}.css',
templateFile: 'config/plop/matcher.css.hbs',
},
{
type: 'add',
path: 'docs/matchers/to-be-accessible-{{lowerCase componentName}}.md',
templateFile: 'config/plop/matcher.md.hbs',
},
{
type: 'add',
path: 'docs/components/{{lowerCase componentName}}/{{properCase componentName}}.tsx',
templateFile: 'config/plop/ExampleDocs.tsx.hbs',
},
{
type: 'add',
path: 'src/matchers/toBeAccessible{{properCase componentName}}/to-be-accessible-{{lowerCase componentName}}.ts',
templateFile: 'config/plop/matcher.hbs',
},
{
type: 'add',
path: 'src/matchers/toBeAccessible{{properCase componentName}}/__tests__/to-be-accessible-{{lowerCase componentName}}.spec.tsx',
templateFile: 'config/plop/matcher.spec.hbs',
},
{
type: 'add',
path: 'src/matchers/toBeAccessible{{properCase componentName}}/examples/{{properCase componentName}}.tsx',
templateFile: 'config/plop/matcher.tsx.hbs',
},
{
type: 'modify',
path: 'docs/css/custom.css',
pattern: /\/\*\* plop-prepend-css-file \*\//gi,
template: "@import './{{lowerCase componentName}}.css';\r\n/** plop-prepend-css-file */",
},
{
type: 'modify',
path: 'src/matchers/index.ts',
pattern: /\/\*\* Other Matchers \*\//gi,
template:
"export * from './toBeAccessible{{properCase componentName}}/to-be-accessible-{{lowerCase componentName}}'\r\n/** Other Matchers */",
},
{
type: 'modify',
path: 'src/types/global.d.ts',
pattern: / type JestMatcherUtils = typeof jestMatcherUtils/gi,
template:
" | '{{lowerCase componentName}}'\r\n type JestMatcherUtils = typeof jestMatcherUtils",
},
{
type: 'modify',
path: 'src/types/jest.d.ts',
pattern: /\/\*\* plop-prepend-matcher \*\//gi,
template: ` /**
* Assert whether an element has the correct role, properties and keyboard interactions for \`{{lowerCase componentName}}\`.
* @summary A \`{{lowerCase componentName}}\` is ...
* @example
* <div role="{{lowerCase componentName}}">...</div>
*
* expect(screen.getByRole('{{lowerCase componentName}}')).toBeAccessible{{properCase componentName}}()
* @see
* [jest-a11y/matchers/{{lowerCase componentName}}](https://veiko.github.io/jest-a11y/matchers/{{lowerCase componentName}})
*/
toBeAccessible{{properCase componentName}}(): CustomMatcherResult
/** plop-prepend-matcher */`,
},
{
type: 'modify',
path: 'src/utils/assertRole.ts',
pattern: /\/\*\* plop-prepend-func \*\//gi,
template:
"\r\nconst has{{properCase componentName}}Role = (el: HTMLElement) => getRole(el) === '{{lowerCase componentName}}'\r\n/** plop-prepend-func */",
},
{
type: 'modify',
path: 'src/utils/assertRole.ts',
pattern: /\/\*\* plop-prepend-assertion \*\//gi,
template:
' {{lowerCase componentName}}: has{{properCase componentName}}Role,\r\n/** plop-prepend-assertion */',
},
],
})
}