@@ -42,7 +42,7 @@ export default {
42
42
},
43
43
computed: {
44
44
// needs access to current component aka activeComponent
45
- ... mapState ([' componentMap' , ' activeComponent' ])
45
+ ... mapState ([' componentMap' , ' activeComponent' , ' activeComponentObj ' ])
46
46
},
47
47
methods: {
48
48
getWindowHeight (e ) {
@@ -60,10 +60,12 @@ export default {
60
60
},
61
61
// Creates beginner boilerplate
62
62
createTemplate (componentName , children ) {
63
- let output = ` `
64
- output += ` <div>\n `
63
+ // not sure why output was set up like this, was imputted into return statement
64
+ // using string literal
65
+ // let output = ``
66
+ // output += ` <div>\n`
65
67
let templateTagStr = this .writeTemplateTag (componentName)
66
- return ` <template>\n ${ output } ${ templateTagStr} </div>\n </template>`
68
+ return ` <template>\n <div> \n ${ templateTagStr} </div>\n </template>`
67
69
},
68
70
// Creates <template> boilerplate
69
71
writeTemplateTag (componentName ) {
@@ -138,16 +140,80 @@ export default {
138
140
},
139
141
// Creates boiler text for <script> and <style>
140
142
createBoiler (componentName , children ) {
141
- let str = ' '
142
- children .forEach ((name ) => {
143
- str += ` import ${ name} from '@/components/${ name} .vue';\n `
143
+ // add import mapstate and mapactions if they exist
144
+ let imports = ' '
145
+ if (this .activeComponentObj .actions .length || this .activeComponentObj .state .length ) {
146
+ imports += ' import { '
147
+ if (this .activeComponentObj .actions .length && this .activeComponentObj .state .length ) {
148
+ imports += ' mapState, mapActions'
149
+ } else if (this .activeComponentObj .state .length ) imports += ' mapState'
150
+ else imports += ' mapActions'
151
+ imports += ' } from "vuex"\n '
152
+ }
153
+
154
+ // add imports for children
155
+ children .forEach (name => {
156
+ imports += ` import ${ name} from '@/components/${ name} .vue';\n `
144
157
})
158
+
159
+ // add components section
145
160
let childrenComponentNames = ' '
146
161
children .forEach ((name ) => {
147
162
childrenComponentNames += ` ${ name} ,\n `
148
163
})
164
+
165
+ // if true add data section and populate with props
166
+ let data = ' '
167
+ if (this .activeComponentObj .props .length ) {
168
+ data += ' data () {\n return {'
169
+ this .activeComponentObj .props .forEach (prop => {
170
+ data += ` \n ${ prop} : "PLACEHOLDER FOR VALUE",`
171
+ })
172
+ data += ' \n '
173
+ data += ' }\n '
174
+ data += ' },\n '
175
+ }
176
+
177
+ // if true add computed section and populate with state
178
+ let computed = ' '
179
+ if (this .activeComponentObj .state .length ) {
180
+ computed += ' computed: {'
181
+ computed += ' \n ...mapState(['
182
+ this .activeComponentObj .state .forEach ((state ) => {
183
+ computed += ` \n "${ state} ",`
184
+ })
185
+ computed += ' \n ]),\n '
186
+ computed += ' },\n '
187
+ }
188
+
189
+ // if true add methods section and populate with actions
190
+ let methods = ' '
191
+ if (this .activeComponentObj .actions .length ) {
192
+ methods += ' methods: {'
193
+ methods += ' \n ...mapActions(['
194
+ this .activeComponentObj .actions .forEach ((action ) => {
195
+ methods += ` \n "${ action} ",`
196
+ })
197
+ methods += ' \n ]),\n '
198
+ methods += ' },\n '
199
+ }
200
+
201
+ // concat all code within script tags
202
+ let output = ' \n\n <script>\n '
203
+ output += imports + ' \n export default {\n name: ' + componentName
204
+ output += ' ,\n components: {\n '
205
+ output += childrenComponentNames + ' },\n '
206
+ output += data
207
+ output += computed
208
+ output += methods
209
+ output += ' };\n <\/ script>\n\n <style scoped>\n </style>'
210
+ // add props/data
211
+
149
212
// eslint-disable-next-line no-useless-escape
150
- return ` \n\n <script>\n ${ str} \n export default {\n name: '${ componentName} ',\n components: {\n ${ childrenComponentNames} }\n };\n <\/ script>\n\n <style scoped>\n </style>`
213
+ // return `\n\n<script>\n${str}\nexport default {\n name: '${componentName}',\n
214
+ // components: {\n${childrenComponentNames} }\n};\n<\/script>\n\n<style scoped>\n
215
+ // </style>`
216
+ return output
151
217
}
152
218
},
153
219
mounted () {
0 commit comments