From 1b5c3010c386a2493f41220c617545ae118f3f5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 15 Jul 2024 21:20:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugin/plugin.ts | 2 +- src/y3-helper.ts | 3 +- template/plugin/y3-helper.d.ts | 151 +++++++++++++++++---------------- 3 files changed, 79 insertions(+), 77 deletions(-) diff --git a/src/plugin/plugin.ts b/src/plugin/plugin.ts index f7c8649..cd83404 100644 --- a/src/plugin/plugin.ts +++ b/src/plugin/plugin.ts @@ -29,7 +29,7 @@ export class Plugin { for (let i = 0; i < lines.length; i++) { let line = lines[i]; if (line.startsWith('export ')) { - lines[i] = line.replace(/export\s+(async\s+)function\s+([\w_\u10000-\uFFFFFFFF]+)/, (_, async, name) => { + lines[i] = line.replace(/export\s+(async\s+)?function\s+([\w_\u10000-\uFFFFFFFF]+)/, (_, async, name) => { this.exports[name] = { name, async: async !== '', diff --git a/src/y3-helper.ts b/src/y3-helper.ts index 7f05d65..cebbf95 100644 --- a/src/y3-helper.ts +++ b/src/y3-helper.ts @@ -1,7 +1,8 @@ import * as vscode from 'vscode'; import { fs, log } from './tools'; -export * as excel from './editorTable/excel2'; +export { fs, log } from './tools'; +export * as excel from './editorTable/excel'; export * as table from './editorTable/editorTable'; export * as language from './editorTable/language'; export * from './tools'; diff --git a/template/plugin/y3-helper.d.ts b/template/plugin/y3-helper.d.ts index e357ca5..4c76c25 100644 --- a/template/plugin/y3-helper.d.ts +++ b/template/plugin/y3-helper.d.ts @@ -7,6 +7,7 @@ declare module 'y3-helper' { import * as vscode from 'vscode'; + export { fs, log } from 'y3-helper/tools'; export * as excel from 'y3-helper/editorTable/excel'; export * as table from 'y3-helper/editorTable/editorTable'; export * as language from 'y3-helper/editorTable/language'; @@ -39,6 +40,13 @@ declare module 'y3-helper' { export function sleep(ms: number): Promise; } +declare module 'y3-helper/tools' { + export { download } from 'y3-helper/tools/download'; + export { log } from 'y3-helper/tools/log'; + export * as fs from 'y3-helper/tools/fs'; + export * as json from 'y3-helper/tools/json'; +} + import * as vscode from 'vscode'; export declare function loadFile(uri: vscode.Uri, sheet?: number | string): Promise<(string | undefined)[][] | undefined>; export declare function init(): void; @@ -211,13 +219,6 @@ declare module 'y3-helper/editorTable/language' { export function keyOf(value: string | number, preferNumber?: boolean): string | number; } -declare module 'y3-helper/tools' { - export { download } from 'y3-helper/tools/download'; - export { log } from 'y3-helper/tools/log'; - export * as fs from 'y3-helper/tools/fs'; - export * as json from 'y3-helper/tools/json'; -} - declare module 'y3-helper/constants' { export namespace Table { const path: { @@ -407,6 +408,74 @@ declare module 'y3-helper/plugin' { export function init(): Promise; } +declare module 'y3-helper/tools/download' { + import * as https from 'https'; + export function download(options: string | URL | https.RequestOptions): Promise; +} + +declare module 'y3-helper/tools/log' { + import * as vscode from 'vscode'; + let log: vscode.LogOutputChannel; + export { log }; +} + +declare module 'y3-helper/tools/fs' { + import * as vscode from 'vscode'; + class File { + write(data: Uint8Array): this; + get buffer(): Buffer; + get string(): string; + } + export function readFile(uri: vscode.Uri | string, relativePath?: string): Promise; + export function writeFile(uri: vscode.Uri | string, relativePath: string | undefined, data: string): Promise; + export function writeFile(uri: vscode.Uri | string, data: string): Promise; + interface DeleteOptions { + /** + * 递归删除文件夹 + */ + recursive?: boolean; + /** + * 尝试移动到回收站 + */ + useTrash?: boolean; + } + export function removeFile(uri: vscode.Uri | string, options?: DeleteOptions): Promise; + export function removeFile(uri: vscode.Uri | string, relativePath?: string, options?: DeleteOptions): Promise; + export function dir(uri: vscode.Uri | string, relativePath?: string): Promise<[string, vscode.FileType][]>; + export function scan(uri: vscode.Uri | string, relativePath?: string): Promise<[string, vscode.FileType][]>; + export function stat(uri: vscode.Uri | string, relativePath?: string): Promise; + export function isFile(uri: vscode.Uri | string, relativePath?: string): Promise; + export function isDirectory(uri: vscode.Uri | string, relativePath?: string): Promise; + export function isExists(uri: vscode.Uri | string, relativePath?: string): Promise; + interface CopyOptions { + overwrite?: boolean; + recursive?: boolean; + nameMap?: string; + pattern?: RegExp; + } + export function copy(source: vscode.Uri | string, target: vscode.Uri | string, options?: CopyOptions): Promise; + export function isRelativePath(path: string): boolean; + export function isAbsolutePath(path: string): boolean; + export {}; +} + +declare module 'y3-helper/tools/json' { + import * as jsonc from 'jsonc-parser'; + export type Item = string | boolean | number | null | Object | Array; + export type Array = Item[]; + export type Object = { + [key: string]: Item; + }; + export class Json { + constructor(text: string); + get text(): string; + get data(): Object | undefined; + get tree(): jsonc.Node | undefined; + get(key: string): Item | undefined; + set(key: string, value: any): boolean; + } +} + declare module 'y3-helper/editor_meta/unit' { export interface UnitData { /** @@ -2850,71 +2919,3 @@ declare module 'y3-helper/editor_meta/tech' { } } -declare module 'y3-helper/tools/download' { - import * as https from 'https'; - export function download(options: string | URL | https.RequestOptions): Promise; -} - -declare module 'y3-helper/tools/log' { - import * as vscode from 'vscode'; - let log: vscode.LogOutputChannel; - export { log }; -} - -declare module 'y3-helper/tools/fs' { - import * as vscode from 'vscode'; - class File { - write(data: Uint8Array): this; - get buffer(): Buffer; - get string(): string; - } - export function readFile(uri: vscode.Uri | string, relativePath?: string): Promise; - export function writeFile(uri: vscode.Uri | string, relativePath: string | undefined, data: string): Promise; - export function writeFile(uri: vscode.Uri | string, data: string): Promise; - interface DeleteOptions { - /** - * 递归删除文件夹 - */ - recursive?: boolean; - /** - * 尝试移动到回收站 - */ - useTrash?: boolean; - } - export function removeFile(uri: vscode.Uri | string, options?: DeleteOptions): Promise; - export function removeFile(uri: vscode.Uri | string, relativePath?: string, options?: DeleteOptions): Promise; - export function dir(uri: vscode.Uri | string, relativePath?: string): Promise<[string, vscode.FileType][]>; - export function scan(uri: vscode.Uri | string, relativePath?: string): Promise<[string, vscode.FileType][]>; - export function stat(uri: vscode.Uri | string, relativePath?: string): Promise; - export function isFile(uri: vscode.Uri | string, relativePath?: string): Promise; - export function isDirectory(uri: vscode.Uri | string, relativePath?: string): Promise; - export function isExists(uri: vscode.Uri | string, relativePath?: string): Promise; - interface CopyOptions { - overwrite?: boolean; - recursive?: boolean; - nameMap?: string; - pattern?: RegExp; - } - export function copy(source: vscode.Uri | string, target: vscode.Uri | string, options?: CopyOptions): Promise; - export function isRelativePath(path: string): boolean; - export function isAbsolutePath(path: string): boolean; - export {}; -} - -declare module 'y3-helper/tools/json' { - import * as jsonc from 'jsonc-parser'; - export type Item = string | boolean | number | null | Object | Array; - export type Array = Item[]; - export type Object = { - [key: string]: Item; - }; - export class Json { - constructor(text: string); - get text(): string; - get data(): Object | undefined; - get tree(): jsonc.Node | undefined; - get(key: string): Item | undefined; - set(key: string, value: any): boolean; - } -} -