openmemo 0.2.1 → 0.2.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/bin/openmemo CHANGED
@@ -1,11 +1,8 @@
1
1
  #!/bin/sh
2
2
  set -e
3
3
 
4
- # Get the directory where this script is located
5
4
  SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
6
- PKG_DIR="$(dirname "$SCRIPT_DIR")"
7
5
 
8
- # Detect platform
9
6
  OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
10
7
  ARCH="$(uname -m)"
11
8
 
@@ -20,36 +17,15 @@ case "$ARCH" in
20
17
  arm64|aarch64) ARCH="arm64" ;;
21
18
  esac
22
19
 
23
- PLATFORM="${OS}-${ARCH}"
24
- BIN_PKG="openmemo-${PLATFORM}"
20
+ BIN_NAME="openmemo-${OS}-${ARCH}"
21
+ [ "$OS" = "windows" ] && BIN_NAME="${BIN_NAME}.exe"
25
22
 
26
- # Try to find the binary in node_modules (global install structure)
27
- # Path 1: Global install - binary package is a sibling in node_modules
28
- GLOBAL_BIN="$PKG_DIR/../$BIN_PKG/openmemo-${PLATFORM}"
23
+ BIN_PATH="$SCRIPT_DIR/$BIN_NAME"
29
24
 
30
- # Path 2: Local install - binary package is in package's node_modules
31
- LOCAL_BIN="$PKG_DIR/node_modules/$BIN_PKG/openmemo-${PLATFORM}"
32
-
33
- # Windows executable paths
34
- GLOBAL_BIN_EXE="$PKG_DIR/../$BIN_PKG/openmemo-${PLATFORM}.exe"
35
- LOCAL_BIN_EXE="$PKG_DIR/node_modules/$BIN_PKG/openmemo-${PLATFORM}.exe"
36
-
37
- # Try each path
38
- if [ -x "$GLOBAL_BIN" ]; then
39
- exec "$GLOBAL_BIN" "$@"
40
- elif [ -x "$LOCAL_BIN" ]; then
41
- exec "$LOCAL_BIN" "$@"
42
- elif [ -x "$GLOBAL_BIN_EXE" ]; then
43
- exec "$GLOBAL_BIN_EXE" "$@"
44
- elif [ -x "$LOCAL_BIN_EXE" ]; then
45
- exec "$LOCAL_BIN_EXE" "$@"
25
+ if [ -x "$BIN_PATH" ]; then
26
+ exec "$BIN_PATH" "$@"
46
27
  else
47
- echo "Error: Could not find openmemo binary for platform $PLATFORM"
48
- echo ""
49
- echo "Searched paths:"
50
- echo " - $GLOBAL_BIN"
51
- echo " - $LOCAL_BIN"
52
- echo ""
53
- echo "Please reinstall: npm install -g openmemo"
28
+ echo "Error: Binary not found at $BIN_PATH"
29
+ echo "Try reinstalling: npm install -g openmemo"
54
30
  exit 1
55
31
  fi
@@ -1,43 +1,76 @@
1
- import { platform, arch } from "os";
2
- import { existsSync } from "fs";
3
- import { dirname, join } from "path";
4
- import { fileURLToPath } from "url";
1
+ import { platform, arch } from "os"
2
+ import { existsSync, createWriteStream, chmodSync } from "fs"
3
+ import { dirname, join } from "path"
4
+ import { fileURLToPath } from "url"
5
+ import { createRequire } from "module"
6
+ import https from "https"
5
7
 
6
- const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ // Skip during CI builds
9
+ if (process.env.CI) {
10
+ console.log("[openmemo] Skipping binary download in CI environment")
11
+ process.exit(0)
12
+ }
13
+
14
+ const require = createRequire(import.meta.url)
15
+ const __dirname = dirname(fileURLToPath(import.meta.url))
16
+ const pkg = require("../package.json")
7
17
 
8
- const platformMap = {
9
- darwin: "darwin",
10
- linux: "linux",
11
- win32: "windows",
12
- };
18
+ const REPO = "arkjun/openmemo"
19
+ const VERSION = pkg.version
13
20
 
