@@ -363,13 +363,14 @@ export default {
363363 // creates main.js boilerplate
364364 createMainFile (location ) {
365365 let str = ` import { createApp } from 'vue';` ;
366+ str += ` \n import store from './store'`
366367 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);` ;
371370 str += ` \n app.use(router);` ;
372- str += ` \n app.mount('#app');` ;
371+ str += ` \n app.use(store)` ;
372+ str += ` \n app.mount('#app');` ;
373+
373374 // if using typescript, export with .ts extension
374375 if (this .exportAsTypescript === " on" ) {
375376 fs .writeFileSync (path .join (location, " src" , " main.ts" ), str);
@@ -441,6 +442,50 @@ export default {
441442 return ;
442443 }
443444 },
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+ },
444489 // create package.json file
445490 createPackage (location ) {
446491 let str = ` {` ;
@@ -490,6 +535,7 @@ export default {
490535 fs .mkdirSync (path .join (data, " src" , " components" ));
491536 fs .mkdirSync (path .join (data, " src" , " views" ));
492537 fs .mkdirSync (path .join (data, " src" , " router" ));
538+ fs .mkdirSync (path .join (data, " src" , " store" ));
493539 }
494540 // creating basic boilerplate for vue app
495541 this .createIndexFile (data);
@@ -500,6 +546,7 @@ export default {
500546 this .createTSViteConfig (data);
501547 this .createTSDeclaration (data);
502548 this .createPackage (data);
549+ this .createStore (data);
503550 // exports images to the /assets folder
504551 // eslint-disable-next-line no-unused-vars
505552 for (let [routeImage, imageLocation] of Object .entries (this .imagePath )) {
@@ -542,7 +589,7 @@ export default {
542589 },
543590 },
544591 computed: {
545- ... mapState ([" componentMap" , " imagePath" , " routes" , " exportAsTypescript" , " activeComponent" ]),
592+ ... mapState ([" componentMap" , " imagePath" , " routes" , " exportAsTypescript" , " activeComponent" , " userState " , " userActions " ]),
546593 },
547594};
548595< / script>
0 commit comments