Skip to content

Commit 10e4211

Browse files
committed
Fixing issue related with vuex and vue-router. More infor in release description.
1 parent cab03dc commit 10e4211

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

generator/index.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,27 @@ module.exports = (api, options) => {
1414
if (options.tailwind) optionals.addTailwindConfig(api);
1515

1616
api.onCreateComplete(() => {
17-
emptyDirs();
17+
if (!api.hasPlugin("router")) {
18+
const directories = ["views/", "router/"];
19+
emptyDirs([...directories, "components/"], () => false);
20+
for (let dir of directories) fs.rmdirSync(api.resolve(`src/${dir}`));
21+
modifiedFiles.splice(0, 2);
22+
} else {
23+
emptyDirs(["views/", "components/"], (file) => file === "Home.vue");
24+
}
1825
showLogs();
1926
});
2027

21-
function emptyDirs() {
22-
const directories = ["views/", "components/"];
28+
function emptyDirs(directories, exception) {
2329
for (let i = 0; i < directories.length; i++) {
2430
const directory = `src/${directories[i]}`;
2531
const dirPath = api.resolve(directory);
2632
const files = fs.readdirSync(dirPath);
2733
for (const file of files) {
2834
const filePath = path.join(dirPath, file);
29-
if (fs.lstatSync(filePath).isFile()) {
30-
if (file !== "Home.vue") {
31-
fs.unlinkSync(filePath);
32-
deletedFiles.push(file);
33-
}
35+
if (fs.lstatSync(filePath).isFile() && !exception(file)) {
36+
fs.unlinkSync(filePath);
37+
deletedFiles.push(`${directory + file}`);
3438
}
3539
}
3640
}

optionals/baseComponents/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
const fs = require("fs");
22
const path = require("path");
3-
3+
44
module.exports = function addBaseComponents(api) {
55
const root = api.resolve("src/../");
66
fs.copyFileSync(path.join(__dirname, "resources/icons.svg"), path.join(root, "public/icons.svg"));
7+
const addPlugin = (plugin, option) => {
8+
if (api.hasPlugin(plugin)) {
9+
if (!option) option = plugin;
10+
api.injectImports(api.entryFile, `import ${option} from "./${option}"`);
11+
api.injectRootOptions(api.entryFile, `${option}`);
12+
}
13+
}
714

815
api.extendPackage({
916
devDependencies: {
@@ -12,6 +19,9 @@ module.exports = function addBaseComponents(api) {
1219
});
1320

1421
api.render("./template");
22+
addPlugin("vuex", "store");
23+
addPlugin("router");
24+
1525
createdFiles.push("public/icons.svg");
1626
createdFiles.push("src/components/base/BaseIcon.vue");
1727
if (!modifiedFiles.includes(`${api.entryFile}`)) modifiedFiles.push(`${api.entryFile}`);

optionals/baseComponents/template/src/main.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import Vue from "vue";
22
import App from "./App.vue";
3-
import router from "./router";
4-
import store from "./store";
53
import upperFirst from "lodash/upperFirst";
64
import camelCase from "lodash/camelCase";
75

@@ -27,7 +25,5 @@ requireComponent.keys().forEach(fileName => {
2725
});
2826

2927
new Vue({
30-
router,
31-
store,
3228
render: h => h(App),
3329
}).$mount("#app");

0 commit comments

Comments
 (0)