tachybase_todo/packages/presets/nocobase/src/index.ts
katherinehhh 4085ed0db7
Feat/collection templates (#1124)
* feat: add collection templates

* feat:  collection templates

* feat:  collection templates

* feat:  collection templates

* feat:  collection templates

* feat: collection templates

* feat: calendar collection template

* feat: no id does not support sorting

* feat: collection template edit

* feat: collectiom templates code improve

* feat: collection template supports configurable field interface

* feat: collection template supports configurable field interface

* feat: establish relation field when there is no id

* feat: collection templates

* feat: collection templates locale

* feat: calendar collection

* feat: calendar collection default fields

* feat: code optimization

* feat: code optimization

* feat: code optimization

* feat: collectin template fix

* feat: add sample-custom-collection-template

* feat: code optimization

* feat: code optimization

* feat: code optimization

* feat: code optimization

* feat: import code

* feat: collection template local

* feat: code opimization

* feat: code opimization

* feat: code opimization

* feat: code opimization

* feat: code opimization

* feat: collection template local

* feat: collection template local

* fix(collection-manager): exclude reverse parameters when overriding

* feat: update docs

* feat: disabled

* feat: improve code

* feat: update submodule

* feat: submodules: true

* fix: token

* fix: with ssh-key

* fix: update dockerfile

* fix: ci

* fix: ci

* fix: ci

* fix: ci

* fix: --no-verify-access

* fix: ci

* fix: ci

* fix: ci

* fix: missing env

* fix: env

Co-authored-by: chenos <chenlinxh@gmail.com>
Co-authored-by: chareice <chareice@live.com>
2022-11-29 11:31:30 +08:00

76 lines
2.1 KiB
TypeScript

import { Plugin } from '@nocobase/server';
import path from 'path';
export class PresetNocoBase extends Plugin {
async addBuiltInPlugins() {
const plugins = process.env.PRESET_NOCOBASE_PLUGINS
? process.env.PRESET_NOCOBASE_PLUGINS.split(',')
: [
'error-handler',
'collection-manager',
'ui-schema-storage',
'ui-routes-storage',
'file-manager',
'system-settings',
'verification',
'users',
'acl',
'china-region',
'workflow',
'client',
'export',
'import',
'audit-logs',
];
await this.app.pm.add(plugins, {
enabled: true,
builtIn: true,
installed: true,
});
const samples = ['sample-hello'];
await this.app.pm.add(samples, {});
await this.app.reload();
}
afterAdd() {
this.app.on('beforeLoad', async (app, options) => {
if (options?.method !== 'upgrade') {
return;
}
const version = await this.app.version.get();
console.log(`The version number before upgrade is ${version}`);
const result = await this.app.version.satisfies('<0.8.0-alpha.1');
if (result) {
const r = await this.db.collectionExistsInDb('applicationPlugins');
if (r) {
console.log(`Clear the installed application plugins`);
await this.db.getRepository('applicationPlugins').destroy({ truncate: true });
await this.app.reload();
}
}
});
this.app.on('beforeUpgrade', async () => {
const result = await this.app.version.satisfies('<0.8.0-alpha.1');
if (result) {
console.log(`Initialize all built-in plugins`);
await this.addBuiltInPlugins();
}
});
this.app.on('beforeInstall', async () => {
console.log(`Initialize all built-in plugins`);
await this.addBuiltInPlugins();
});
}
beforeLoad() {
this.db.addMigrations({
namespace: this.getName(),
directory: path.resolve(__dirname, './migrations'),
context: {
plugin: this,
},
});
}
}
export default PresetNocoBase;