@@ -363,13 +363,14 @@ export default {
363
363
// creates main.js boilerplate
364
364
createMainFile (location ) {
365
365
let str = ` import { createApp } from 'vue';` ;
366
+ str += ` \n import store from './store'`
366
367
str += ` \n import App from './App.vue';` ;
367
- str += ` \n import router from './router';` ;
368
- // str += `\n\n import './index.css'`
369
- str += ` \n\n const app = createApp(App);` ;
370
- // str += `\n\trouter,
368
+ str += ` \n import router from './router';\n ` ;
369
+ str += ` \n const app = createApp(App);` ;
371
370
str += ` \n app.use(router);` ;
372
- str += ` \n app.mount('#app');` ;
371
+ str += ` \n app.use(store)` ;
372
+ str += ` \n app.mount('#app');` ;
373
+
373
374
// if using typescript, export with .ts extension
374
375
if (this .exportAsTypescript === " on" ) {
375
376
fs .writeFileSync (path .join (location, " src" , " main.ts" ), str);
@@ -441,6 +442,50 @@ export default {
441
442
return ;
442
443
}
443
444
},
445
+ createStore (location ) {
446
+ let str = ` import { createStore } from 'vuex';\n ` ;
447
+ str += ` \n const store = createStore({` ;
448
+ str += ` \n\t state () {` ;
449
+ str += ` \n\t\t return {` ;
450
+ if (! this .userState .length ){
451
+ str += ` \n\t\t\t //placeholder for state`
452
+ }
453
+ for (let i = 0 ; i < this .userState .length ; i++ ){
454
+ str+= ` \n\t\t\t ${ this .userState [i]} : "PLACEHOLDER FOR VALUE",`
455
+ if (i === this .userState .length - 1 ){str = str .slice (0 , - 1 )}
456
+ }
457
+ str += ` \n\t\t }` ;
458
+ str += ` \n\t },` ;
459
+ str += ` \n\t mutations: {` ;
460
+ if (! this .userActions .length ){
461
+ str += ` \n\t\t\t //placeholder for mutations`
462
+ }
463
+ for (let i = 0 ; i < this .userActions .length ; i++ ){
464
+ str += ` \n\t\t ${ this .userActions [i]} (state) {` ;
465
+ str += ` \n\t\t\t //placeholder for your mutation` ;
466
+ str += ` \n\t\t },` ;
467
+ if (i === this .userActions .length - 1 ){str = str .slice (0 , - 1 )}
468
+ }
469
+ str += ` \n\t },` ;
470
+ str += ` \n\t actions: {` ;
471
+ if (! this .userActions .length ){
472
+ str += ` \n\t\t\t //placeholder for actions`
473
+ }
474
+ for (let i = 0 ; i < this .userActions .length ; i++ ){
475
+ str += ` \n\t\t ${ this .userActions [i]} () {` ;
476
+ str += ` \n\t\t\t store.commit('${ this .userActions [i]} ')` ;
477
+ str += ` \n\t\t },` ;
478
+ if (i === this .userActions .length - 1 ){str = str .slice (0 , - 1 )}
479
+ }
480
+ str += ` \n\t }` ;
481
+ str += ' \n })\n ' ;
482
+ str += ` \n export default store;`
483
+ if (this .exportAsTypescript === " on" ) {
484
+ fs .writeFileSync (path .join (location, " src" , " store" , " index.ts" ), str);
485
+ } else {
486
+ fs .writeFileSync (path .join (location, " src" , " store" , " index.js" ), str);
487
+ }
488
+ },
444
489
// create package.json file
445
490
createPackage (location ) {
446
491
let str = ` {` ;
@@ -490,6 +535,7 @@ export default {
490
535
fs .mkdirSync (path .join (data, " src" , " components" ));
491
536
fs .mkdirSync (path .join (data, " src" , " views" ));
492
537
fs .mkdirSync (path .join (data, " src" , " router" ));
538
+ fs .mkdirSync (path .join (data, " src" , " store" ));
493
539
}
494
540
// creating basic boilerplate for vue app
495
541
this .createIndexFile (data);
@@ -500,6 +546,7 @@ export default {
500
546
this .createTSViteConfig (data);
501
547
this .createTSDeclaration (data);
502
548
this .createPackage (data);
549
+ this .createStore (data);
503
550
// exports images to the /assets folder
504
551
// eslint-disable-next-line no-unused-vars
505
552
for (let [routeImage, imageLocation] of Object .entries (this .imagePath )) {
@@ -542,7 +589,7 @@ export default {
542
589
},
543
590
},
544
591
computed: {
545
- ... mapState ([" componentMap" , " imagePath" , " routes" , " exportAsTypescript" , " activeComponent" ]),
592
+ ... mapState ([" componentMap" , " imagePath" , " routes" , " exportAsTypescript" , " activeComponent" , " userState " , " userActions " ]),
546
593
},
547
594
};
548
595
< / script>
0 commit comments