@@ -369,13 +369,14 @@ export default {
369369 // creates main.js boilerplate
370370 createMainFile (location ) {
371371 let str = ` import { createApp } from 'vue';` ;
372+ str += ` \n import store from './store'`
372373 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);` ;
377376 str += ` \n app.use(router);` ;
378- str += ` \n app.mount('#app');` ;
377+ str += ` \n app.use(store)` ;
378+ str += ` \n app.mount('#app');` ;
379+
379380 // if using typescript, export with .ts extension
380381 if (this .exportAsTypescript === " on" ) {
381382 fs .writeFileSync (path .join (location, " src" , " main.ts" ), str);
@@ -447,6 +448,50 @@ export default {
447448 return ;
448449 }
449450 },
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+ },
450495 // create package.json file
451496 createPackage (location ) {
452497 let str = ` {` ;
@@ -495,6 +540,7 @@ export default {
495540 fs .mkdirSync (path .join (data, " src" , " components" ));
496541 fs .mkdirSync (path .join (data, " src" , " views" ));
497542 fs .mkdirSync (path .join (data, " src" , " router" ));
543+ fs .mkdirSync (path .join (data, " src" , " store" ));
498544 }
499545 // creating basic boilerplate for vue app
500546 this .createIndexFile (data);
@@ -505,6 +551,7 @@ export default {
505551 this .createTSViteConfig (data);
506552 this .createTSDeclaration (data);
507553 this .createPackage (data);
554+ this .createStore (data);
508555 // exports images to the /assets folder
509556 // eslint-disable-next-line no-unused-vars
510557 for (let [routeImage, imageLocation] of Object .entries (this .imagePath )) {
@@ -547,7 +594,7 @@ export default {
547594 },
548595 },
549596 computed: {
550- ... mapState ([" componentMap" , " imagePath" , " routes" , " exportAsTypescript" , " activeComponent" ]),
597+ ... mapState ([" componentMap" , " imagePath" , " routes" , " exportAsTypescript" , " activeComponent" , " userState " , " userActions " ]),
551598 },
552599};
553600< / script>
0 commit comments