Skip to content

Commit e0c80af

Browse files
authored
Merge pull request #150 from open-source-labs/bryan/vuexStore
Now exporting Vuex boilerplate for both TS and JS. Store will be popu…
2 parents 32b6ade + 647c703 commit e0c80af

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
@@ -369,13 +369,14 @@ export default {
369369
// creates main.js boilerplate
370370
createMainFile(location) {
371371
let str = `import { createApp } from 'vue';`;
372+
str += `\nimport store from './store'`
372373
str += `\nimport App from './App.vue';`;
373-
str += `\nimport router from './router';`;
374-
// str += `\n\n import './index.css'`
375-
str += `\n\n const app = createApp(App);`;
376-
// str += `\n\trouter,
374+
str += `\nimport router from './router';\n`;
375+
str += `\nconst app = createApp(App);`;
377376
str += `\napp.use(router);`;
378-
str += `\n app.mount('#app');`;
377+
str += `\napp.use(store)`;
378+
str += `\napp.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 += `\nconst store = createStore({`;
454+
str += `\n\tstate () {`;
455+
str += `\n\t\treturn {`;
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\tmutations: {`;
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\tactions: {`;
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\tstore.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 += `\nexport 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

Comments
 (0)