@vc-shell/create-vc-app 1.0.127 → 1.0.129

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/index.js +134 -169
  3. package/dist/templates/base/_env +1 -3
  4. package/dist/templates/base/package.json +28 -27
  5. package/dist/templates/base/src/pages/App.vue +116 -0
  6. package/dist/templates/base/src/router/index.ts +5 -113
  7. package/dist/templates/base/src/router/routes.ts +67 -0
  8. package/dist/templates/base/tailwind.config.ts +7 -0
  9. package/dist/templates/base/{vite.config.ts → vite.config.mts} +7 -7
  10. package/dist/templates/variants/both/src/main.ts +7 -6
  11. package/dist/templates/variants/both/src/modules/classic-module/pages/details.vue +1 -0
  12. package/dist/templates/variants/both/src/modules/classic-module/pages/list.vue +7 -0
  13. package/dist/templates/variants/both/src/modules/dynamic-module/composables/useList/index.ts +2 -2
  14. package/dist/templates/variants/both/src/modules/dynamic-module/pages/list.ts +5 -0
  15. package/dist/templates/variants/classic/src/main.ts +7 -6
  16. package/dist/templates/variants/classic/src/modules/classic-module/pages/list.vue +7 -0
  17. package/dist/templates/variants/dynamic/src/main.ts +7 -6
  18. package/dist/templates/variants/dynamic/src/modules/dynamic-module/composables/useList/index.ts +2 -2
  19. package/dist/templates/variants/dynamic/src/modules/dynamic-module/pages/list.ts +5 -0
  20. package/package.json +7 -5
  21. package/dist/index.js.map +0 -1
  22. package/dist/templates/base/tailwind.config.js +0 -7
  23. package/dist/templates/variants/both/src/pages/App.vue +0 -369
  24. package/dist/templates/variants/classic/src/pages/App.vue +0 -362
  25. package/dist/templates/variants/dynamic/src/pages/App.vue +0 -362
  26. package/dist/tsconfig.tsbuildinfo +0 -1
  27. /package/dist/templates/base/{postcss.config.js → postcss.config.cjs} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## [1.0.129](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.128...v1.0.129) (2023-12-27)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **sample:** update dependencies in package.json ([5c3e4a0](https://github.com/VirtoCommerce/vc-shell/commit/5c3e4a0ada021acc60480f1f57a0f599fa11a2db))
