Skip to content

Commit 647c703

Browse files
committed
Now exporting Vuex boilerplate for both TS and JS. Store will be populated with placeholder text, or with the state added by user. Actions and mutations will be generated as well either with placeholders or as added by users.
1 parent dc6a287 commit 647c703

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

src/components/file_system_interface/ExportProject.vue

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,14 @@ export default {
363363
// creates main.js boilerplate
364364
createMainFile(location) {
365365
let str = `import { createApp } from 'vue';`;
366+
str += `\nimport store from './store'`
366367
str += `\nimport App from './App.vue';`;
367-
str += `\nimport router from './router';`;
368-
// str += `\n\n import './index.css'`
369-
str += `\n\n const app = createApp(App);`;
370-
// str += `\n\trouter,
368+
str += `\nimport router from './router';\n`;
369+
str += `\nconst app = createApp(App);`;
371370
str += `\napp.use(router);`;
372-
str += `\n app.mount('#app');`;
371+
str += `\napp.use(store)`;
372+
str += `\napp.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 += `\nconst store = createStore({`;
448+
str += `\n\tstate () {`;
449+
str += `\n\t\treturn {`;
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\tmutations: {`;
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\tactions: {`;
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\tstore.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 += `\nexport 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

Comments
 (0)