utools-helper
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

utools-helper

utool 插件开发辅助包,提供完善代码提示(d.ts),以及模板插件辅助开发功能,支持 typescript

install

npm i utools-helper

Usage

设置代码提示

v2.0.0 后已移除,请使用官方仓库 https://github.com/uTools-Labs/utools-api-types

快速添加一个模板插件

// preload.ts
import { InitPlugins } from "utools-helper";
import { Storage } from "./storage";

InitPlugins([new Storage()]);

// storage.ts
import { Plugin } from "utools-helper";
import { Action, TplFeatureMode } from "utools-helper/@types/utools";
import { join } from "path";

export function GetStorage(): string {
  let item = utools.db.get<string>(getStorageID());
  if (item && item.data) return item.data;
  return join(utools.getPath("appData"), "Code", "storage.json");
}

function getStorageID(): string {
  return utools.getLocalId() + "storage";
}

export class Storage implements Plugin {
  mode: TplFeatureMode = "none";
  code = "vsc-storage";
  enter(action: Action) {
    let item = utools.db.get<string>(getStorageID());
    if (!item) {
      item = {
        _id: getStorageID(),
        data: action.payload[0].path,
      };
    }
    item.data = action.payload[0].path;

    let res = utools.db.put(item);
    if (res.ok) {
      utools.showNotification("storage.json 设置成功", "vsc-setting");
    } else {
      utools.showNotification("storage.json 设置失败");
      throw new Error(JSON.stringify(res));
    }
    utools.hideMainWindow();
    utools.outPlugin();
  }
}

Example

请查看: vscode

Utools API

请点击查看

Readme

Keywords

none

Package Sidebar

Install

npm i utools-helper

Weekly Downloads

40

Version

2.1.0

License

MIT

Unpacked Size

540 kB

Total Files

46

Last publish

Collaborators

  • mohuishou