7
+
8
+
9
+ ### Features
10
+
11
+ * **create-vc-app:** build as es6 module ([0452713](https://github.com/VirtoCommerce/vc-shell/commit/04527133e1e6351f1d5f6440b50e57b2b6fa1966))
12
+
13
+
14
+
15
+ ## [1.0.128](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.127...v1.0.128) (2023-12-14)
16
+
17
+
18
+
1
19
  ## [1.0.127](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.126...v1.0.127) (2023-12-13)
2
20
 
3
21
 
package/dist/index.js CHANGED
@@ -1,182 +1,147 @@
1
1
  #!/usr/bin/env node
2
- import prompts from "prompts";
3
- import mri from "mri";
4
- import { default as chalk } from "chalk";
5
- import path from "path";
6
- import fs from "fs";
7
- import { fileURLToPath } from "node:url";
8
- const renameFiles = {
9
- _gitignore: ".gitignore",
10
- "_yarnrc.yml": ".yarnrc.yml",
11
- _browserslistrc: ".browserslistrc",
12
- "_commitlintrc.json": ".commitlintrc.json",
13
- _editorconfig: ".editorconfig",
14
- _env: ".env",
15
- _eslintignore: ".eslintignore",
16
- _prettierignore: ".prettierignore",
17
- _prettierrc: ".prettierrc",
18
- "_eslintrc.js": ".eslintrc.js",
19
- _github: "github",
20
- _husky: ".husky",
21
- _vscode: ".vscode",
22
- _yarn: ".yarn",
2
+ import k from "prompts";
3
+ import N from "mri";
4
+ import o from "chalk";
5
+ import i from "node:path";
6
+ import r from "node:fs";
7
+ import { fileURLToPath as $ } from "node:url";
8
+ import { cwd as x, argv as C, exit as F } from "node:process";
9
+ const P = {
10
+ _gitignore: ".gitignore",
11
+ "_yarnrc.yml": ".yarnrc.yml",
12
+ _browserslistrc: ".browserslistrc",
13
+ "_commitlintrc.json": ".commitlintrc.json",
14
+ _editorconfig: ".editorconfig",
15
+ _env: ".env",
16
+ _eslintignore: ".eslintignore",
17
+ _prettierignore: ".prettierignore",
18
+ _prettierrc: ".prettierrc",
19
+ "_eslintrc.js": ".eslintrc.js",
20
+ _github: "github",
21
+ _husky: ".husky",
22
+ _vscode: ".vscode",
23
+ _yarn: ".yarn"
23
24
  };
24
- function isValidName(appName) {
25
- return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(appName);
25
+ function h(t) {
26
+ return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(t);
26
27
  }
27
- function toValidName(appName) {
28
- return appName
29
- .trim()
30
- .toLowerCase()
31
- .replace(/\s+/g, "-")
32
- .replace(/^[._]/, "")
33
- .replace(/[^a-z0-9-~]+/g, "-");
28
+ function d(t) {
29
+ return t.trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z0-9-~]+/g, "-");
34
30
  }
35
- function emptyDir(dir) {
36
- if (!fs.existsSync(dir)) {
37
- return;
38
- }
31
+ function z(t) {
32
+ r.existsSync(t);
39
33
  }
40
- function isEmpty(path) {
41
- const files = fs.readdirSync(path);
42
- return files.length === 0 || (files.length === 1 && files[0] === ".git");
34
+ function D(t) {
35
+ const a = r.readdirSync(t);
36
+ return a.length === 0 || a.length === 1 && a[0] === ".git";
43
37
  }
44
- function copy(src, dest) {
45
- const stat = fs.statSync(src);
46
- if (stat.isDirectory()) {
47
- copyDir(src, dest);
48
- }
49
- else {
50
- fs.copyFileSync(src, dest);
51
- }
38
+ function _(t, a) {
39
+ r.statSync(t).isDirectory() ? E(t, a) : r.copyFileSync(t, a);
52
40
  }
53
- function copyDir(srcDir, destDir) {
54
- fs.mkdirSync(destDir, { recursive: true });
55
- for (const file of fs.readdirSync(srcDir)) {
56
- const srcFile = path.resolve(srcDir, file);
57
- const destFile = path.resolve(destDir, file);
58
- copy(srcFile, destFile);
59
- }
41
+ function E(t, a) {
42
+ r.mkdirSync(a, { recursive: !0 });
43
+ for (const n of r.readdirSync(t)) {
44
+ const m = i.resolve(t, n), c = i.resolve(a, n);
45
+ _(m, c);
46
+ }
60
47
  }
61
- const AppVariants = [
62
- {
63
- name: "classic",
64
- display: "Classic modules boilerplate",
65
- },
66
- {
67
- name: "dynamic",
68
- display: "Dynamic modules boilerplate",
69
- },
70
- {
71
- name: "both",
72
- display: "Classic modules + Dynamic modules boilerplate",
73
- },
74
- ];
75
- const variantMap = {
76
- both: "variants/both",
77
- classic: "variants/classic",
78
- dynamic: "variants/dynamic",
48
+ const O = [
49
+ {
50
+ name: "classic",
51
+ display: "Classic modules boilerplate"
52
+ },
53
+ {
54
+ name: "dynamic",
55
+ display: "Dynamic modules boilerplate"
56
+ },
57
+ {
58
+ name: "both",
59
+ display: "Classic modules + Dynamic modules boilerplate"
60
+ }
61
+ ], R = {
62
+ both: "variants/both",
63
+ classic: "variants/classic",
64
+ dynamic: "variants/dynamic"
79
65
  };
80
- async function create() {
81
- const cwd = process.cwd();
82
- const args = mri(process.argv.slice(2));
83
- let dir = args._[0];
84
- const defaultAppName = !dir ? "vc-app" : dir;
85
- const getProjectName = () => (dir === "." ? path.basename(path.resolve()) : dir);
86
- let config;
87
- try {
88
- config = await prompts([
89
- {
90
- name: "appName",
91
- type: dir ? null : "text",
92
- message: chalk.reset("Project name:"),
93
- initial: defaultAppName,
94
- onState: (state) => (dir = toValidName(String(state.value).trim()) || defaultAppName),
95
- format: (value) => toValidName(String(value).trim()),
96
- },
97
- {
98
- type: () => (!fs.existsSync(dir) || isEmpty(dir) ? null : "confirm"),
99
- name: "overwrite",
100
- message: () => (dir === "." ? "Current directory" : `Target directory "${dir}"`) +
101
- ` is not empty. Remove existing files and continue?`,
102
- },
103
- {
104
- type: (_, { overwrite }) => {
105
- if (overwrite === false) {
106
- throw new Error(chalk.red("✖") + " Operation cancelled");
107
- }
108
- return null;
109
- },
110
- name: "overwriteChecker",
111
- },
112
- {
113
- name: "packageName",
114
- type: () => (isValidName(getProjectName()) ? null : "text"),
115
- message: chalk.reset("Package name:"),
116
- initial: () => toValidName(getProjectName()),
117
- validate: (dir) => isValidName(dir) || "Invalid package.json name",
118
- },
119
- {
120
- type: "select",
121
- name: "variant",
122
- message: chalk.reset("Select module variant:"),
123
- choices: AppVariants.map((variant) => {
124
- return {
125
- title: variant.display,
126
- value: variant.name,
127
- };
128
- }),
129
- },
130
- ], {
131
- onCancel: () => {
132
- throw new Error(chalk.red("✖") + " Creation cancelled");
133
- },
134
- });
135
- }
136
- catch (e) {
137
- console.log(e.message);
138
- process.exit(1);
139
- }
140
- const { packageName, variant } = config;
141
- const root = path.join(cwd, dir);
142
- if (fs.existsSync(root)) {
143
- emptyDir(root);
144
- }
145
- else if (!fs.existsSync(root)) {
146
- fs.mkdirSync(root);
147
- }
148
- console.log(`\nScaffolding app in ${root}...`);
149
- const templateRoot = path.resolve(fileURLToPath(import.meta.url), "..", "templates");
150
- const write = (file, templateName, content) => {
151
- const targetPath = path.join(root, renameFiles[file] ?? file);
152
- if (content) {
153
- fs.writeFileSync(targetPath, content);
66
+ async function V() {
67
+ const t = x();
68
+ let n = N(C.slice(2))._[0];
69
+ const m = n || "vc-app", c = () => n === "." ? i.basename(i.resolve()) : n;
70
+ let f;
71
+ try {
72
+ f = await k(
73
+ [
74
+ {
75
+ name: "appName",
76
+ type: n ? null : "text",
77
+ message: o.reset("Project name:"),
78
+ initial: m,
79
+ onState: (e) => n = d(String(e.value).trim()) || m,
80
+ format: (e) => d(String(e).trim())
81
+ },
82
+ {
83
+ type: () => !r.existsSync(n) || D(n) ? null : "confirm",
84
+ name: "overwrite",
85
+ message: () => (n === "." ? "Current directory" : `Target directory "${n}"`) + " is not empty. Remove existing files and continue?"
86
+ },
87
+ {
88
+ type: (e, { overwrite: l }) => {
89
+ if (l === !1)
90
+ throw new Error(o.red("✖") + " Operation cancelled");
91
+ return null;
92
+ },
93
+ name: "overwriteChecker"
94
+ },
95
+ {
96
+ name: "packageName",
97
+ type: () => h(c()) ? null : "text",
98
+ message: o.reset("Package name:"),
99
+ initial: () => d(c()),
100
+ validate: (e) => h(e) || "Invalid package.json name"
101
+ },
102
+ {
103
+ type: "select",
104
+ name: "variant",
105
+ message: o.reset("Select module variant:"),
106
+ choices: O.map((e) => ({
107
+ title: e.display,
108
+ value: e.name
109
+ }))
154
110
  }
155
- else {
156
- copy(path.join(templateRoot, templateName, file), targetPath);
111
+ ],
112
+ {
113
+ onCancel: () => {
114
+ throw new Error(o.red("✖") + " Creation cancelled");
157
115
  }
158
- };
159
- const render = (templateName) => {
160
- const templateDir = path.resolve(templateRoot, templateName);
161
- const files = fs.readdirSync(templateDir);
162
- for (const file of files.filter((f) => f !== "package.json")) {
163
- write(file, templateName);
164
- }
165
- };
166
- render("base");
167
- render(variantMap[variant]);
168
- const pkg = JSON.parse(fs.readFileSync(path.join(templateRoot, `./base/package.json`), "utf-8"));
169
- pkg.name = packageName || getProjectName();
170
- write("package.json", "", JSON.stringify(pkg, null, 2) + "\n");
171
- console.log(`\nDone. You can now run application:\n`);
172
- if (root !== cwd) {
173
- const cdProjectName = path.relative(cwd, root);
174
- console.log(` ${chalk.bold(chalk.green(`cd ${cdProjectName.includes(" ") ? `"${cdProjectName}"` : cdProjectName}`))}`);
175
- }
176
- console.log(` ${chalk.bold(chalk.green("yarn"))}`);
177
- console.log(` ${chalk.bold(chalk.green("yarn serve"))}`);
116
+ }
117
+ );
118
+ } catch (e) {
119
+ console.log(e.message), F(1);
120
+ }
121
+ const { packageName: b, variant: j } = f, s = i.join(t, n);
122
+ r.existsSync(s) ? z(s) : r.existsSync(s) || r.mkdirSync(s), console.log(`
123
+ Scaffolding app in ${s}...`);
124
+ const y = i.resolve($(import.meta.url), "..", "templates"), u = (e, l, p) => {
125
+ const g = i.join(s, P[e] ?? e);
126
+ p ? r.writeFileSync(g, p) : _(i.join(y, l, e), g);
127
+ }, v = (e) => {
128
+ const l = i.resolve(y, e), p = r.readdirSync(l);
129
+ for (const g of p.filter((w) => w !== "package.json"))
130
+ u(g, e);
131
+ };
132
+ v("base"), v(R[j]);
133
+ const S = JSON.parse(r.readFileSync(i.join(y, "./base/package.json"), "utf-8"));
134
+ if (S.name = b || c(), u("package.json", "", JSON.stringify(S, null, 2) + `
135
+ `), console.log(`
136
+ Done. You can now run application:
137
+ `), s !== t) {
138
+ const e = i.relative(t, s);
139
+ console.log(
140
+ ` ${o.bold(o.green(`cd ${e.includes(" ") ? `"${e}"` : e}`))}`
141
+ );
142
+ }
143
+ console.log(` ${o.bold(o.green("yarn"))}`), console.log(` ${o.bold(o.green("yarn serve"))}`);
178
144
  }
179
- create().catch((e) => {
180
- console.error(e);
145
+ V().catch((t) => {
146
+ console.error(t);
181
147
  });
182
- //# sourceMappingURL=index.js.map
@@ -1,4 +1,2 @@
1
- APP_LOG_ENABLED=true
2
- APP_LOG_LEVEL=debug
3
- APP_PLATFORM_URL=https://vcmp-dev.paas.govirto.com/
1
+ #APP_PLATFORM_URL=add_platform_url_here
4
2
  APP_BASE_PATH=/apps/application/
@@ -17,51 +17,52 @@
17
17
  "devDependencies": {
18
18
  "@commitlint/cli": "^17.6.3",
19
19
  "@commitlint/config-conventional": "^17.6.3",
20
- "@rollup/plugin-typescript": "^11.1.1",
20
+ "@laynezh/vite-plugin-lib-assets": "^0.5.6",
21
+ "@rollup/plugin-typescript": "^11.1.5",
21
22
  "@types/lodash-es": "^4.17.7",
22
- "@typescript-eslint/eslint-plugin": "^5.59.7",
23
- "@typescript-eslint/parser": "^5.59.7",
24
- "@vc-shell/api-client-generator": "^1.0.127",
25
- "@vc-shell/ts-config": "^1.0.127",
26
- "@vitejs/plugin-vue": "^4.2.3",
27
- "@vue/eslint-config-prettier": "^7.1.0",
28
- "@vue/eslint-config-typescript": "^11.0.3",
23
+ "@typescript-eslint/eslint-plugin": "^6.13.2",
24
+ "@typescript-eslint/parser": "^6.13.2",
25
+ "@vc-shell/api-client-generator": "^1.0.129",
26
+ "@vc-shell/release-config": "^1.0.128",
27
+ "@vc-shell/ts-config": "^1.0.129",
28
+ "@vitejs/plugin-vue": "^4.5.1",
29
+ "@vue/eslint-config-prettier": "^8.0.0",
30
+ "@vue/eslint-config-typescript": "^12.0.0",
29
31
  "autoprefixer": "^10.4.14",
30
- "buffer-esm": "^1.2.0",
31
32
  "conventional-changelog-cli": "^2.2.2",
32
33
  "cross-env": "^7.0.3",
33
34
  "eslint": "^8.41.0",
34
- "eslint-import-resolver-typescript": "^3.5.5",
35
- "eslint-plugin-import": "^2.27.5",
36
- "eslint-plugin-prettier": "^4.2.1",
37
- "eslint-plugin-vue": "^9.14.1",
35
+ "eslint-import-resolver-typescript": "^3.6.1",
36
+ "eslint-plugin-import": "^2.29.0",
37
+ "eslint-plugin-prettier": "^5.0.1",
38
+ "eslint-plugin-vue": "^9.19.2",
38
39
  "husky": "^8.0.3",
39
40
  "lint-staged": "^13.2.2",
40
41
  "lodash-es": "^4.17.21",
41
- "postcss": "^8.4.23",
42
- "prettier": "^2.8.8",
42
+ "postcss": "^8.4.32",
43
+ "prettier": "^3.1.0",
43
44
  "querystring-es3": "^0.2.1",
44
- "sass": "^1.62.1",
45
+ "sass": "^1.69.5",
45
46
  "tailwindcss": "^3.3.2",
46
47
  "tsx": "^3.13.0",
47
- "typescript": "~5.0.4",
48
- "vite": "^4.3.9",
48
+ "typescript": "5.3.3",
49
+ "vite": "4.5.0",
49
50
  "vite-plugin-checker": "^0.6.0",
50
51
  "vite-plugin-mkcert": "^1.15.0",
51
- "vite-plugin-pwa": "^0.16.5",
52
- "vue-eslint-parser": "^9.3.0",
53
- "vue-tsc": "^1.8.20"
52
+ "vite-plugin-pwa": "^0.17.3",
53
+ "vue-eslint-parser": "^9.3.2",
54
+ "vue-tsc": "^1.8.25"
54
55
  },
55
56
  "dependencies": {
56
57
  "@fortawesome/fontawesome-free": "^5.15.3",
57
- "@vc-shell/config-generator": "^1.0.127",
58
- "@vc-shell/framework": "^1.0.127",
59
- "@vueuse/core": "^10.1.2",
60
- "@vueuse/integrations": "^10.1.2",
58
+ "@vc-shell/config-generator": "^1.0.129",
59
+ "@vc-shell/framework": "^1.0.129",
60
+ "@vueuse/core": "^10.7.0",
61
+ "@vueuse/integrations": "^10.7.0",
61
62
  "moment": "^2.29.4",
62
63
  "roboto-fontface": "^0.10.0",
63
- "vee-validate": "^4.9.4",
64
- "vue": "^3.3.7",
64
+ "vee-validate": "^4.11.8",
65
+ "vue": "3.3.13",
65
66
  "vue-router": "^4.2.5"
66
67
  },
67
68
  "lint-staged": {
@@ -0,0 +1,116 @@
1
+ <template>
2
+ <VcApp
3
+ :is-ready="isReady"
4
+ :logo="uiSettings.logo"
5
+ :title="uiSettings.title"
6
+ :version="version"
7
+ >
8
+ </VcApp>
9
+ </template>
10
+
11
+ <script lang="ts" setup>
12
+ import { useSettings, useUser } from "@vc-shell/framework";
13
+ import { onMounted, ref, watch } from "vue";
14
+ // eslint-disable-next-line import/no-unresolved
15
+ import logoImage from "/assets/logo.svg";
16
+
17
+ const { uiSettings, applySettings } = useSettings();
18
+ const isReady = ref(false);
19
+ const version = import.meta.env.PACKAGE_VERSION;
20
+
21
+ const { isAuthenticated } = useUser();
22
+
23
+ onMounted(async () => {
24
+ try {
25
+ if (isAuthenticated.value) {
26
+ await customizationHandler();
27
+
28
+ isReady.value = true;
29
+ }
30
+ } catch (e) {
31
+ console.log(e);
32
+ throw e;
33
+ }
34
+ });
35
+
36
+ console.debug(`Initializing App`);
37
+
38
+ async function customizationHandler() {
39
+ applySettings({
40
+ title: uiSettings.value?.title || undefined,
41
+ logo: uiSettings.value?.logo || logoImage,
42
+ });
43
+ }
44
+ </script>
45
+
46
+ <style lang="scss">
47
+ :root {
48
+ --background-color: #f5f6f9;
49
+ --top-bar-color: #161d25;
50
+ --basic-black-color: #333333;
51
+ --tooltips-color: #a5a5a5;
52
+
53
+ --primary-color: #43b0e6;
54
+ --primary-color-hover: #319ed4;
55
+ --primary-color-disabled: #a9ddf6;
56
+
57
+ --special-color: #f89406;
58
+ --special-color-hover: #eb8b03;
59
+ --special-color-disabled: #fed498;
60
+
61
+ /* Layout variables */
62
+ --app-bar-background-color: var(--top-bar-color);
63
+ --app-bar-toolbar-icon-background-hover: #2e3d4e;
64
+ --app-bar-toolbar-item-width: 50px;
65
+ --app-bar-toolbar-icon-color: #7e8e9d;
66
+ --app-bar-account-info-role-color: #838d9a;
67
+
68
+ --background-color: #f2f2f2;
69
+ --top-bar-color: #ffffff;
70
+ --app-background: linear-gradient(180deg, #e4f5fb 5.06%, #e8f3f2 100%), linear-gradient(0deg, #e8f2f3, #e8f2f3),
71
+ #eef2f8;
72
+ --app-bar-background-color: #ffffff;
73
+ --app-bar-divider-color: #ffffff;
74
+ --app-bar-toolbar-item-width: 50px;
75
+ --app-bar-toolbar-icon-color: #7e8e9d;
76
+ --app-bar-toolbar-icon-color-hover: #465769;
77
+ --app-bar-toolbar-icon-background-hover: #ffffff;
78
+ --app-bar-account-info-name-color: #161d25;
79
+ --app-bar-account-info-role-color: #7e8e9d;
80
+ }
81
+
82
+ html,
83
+ body,
84
+ #app {
85
+ @apply tw-font-roboto tw-h-full tw-w-full tw-m-0 tw-fixed tw-overflow-hidden tw-overscroll-y-none;
86
+ }
87
+
88
+ body {
89
+ @apply tw-text-base;
90
+ }
91
+
92
+ h1,
93
+ h2,
94
+ h3,
95
+ h4,
96
+ h5,
97
+ h6,
98
+ button,
99
+ input,
100
+ select,
101
+ textarea {
102
+ @apply tw-font-roboto;
103
+ }
104
+ ::-webkit-input-placeholder {
105
+ @apply tw-font-roboto;
106
+ }
107
+ :-moz-placeholder {
108
+ @apply tw-font-roboto;
109
+ }
110
+ ::-moz-placeholder {
111
+ @apply tw-font-roboto;
112
+ }
113
+ :-ms-input-placeholder {
114
+ @apply tw-font-roboto;
115
+ }
116
+ </style>
@@ -1,118 +1,10 @@
1
- import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
2
- import { inject } from "vue";
3
- import { useLogin } from "../composables";
4
- import {
5
- usePermissions,
6
- useUser,
7
- BladePageComponent,
8
- notification,
9
- useBladeNavigation,
10
- Login,
11
- ResetPassword,
12
- Invite,
13
- } from "@vc-shell/framework";
1
+ import { createRouter, createWebHashHistory } from "vue-router";
14
2
 
15
- /**
16
- * Pages
17
- */
18
- import Dashboard from "../pages/Dashboard.vue";
19
- // eslint-disable-next-line import/no-unresolved
20
- import App from "./../pages/App.vue";
21
-
22
- // eslint-disable-next-line import/no-unresolved
23
- import whiteLogoImage from "/assets/logo-white.svg";
24
- // eslint-disable-next-line import/no-unresolved
25
- import bgImage from "/assets/background.jpg";
26
-
27
- const routes: RouteRecordRaw[] = [
28
- {
29
- path: "/",
30
- component: App,
31
- name: "App",
32
- meta: {
33
- root: true,
34
- },
35
- children: [
36
- {
37
- name: "Dashboard",
38
- path: "",
39
- alias: "/",
40
- component: Dashboard,
41
- },
42
- ],
43
- },
44
- {
45
- path: "/login",
46
- name: "Login",
47
- component: Login,
48
- props: () => ({
49
- composable: useLogin,
50
- logo: whiteLogoImage,
51
- background: bgImage,
52
- title: "application",
53
- }),
54
- },
55
- {
56
- name: "invite",
57
- path: "/invite",
58
- component: Invite,
59
- props: (route) => ({
60
- userId: route.query.userId,
61
- token: route.query.token,
62
- userName: route.query.userName,
63
- }),
64
- },
65
- {
66
- name: "resetpassword",
67
- path: "/resetpassword",
68
- component: ResetPassword,
69
- props: (route) => ({
70
- userId: route.query.userId,
71
- token: route.query.token,
72
- userName: route.query.userName,
73
- }),
74
- },
75
- {
76
- path: "/:pathMatch(.*)*",
77
- component: App,
78
- beforeEnter: (to) => {
79
- const { resolveUnknownRoutes } = useBladeNavigation();
80
-
81
- return resolveUnknownRoutes(to);
82
- },
83
- },
84
- ];
3
+ import { routes } from "./routes";
85
4
 
86
5
  export const router = createRouter({
87
- history: createWebHashHistory(import.meta.env.APP_BASE_PATH as string),
88
- routes,
6
+ history: createWebHashHistory(import.meta.env.APP_BASE_PATH),
7
+ routes: [],
89
8
  });
90
9
 
91
- router.beforeEach(async (to, from) => {
92
- const { hasAccess } = usePermissions();
93
- const { resolveBlades } = useBladeNavigation();
94
- const { isAuthenticated } = useUser();
95
- const pages = inject<BladePageComponent[]>("pages");
96
-
97
- if (to.name !== "Login" && to.name !== "ResetPassword" && to.name !== "Invite") {
98
- try {
99
- const component = pages.find((blade) => blade?.url === to.path);
100
-
101
- const _hasAccess = hasAccess(component?.permissions);
102
-
103
- if (!(await isAuthenticated()) && to.name !== "Login") {
104
- return { name: "Login" };
105
- } else if (_hasAccess && to.name !== "Login") {
106
- const resolvedBladeUrl = resolveBlades(to);
107
- return resolvedBladeUrl ? resolvedBladeUrl : true;
108
- } else if (!_hasAccess) {
109
- notification.error("Access restricted", {
110
- timeout: 3000,
111
- });
112
- return from.path;
113
- }
114
- } catch (e) {
115
- return { name: "Login" };
116
- }
117
- } else return true;
118
- });
10
+ routes.forEach((route) => router.addRoute(route));