0.0.6 • Published 11 months ago

@swanide/extension v0.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

@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 扩展点
  • toolbars 扩展点

widgets 扩展点

开发者工具扩展支持在 renderer 视图注入 widget,每个 widget 为一个扩展模块,在 workbench 主视图加载后进行加载。 widget 模块 为工具提供操作主视图的能力,同时支持更多 swanide 相关API。

package.json 扩展点如下:

"contributes": {
    // widget 扩展点
    "widgets": [
        {
            // widget id 模块唯一标识,不可重复
            "id": "swanide-extension-example.widget",
            // widget 入口
            "entry": "./dist/widget.js",
            // 入口加载模式,默认为 amd,由于开发者工具更依赖 commonjs 模块,这里提供了 commonjs 加载模式
            "entryType": "commonjs"
        }
    ]
},

widget 入口模块:

/**
 * swanide 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 扩展点
    "toolbars": [
        {
            "name": "swanide-extension-example-btn",
            "text": "示例扩展按钮",
            "icon": "search",
            "command": "editor.action.formatDocument",
            "tooltip": "示例扩展按钮",
            "type": "button",
            // 分组:develop | deploy | debug | cloud | guide | info
            "group": "right",
            // 分组内排序
            "order": 100
        }
    ]
},
0.0.6

11 months ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago