插件如何自动更新?

我想在发布插件之后当检测到有新版本时自动更新到最新版。

这个过程可以是自动的也可以是通过指令手动触发,由用户选择。

2 个赞

是这样的,你可以发到求插件板块!我也想要这种

1 个赞

So there are 2 kinds of logics that you should implement:

1. Checking the latest version and compare to local version

It is easily to utilise the installer service from the market plugin for managing your other plugins:

  • use ctx.installer.resolveName(name) to resolve the name of the plugin to the actual name of the package name.
  • use ctx.installer.getDeps() to get the dependencies map which you could resolve to the package metadata.
  • use gt(latest, resolved) function from package semver to compare the remote version and local version while these parameters are both coming from the value of the package metadata mentioned above.

2. Trigger the installation

We will also utilise installer service for upgrading our plugin by:

ctx.installer.install(['name'])

Note: the mechanism described above is just a demonstration, in the realm you should apply more than this such as exception catching, configuration maintenance, side-effect cleaning, misuse evidence, etc.

3 个赞

谢谢佬!

1 个赞