-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathplopfile.js
137 lines (133 loc) · 4.64 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/** List of all svelte-konva components that are autogenerated */
const COMPONENT_LIST = [
{
componentName: 'Circle',
example: '<Circle x={100} y={100} radius={50} fill="blue" />',
testConfig: '{ x: 0, y: 0, radius: 100 }'
},
{
componentName: 'Rect',
example: '<Rect x={100} y={100} width={100} height={100} fill="blue" />',
testConfig: '{ x: 0, y: 0, width: 100, height: 100 }'
},
{
componentName: 'Ellipse',
example: '<Ellipse x={100} y={100} radiusX={50} radiusY={25} fill="blue"/>',
testConfig: '{ x: 0, y: 0, radiusX: 120, radiusY: 70 }'
},
{
componentName: 'Wedge',
example: '<Wedge x={100} y={100} radius={100} angle={120} fill="blue" />',
testConfig: '{ x: 0, y: 0, radius: 100, angle: 300 }'
},
{
componentName: 'Line',
example: '<Line points={[0, 0, 60, 30, 300, 90, 30, 100]} stroke="blue" strokeWidth={10} />',
testConfig: "{ x: 0, y: 0, points: [0, 0, 100, 100], strokeWidth: 10, stroke: 'black' }"
},
{
componentName: 'Sprite',
example:
'<Sprite x={100} y={100} image={imageObj} animation="idle" animations={animations} frameRate={7} frameIndex={0} />'
},
{
componentName: 'Image',
example: '<Image x={100} y={100} image={imageObj} width={100} height={100} />'
},
{
componentName: 'Text',
example: '<Text x={100} y={100} text="some text" fontSize={25} fill="blue" />',
testConfig: "{ x: 0, y: 0, fontSize: 100, text: 'some text', fill: 'black' }"
},
{
componentName: 'TextPath',
example:
'<TextPath x={100} y={100} fill="#333" text="some text" fontSize={25} data="M10 10 C0 0 10 150 100 100 S300 150 5.0.300" />',
testConfig: "{ x: 0, y: 0, fontSize: 100, text: 'some text', data: 'M 1 60 H 168 Z' }"
},
{
componentName: 'Star',
example: '<Star x={100} y={100} innerRadius={25} outerRadius={50} numPoints={5} fill="blue" />',
testConfig: '{ x: 0, y: 0, innerRadius: 100, outerRadius: 200, numPoints: 5 }'
},
{
componentName: 'Ring',
example: '<Ring x={100} y={100} innerRadius={25} outerRadius={50} fill="blue" />',
testConfig: '{ x: 0, y: 0, innerRadius: 20, outerRadius: 100 }'
},
{
componentName: 'Arc',
example: '<Arc x={100} y={100} innerRadius={25} outerRadius={50} angle={120} fill="blue" />',
testConfig: '{ x: 0, y: 0, innerRadius: 20, outerRadius: 100, angle: 300 }'
},
{
componentName: 'Path',
example:
'<Path x={100} y={100} width={100} height={100} fill="blue" data="M213.1,6.7c-32.4-14.4-73.7,0-88.1,30.6C110.6,4.9,67.5-9.5,36.9,6.7C2.8,22.9-13.4,62.4,13.5,110.9C33.3,145.1,67.5,170.3,125,217c59.3-46.7,93.5-71.9,111.5-106.1C263.4,64.2,247.2,22.9,213.1,6.7z" />',
testConfig: "{ x: 0, y: 0, data: 'M 2 2 H 100 V 60 H 2 V 2 Z' }"
},
{
componentName: 'RegularPolygon',
example: '<RegularPolygon x={100} y={100} sides={7} radius={70} fill="blue" />',
testConfig: '{ x: 0, y: 0, sides: 7, radius: 80 }'
},
{
componentName: 'Arrow',
example:
'<Arrow x={100} y={100} points={[0, 0, 40, 40]} pointerLength={20} pointerWidth={20} fill="blue" stroke="blue" strokeWidth={6} />',
testConfig: "{ x: 0, y: 0, points: [0, 0, 100, 100], strokeWidth: 10, stroke: 'black' }"
},
{
componentName: 'Shape',
example: '<Shape x={100} y={100} width={100} height={50} fill="blue" sceneFunc={() => {}} />'
},
{
componentName: 'Tag',
example:
'<Tag x={10} y={20} fill="black" pointerDirection="down" pointerWidth={10} pointerHeight={10} lineJoin="round" />',
testConfig: "{ x: 0, y: 0, pointerDirection: 'down', pointerWidth: 500, pointerHeight: 200 }"
}
];
const SVELTE_KONVA_COMPONENT_ACTION_LIST = COMPONENT_LIST.map((data) => {
switch (data.componentName) {
case 'Tag':
data.importPath = `konva/lib/shapes/Label`;
break;
case 'Shape':
data.importPath = `konva/lib/${data.componentName}`;
break;
default:
data.importPath = `konva/lib/shapes/${data.componentName}`;
break;
}
return {
type: 'add',
force: true,
path: `src/lib/${data.componentName}.svelte`,
data,
templateFile: 'src/templates/svelteKonvaComponent.hbs'
};
});
const SVELTE_KONVA_COMPONENT_TEST_ACTION_LIST = COMPONENT_LIST.filter(
(data) => data.testConfig
).map((data) => {
return {
type: 'add',
force: true,
path: `src/tests/${data.componentName.toLowerCase()}.test.ts`,
data,
templateFile: 'src/templates/svelteKonvaComponentTests.hbs'
};
});
export default function (plop) {
plop.setGenerator('svelteKonvaComponents', {
description: 'Creates all svelte-konva components that contain similar logic',
prompts: [],
actions: SVELTE_KONVA_COMPONENT_ACTION_LIST
});
plop.setGenerator('svelteKonvaComponentTests', {
description: 'Creates all svelte-konva component tests that contain similar logic',
prompts: [],
actions: SVELTE_KONVA_COMPONENT_TEST_ACTION_LIST
});
}