Socket
Book a DemoInstallSign in
Socket

@swanide/extension

Package Overview
Dependencies
Maintainers
4
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swanide/extension

swanide extension api

0.0.6
latest
npmnpm
Version published
Weekly downloads
2
100%
Maintainers
4
Weekly downloads
 
Created
Source

@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
        }
    ]
},

FAQs

Package last updated on 08 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.