@vc-shell/framework 1.0.252 → 1.0.254

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## [1.0.254](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.253...v1.0.254) (2024-07-12)
2
+
3
+
4
+ ### Features
5
+
6
+ * dynamic module loader ([4d15575](https://github.com/VirtoCommerce/vc-shell/commit/4d15575bb5448e16b4034782bafc7097189742f1))
7
+
8
+
9
+
10
+ ## [1.0.253](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.252...v1.0.253) (2024-07-12)
11
+
12
+
13
+ ### Features
14
+
15
+ * **shared:** update login logic to redirect to the previous page after successful login ([8701044](https://github.com/VirtoCommerce/vc-shell/commit/8701044315a7b13609474e00e83a069d542bb256))
16
+
17
+
18
+
1
19
  ## [1.0.252](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.251...v1.0.252) (2024-07-08)
2
20
 
3
21
 
@@ -137,3 +137,5 @@ export const createAppModule = (
137
137
  },
138
138
  };
139
139
  };
140
+
141
+ export * from "./loader";
@@ -0,0 +1,97 @@
1
+ import { App, Plugin } from "vue";
2
+ import { Router } from "vue-router";
3
+
4
+ interface ModuleManifest {
5
+ file: string;
6
+ name: string;
7
+ src: string;
8
+ isEntry: boolean;
9
+ }
10
+
11
+ interface CssManifest {
12
+ file: string;
13
+ src: string;
14
+ }
15
+
16
+ interface Manifest {
17
+ [key: string]: ModuleManifest | CssManifest;
18
+ }
19
+
20
+ interface Apps {
21
+ [x: string]: {
22
+ modules: { id: string; url: string }[];
23
+ };
24
+ }
25
+
26
+ function loadCSS(url: string) {
27
+ return new Promise<void>((resolve, reject) => {
28
+ const link = document.createElement("link");
29
+ link.rel = "stylesheet";
30
+ link.href = url;
31
+ link.onload = () => resolve();
32
+ link.onerror = () => reject(new Error(`Failed to load CSS: ${url}`));
33
+ document.head.appendChild(link);
34
+ });
35
+ }
36
+
37
+ export function useDynamicModules(app: App, { router, appName }: { router: Router; appName: string }) {
38
+ if (!appName) return;
39
+
40
+ async function load() {
41
+ try {
42
+ const appsUrl = "/Modules/$(VirtoCommerce.MarketplaceVendor)/Content/apps.json";
43
+ const modules: Apps[] = await fetch(appsUrl).then((res) => res.json());
44
+
45
+ for (const module of modules) {
46
+ const appModules = module[appName].modules;
47
+
48
+ if (!appModules.length) {
49
+ throw new Error("Modules not found");
50
+ }
51
+
52
+ for (const module of appModules) {
53
+ const moduleUrl = module.url.replace(/^([^/])/, "/$1").replace(/([^/])$/, "$1/");
54
+ const manifestResponse = await fetch(moduleUrl + "manifest.json");
55
+
56
+ if (!manifestResponse.ok) {
57
+ throw new Error(`Failed to load manifest: ${manifestResponse.statusText}`);
58
+ }
59
+
60
+ const manifest: Manifest = await manifestResponse.json();
61
+
62
+ // Find entry point
63
+ const entry = Object.values(manifest).find((file) => (file as ModuleManifest).isEntry);
64
+
65
+ if (!entry) {
66
+ throw new Error("Entry file not found");
67
+ }
68
+
69
+ await Promise.all(
70
+ Object.values(manifest)
71
+ .filter((file) => file.file.endsWith(".css"))
72
+ .map((file) => loadCSS(moduleUrl + `${file.file}`)),
73
+ ).catch((error) => {
74
+ console.error("Failed to load styles", error);
75
+ });
76
+
77
+ await import(/* @vite-ignore */ moduleUrl + entry.file).catch((error) => {
78
+ console.error("Failed to load module", error);
79
+ });
80
+
81
+ Object.values(window.VcShellDynamicModules).forEach((mod) => {
82
+ app.use((mod as Record<"default", Plugin>)?.default, { router });
83
+ });
84
+
85
+ app.config.globalProperties.$dynamicModules = window.VcShellDynamicModules;
86
+ app.provide("$dynamicModules", app.config.globalProperties.$dynamicModules);
87
+ }
88
+ }
89
+ } catch (error) {
90
+ console.error("Failed to load modules", error);
91
+ }
92
+ }
93
+
94
+ return {
95
+ load,
96
+ };
97
+ }
@@ -19,4 +19,5 @@ export declare const createAppModule: (pages: {
19
19
  router: Router;
20
20
  }): void;
21
21
  };
22
+ export * from "./loader";
22
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../core/plugins/modularity/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAK,MAAM,KAAK,CAAC;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAc,MAAM,qDAAqD,CAAC;AAK3G,eAAO,MAAM,YAAY;;aAAuE,OAAO;iBACxF,GAAG,GAAG,IAAI;CAavB,CAAC;AAEH,eAAO,MAAM,eAAe;;;;;;;;;iBAOX,GAAG,YAAY;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;CA2GxD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../core/plugins/modularity/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAK,MAAM,KAAK,CAAC;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAc,MAAM,qDAAqD,CAAC;AAK3G,eAAO,MAAM,YAAY;;aAAuE,OAAO;iBACxF,GAAG,GAAG,IAAI;CAavB,CAAC;AAEH,eAAO,MAAM,eAAe;;;;;;;;;iBAOX,GAAG,YAAY;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;CA2GxD,CAAC;AAEF,cAAc,UAAU,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { App } from "vue";
2
+ import { Router } from "vue-router";
3
+ export declare function useDynamicModules(app: App, { router, appName }: {
4
+ router: Router;
5
+ appName: string;
6
+ }): {
7
+ load: () => Promise<void>;
8
+ } | undefined;
9
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../../core/plugins/modularity/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAU,MAAM,KAAK,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAmCpC,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE;;cA4DnG"}