@vnejs/core 0.2.14 → 0.2.16

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/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
+ import "@vnejs/plugins.core.storage.contract";
2
+ import "@vnejs/plugins.core.system.contract";
1
3
  import { Observer } from "@vnejs/observer";
2
4
  import { type ModuleGlobalStateRegistry } from "@vnejs/module";
3
5
  import type { VneModuleClass } from "@vnejs/shared";
4
6
  import type { ModuleShared, VneCoreModules } from "./types.js";
5
- export type { ModuleMedia, ModuleShared, VneCoreModules } from "./types.js";
7
+ export type { ModInfo, ModuleMedia, ModuleShared, VneCoreModules } from "./types.js";
6
8
  export declare class VneCore {
7
9
  observer: Observer;
8
10
  modules: VneCoreModules;
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import "@vnejs/plugins.core.storage.contract";
2
+ import "@vnejs/plugins.core.system.contract";
1
3
  import { Observer } from "@vnejs/observer";
2
4
  import { VNE, VNE_MODULES } from "@vnejs/shared";
3
5
  import { toJson } from "@vnejs/helpers";
@@ -14,7 +16,9 @@ export class VneCore {
14
16
  const CONST = VNE.CONST;
15
17
  const ts = Math.round(new Date().getTime() / 1000 / 60 / 60);
16
18
  const mods = (await fetch(`${CONST.SYSTEM.HOST}/mods.json?ts=${ts}`).then(toJson));
17
- const fetchResult = await Promise.all(mods.map((mod) => fetch(`${CONST.SYSTEM.HOST}/media.${mod}.json?ts=${ts}`).then(toJson)));
19
+ const fetchResult = await Promise.all(Object.entries(mods)
20
+ .filter(([, mod]) => mod.hasMediaDir)
21
+ .map(([mod]) => fetch(`${CONST.SYSTEM.HOST}/media.${mod}.json?ts=${ts}`).then(toJson)));
18
22
  const media = fetchResult.reduce(mergeFetchResult, {});
19
23
  const injectArg = { observer: this.observer, state: this.state, shared: this.shared, media };
20
24
  Object.values(this.modules).forEach((module) => {
@@ -36,14 +40,13 @@ export class VneCore {
36
40
  window.uninitedModules = window.uninitedModules.filter((k) => k !== module.name);
37
41
  }));
38
42
  console.log("init modules finish");
39
- const started = VNE.EVENTS.SYSTEM?.STARTED;
40
- if (started)
41
- await this.observer.emit(started);
43
+ const { STARTED } = VNE.EVENTS.SYSTEM;
44
+ await this.observer.emit(STARTED);
42
45
  };
43
46
  reset = async () => {
44
- const EVENTS = VNE.EVENTS;
45
- await this.observer.emit(EVENTS.STORAGE.CLEAR);
46
- await this.observer.emit(EVENTS.SYSTEM.RELOAD);
47
+ const { STORAGE, SYSTEM } = VNE.EVENTS;
48
+ await this.observer.emit(STORAGE.CLEAR);
49
+ await this.observer.emit(SYSTEM.RELOAD);
47
50
  };
48
51
  addModule = (ModuleClass) => {
49
52
  const module = new ModuleClass();
package/dist/types.d.ts CHANGED
@@ -1,23 +1,17 @@
1
1
  import type { Module, ModuleMedia, ModuleShared } from "@vnejs/module";
2
+ import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry } from "@vnejs/shared";
3
+ import type { PluginName as StoragePluginName, SubscribeEvents as StorageSubscribeEvents } from "@vnejs/plugins.core.storage.contract";
4
+ import type { Constants as SystemConstants, PluginName as SystemPluginName, SubscribeEvents as SystemSubscribeEvents } from "@vnejs/plugins.core.system.contract";
2
5
  export type VneCoreModules = Record<string, Module | undefined>;
3
6
  export type { ModuleMedia, ModuleShared };
7
+ export type ModInfo = Record<string, unknown> & {
8
+ hasMediaDir: boolean;
9
+ hasPublicDir: boolean;
10
+ };
11
+ export type CorePluginConstants = VnePluginConstantsMapRegistry & Record<SystemPluginName, SystemConstants>;
12
+ export type CorePluginEvents = VnePluginEventsMapRegistry & Record<SystemPluginName, SystemSubscribeEvents> & Record<StoragePluginName, StorageSubscribeEvents>;
4
13
  declare global {
5
14
  interface Window {
6
15
  uninitedModules: string[];
7
16
  }
8
17
  }
9
- export interface CoreVnePluginEventsMap {
10
- STORAGE: {
11
- CLEAR: string;
12
- };
13
- SYSTEM: {
14
- RELOAD: string;
15
- STARTED: string;
16
- HOST: string;
17
- };
18
- }
19
- export interface CoreVnePluginConstantsMap {
20
- SYSTEM: {
21
- HOST: string;
22
- };
23
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/core",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -26,15 +26,17 @@
26
26
  "@capacitor/splash-screen": "5.0.8",
27
27
  "@capacitor/assets": "3.0.5",
28
28
  "@capacitor/cli": "5.0.2",
29
- "@vnejs/constants": "~0.0.1",
30
- "@vnejs/shared": "~0.0.8",
31
- "@vnejs/semaphore": "~0.0.1",
32
- "@vnejs/build": "~0.0.19",
33
- "@vnejs/desktop": "~0.0.29",
29
+ "@vnejs/constants": "~0.1.0",
30
+ "@vnejs/shared": "~0.1.0",
31
+ "@vnejs/semaphore": "~0.1.0",
32
+ "@vnejs/build": "~0.0.1",
33
+ "@vnejs/desktop": "~0.0.1",
34
34
  "@vnejs/module": "~0.0.1",
35
35
  "@vnejs/module.components": "~0.0.1",
36
- "@vnejs/observer": "~0.0.1",
37
- "@vnejs/helpers": "~0.1.0"
36
+ "@vnejs/observer": "~0.1.0",
37
+ "@vnejs/helpers": "~0.1.0",
38
+ "@vnejs/plugins.core.storage.contract": "~0.0.1",
39
+ "@vnejs/plugins.core.system.contract": "~0.0.1"
38
40
  },
39
41
  "devDependencies": {
40
42
  "@vnejs/configs.ts-common": "~0.0.1"
package/src/index.ts CHANGED
@@ -1,13 +1,16 @@
1
+ import "@vnejs/plugins.core.storage.contract";
2
+ import "@vnejs/plugins.core.system.contract";
3
+
1
4
  import { Observer } from "@vnejs/observer";
2
5
  import { Module, type ModuleGlobalStateRegistry, type ModuleInject } from "@vnejs/module";
3
6
  import { VNE, VNE_MODULES } from "@vnejs/shared";
4
7
  import type { VneModuleClass } from "@vnejs/shared";
5
8
  import { toJson } from "@vnejs/helpers";
6
9
 
7
- import type { CoreVnePluginConstantsMap, CoreVnePluginEventsMap, ModuleMedia, ModuleShared, VneCoreModules } from "./types.js";
10
+ import type { CorePluginConstants, CorePluginEvents, ModInfo, ModuleMedia, ModuleShared, VneCoreModules } from "./types.js";
8
11
  import { mergeFetchResult } from "./utils.js";
9
12
 
10
- export type { ModuleMedia, ModuleShared, VneCoreModules } from "./types.js";
13
+ export type { ModInfo, ModuleMedia, ModuleShared, VneCoreModules } from "./types.js";
11
14
 
12
15
  export class VneCore {
13
16
  observer = new Observer();
@@ -20,11 +23,15 @@ export class VneCore {
20
23
  }
21
24
 
22
25
  init = async () => {
23
- const CONST = VNE.CONST as unknown as CoreVnePluginConstantsMap;
26
+ const CONST = VNE.CONST as CorePluginConstants;
24
27
  const ts = Math.round(new Date().getTime() / 1000 / 60 / 60);
25
28
 
26
- const mods = (await fetch(`${CONST.SYSTEM.HOST}/mods.json?ts=${ts}`).then(toJson)) as string[];
27
- const fetchResult = await Promise.all(mods.map((mod) => fetch(`${CONST.SYSTEM.HOST}/media.${mod}.json?ts=${ts}`).then(toJson) as Promise<ModuleMedia>));
29
+ const mods = (await fetch(`${CONST.SYSTEM.HOST}/mods.json?ts=${ts}`).then(toJson)) as Record<string, ModInfo>;
30
+ const fetchResult = await Promise.all(
31
+ Object.entries(mods)
32
+ .filter(([, mod]) => mod.hasMediaDir)
33
+ .map(([mod]) => fetch(`${CONST.SYSTEM.HOST}/media.${mod}.json?ts=${ts}`).then(toJson) as Promise<ModuleMedia>),
34
+ );
28
35
  const media = fetchResult.reduce(mergeFetchResult, {} as ModuleMedia);
29
36
  const injectArg: ModuleInject = { observer: this.observer, state: this.state, shared: this.shared, media };
30
37
 
@@ -50,15 +57,15 @@ export class VneCore {
50
57
  );
51
58
  console.log("init modules finish");
52
59
 
53
- const started = VNE.EVENTS.SYSTEM?.STARTED;
54
- if (started) await this.observer.emit(started);
60
+ const { STARTED } = (VNE.EVENTS as CorePluginEvents).SYSTEM;
61
+ await this.observer.emit(STARTED);
55
62
  };
56
63
 
57
64
  reset = async () => {
58
- const EVENTS = VNE.EVENTS as unknown as CoreVnePluginEventsMap;
65
+ const { STORAGE, SYSTEM } = VNE.EVENTS as CorePluginEvents;
59
66
 
60
- await this.observer.emit(EVENTS.STORAGE.CLEAR);
61
- await this.observer.emit(EVENTS.SYSTEM.RELOAD);
67
+ await this.observer.emit(STORAGE.CLEAR);
68
+ await this.observer.emit(SYSTEM.RELOAD);
62
69
  };
63
70
 
64
71
  addModule = (ModuleClass: VneModuleClass) => {
package/src/types.ts CHANGED
@@ -1,20 +1,25 @@
1
1
  import type { Module, ModuleMedia, ModuleShared } from "@vnejs/module";
2
+ import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry } from "@vnejs/shared";
3
+ import type { PluginName as StoragePluginName, SubscribeEvents as StorageSubscribeEvents } from "@vnejs/plugins.core.storage.contract";
4
+ import type { Constants as SystemConstants, PluginName as SystemPluginName, SubscribeEvents as SystemSubscribeEvents } from "@vnejs/plugins.core.system.contract";
2
5
 
3
6
  export type VneCoreModules = Record<string, Module | undefined>;
4
7
 
5
8
  export type { ModuleMedia, ModuleShared };
6
9
 
10
+ export type ModInfo = Record<string, unknown> & {
11
+ hasMediaDir: boolean;
12
+ hasPublicDir: boolean;
13
+ };
14
+
15
+ export type CorePluginConstants = VnePluginConstantsMapRegistry & Record<SystemPluginName, SystemConstants>;
16
+
17
+ export type CorePluginEvents = VnePluginEventsMapRegistry &
18
+ Record<SystemPluginName, SystemSubscribeEvents> &
19
+ Record<StoragePluginName, StorageSubscribeEvents>;
20
+
7
21
  declare global {
8
22
  interface Window {
9
23
  uninitedModules: string[];
10
24
  }
11
25
  }
12
-
13
- export interface CoreVnePluginEventsMap {
14
- STORAGE: { CLEAR: string };
15
- SYSTEM: { RELOAD: string; STARTED: string; HOST: string };
16
- }
17
-
18
- export interface CoreVnePluginConstantsMap {
19
- SYSTEM: { HOST: string };
20
- }