fix: auto install a plugin on enable (#852)
This commit is contained in:
parent
f4a10cb7ad
commit
7e929b8f68
@ -15,6 +15,7 @@ const env = {
|
||||
DB_TIMEZONE: '+00:00',
|
||||
DEFAULT_STORAGE_TYPE: 'local',
|
||||
LOCAL_STORAGE_DEST: 'storage/uploads',
|
||||
MFSU_AD: 'none',
|
||||
};
|
||||
|
||||
if (!process.env.APP_ENV_PATH && process.argv[2] && process.argv[2] === 'test') {
|
||||
|
@ -37,6 +37,7 @@ export class PluginManager {
|
||||
{ type: 'string', name: 'name', unique: true },
|
||||
{ type: 'string', name: 'version' },
|
||||
{ type: 'boolean', name: 'enabled' },
|
||||
{ type: 'boolean', name: 'installed' },
|
||||
{ type: 'boolean', name: 'builtIn' },
|
||||
{ type: 'json', name: 'options' },
|
||||
],
|
||||
@ -71,6 +72,12 @@ export class PluginManager {
|
||||
ctx.throw(400, 'plugin invalid');
|
||||
}
|
||||
await app.reload();
|
||||
if (plugin.model && !plugin.model.get('installed')) {
|
||||
await app.db.sync();
|
||||
await plugin.install();
|
||||
plugin.model.set('installed', true);
|
||||
await plugin.model.save();
|
||||
}
|
||||
await app.start();
|
||||
ctx.body = 'ok';
|
||||
await next();
|
||||
@ -128,6 +135,7 @@ export class PluginManager {
|
||||
await this.collection.sync();
|
||||
});
|
||||
this.app.on('beforeLoadAll', async (options) => {
|
||||
await this.collection.sync();
|
||||
const exists = await this.app.db.collectionExistsInDb('applicationPlugins');
|
||||
if (!exists) {
|
||||
return;
|
||||
@ -184,7 +192,7 @@ export class PluginManager {
|
||||
for (const plugin of pluginClass) {
|
||||
await this.add(plugin);
|
||||
}
|
||||
}
|
||||
};
|
||||
return addMultiple();
|
||||
}
|
||||
if (typeof pluginClass === 'string') {
|
||||
|
@ -28,6 +28,7 @@ export class PresetNocoBase<O = any> extends Plugin {
|
||||
if (instance.model && plugin !== 'hello') {
|
||||
instance.model.enabled = true;
|
||||
instance.model.builtIn = true;
|
||||
instance.model.installed = true;
|
||||
await instance.model.save();
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ yarn pm enable sample-hello
|
||||
yarn dev
|
||||
|
||||
# for production
|
||||
yarn build samples/hello
|
||||
yarn build
|
||||
yarn start
|
||||
```
|
||||
|
||||
|
@ -19,7 +19,7 @@ yarn pm enable sample-shop-modeling
|
||||
yarn dev
|
||||
|
||||
# for production
|
||||
yarn build samples/shop-modeling
|
||||
yarn build
|
||||
yarn start
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user