2022-10-31 23:14:24 +08:00
# v0.8: Plugin manager & docs
2022-10-31 23:03:50 +08:00
2022-10-31 23:14:24 +08:00
Starting with v0.8, NocoBase begins to provide an available plugin manager and development documentation. Here are the main changes in v0.8.
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
## Tweaks to the top right corner of the interface
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
- UI Editor
- Plugin Manager
2023-11-13 11:01:18 +08:00
- Plugin Settings Manager
2022-10-31 23:14:24 +08:00
- Personal Center
2022-10-31 22:41:24 +08:00
< img src = "./v08-changelog/topright.jpg" style = "max-width: 500px;" / >
2022-10-31 23:14:24 +08:00
## The new plugin manager
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
v0.8 provides a powerful plugin manager for managing plugins in a no-code way.
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
### Plugin manager flow
2022-10-31 22:41:24 +08:00
< img src = "./v08-changelog/pm-flow.svg" style = "max-width: 580px;" / >
2022-10-31 23:14:24 +08:00
### Plugin Manager interface
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
Currently it is mainly used for disabling, activating and deleting local plugins. Built-in plugins cannot be deleted.
2022-10-31 22:41:24 +08:00
< img src = "./v08-changelog/pm-ui.jpg" / >
2022-10-31 23:14:24 +08:00
### Plugin Manager command
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
In addition to being able to activate and disable plugins from the no-code interface, you can also manage plugins more completely from the command line.
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
```
# Create a plugin
2022-10-31 22:41:24 +08:00
yarn pm create hello
2022-10-31 23:14:24 +08:00
# Register the plugin
2022-10-31 22:41:24 +08:00
yarn pm add hello
2022-10-31 23:14:24 +08:00
# Activate the plugin
2022-10-31 22:41:24 +08:00
yarn pm enable hello
2022-10-31 23:14:24 +08:00
# Disable the plugin
2022-10-31 22:41:24 +08:00
yarn pm disable hello
2022-10-31 23:14:24 +08:00
# Remove the plugin
2022-10-31 22:41:24 +08:00
yarn pm remove hello
2022-10-31 23:14:24 +08:00
2022-10-31 22:41:24 +08:00
```
2022-10-31 23:14:24 +08:00
Note: Releases and upgrades for plugins will be supported in subsequent releases.
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
```
# Publish the plugin
2022-10-31 22:41:24 +08:00
yarn pm publish hello
2022-10-31 23:14:24 +08:00
# Publish the plugin
2022-10-31 22:41:24 +08:00
yarn pm upgrade hello
2022-10-31 23:14:24 +08:00
2022-10-31 22:41:24 +08:00
```
2022-10-31 23:14:24 +08:00
For more plugin examples, see [packages/samples ](https://github.com/nocobase/nocobase/tree/main/packages/samples ).
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
## Changes of plugin
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
### Plugin’ s directory structure
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
```
2022-10-31 22:41:24 +08:00
|- /hello
|- /src
2022-10-31 23:14:24 +08:00
|- /client # Plugin client
|- /server # Plugin server
2022-10-31 22:41:24 +08:00
|- client.d.ts
|- client.js
2022-10-31 23:14:24 +08:00
|- package.json # Plugin package information
2022-10-31 22:41:24 +08:00
|- server.d.ts
|- server.js
2022-10-31 23:14:24 +08:00
2022-10-31 22:41:24 +08:00
```
2022-10-31 23:14:24 +08:00
### Plugin’ s name specification
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
NocoBase plugin is also an NPM package, the correspondence rule between plugin name and NPM package name is `${PLUGIN_PACKAGE_PREFIX}-${pluginName}` .
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
`PLUGIN_PACKAGE_PREFIX` is the plugin package prefix, which can be customized in .env, [click here for PLUGIN_PACKAGE_PREFIX description ](https://www.notion.so/api/env#plugin_package_prefix ).
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
For example, a project named `my-nocobase-app` adds the `hello` plugin with package name `@my-nocobase-app/plugin-hello` .
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
`PLUGIN_PACKAGE_PREFIX` is configured as follows.
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
```
2022-10-31 22:41:24 +08:00
PLUGIN_PACKAGE_PREFIX=@nocobase/plugin-,@nocobase/preset-,@my-nocobase-app/plugin-
2022-10-31 23:14:24 +08:00
2022-10-31 22:41:24 +08:00
```
2022-10-31 23:14:24 +08:00
The correspondence between plugin names and package names is
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
- `users` plugin package name is `@nocobase/plugin-users`
- `nocobase` plugin package name is `@nocobase/preset-nocobase`
- `hello` plugin package named `@my-nocobase-app/plugin-hello`
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
### Plugin’ s lifecycle
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
v0.8 provides a more complete approach to the plugin lifecycle.
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
```
2022-10-31 22:41:24 +08:00
import { InstallOptions, Plugin } from '@nocobase/server';
export class HelloPlugin extends Plugin {
afterAdd() {
2022-10-31 23:14:24 +08:00
// After the plugin has been added via pm.add
2022-10-31 22:41:24 +08:00
}
beforeLoad() {
2022-10-31 23:14:24 +08:00
// Before all plugins are loaded, generally used to register classes and event listeners
2022-10-31 22:41:24 +08:00
}
async load() {
2022-10-31 23:14:24 +08:00
// Load configuration
2022-10-31 22:41:24 +08:00
}
async install(options?: InstallOptions) {
2022-10-31 23:14:24 +08:00
// Install logic
2022-10-31 22:41:24 +08:00
}
async afterEnable() {
2022-10-31 23:14:24 +08:00
// After activation
2022-10-31 22:41:24 +08:00
}
async afterDisable() {
2022-10-31 23:14:24 +08:00
// After disable
2022-10-31 22:41:24 +08:00
}
async remove() {
2022-10-31 23:14:24 +08:00
// Remove logic
2022-10-31 22:41:24 +08:00
}
}
export default HelloPlugin;
2022-10-31 23:14:24 +08:00
2022-10-31 22:41:24 +08:00
```
2022-10-31 23:14:24 +08:00
### Front- and back-end entrance for plugins
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
The lifecycle of the plugin is controlled by the server
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
```
2022-10-31 22:41:24 +08:00
import { Application } from '@nocobase/server';
const app = new Application({
// ...
});
class MyPlugin extends Plugin {
afterAdd() {}
beforeLoad() {}
load() {}
install() {}
afterEnable() {}
afterDisable() {}
remove() {}
}
app.plugin(MyPlugin, { name: 'my-plugin' });
2022-10-31 23:14:24 +08:00
2022-10-31 22:41:24 +08:00
```
2022-10-31 23:14:24 +08:00
The client side of the plugin exists as Context.Provider (similar to Middleware on the server side)
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
```
2022-10-31 22:41:24 +08:00
import React from 'react';
import { Application } from '@nocobase/client';
const app = new Application({
apiClient: {
baseURL: process.env.API_BASE_URL,
},
dynamicImport: (name: string) => {
return import(`../plugins/${name}`);
},
});
2022-10-31 23:14:24 +08:00
// When you visit the /hello page, it displays Hello world!
2022-10-31 22:41:24 +08:00
const HelloProvider = React.memo((props) => {
const location = useLocation();
if (location.pathname === '/hello') {
return < div > Hello world!< / div >
}
return < >{props.children}< />
});
2023-06-06 19:33:04 +08:00
HelloProvider.displayName = 'HelloProvider'
2022-10-31 22:41:24 +08:00
app.use(HelloProvider);
2022-10-31 23:14:24 +08:00
```
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
## Custom business code
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
v0.7 plugins are not complete, custom business code may be scattered in `packages/app/client` and `packages/app/server` , which is not conducive to upgrade and maintenance. v0.8 recommends organizing as a plugin package and using `yarn pm` to manage plugins.
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
## More complete documentation is provided
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
- **Welcome**: a quick look at NocoBase
- **Manual**: learn more about the core features provided by the NocoBase platform
- **Plugin Development Tutorial**: Advanced dive into plugin development
- **API Reference**: Check the API usage during plugin development
- **Client Components Library** (in preparation): provides examples and usage of NocoBase components
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
## More plugin examples are provided
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
- [command ](https://github.com/nocobase/nocobase/tree/develop/packages/samples/command )
- [custom-block ](https://github.com/nocobase/nocobase/tree/develop/packages/samples/custom-block )
- [custom-page ](https://github.com/nocobase/nocobase/tree/develop/packages/samples/custom-page )
- [custom-signup-page ](https://github.com/nocobase/nocobase/tree/develop/packages/samples/custom-signup-page )
- [hello ](https://github.com/nocobase/nocobase/tree/develop/packages/samples/hello )
- [ratelimit ](https://github.com/nocobase/nocobase/tree/develop/packages/samples/ratelimit )
- [shop-actions ](https://github.com/nocobase/nocobase/tree/develop/packages/samples/shop-actions )
- [shop-events ](https://github.com/nocobase/nocobase/tree/develop/packages/samples/shop-events )
- [shop-i18n ](https://github.com/nocobase/nocobase/tree/develop/packages/samples/shop-i18n )
- [shop-modeling ](https://github.com/nocobase/nocobase/tree/develop/packages/samples/shop-modeling )
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
## Other new features and functionality
2022-10-31 22:41:24 +08:00
2022-10-31 23:14:24 +08:00
- Import from Excel
- Bulk Update & Edit
- Graphical collection
- Workflow support for viewing execution history
- JSON field