finny 0.6.8

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.
Files changed (3) hide show
  1. package/bin/finny +98 -0
  2. package/package.json +24 -0
  3. package/postinstall.mjs +125 -0
package/bin/finny ADDED
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { createRequire } from "module"
4
+ import { spawn } from "child_process"
5
+ import os from "os"
6
+ import path from "path"
7
+ import fs from "fs"
8
+ import { fileURLToPath } from "url"
9
+
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
11
+ const require = createRequire(import.meta.url)
12
+
13
+ function getPlatformPackageName() {
14
+ let platform
15
+ switch (os.platform()) {
16
+ case "darwin":
17
+ platform = "darwin"
18
+ break
19
+ case "linux":
20
+ platform = "linux"
21
+ break
22
+ case "win32":
23
+ platform = "windows"
24
+ break
25
+ default:
26
+ platform = os.platform()
27
+ break
28
+ }
29
+
30
+ let arch
31
+ switch (os.arch()) {
32
+ case "x64":
33
+ arch = "x64"
34
+ break
35
+ case "arm64":
36
+ arch = "arm64"
37
+ break
38
+ default:
39
+ arch = os.arch()
40
+ break
41
+ }
42
+
43
+ return `finny-${platform}-${arch}`
44
+ }
45
+
46
+ function findBinary() {
47
+ const packageName = getPlatformPackageName()
48
+ const binaryName = os.platform() === "win32" ? "finny.exe" : "finny"
49
+
50
+ // Try multiple search paths
51
+ const searchPaths = []
52
+
53
+ // Try require.resolve first
54
+ try {
55
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
56
+ const packageDir = path.dirname(packageJsonPath)
57
+ searchPaths.push(path.join(packageDir, "bin", binaryName))
58
+ } catch {
59
+ // Package not found via require.resolve
60
+ }
61
+
62
+ // npm global install - node_modules sibling
63
+ searchPaths.push(path.join(__dirname, "..", "node_modules", packageName, "bin", binaryName))
64
+ // npm global install - hoisted to parent
65
+ searchPaths.push(path.join(__dirname, "..", "..", packageName, "bin", binaryName))
66
+ // npm global lib directory
67
+ searchPaths.push(path.join(__dirname, "..", "..", "..", packageName, "bin", binaryName))
68
+
69
+ for (const searchPath of searchPaths) {
70
+ if (fs.existsSync(searchPath)) {
71
+ return searchPath
72
+ }
73
+ }
74
+
75
+ console.error(`Could not find finny binary for platform: ${os.platform()}-${os.arch()}`)
76
+ console.error(`Expected package: ${packageName}`)
77
+ console.error(`Searched paths:`)
78
+ for (const p of searchPaths) {
79
+ console.error(` - ${p}`)
80
+ }
81
+ console.error(`\nTry reinstalling: npm install -g finny`)
82
+ process.exit(1)
83
+ }
84
+
85
+ const binaryPath = findBinary()
86
+ const child = spawn(binaryPath, process.argv.slice(2), {
87
+ stdio: "inherit",
88
+ env: process.env,
89
+ })
90
+
91
+ child.on("close", (code) => {
92
+ process.exit(code ?? 0)
93
+ })
94
+
95
+ child.on("error", (err) => {
96
+ console.error(`Failed to start finny: ${err.message}`)
97
+ process.exit(1)
98
+ })
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "finny",
3
+ "version": "0.6.8",
4
+ "description": "AI-powered quantitative trading CLI",
5
+ "type": "module",
6
+ "bin": {
7
+ "finny": "./bin/finny"
8
+ },
9
+ "scripts": {
10
+ "postinstall": "node ./postinstall.mjs"
11
+ },
12
+ "optionalDependencies": {
13
+ "finny-darwin-arm64": "0.6.7",
14
+ "finny-darwin-x64": "0.6.7",
15
+ "finny-linux-arm64": "0.6.7",
16
+ "finny-linux-x64": "0.6.7",
17
+ "finny-windows-x64": "0.6.7"
18
+ },
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/anomalyco/finny"
23
+ }
24
+ }
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "fs"
4
+ import path from "path"
5
+ import os from "os"
6
+ import { fileURLToPath } from "url"
7
+ import { createRequire } from "module"
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
+ const require = createRequire(import.meta.url)
11
+
12
+ function detectPlatformAndArch() {
13
+ // Map platform names
14
+ let platform
15
+ switch (os.platform()) {
16
+ case "darwin":
17
+ platform = "darwin"
18
+ break
19
+ case "linux":
20
+ platform = "linux"
21
+ break
22
+ case "win32":
23
+ platform = "windows"
24
+ break
25
+ default:
26
+ platform = os.platform()
27
+ break
28
+ }
29
+
30
+ // Map architecture names
31
+ let arch
32
+ switch (os.arch()) {
33
+ case "x64":
34
+ arch = "x64"
35
+ break
36
+ case "arm64":
37
+ arch = "arm64"
38
+ break
39
+ case "arm":
40
+ arch = "arm"
41
+ break
42
+ default:
43
+ arch = os.arch()
44
+ break
45
+ }
46
+
47
+ return { platform, arch }
48
+ }
49
+
50
+ function findBinary() {
51
+ const { platform, arch } = detectPlatformAndArch()
52
+ const packageName = `finny-${platform}-${arch}`
53
+ const binaryName = platform === "windows" ? "finny.exe" : "finny"
54
+
55
+ try {
56
+ // Use require.resolve to find the package
57
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
58
+ const packageDir = path.dirname(packageJsonPath)
59
+ const binaryPath = path.join(packageDir, "bin", binaryName)
60
+
61
+ if (!fs.existsSync(binaryPath)) {
62
+ throw new Error(`Binary not found at ${binaryPath}`)
63
+ }
64
+
65
+ return { binaryPath, binaryName }
66
+ } catch (error) {
67
+ throw new Error(`Could not find package ${packageName}: ${error.message}`)
68
+ }
69
+ }
70
+
71
+ function prepareBinDirectory(binaryName) {
72
+ const binDir = path.join(__dirname, "bin")
73
+ const targetPath = path.join(binDir, binaryName)
74
+
75
+ // Ensure bin directory exists
76
+ if (!fs.existsSync(binDir)) {
77
+ fs.mkdirSync(binDir, { recursive: true })
78
+ }
79
+
80
+ // Remove existing binary/symlink if it exists
81
+ if (fs.existsSync(targetPath)) {
82
+ fs.unlinkSync(targetPath)
83
+ }
84
+
85
+ return { binDir, targetPath }
86
+ }
87
+
88
+ function symlinkBinary(sourcePath, binaryName) {
89
+ const { targetPath } = prepareBinDirectory(binaryName)
90
+
91
+ fs.symlinkSync(sourcePath, targetPath)
92
+ console.log(`finny binary symlinked: ${targetPath} -> ${sourcePath}`)
93
+
94
+ // Verify the file exists after operation
95
+ if (!fs.existsSync(targetPath)) {
96
+ throw new Error(`Failed to symlink binary to ${targetPath}`)
97
+ }
98
+ }
99
+
100
+ async function main() {
101
+ try {
102
+ if (os.platform() === "win32") {
103
+ // On Windows, the .exe is already included in the package and bin field points to it
104
+ // No postinstall setup needed
105
+ console.log("Windows detected: binary setup not needed (using packaged .exe)")
106
+ return
107
+ }
108
+
109
+ // On non-Windows platforms, just verify the binary package exists
110
+ // Don't replace the wrapper script - it handles binary execution
111
+ const { binaryPath } = findBinary()
112
+ console.log(`Platform binary verified at: ${binaryPath}`)
113
+ console.log("Wrapper script will handle binary execution")
114
+ } catch (error) {
115
+ console.error("Failed to setup finny binary:", error.message)
116
+ process.exit(1)
117
+ }
118
+ }
119
+
120
+ try {
121
+ main()
122
+ } catch (error) {
123
+ console.error("Postinstall script error:", error.message)
124
+ process.exit(0)
125
+ }