@mekuru/platform 0.0.0-stage → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.jp.md +3 -0
- package/README.md +4 -2
- package/package.json +14 -4
- package/src/index.ts +26 -0
package/README.jp.md
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mekuru/platform
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared operating system integration.
|
|
4
|
+
|
|
5
|
+
`configDir()` resolves the Mekuru settings directory. `openBrowser(url)` starts the operating system browser, including WSL. Service-specific authentication belongs to the upload packages.
|
package/package.json
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mekuru/platform",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./src/index.ts"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"src"
|
|
10
|
+
],
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"dependencies": {},
|
|
13
|
+
"engines": {
|
|
14
|
+
"bun": ">=1.4"
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
export const configDir = (): string => {
|
|
5
|
+
if (process.env.MEKURU_CONFIG_DIR) return process.env.MEKURU_CONFIG_DIR;
|
|
6
|
+
if (process.platform === "win32") return join(process.env.APPDATA ?? join(homedir(), "AppData", "Roaming"), "mekuru");
|
|
7
|
+
return join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "mekuru");
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const openBrowser = (url: string): void => {
|
|
11
|
+
const wsl = process.platform === "linux" && (!!process.env.WSL_INTEROP || existsSync("/proc/sys/fs/binfmt_misc/WSLInterop"));
|
|
12
|
+
const tries: string[][] = wsl
|
|
13
|
+
? [["wslview"], ["cmd.exe", "/c", "start", ""]]
|
|
14
|
+
: process.platform === "darwin"
|
|
15
|
+
? [["open"]]
|
|
16
|
+
: process.platform === "win32"
|
|
17
|
+
? [["cmd", "/c", "start", ""]]
|
|
18
|
+
: [["xdg-open"]];
|
|
19
|
+
for (const [cmd, ...args] of tries) {
|
|
20
|
+
const target = cmd.startsWith("cmd") ? url.replaceAll("&", "^&") : url;
|
|
21
|
+
try {
|
|
22
|
+
Bun.spawn([cmd, ...args, target], { stdin: "ignore", stdout: "ignore", stderr: "ignore", cwd: wsl ? "/mnt/c" : undefined }).unref();
|
|
23
|
+
break;
|
|
24
|
+
} catch {}
|
|
25
|
+
}
|
|
26
|
+
};
|