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