From 3750484cbca3efc2c0e17f056234c864c636f556 Mon Sep 17 00:00:00 2001 From: chenos Date: Sun, 24 Apr 2022 23:17:42 +0800 Subject: [PATCH] fix: lang option for install command --- packages/core/client/src/user/SwitchRole.tsx | 4 +++- packages/core/server/src/index.ts | 7 ++++--- packages/plugins/client/src/plugin.ts | 5 +---- packages/plugins/system-settings/src/plugin.ts | 13 +++++++++++-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/core/client/src/user/SwitchRole.tsx b/packages/core/client/src/user/SwitchRole.tsx index 86415ec97e..c2a3fc39e1 100644 --- a/packages/core/client/src/user/SwitchRole.tsx +++ b/packages/core/client/src/user/SwitchRole.tsx @@ -4,11 +4,13 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; import { useACLRoleContext } from '../acl'; import { useAPIClient } from '../api-client'; +import { useCompile } from '../schema-component'; import { useCurrentUserContext } from './CurrentUserProvider'; const useCurrentRoles = () => { const { allowAnonymous } = useACLRoleContext(); const { data } = useCurrentUserContext(); + const compile = useCompile(); const options = (data?.data?.roles || []).map((item) => { return { title: item.title, @@ -21,7 +23,7 @@ const useCurrentRoles = () => { name: 'anonymous', }); } - return options; + return compile(options); }; export const SwitchRole = () => { diff --git a/packages/core/server/src/index.ts b/packages/core/server/src/index.ts index a28a57ba35..a6da222eb9 100644 --- a/packages/core/server/src/index.ts +++ b/packages/core/server/src/index.ts @@ -1,7 +1,8 @@ +export { AppManager } from './app-manager'; export * from './application'; -export { PluginManager } from './plugin-manager'; +export { Application as default } from './application'; export * as middlewares from './middlewares'; export * from './plugin'; -export { Application as default } from './application'; -export { AppManager } from './app-manager'; +export * from './plugin-manager'; export * from './read-config'; + diff --git a/packages/plugins/client/src/plugin.ts b/packages/plugins/client/src/plugin.ts index ea0eafcf37..8b4ce1f35d 100644 --- a/packages/plugins/client/src/plugin.ts +++ b/packages/plugins/client/src/plugin.ts @@ -9,14 +9,11 @@ export class ClientPlugin extends Plugin { const cmd = this.app.findCommand('install'); if (cmd) { cmd.option('--import-demo'); - cmd.option('--lang [lang]'); } - this.app.on('afterInstall', async (app, options) => { const [opts] = options?.cliArgs || [{}]; if (opts?.importDemo) { - } - if (opts?.lang) { + // } }); } diff --git a/packages/plugins/system-settings/src/plugin.ts b/packages/plugins/system-settings/src/plugin.ts index c0f43a3843..a51e20b156 100644 --- a/packages/plugins/system-settings/src/plugin.ts +++ b/packages/plugins/system-settings/src/plugin.ts @@ -1,12 +1,14 @@ import { skip } from '@nocobase/acl'; -import { Plugin } from '@nocobase/server'; +import { InstallOptions, Plugin } from '@nocobase/server'; import { resolve } from 'path'; export class SystemSettingsPlugin extends Plugin { - async install() { + async install(options: InstallOptions) { + const [opts] = options.cliArgs; await this.db.getRepository('systemSettings').create({ values: { title: 'NocoBase', + appLang: opts?.lang || 'en-US', logo: { title: 'nocobase-logo', filename: '682e5ad037dd02a0fe4800a3e91c283b.png', @@ -18,6 +20,13 @@ export class SystemSettingsPlugin extends Plugin { }); } + beforeLoad() { + const cmd = this.app.findCommand('install'); + if (cmd) { + cmd.option('--lang [lang]'); + } + } + async load() { await this.app.db.import({ directory: resolve(__dirname, 'collections'),