fix: lang option for install command

This commit is contained in:
chenos 2022-04-24 23:17:42 +08:00
parent c1f94d3d1b
commit 3750484cbc
4 changed files with 19 additions and 10 deletions

View File

@ -4,11 +4,13 @@ import React from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useACLRoleContext } from '../acl'; import { useACLRoleContext } from '../acl';
import { useAPIClient } from '../api-client'; import { useAPIClient } from '../api-client';
import { useCompile } from '../schema-component';
import { useCurrentUserContext } from './CurrentUserProvider'; import { useCurrentUserContext } from './CurrentUserProvider';
const useCurrentRoles = () => { const useCurrentRoles = () => {
const { allowAnonymous } = useACLRoleContext(); const { allowAnonymous } = useACLRoleContext();
const { data } = useCurrentUserContext(); const { data } = useCurrentUserContext();
const compile = useCompile();
const options = (data?.data?.roles || []).map((item) => { const options = (data?.data?.roles || []).map((item) => {
return { return {
title: item.title, title: item.title,
@ -21,7 +23,7 @@ const useCurrentRoles = () => {
name: 'anonymous', name: 'anonymous',
}); });
} }
return options; return compile(options);
}; };
export const SwitchRole = () => { export const SwitchRole = () => {

View File

@ -1,7 +1,8 @@
export { AppManager } from './app-manager';
export * from './application'; export * from './application';
export { PluginManager } from './plugin-manager'; export { Application as default } from './application';
export * as middlewares from './middlewares'; export * as middlewares from './middlewares';
export * from './plugin'; export * from './plugin';
export { Application as default } from './application'; export * from './plugin-manager';
export { AppManager } from './app-manager';
export * from './read-config'; export * from './read-config';

View File

@ -9,14 +9,11 @@ export class ClientPlugin extends Plugin {
const cmd = this.app.findCommand('install'); const cmd = this.app.findCommand('install');
if (cmd) { if (cmd) {
cmd.option('--import-demo'); cmd.option('--import-demo');
cmd.option('--lang [lang]');
} }
this.app.on('afterInstall', async (app, options) => { this.app.on('afterInstall', async (app, options) => {
const [opts] = options?.cliArgs || [{}]; const [opts] = options?.cliArgs || [{}];
if (opts?.importDemo) { if (opts?.importDemo) {
} //
if (opts?.lang) {
} }
}); });
} }

View File

@ -1,12 +1,14 @@
import { skip } from '@nocobase/acl'; import { skip } from '@nocobase/acl';
import { Plugin } from '@nocobase/server'; import { InstallOptions, Plugin } from '@nocobase/server';
import { resolve } from 'path'; import { resolve } from 'path';
export class SystemSettingsPlugin extends Plugin { export class SystemSettingsPlugin extends Plugin {
async install() { async install(options: InstallOptions) {
const [opts] = options.cliArgs;
await this.db.getRepository('systemSettings').create({ await this.db.getRepository('systemSettings').create({
values: { values: {
title: 'NocoBase', title: 'NocoBase',
appLang: opts?.lang || 'en-US',
logo: { logo: {
title: 'nocobase-logo', title: 'nocobase-logo',
filename: '682e5ad037dd02a0fe4800a3e91c283b.png', 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() { async load() {
await this.app.db.import({ await this.app.db.import({
directory: resolve(__dirname, 'collections'), directory: resolve(__dirname, 'collections'),