@morphllm/morphcode 1.0.1 → 1.0.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/morphcode +25 -71
- package/package.json +14 -14
- package/postinstall.mjs +2 -121
package/bin/morphcode
CHANGED
|
@@ -1,84 +1,38 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const childProcess = require("child_process")
|
|
4
|
-
const fs = require("fs")
|
|
5
|
-
const path = require("path")
|
|
6
3
|
const os = require("os")
|
|
4
|
+
const { execSync, spawn } = require("child_process")
|
|
5
|
+
const path = require("path")
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
stdio: "inherit",
|
|
11
|
-
})
|
|
12
|
-
if (result.error) {
|
|
13
|
-
console.error(result.error.message)
|
|
14
|
-
process.exit(1)
|
|
15
|
-
}
|
|
16
|
-
const code = typeof result.status === "number" ? result.status : 0
|
|
17
|
-
process.exit(code)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const envPath = process.env.MORPHCODE_BIN_PATH
|
|
21
|
-
if (envPath) {
|
|
22
|
-
run(envPath)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const scriptPath = fs.realpathSync(__filename)
|
|
26
|
-
const scriptDir = path.dirname(scriptPath)
|
|
27
|
-
|
|
28
|
-
const platformMap = {
|
|
29
|
-
darwin: "darwin",
|
|
30
|
-
linux: "linux",
|
|
31
|
-
win32: "windows",
|
|
32
|
-
}
|
|
33
|
-
const archMap = {
|
|
34
|
-
x64: "x64",
|
|
35
|
-
arm64: "arm64",
|
|
36
|
-
arm: "arm",
|
|
37
|
-
}
|
|
7
|
+
const platform = process.platform === "win32" ? "windows" : process.platform
|
|
8
|
+
const arch = process.arch
|
|
38
9
|
|
|
39
|
-
let platform = platformMap[os.platform()]
|
|
40
|
-
if (!platform) {
|
|
41
|
-
platform = os.platform()
|
|
42
|
-
}
|
|
43
|
-
let arch = archMap[os.arch()]
|
|
44
|
-
if (!arch) {
|
|
45
|
-
arch = os.arch()
|
|
46
|
-
}
|
|
47
10
|
const base = "@morphllm/morphcode-" + platform + "-" + arch
|
|
48
11
|
const binary = platform === "windows" ? "morphcode.exe" : "morphcode"
|
|
49
12
|
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const parent = path.dirname(current)
|
|
67
|
-
if (parent === current) {
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
current = parent
|
|
13
|
+
function getBinaryPath() {
|
|
14
|
+
try {
|
|
15
|
+
const pkgPath = require.resolve(base + "/package.json")
|
|
16
|
+
return path.join(path.dirname(pkgPath), "bin", binary)
|
|
17
|
+
} catch {}
|
|
18
|
+
|
|
19
|
+
// Try baseline for x64
|
|
20
|
+
if (arch === "x64") {
|
|
21
|
+
try {
|
|
22
|
+
const baselinePkg = base + "-baseline"
|
|
23
|
+
const pkgPath = require.resolve(baselinePkg + "/package.json")
|
|
24
|
+
return path.join(path.dirname(pkgPath), "bin", binary)
|
|
25
|
+
} catch {}
|
|
71
26
|
}
|
|
72
|
-
}
|
|
73
27
|
|
|
74
|
-
|
|
75
|
-
if (!resolved) {
|
|
76
|
-
console.error(
|
|
77
|
-
'It seems that your package manager failed to install the right version of the morphcode CLI for your platform. You can try manually installing the "' +
|
|
78
|
-
base +
|
|
79
|
-
'" package',
|
|
80
|
-
)
|
|
28
|
+
console.error("Could not find morphcode binary for " + platform + "-" + arch)
|
|
81
29
|
process.exit(1)
|
|
82
30
|
}
|
|
83
31
|
|
|
84
|
-
|
|
32
|
+
const binaryPath = getBinaryPath()
|
|
33
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
34
|
+
stdio: "inherit",
|
|
35
|
+
env: process.env,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
child.on("exit", (code) => process.exit(code ?? 0))
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morphllm/morphcode",
|
|
3
3
|
"bin": {
|
|
4
|
-
"
|
|
4
|
+
"morphcode": "./bin/morphcode"
|
|
5
5
|
},
|
|
6
6
|
"scripts": {
|
|
7
|
-
"postinstall": "
|
|
7
|
+
"postinstall": "node ./postinstall.mjs"
|
|
8
8
|
},
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.3",
|
|
10
10
|
"optionalDependencies": {
|
|
11
|
-
"@morphllm/morphcode-linux-arm64": "1.0.
|
|
12
|
-
"@morphllm/morphcode-linux-x64": "1.0.
|
|
13
|
-
"@morphllm/morphcode-linux-x64-baseline": "1.0.
|
|
14
|
-
"@morphllm/morphcode-linux-arm64-musl": "1.0.
|
|
15
|
-
"@morphllm/morphcode-linux-x64-musl": "1.0.
|
|
16
|
-
"@morphllm/morphcode-linux-x64-baseline-musl": "1.0.
|
|
17
|
-
"@morphllm/morphcode-darwin-arm64": "1.0.
|
|
18
|
-
"@morphllm/morphcode-darwin-x64": "1.0.
|
|
19
|
-
"@morphllm/morphcode-darwin-x64-baseline": "1.0.
|
|
20
|
-
"@morphllm/morphcode-windows-x64": "1.0.
|
|
21
|
-
"@morphllm/morphcode-windows-x64-baseline": "1.0.
|
|
11
|
+
"@morphllm/morphcode-linux-arm64": "1.0.3",
|
|
12
|
+
"@morphllm/morphcode-linux-x64": "1.0.3",
|
|
13
|
+
"@morphllm/morphcode-linux-x64-baseline": "1.0.3",
|
|
14
|
+
"@morphllm/morphcode-linux-arm64-musl": "1.0.3",
|
|
15
|
+
"@morphllm/morphcode-linux-x64-musl": "1.0.3",
|
|
16
|
+
"@morphllm/morphcode-linux-x64-baseline-musl": "1.0.3",
|
|
17
|
+
"@morphllm/morphcode-darwin-arm64": "1.0.3",
|
|
18
|
+
"@morphllm/morphcode-darwin-x64": "1.0.3",
|
|
19
|
+
"@morphllm/morphcode-darwin-x64-baseline": "1.0.3",
|
|
20
|
+
"@morphllm/morphcode-windows-x64": "1.0.3",
|
|
21
|
+
"@morphllm/morphcode-windows-x64-baseline": "1.0.3"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/postinstall.mjs
CHANGED
|
@@ -1,122 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
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 = `@morphllm/morphcode-${platform}-${arch}`
|
|
53
|
-
const binaryName = platform === "windows" ? "morphcode.exe" : "morphcode"
|
|
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(`morphcode 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
|
-
const { binaryPath, binaryName } = findBinary()
|
|
110
|
-
symlinkBinary(binaryPath, binaryName)
|
|
111
|
-
} catch (error) {
|
|
112
|
-
console.error("Failed to setup morphcode binary:", error.message)
|
|
113
|
-
process.exit(1)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
main()
|
|
119
|
-
} catch (error) {
|
|
120
|
-
console.error("Postinstall script error:", error.message)
|
|
121
|
-
process.exit(0)
|
|
122
|
-
}
|
|
2
|
+
// Postinstall script for morphcode
|
|
3
|
+
console.log("morphcode installed successfully")
|