14
- const archMap = {
15
- x64: "x64",
16
- arm64: "arm64",
17
- };
21
+ const platformMap = { darwin: "darwin", linux: "linux", win32: "windows" }
22
+ const archMap = { x64: "x64", arm64: "arm64" }
18
23
 
19
- const os = platformMap[platform()];
20
- const cpu = archMap[arch()];
24
+ const os = platformMap[platform()]
25
+ const cpu = archMap[arch()]
21
26
 
22
27
  if (!os || !cpu) {
23
- console.warn(`[openmemo] Unsupported platform: ${platform()}-${arch()}`);
24
- process.exit(0);
28
+ console.warn(`[openmemo] Unsupported platform: ${platform()}-${arch()}`)
29
+ process.exit(0)
30
+ }
31
+
32
+ const binaryName = `openmemo-${os}-${cpu}${os === "windows" ? ".exe" : ""}`
33
+ const binaryPath = join(__dirname, binaryName)
34
+
35
+ // Skip if already exists
36
+ if (existsSync(binaryPath)) {
37
+ console.log(`[openmemo] Binary already exists`)
38
+ process.exit(0)
25
39
  }
26
40
 
27
- const pkgName = `openmemo-${os}-${cpu}`;
28
- const ext = os === "windows" ? ".exe" : "";
29
-
30
- // Check global install path (sibling package)
31
- const globalPath = join(__dirname, "..", "..", pkgName, `openmemo-${os}-${cpu}${ext}`);
32
- // Check local install path
33
- const localPath = join(__dirname, "..", "node_modules", pkgName, `openmemo-${os}-${cpu}${ext}`);
34
-
35
- if (existsSync(globalPath) || existsSync(localPath)) {
36
- console.log(`[openmemo] Binary found for ${os}-${cpu}`);
37
- } else {
38
- console.warn(`[openmemo] Binary not found for ${os}-${cpu}`);
39
- console.warn(`[openmemo] Searched paths:`);
40
- console.warn(`[openmemo] - ${globalPath}`);
41
- console.warn(`[openmemo] - ${localPath}`);
42
- console.warn(`[openmemo] This platform may not be supported yet.`);
41
+ const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${binaryName}`
42
+
43
+ console.log(`[openmemo] Downloading binary for ${os}-${cpu}...`)
44
+
45
+ function download(url, dest) {
46
+ return new Promise((resolve, reject) => {
47
+ const request = (url) => {
48
+ https.get(url, (res) => {
49
+ if (res.statusCode === 302 || res.statusCode === 301) {
50
+ request(res.headers.location)
51
+ return
52
+ }
53
+ if (res.statusCode !== 200) {
54
+ reject(new Error(`Download failed: ${res.statusCode}`))
55
+ return
56
+ }
57
+ const file = createWriteStream(dest)
58
+ res.pipe(file)
59
+ file.on("finish", () => {
60
+ file.close()
61
+ chmodSync(dest, 0o755)
62
+ resolve()
63
+ })
64
+ }).on("error", reject)
65
+ }
66
+ request(url)
67
+ })
43
68
  }
69
+
70
+ download(url, binaryPath)
71
+ .then(() => console.log(`[openmemo] Binary installed successfully`))
72
+ .catch((err) => {
73
+ console.error(`[openmemo] Failed to download binary: ${err.message}`)
74
+ console.error(`[openmemo] URL: ${url}`)
75
+ process.exit(1)
76
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmemo",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "OpenTUI-based memo app inspired by mattn/memo",
5
5
  "bin": {
6
6
  "openmemo": "bin/openmemo"
@@ -32,11 +32,5 @@
32
32
  },
33
33
  "scripts": {
34
34
  "postinstall": "node bin/postinstall.mjs"
35
- },
36
- "optionalDependencies": {
37
- "openmemo-darwin-arm64": "0.2.1",
38
- "openmemo-linux-x64": "0.2.1",
39
- "openmemo-linux-arm64": "0.2.1",
40
- "openmemo-windows-x64": "0.2.1"
41
35
  }
42
36
  }