@higgsfield/cli 0.1.31 → 0.1.33
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/run.js +28 -2
- package/install.js +22 -0
- package/package.json +1 -1
package/bin/run.js
CHANGED
|
@@ -2,9 +2,26 @@ const { spawn } = require("child_process");
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
|
|
5
|
+
function detectPackageManager() {
|
|
6
|
+
const ua = process.env.npm_config_user_agent || "";
|
|
7
|
+
if (ua.startsWith("pnpm/")) return "pnpm";
|
|
8
|
+
if (ua.startsWith("yarn/")) return "yarn";
|
|
9
|
+
if (ua.startsWith("bun/")) return "bun";
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function readInstallMetadata(vendorDir) {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(fs.readFileSync(path.join(vendorDir, "install.json"), "utf8"));
|
|
16
|
+
} catch (_) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
5
21
|
module.exports = function run() {
|
|
6
22
|
const binName = process.platform === "win32" ? "hf.exe" : "hf";
|
|
7
|
-
const
|
|
23
|
+
const vendorDir = path.join(__dirname, "..", "vendor");
|
|
24
|
+
const bin = path.join(vendorDir, binName);
|
|
8
25
|
if (!fs.existsSync(bin)) {
|
|
9
26
|
console.error(
|
|
10
27
|
"@higgsfield/cli: binary not found at " +
|
|
@@ -13,7 +30,16 @@ module.exports = function run() {
|
|
|
13
30
|
);
|
|
14
31
|
process.exit(1);
|
|
15
32
|
}
|
|
16
|
-
const
|
|
33
|
+
const metadata = readInstallMetadata(vendorDir);
|
|
34
|
+
const child = spawn(bin, process.argv.slice(2), {
|
|
35
|
+
stdio: "inherit",
|
|
36
|
+
env: {
|
|
37
|
+
...process.env,
|
|
38
|
+
HIGGSFIELD_INSTALL_METHOD: "npm",
|
|
39
|
+
HIGGSFIELD_PACKAGE_MANAGER:
|
|
40
|
+
metadata.package_manager || detectPackageManager() || "npm",
|
|
41
|
+
},
|
|
42
|
+
});
|
|
17
43
|
child.on("exit", (code, signal) => {
|
|
18
44
|
if (signal) process.kill(process.pid, signal);
|
|
19
45
|
else process.exit(code ?? 0);
|
package/install.js
CHANGED
|
@@ -28,6 +28,15 @@ const url = `https://github.com/higgsfield-ai/cli/releases/download/v${VERSION}/
|
|
|
28
28
|
const vendorDir = path.join(__dirname, "vendor");
|
|
29
29
|
fs.mkdirSync(vendorDir, { recursive: true });
|
|
30
30
|
const tarballPath = path.join(vendorDir, tarball);
|
|
31
|
+
const metadataPath = path.join(vendorDir, "install.json");
|
|
32
|
+
|
|
33
|
+
function detectPackageManager() {
|
|
34
|
+
const ua = process.env.npm_config_user_agent || "";
|
|
35
|
+
if (ua.startsWith("pnpm/")) return "pnpm";
|
|
36
|
+
if (ua.startsWith("yarn/")) return "yarn";
|
|
37
|
+
if (ua.startsWith("bun/")) return "bun";
|
|
38
|
+
return "npm";
|
|
39
|
+
}
|
|
31
40
|
|
|
32
41
|
function download(targetUrl, dest, redirects = 0) {
|
|
33
42
|
return new Promise((resolve, reject) => {
|
|
@@ -70,6 +79,19 @@ function download(targetUrl, dest, redirects = 0) {
|
|
|
70
79
|
if (platform !== "windows") {
|
|
71
80
|
fs.chmodSync(path.join(vendorDir, binName), 0o755);
|
|
72
81
|
}
|
|
82
|
+
fs.writeFileSync(
|
|
83
|
+
metadataPath,
|
|
84
|
+
JSON.stringify(
|
|
85
|
+
{
|
|
86
|
+
install_method: "npm",
|
|
87
|
+
package_manager: detectPackageManager(),
|
|
88
|
+
package_name: pkg.name,
|
|
89
|
+
version: VERSION,
|
|
90
|
+
},
|
|
91
|
+
null,
|
|
92
|
+
2
|
|
93
|
+
) + "\n"
|
|
94
|
+
);
|
|
73
95
|
fs.unlinkSync(tarballPath);
|
|
74
96
|
console.log("@higgsfield/cli: installed");
|
|
75
97
|
})().catch((err) => {
|