Skip to content

Commit 415880a

Browse files
committed
added vuex store boilerplate to export; removed script setup tag and added import to regular script tag
Co-Authored by: Bryan Bart <[email protected]>
1 parent 47f1888 commit 415880a

File tree

1 file changed

+54
-13
lines changed

1 file changed

+54
-13
lines changed

src/components/nav-buttons/ExportMenu.vue

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */ /*
2-
eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */ /*
3-
eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */ /*
4-
eslint-disable no-unused-vars */ /* eslint-disable no-useless-escape */ /*
5-
eslint-disable no-useless-escape */
61
<!--
72
Description:
83
Displays Export Project button and allows users to export project
@@ -22,14 +17,13 @@ Description:
2217
</q-btn>
2318
</template>
2419

25-
2620
<script>
2721
import { useExportComponent } from "../composables/useExportComponent.js";
2822
import { mapState } from "vuex";
2923
const { fs, ipcRenderer } = window;
3024
3125
export default {
32-
name: "ExportMenu",
26+
name: "ExportProjectComponent",
3327
methods: {
3428
useExportComponentBound(){
3529
useExportComponent.bind(this)();
@@ -367,13 +361,14 @@ export default {
367361
// creates main.js boilerplate
368362
createMainFile(location) {
369363
let str = `import { createApp } from 'vue';`;
364+
str += `\nimport store from './store'`
370365
str += `\nimport App from './App.vue';`;
371-
str += `\nimport router from './router';`;
372-
// str += `\n\n import './index.css'`
373-
str += `\n\n const app = createApp(App);`;
374-
// str += `\n\trouter,
366+
str += `\nimport router from './router';\n`;
367+
str += `\nconst app = createApp(App);`;
375368
str += `\napp.use(router);`;
376-
str += `\n app.mount('#app');`;
369+
str += `\napp.use(store)`;
370+
str += `\napp.mount('#app');`;
371+
377372
// if using typescript, export with .ts extension
378373
if (this.exportAsTypescript === "on") {
379374
fs.writeFileSync(path.join(location, "src", "main.ts"), str);
@@ -445,6 +440,50 @@ export default {
445440
return;
446441
}
447442
},
443+
createStore(location) {
444+
let str = `import { createStore } from 'vuex';\n`;
445+
str += `\nconst store = createStore({`;
446+
str += `\n\tstate () {`;
447+
str += `\n\t\treturn {`;
448+
if (!this.userState.length){
449+
str += `\n\t\t\t//placeholder for state`
450+
}
451+
for (let i = 0; i < this.userState.length; i++){
452+
str+= `\n\t\t\t${this.userState[i]}: "PLACEHOLDER FOR VALUE",`
453+
if (i === this.userState.length-1){str = str.slice(0, -1)}
454+
}
455+
str += `\n\t\t}`;
456+
str += `\n\t},`;
457+
str += `\n\tmutations: {`;
458+
if (!this.userActions.length){
459+
str += `\n\t\t\t//placeholder for mutations`
460+
}
461+
for (let i = 0; i < this.userActions.length; i++){
462+
str += `\n\t\t${this.userActions[i]} (state) {`;
463+
str += `\n\t\t\t//placeholder for your mutation`;
464+
str += `\n\t\t},`;
465+
if (i === this.userActions.length-1){str = str.slice(0, -1)}
466+
}
467+
str += `\n\t},`;
468+
str += `\n\tactions: {`;
469+
if (!this.userActions.length){
470+
str += `\n\t\t\t//placeholder for actions`
471+
}
472+
for (let i = 0; i < this.userActions.length; i++){
473+
str += `\n\t\t${this.userActions[i]} () {`;
474+
str += `\n\t\t\tstore.commit('${this.userActions[i]}')`;
475+
str += `\n\t\t},`;
476+
if (i === this.userActions.length-1){str = str.slice(0, -1)}
477+
}
478+
str += `\n\t}`;
479+
str += '\n})\n';
480+
str += `\nexport default store;`
481+
if (this.exportAsTypescript === "on") {
482+
fs.writeFileSync(path.join(location, "src", "store", "index.ts"), str);
483+
} else {
484+
fs.writeFileSync(path.join(location, "src", "store", "index.js"), str);
485+
}
486+
},
448487
// create package.json file
449488
createPackage(location) {
450489
let str = `{`;
@@ -493,6 +532,7 @@ export default {
493532
fs.mkdirSync(path.join(data, "src", "components"));
494533
fs.mkdirSync(path.join(data, "src", "views"));
495534
fs.mkdirSync(path.join(data, "src", "router"));
535+
fs.mkdirSync(path.join(data, "src", "store"));
496536
}
497537
// creating basic boilerplate for vue app
498538
this.createIndexFile(data);
@@ -503,6 +543,7 @@ export default {
503543
this.createTSViteConfig(data);
504544
this.createTSDeclaration(data);
505545
this.createPackage(data);
546+
this.createStore(data);
506547
// exports images to the /assets folder
507548
// eslint-disable-next-line no-unused-vars
508549
for (let [routeImage, imageLocation] of Object.entries(this.imagePath)) {
@@ -545,7 +586,7 @@ export default {
545586
},
546587
},
547588
computed: {
548-
...mapState(["componentMap", "imagePath", "routes", "exportAsTypescript", "activeComponent"]),
589+
...mapState(["componentMap", "imagePath", "routes", "exportAsTypescript", "activeComponent", "userState", "userActions"]),
549590
},
550591
};
551592
</script>

0 commit comments

Comments
 (0)