Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
SOVLOOKUP committed Oct 1, 2023
1 parent 7644b1d commit b8b1acc
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 94 deletions.
30 changes: 13 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
{
"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": {
"@miniben90/x-win": "^1.3.1",
"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"
]
}
150 changes: 75 additions & 75 deletions src/deprecated/cb.ts
Original file line number Diff line number Diff line change
@@ -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
// }
// }
// }
// }
2 changes: 1 addition & 1 deletion test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Node",
Expand All @@ -8,5 +9,8 @@
"ESNext",
"DOM"
]
}
},
"include": [
"./src/**/*"
]
}

0 comments on commit b8b1acc

Please sign in to comment.