@@ -223,86 +223,94 @@ export default {
223
223
* @description imports child components into <script>
224
224
*/
225
225
writeScript (componentName , children ) {
226
- // let str = ''
227
- // children.forEach(name => {
228
- // str += `import ${name} from '@/components/${name}.vue';\n`
229
- // })
230
- // let childrenComponentNames = ''
231
- // children.forEach(name => {
232
- // childrenComponentNames += `\t\t${name},\n`
233
- // })
234
- // return `\n\n<script>\n${str}\nexport default {\n\tname: '${componentName}'
235
- // ,\n\tcomponents: {\n${childrenComponentNames}\t}\n};\n<\/script>`
236
- // },
237
226
// add import mapstate and mapactions if they exist
238
- let imports = ' '
239
- if (this .activeComponentObj .actions .length || this .activeComponentObj .state .length ){
240
- imports += ' import { '
241
- if (this .activeComponentObj .actions .length && this .activeComponentObj .state .length ) {
242
- imports += ' mapState, mapActions'
243
- }
244
- else if (this .activeComponentObj .state .length ) imports += ' mapState'
245
- else imports += ' mapActions'
246
- imports += ' } from "vuex"\n '
247
- }
248
-
249
- // add imports for children
250
- children .forEach (name => {
251
- imports += ` import ${ name} from '@/components/${ name} .vue';\n `
252
- })
253
-
254
- // add components section
255
- let childrenComponentNames = ' '
256
- children .forEach (name => {
257
- childrenComponentNames += ` ${ name} ,\n `
258
- })
227
+ const currentComponent = this .componentMap [componentName]
228
+ const routes = Object .keys (this .routes )
229
+ console .log (componentName)
230
+ console .log (currentComponent)
231
+ if (! routes .includes (componentName)){
232
+ let imports = ' '
233
+ if (currentComponent .actions .length || currentComponent .state .length ){
234
+ imports += ' import { '
235
+ if (currentComponent .actions .length && currentComponent .state .length ) {
236
+ imports += ' mapState, mapActions'
237
+ }
238
+ else if (currentComponent .state .length ) imports += ' mapState'
239
+ else imports += ' mapActions'
240
+ imports += ' } from "vuex"\n '
241
+ }
259
242
260
- // if true add data section and populate with props
261
- let data = ' '
262
- if (this .activeComponentObj .props .length ){
263
- data += ' data () {\n return {'
264
- this .activeComponentObj .props .forEach (prop => {
265
- data += ` \n ${ prop} : "PLACEHOLDER FOR VALUE",`
243
+ // add imports for children
244
+ children .forEach (name => {
245
+ imports += ` import ${ name} from '@/components/${ name} .vue';\n `
266
246
})
267
- data += ' \n '
268
- data += ' }\n '
269
- data += ' },\n '
270
- }
271
247
272
- // if true add computed section and populate with state
273
- let computed = ' '
274
- if (this .activeComponentObj .state .length ){
275
- computed += ' computed: {'
276
- computed += ' \n ...mapState(['
277
- this .activeComponentObj .state .forEach ((state ) => {
278
- computed += ` \n "${ state} ",`
248
+ // add components section
249
+ let childrenComponentNames = ' '
250
+ children .forEach (name => {
251
+ childrenComponentNames += ` ${ name} ,\n `
279
252
})
280
- computed += ' \n ]),\n '
281
- computed += ' },\n '
253
+
254
+ // if true add data section and populate with props
255
+ let data = ' '
256
+ if (currentComponent .props .length ){
257
+ data += ' data () {\n return {'
258
+ currentComponent .props .forEach (prop => {
259
+ data += ` \n ${ prop} : "PLACEHOLDER FOR VALUE",`
260
+ })
261
+ data += ' \n '
262
+ data += ' }\n '
263
+ data += ' },\n '
264
+ }
265
+
266
+ // if true add computed section and populate with state
267
+ let computed = ' '
268
+ if (currentComponent .state .length ){
269
+ computed += ' computed: {'
270
+ computed += ' \n ...mapState(['
271
+ currentComponent .state .forEach ((state ) => {
272
+ computed += ` \n "${ state} ",`
273
+ })
274
+ computed += ' \n ]),\n '
275
+ computed += ' },\n '
276
+ }
277
+
278
+ // if true add methods section and populate with actions
279
+ let methods = ' '
280
+ if (currentComponent .actions .length ){
281
+ methods += ' methods: {'
282
+ methods += ' \n ...mapActions(['
283
+ currentComponent .actions .forEach ((action ) => {
284
+ methods += ` \n "${ action} ",`
285
+ })
286
+ methods += ' \n ]),\n '
287
+ methods += ' },\n '
288
+ }
289
+
290
+ // concat all code within script tags
291
+ let output = ' \n\n <script>\n '
292
+ output += imports + ' \n export default {\n name: ' + componentName
293
+ output += ' ,\n components: {\n '
294
+ output += childrenComponentNames + ' },\n '
295
+ output += data
296
+ output += computed
297
+ output += methods
298
+ output += ' };\n <\/ script>'
299
+ return output
282
300
}
283
301
284
- // if true add methods section and populate with actions
285
- let methods = ' '
286
- if (this .activeComponentObj .actions .length ){
287
- methods += ' methods: {'
288
- methods += ' \n ...mapActions(['
289
- this .activeComponentObj .actions .forEach ((action ) => {
290
- methods += ` \n "${ action} ",`
302
+ else {
303
+ let str = ' '
304
+ children .forEach (name => {
305
+ str += ` import ${ name} from '@/components/${ name} .vue';\n `
306
+ })
307
+ let childrenComponentNames = ' '
308
+ children .forEach (name => {
309
+ childrenComponentNames += ` ${ name} ,\n `
291
310
})
292
- methods += ' \n ]),\n '
293
- methods += ' },\n '
311
+ return ` \n\n <script>\n ${ str} \n export default {\n name: '${ componentName} ',\n components: {\n ${ childrenComponentNames} }\n };\n <\/ script>`
294
312
}
295
313
296
- // concat all code within script tags
297
- let output = ' \n\n <script>\n '
298
- output += imports + ' \n export default {\n name: ' + componentName
299
- output += ' ,\n components: {\n '
300
- output += childrenComponentNames + ' },\n '
301
- output += data
302
- output += computed
303
- output += methods
304
- output += ' };\n <\/ script>'
305
- return output
306
314
},
307
315
/**
308
316
* @description writes the <style> in vue component
@@ -472,7 +480,7 @@ export default {
472
480
}
473
481
},
474
482
computed: {
475
- ... mapState ([' componentMap' , ' imagePath' , ' activeComponentObj ' ])
483
+ ... mapState ([' componentMap' , ' imagePath' , ' routes ' ])
476
484
}
477
485
}
478
486
0 commit comments