diff --git a/package.json b/package.json index d6620d0..5d2ae9f 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,14 @@ { "name": "rubick-native", "version": "0.0.0", + "type": "module", + "module": "dist/index.js", + "types": "dist/index.d.ts", "scripts": { - "build": "tsup" + "build": "tsc -d" }, - "type": "module", "devDependencies": { "@types/node": "^20.7.1", - "tsup": "^7.2.0", "typescript": "^5.2.2" }, "dependencies": { @@ -15,18 +16,13 @@ "execa": "^8.0.1", "fdir": "^6.1.0" }, - "tsup": { - "entry": [ - "src/index.ts" - ], - "format": [ - "esm", - "cjs" - ], - "target": "es5", - "splitting": true, - "treeshake": true, - "clean": true, - "dts": true - } + "files": [ + "README.md", + "LICENSE", + "dist/", + "addon/package.json", + "addon/index.js", + "addon/index.d.ts", + "addon/*.node" + ] } \ No newline at end of file diff --git a/src/deprecated/cb.ts b/src/deprecated/cb.ts index 418e658..1fa1ebe 100644 --- a/src/deprecated/cb.ts +++ b/src/deprecated/cb.ts @@ -1,76 +1,76 @@ -import { arch, platform, homedir } from "os" -import { onClipboardChange } from "../../addon" -import got from "got" -import { Extract } from "unzip-stream" -import { access, mkdir, constants } from "fs/promises" -import { join } from "path" -import { execaCommand } from "execa" -const getKey = (stdout: string, key: string) => stdout.split(`"${key}": `).at(1)?.split(`,\r\n`).at(0)! -import { asyncFolderWalker } from "async-folder-walker" +// import { arch, platform, homedir } from "os" +// import { onClipboardChange } from "../../addon" +// import got from "got" +// import { Extract } from "unzip-stream" +// import { access, mkdir, constants } from "fs/promises" +// import { join } from "path" +// import { execaCommand } from "execa" +// const getKey = (stdout: string, key: string) => stdout.split(`"${key}": `).at(1)?.split(`,\r\n`).at(0)! +// import { asyncFolderWalker } from "async-folder-walker" -// 启动剪切板程序 -export default async () => { - let latestNum = 0 - const repoURL = "https://ghproxy.com/https://github.com/Slackadays/Clipboard" - let a = arch() - let p: string = platform() - // 确保目录存在 - const dirPath = join(homedir(), "cb") - try { - await access(dirPath, constants.O_DIRECTORY) - } catch { - await mkdir(dirPath) - } - // cb 路径 - const cbPath = join(dirPath, 'bin', p === "win32" ? "cb.exe" : "cb") - // 同步剪切板内容 - const execCB = async () => { - const stdout = (await execaCommand(cbPath + " info", { env: { "CLIPBOARD_SILENT": "true" } })).stdout - // 最新缓存 - latestNum = Number(getKey(stdout, "totalEntries")) - 1 - return stdout - } - try { - await access(cbPath) - } catch { - switch (a) { - case "arm64": - break; - case "x64": - a = "amd64" - break; - default: - throw new Error("Not Support Your Sys Arch") - } - switch (p) { - case "freebsd": - case "linux": - case "netbsd": - case "openbsd": - break; - case "win32": - p = "windows" - break; - case "darwin": - p = "macos" - break; - default: - throw new Error("Not Support Your Sys Arch") - } - const latest = (await fetch(repoURL + "/releases/latest")).url.split("/").pop() - const durl = repoURL + `/releases/download/${latest}/clipboard-${p}-${p === "macos" ? 'arm64-amd64' : a}.zip` - got.stream(durl).pipe(Extract({ path: dirPath })) - } finally { - // 剪切板历史路径 - const basePath = join(getKey(await execCB(), "path").replaceAll('"', ''), "data") - // 剪切板监听 - onClipboardChange(execCB) - return { - latest: () => { - const latestPath = join(basePath, latestNum.toString()) - const walker = asyncFolderWalker(latestPath, { maxDepth: 0 }) - return walker - } - } - } -} +// // 启动剪切板程序 +// export default async () => { +// let latestNum = 0 +// const repoURL = "https://ghproxy.com/https://github.com/Slackadays/Clipboard" +// let a = arch() +// let p: string = platform() +// // 确保目录存在 +// const dirPath = join(homedir(), "cb") +// try { +// await access(dirPath, constants.O_DIRECTORY) +// } catch { +// await mkdir(dirPath) +// } +// // cb 路径 +// const cbPath = join(dirPath, 'bin', p === "win32" ? "cb.exe" : "cb") +// // 同步剪切板内容 +// const execCB = async () => { +// const stdout = (await execaCommand(cbPath + " info", { env: { "CLIPBOARD_SILENT": "true" } })).stdout +// // 最新缓存 +// latestNum = Number(getKey(stdout, "totalEntries")) - 1 +// return stdout +// } +// try { +// await access(cbPath) +// } catch { +// switch (a) { +// case "arm64": +// break; +// case "x64": +// a = "amd64" +// break; +// default: +// throw new Error("Not Support Your Sys Arch") +// } +// switch (p) { +// case "freebsd": +// case "linux": +// case "netbsd": +// case "openbsd": +// break; +// case "win32": +// p = "windows" +// break; +// case "darwin": +// p = "macos" +// break; +// default: +// throw new Error("Not Support Your Sys Arch") +// } +// const latest = (await fetch(repoURL + "/releases/latest")).url.split("/").pop() +// const durl = repoURL + `/releases/download/${latest}/clipboard-${p}-${p === "macos" ? 'arm64-amd64' : a}.zip` +// got.stream(durl).pipe(Extract({ path: dirPath })) +// } finally { +// // 剪切板历史路径 +// const basePath = join(getKey(await execCB(), "path").replaceAll('"', ''), "data") +// // 剪切板监听 +// onClipboardChange(execCB) +// return { +// latest: () => { +// const latestPath = join(basePath, latestNum.toString()) +// const walker = asyncFolderWalker(latestPath, { maxDepth: 0 }) +// return walker +// } +// } +// } +// } diff --git a/test.ts b/test.ts index f8c9c38..6e6475f 100644 --- a/test.ts +++ b/test.ts @@ -5,7 +5,7 @@ // console.log(event); // }) -import * as addon from "./src" +import * as addon from "./dist" console.log(addon); // for await (const i of shortcutWin()) { diff --git a/tsconfig.json b/tsconfig.json index 0044d96..5afb62b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "outDir": "dist", "esModuleInterop": true, "module": "ESNext", "moduleResolution": "Node", @@ -8,5 +9,8 @@ "ESNext", "DOM" ] - } + }, + "include": [ + "./src/**/*" + ] } \ No newline at end of file