diff --git a/package.json b/package.json index fdf8fda64..6c15b9c7b 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "@tachybase/build": "workspace:*", "@tachybase/cli": "workspace:*", "@tachybase/preset-hera-rental": "workspace:*", + "@tachybase/preset-hera-sancongtou": "workspace:*", "@tachybase/preset-tachybase": "workspace:*", "@tachybase/test": "workspace:*", "@types/react": "^18.2.79", diff --git a/packages/core/app/package.json b/packages/core/app/package.json index 3cba914cc..32032b91d 100644 --- a/packages/core/app/package.json +++ b/packages/core/app/package.json @@ -8,7 +8,7 @@ "dependencies": { "@tachybase/database": "workspace:*", "@tachybase/preset-hera-rental": "workspace:*", - "@tachybase/preset-sancongtou": "workspace:*", + "@tachybase/preset-hera-sancongtou": "workspace:*", "@tachybase/preset-tachybase": "workspace:*", "@tachybase/server": "workspace:*" }, diff --git a/packages/core/server/src/plugin-manager/plugin-manager.ts b/packages/core/server/src/plugin-manager/plugin-manager.ts index 2cdc898bb..9e58020f3 100644 --- a/packages/core/server/src/plugin-manager/plugin-manager.ts +++ b/packages/core/server/src/plugin-manager/plugin-manager.ts @@ -1,5 +1,5 @@ import { CleanOptions, Collection, SyncOptions } from '@tachybase/database'; -import { importModule, isURL } from '@tachybase/utils'; +import { Container, importModule, isURL } from '@tachybase/utils'; import { fsExists } from '@tachybase/utils/plugin-symlink'; import execa from 'execa'; import fg from 'fast-glob'; @@ -381,6 +381,10 @@ export class PluginManager { } async load(options: any = {}) { + // FIXME + Container.reset(); + Container.set({ id: 'db', value: this.app.db }); + Container.set({ id: 'app', value: this.app }); this.app.setMaintainingMessage('loading plugins...'); const total = this.pluginInstances.size; diff --git a/packages/plugins/@hera/plugin-core/src/server/plugin.ts b/packages/plugins/@hera/plugin-core/src/server/plugin.ts index 595ef0e24..4362ab039 100644 --- a/packages/plugins/@hera/plugin-core/src/server/plugin.ts +++ b/packages/plugins/@hera/plugin-core/src/server/plugin.ts @@ -32,16 +32,12 @@ export class PluginCoreServer extends Plugin { async load() { await this.pluginDepartments.load(); await this.pluginInterception.load(); - Container.reset(); try { - Container.set({ id: 'db', value: this.db }); - Container.set({ id: 'app', value: this.app }); await Container.get(ConnectionManager).load(); const fontManger = Container.get(FontManager); const sqlLoader = Container.get(SqlLoader); await sqlLoader.loadSqlFiles(path.join(__dirname, './sqls')); await fontManger.loadFonts(); - await Container.get(HomePageService).load(); // init web controllers await Container.get(WebService).load(); this.app.acl.allow('link-manage', 'init', 'public'); @@ -52,6 +48,7 @@ export class PluginCoreServer extends Plugin { } async install(options?: InstallOptions) { await this.pluginDepartments.install(options); + await Container.get(HomePageService).install(); } async afterEnable() {} async afterDisable() {} diff --git a/packages/plugins/@hera/plugin-core/src/server/services/connection-manager.ts b/packages/plugins/@hera/plugin-core/src/server/services/connection-manager.ts index aaa67b4e1..9ff500165 100644 --- a/packages/plugins/@hera/plugin-core/src/server/services/connection-manager.ts +++ b/packages/plugins/@hera/plugin-core/src/server/services/connection-manager.ts @@ -20,7 +20,7 @@ export class ConnectionManager { async unload() { for (const client of [this.redisClient, this.redisPubClient, this.redisSubClient]) { if (client.isOpen) { - await this.redisClient.disconnect(); + await client.disconnect(); } } } @@ -32,6 +32,9 @@ export class ConnectionManager { await this.redisClient.connect(); await this.redisPubClient.connect(); await this.redisSubClient.connect(); + this.app.on('afterStop', () => { + this.unload(); + }); if (isMain()) { const keysToDelete: any = await this.redisClient.KEYS(`${KEY_ONLINE_USERS}*`); if (keysToDelete.length > 0) { diff --git a/packages/plugins/@hera/plugin-core/src/server/services/home-page-service.ts b/packages/plugins/@hera/plugin-core/src/server/services/home-page-service.ts index 27cb4530c..307563aed 100644 --- a/packages/plugins/@hera/plugin-core/src/server/services/home-page-service.ts +++ b/packages/plugins/@hera/plugin-core/src/server/services/home-page-service.ts @@ -10,7 +10,7 @@ export class HomePageService { @Db() private db: Database; - async load() { + async install() { this.app.acl.allow('home_page_presentations', 'list', 'public'); const repo = this.db.getRepository('collections'); if (repo) { diff --git a/packages/presets/hera-rental/.npmignore b/packages/presets/rental/.npmignore similarity index 100% rename from packages/presets/hera-rental/.npmignore rename to packages/presets/rental/.npmignore diff --git a/packages/presets/hera-rental/client.d.ts b/packages/presets/rental/client.d.ts similarity index 100% rename from packages/presets/hera-rental/client.d.ts rename to packages/presets/rental/client.d.ts diff --git a/packages/presets/hera-rental/client.js b/packages/presets/rental/client.js similarity index 100% rename from packages/presets/hera-rental/client.js rename to packages/presets/rental/client.js diff --git a/packages/presets/hera-rental/package.json b/packages/presets/rental/package.json similarity index 100% rename from packages/presets/hera-rental/package.json rename to packages/presets/rental/package.json diff --git a/packages/presets/hera-rental/server.d.ts b/packages/presets/rental/server.d.ts similarity index 100% rename from packages/presets/hera-rental/server.d.ts rename to packages/presets/rental/server.d.ts diff --git a/packages/presets/hera-rental/server.js b/packages/presets/rental/server.js similarity index 100% rename from packages/presets/hera-rental/server.js rename to packages/presets/rental/server.js diff --git a/packages/presets/hera-rental/src/client/index.ts b/packages/presets/rental/src/client/index.ts similarity index 100% rename from packages/presets/hera-rental/src/client/index.ts rename to packages/presets/rental/src/client/index.ts diff --git a/packages/presets/hera-rental/src/index.ts b/packages/presets/rental/src/index.ts similarity index 100% rename from packages/presets/hera-rental/src/index.ts rename to packages/presets/rental/src/index.ts diff --git a/packages/presets/hera-rental/src/server/index.ts b/packages/presets/rental/src/server/index.ts similarity index 53% rename from packages/presets/hera-rental/src/server/index.ts rename to packages/presets/rental/src/server/index.ts index 4c4a5d412..1b7043bac 100644 --- a/packages/presets/hera-rental/src/server/index.ts +++ b/packages/presets/rental/src/server/index.ts @@ -2,11 +2,17 @@ import PresetTachyBase from '@tachybase/preset-tachybase'; import _ from 'lodash'; export class PluginRental extends PresetTachyBase { - #builtInPlugins = ['approval-mobile', 'core', 'rental', 'mobile-client']; + #builtInPlugins = ['approval-mobile', 'core']; get builtInPlugins() { return super.builtInPlugins.concat(this.#builtInPlugins); } + + #localPlugins = ['rental>=0.21.0']; + + get localPlugins() { + return super.localPlugins.concat(this.#localPlugins); + } } -export default PresetTachyBase; +export default PluginRental; diff --git a/packages/presets/sancongtou/package.json b/packages/presets/sancongtou/package.json index 1bf6900c5..a73bc95c0 100644 --- a/packages/presets/sancongtou/package.json +++ b/packages/presets/sancongtou/package.json @@ -1,5 +1,5 @@ { - "name": "@tachybase/preset-sancongtou", + "name": "@tachybase/preset-hera-sancongtou", "version": "0.21.20", "license": "Apache-2.0", "main": "./lib/server/index.js", diff --git a/packages/presets/sancongtou/src/server/index.ts b/packages/presets/sancongtou/src/server/index.ts index 84f5a3583..9e6ae06a1 100644 --- a/packages/presets/sancongtou/src/server/index.ts +++ b/packages/presets/sancongtou/src/server/index.ts @@ -1,12 +1,18 @@ import PresetTachyBase from '@tachybase/preset-tachybase'; import _ from 'lodash'; -export class PluginRental extends PresetTachyBase { - #builtInPlugins = ['approval-mobile', 'core', 'rental', 'mobile-client', 'sancongtou']; +export class PluginSancongtou extends PresetTachyBase { + #builtInPlugins = ['approval-mobile', 'core']; get builtInPlugins() { return super.builtInPlugins.concat(this.#builtInPlugins); } + + #localPlugins = ['sancongtou>=0.21.0']; + + get localPlugins() { + return super.localPlugins.concat(this.#localPlugins); + } } -export default PresetTachyBase; +export default PluginSancongtou; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d381667b4..f6403429d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -51,7 +51,10 @@ importers: version: link:packages/core/cli '@tachybase/preset-hera-rental': specifier: workspace:* - version: link:packages/presets/hera-rental + version: link:packages/presets/rental + '@tachybase/preset-hera-sancongtou': + specifier: workspace:* + version: link:packages/presets/sancongtou '@tachybase/preset-tachybase': specifier: workspace:* version: link:packages/presets/base @@ -169,8 +172,8 @@ importers: version: link:../database '@tachybase/preset-hera-rental': specifier: workspace:* - version: link:../../presets/hera-rental - '@tachybase/preset-sancongtou': + version: link:../../presets/rental + '@tachybase/preset-hera-sancongtou': specifier: workspace:* version: link:../../presets/sancongtou '@tachybase/preset-tachybase': @@ -4174,7 +4177,7 @@ importers: specifier: ^4.17.0 version: 4.17.0 - packages/presets/hera-rental: + packages/presets/rental: dependencies: '@hera/plugin-approval': specifier: workspace:*