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