feat: improve tachybase presets (#1609)

Co-authored-by: sealday <sealday@gmail.com>
Reviewed-on: daoyoucloud/tachybase#1609
This commit is contained in:
sealday 2024-10-16 12:04:27 +08:00
parent ee7f011b31
commit 388172e098
3 changed files with 101 additions and 56 deletions

View File

@ -73,3 +73,9 @@ INIT_ROOT_USERNAME=tachybase
# SENTRY_SESSION_REPLAY_ENABLE=on # 是否启用 Sentry 会话重放,文档 https://docs.sentry.io/platforms/javascript/guides/react/session-replay/ # SENTRY_SESSION_REPLAY_ENABLE=on # 是否启用 Sentry 会话重放,文档 https://docs.sentry.io/platforms/javascript/guides/react/session-replay/
# SENTRY_SESSION_REPLAY_SAMPLE_RATE=0.1 # Sentry 会话重放采样率1.0 为 100%0.0 为 0%,默认为 0.1 # SENTRY_SESSION_REPLAY_SAMPLE_RATE=0.1 # Sentry 会话重放采样率1.0 为 100%0.0 为 0%,默认为 0.1
# SENTRY_SESSION_REPLAY_ONERROR_SAMPLE_RATE=1.0 # Sentry 会话重放错误采样率1.0 为 100%0.0 为 0%,默认为 1.0 # SENTRY_SESSION_REPLAY_ONERROR_SAMPLE_RATE=1.0 # Sentry 会话重放错误采样率1.0 为 100%0.0 为 0%,默认为 1.0
##### PRESETS #####
# 单写名称:添加指定插件且默认启用 名称前加!:移除指定插件 名称前加|:添加指定插件但默认禁用
# PRESETS_CORE_PLUGINS=api-doc,api-keys,!messages
# PRESETS_LOCAL_PLUGINS=gantt,!iframe-block,|audit-logs

View File

@ -28,6 +28,7 @@ const WelcomeCard = () => {
> >
<Space> <Space>
<Button>使</Button> <Button>使</Button>
<Button></Button>
<Button type="primary"></Button> <Button type="primary"></Button>
</Space> </Space>
</Flex> </Flex>

View File

@ -17,27 +17,6 @@ export class PresetTachyBase extends Plugin {
'users', 'users',
'acl', 'acl',
'messages', 'messages',
// optional plugins, default enabled
'online-user',
'action-bulk-edit',
'action-bulk-update',
'action-duplicate',
'action-print',
'backup-restore',
'calendar',
'china-region',
'custom-request',
'data-visualization',
'export',
'formula-field',
'gantt',
'iframe-block',
'import',
'kanban',
'logger',
'sequence-field',
'workflow',
'audit-logs',
]; ];
get builtInPlugins() { get builtInPlugins() {
@ -45,33 +24,54 @@ export class PresetTachyBase extends Plugin {
} }
#localPlugins = [ #localPlugins = [
// optional plugins, default disabled // [name, version, enabled]
'adapter-bullmq>=0.21.76', ['online-user', '0.22.7', true],
'homepage>=0.22.6', ['action-bulk-edit', '0.22.7', true],
'core>=0.22.6', ['action-bulk-update', '0.22.7', true],
'rental>=0.22.6', ['action-duplicate', '0.22.7', true],
'field-markdown-vditor>=0.22.6', ['action-print', '0.22.7', true],
'comments>=0.22.6', ['backup-restore', '0.22.7', true],
'sancongtou>=0.22.6', ['calendar', '0.22.7', true],
'approval-mobile>=0.22.6', ['china-region', '0.22.7', true],
'api-doc>=0.13.0-alpha.1', ['custom-request', '0.22.7', true],
'api-keys>=0.10.1-alpha.1', ['data-visualization', '0.22.7', true],
'cas>=0.13.0-alpha.5', ['export', '0.22.7', true],
'data-source-external>=0.22.5', ['formula-field', '0.22.7', true],
'dingtalk>=0.21.76', ['gantt', '0.22.7', true],
'graph-collection-manager>=0.9.0-alpha.1', ['iframe-block', '0.22.7', true],
'localization-management>=0.11.1-alpha.1', ['import', '0.22.7', true],
'map>=0.8.1-alpha.3', ['kanban', '0.22.7', true],
'mobile-client>=0.10.0-alpha.2', ['logger', '0.22.7', true],
'multi-app-manager>=0.7.0-alpha.1', ['sequence-field', '0.22.7', true],
'multi-app-share-collection>=0.9.2-alpha.1', ['workflow', '0.22.7', true],
'oidc>=0.9.2-alpha.1', ['audit-logs', '0.22.7', true],
'saml>=0.8.1-alpha.3', // default disable
'sms-auth>=0.10.0-alpha.2', ['adapter-bullmq', '0.21.76', false],
'snapshot-field>=0.8.1-alpha.3', ['homepage', '0.22.6', false],
'theme-editor>=0.11.1-alpha.1', ['core', '0.22.6', false],
'wechat-auth>=0.21.89', ['rental', '0.22.6', false],
'work-wechat>=0.21.76', ['field-markdown-vditor', '0.22.6', false],
['comments', '0.22.6', false],
['sancongtou', '0.22.6', false],
['approval-mobile', '0.22.6', false],
['api-doc', '0.13.0-alpha.1', false],
['api-keys', '0.10.1-alpha.1', false],
['cas', '0.13.0-alpha.5', false],
['data-source-external', '0.22.5', false],
['dingtalk', '0.21.76', false],
['graph-collection-manager', '0.9.0-alpha.1', false],
['localization-management', '0.11.1-alpha.1', false],
['map', '0.8.1-alpha.3', false],
['mobile-client', '0.10.0-alpha.2', false],
['multi-app-manager', '0.7.0-alpha.1', false],
['multi-app-share-collection', '0.9.2-alpha.1', false],
['oidc', '0.9.2-alpha.1', false],
['saml', '0.8.1-alpha.3', false],
['sms-auth', '0.10.0-alpha.2', false],
['snapshot-field', '0.8.1-alpha.3', false],
['theme-editor', '0.11.1-alpha.1', false],
['wechat-auth', '0.21.89', false],
['work-wechat', '0.21.76', false],
]; ];
get localPlugins() { get localPlugins() {
@ -83,15 +83,51 @@ export class PresetTachyBase extends Plugin {
} }
getBuiltInPlugins() { getBuiltInPlugins() {
const { APPEND_PRESET_BUILT_IN_PLUGINS } = process.env; const { PRESETS_CORE_PLUGINS } = process.env;
return _.uniq(this.splitNames(APPEND_PRESET_BUILT_IN_PLUGINS).concat(this.builtInPlugins)); const [addPlugins, removedPlugins] = this.parseNames(PRESETS_CORE_PLUGINS);
return _.uniq(this.builtInPlugins.concat(addPlugins).filter((name) => !removedPlugins.includes(name)));
}
parseNames(plugins: string) {
const addPlugins = this.splitNames(plugins).filter((name) => !name.startsWith('!') && !name.startsWith('|'));
const removedPlugins = this.splitNames(plugins)
.filter((name) => name.startsWith('!'))
.map((name) => name.slice(1));
const addDisabledPlugins = this.splitNames(plugins)
.filter((name) => name.startsWith('|'))
.map((name) => name.slice(1));
return [addPlugins, removedPlugins, addDisabledPlugins];
} }
getLocalPlugins() { getLocalPlugins() {
const { APPEND_PRESET_LOCAL_PLUGINS } = process.env; const { PRESETS_LOCAL_PLUGINS } = process.env;
const plugins = this.splitNames(APPEND_PRESET_LOCAL_PLUGINS) let plugins = [].concat(this.localPlugins);
.concat(this.localPlugins) const [addPlugins, removedPlugins, addDisabledPlugins] = this.parseNames(PRESETS_LOCAL_PLUGINS);
.map((name) => name.split('>='));
addPlugins.forEach((plugin) => {
const found = plugins.find((p) => p[0] === plugin);
if (found) {
found[2] = true;
} else {
plugins.push([plugin, '0.0.0', true]);
}
});
removedPlugins.forEach((plugin) => {
plugins = plugins.filter((p) => p[0] !== plugin);
});
addDisabledPlugins.forEach((plugin) => {
const found = plugins.find((p) => p === plugin);
if (found) {
found[2] = false;
} else {
plugins.push([plugin, '0.0.0', false]);
}
});
return plugins; return plugins;
} }
@ -124,8 +160,9 @@ export class PresetTachyBase extends Plugin {
await Promise.all( await Promise.all(
this.getLocalPlugins().map(async (plugin) => { this.getLocalPlugins().map(async (plugin) => {
const name = plugin[0]; const name = plugin[0];
const enabled = plugin[2];
const packageJson = await this.getPackageJson(name); const packageJson = await this.getPackageJson(name);
return { name, packageName: packageJson.name, version: packageJson.version }; return { name, packageName: packageJson.name, version: packageJson.version, enabled };
}), }),
), ),
); );
@ -154,8 +191,9 @@ export class PresetTachyBase extends Plugin {
} }
} }
const name = plugin[0]; const name = plugin[0];
const enabled = plugin[2];
const packageJson = await this.getPackageJson(name); const packageJson = await this.getPackageJson(name);
plugins.push({ name, packageName: packageJson.name, version: packageJson.version }); plugins.push({ name, packageName: packageJson.name, version: packageJson.version, enabled });
} }
return plugins; return plugins;
} }