@swanide/extension
swanide 扩展 API,可以在 百度小程序开发工具 中进行扩展开发。
下载 百度小程序开发工具。
使用方法
在开发者工具 extension
扩展中:
import {swanideInExtension as swanide} from '@swanide/extension';
export function activate() {
swanide.ideReady(() => {
swanide.executeCommand('swanide.simulator.refresh');
});
}
注意: extension 扩展的加载顺序可能会在工具 ready 之前,需要调用 ideReady
事件才可以运行工具提供的函数。
在开发者工具 widget
扩展中:
import {ExtensionContext} from 'vscode';
import {swanideInWidget as swanide} from '@swanide/extension';
export function activate(context: ExtensionContext) {
swanide.executeCommand('swanide.simulator.refresh');
}
在开发者工具 window
窗口中:
import {swanideInWindow as swanide} from '@swanide/extension';
swanide.executeCommand('swanide.simulator.refresh');
开发者工具扩展点
开发者工具对 vscode 扩展点做了增强,增加了以下几个扩展点:
widgets 扩展点
开发者工具扩展支持在 renderer 视图注入 widget,每个 widget 为一个扩展模块,在 workbench 主视图加载后进行加载。
widget 模块 为工具提供操作主视图的能力,同时支持更多 swanide 相关API。
package.json 扩展点如下:
"contributes": {
"widgets": [
{
"id": "swanide-extension-example.widget",
"entry": "./dist/widget.js",
"entryType": "commonjs"
}
]
},
widget 入口模块:
import {swanide, WidgetContext} from '@swanide/extension';
export function activate(context: WidgetContext) {
console.log('swanide extension path', context.extensionPath);
swanide.executeCommand('swanide-extension-example.helloWorld');
}
toolbars 扩展点
开发者工具扩展支持工具栏按钮设置,点击按钮运行指定命令。
package.json 扩展点如下:
"contributes": {
"toolbars": [
{
"name": "swanide-extension-example-btn",
"text": "示例扩展按钮",
"icon": "search",
"command": "editor.action.formatDocument",
"tooltip": "示例扩展按钮",
"type": "button",
"group": "right",
"order": 100
}
]
},