@higgsfield/cli 0.1.16
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/higgs.js +2 -0
- package/bin/higgsfield.js +2 -0
- package/bin/run.js +24 -0
- package/install.js +75 -0
- package/package.json +36 -0
package/bin/higgs.js
ADDED
package/bin/run.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const { spawn } = require("child_process");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
|
|
5
|
+
module.exports = function run() {
|
|
6
|
+
const bin = path.join(__dirname, "..", "vendor", "hf");
|
|
7
|
+
if (!fs.existsSync(bin)) {
|
|
8
|
+
console.error(
|
|
9
|
+
"@higgsfield/cli: binary not found at " +
|
|
10
|
+
bin +
|
|
11
|
+
". Reinstall: npm i -g @higgsfield/cli"
|
|
12
|
+
);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
const child = spawn(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
16
|
+
child.on("exit", (code, signal) => {
|
|
17
|
+
if (signal) process.kill(process.pid, signal);
|
|
18
|
+
else process.exit(code ?? 0);
|
|
19
|
+
});
|
|
20
|
+
child.on("error", (err) => {
|
|
21
|
+
console.error("@higgsfield/cli: failed to exec —", err.message);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
});
|
|
24
|
+
};
|
package/install.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const https = require("https");
|
|
5
|
+
const { execFileSync } = require("child_process");
|
|
6
|
+
|
|
7
|
+
const pkg = require("./package.json");
|
|
8
|
+
const VERSION = pkg.version;
|
|
9
|
+
|
|
10
|
+
const PLATFORM_MAP = { darwin: "darwin", linux: "linux" };
|
|
11
|
+
const ARCH_MAP = { x64: "amd64", arm64: "arm64" };
|
|
12
|
+
|
|
13
|
+
const platform = PLATFORM_MAP[process.platform];
|
|
14
|
+
const arch = ARCH_MAP[process.arch];
|
|
15
|
+
|
|
16
|
+
if (!platform || !arch) {
|
|
17
|
+
console.error(
|
|
18
|
+
`@higgsfield/cli: unsupported platform ${process.platform}/${process.arch}`
|
|
19
|
+
);
|
|
20
|
+
console.error("Supported: darwin|linux × x64|arm64");
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const tarball = `hf_${VERSION}_${platform}_${arch}.tar.gz`;
|
|
25
|
+
const url = `https://github.com/higgsfield-ai/cli/releases/download/v${VERSION}/${tarball}`;
|
|
26
|
+
|
|
27
|
+
const vendorDir = path.join(__dirname, "vendor");
|
|
28
|
+
fs.mkdirSync(vendorDir, { recursive: true });
|
|
29
|
+
const tarballPath = path.join(vendorDir, tarball);
|
|
30
|
+
|
|
31
|
+
function download(targetUrl, dest, redirects = 0) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
if (redirects > 5) return reject(new Error("too many redirects"));
|
|
34
|
+
const file = fs.createWriteStream(dest);
|
|
35
|
+
https
|
|
36
|
+
.get(targetUrl, (res) => {
|
|
37
|
+
if (
|
|
38
|
+
res.statusCode >= 300 &&
|
|
39
|
+
res.statusCode < 400 &&
|
|
40
|
+
res.headers.location
|
|
41
|
+
) {
|
|
42
|
+
file.close();
|
|
43
|
+
fs.unlinkSync(dest);
|
|
44
|
+
return resolve(download(res.headers.location, dest, redirects + 1));
|
|
45
|
+
}
|
|
46
|
+
if (res.statusCode !== 200) {
|
|
47
|
+
file.close();
|
|
48
|
+
try {
|
|
49
|
+
fs.unlinkSync(dest);
|
|
50
|
+
} catch (_) {}
|
|
51
|
+
return reject(new Error(`HTTP ${res.statusCode} for ${targetUrl}`));
|
|
52
|
+
}
|
|
53
|
+
res.pipe(file);
|
|
54
|
+
file.on("finish", () => file.close(() => resolve()));
|
|
55
|
+
})
|
|
56
|
+
.on("error", (err) => {
|
|
57
|
+
try {
|
|
58
|
+
fs.unlinkSync(dest);
|
|
59
|
+
} catch (_) {}
|
|
60
|
+
reject(err);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
(async () => {
|
|
66
|
+
console.log(`@higgsfield/cli: downloading ${url}`);
|
|
67
|
+
await download(url, tarballPath);
|
|
68
|
+
execFileSync("tar", ["-xzf", tarballPath, "-C", vendorDir, "hf"]);
|
|
69
|
+
fs.chmodSync(path.join(vendorDir, "hf"), 0o755);
|
|
70
|
+
fs.unlinkSync(tarballPath);
|
|
71
|
+
console.log("@higgsfield/cli: installed");
|
|
72
|
+
})().catch((err) => {
|
|
73
|
+
console.error("@higgsfield/cli: install failed —", err.message);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@higgsfield/cli",
|
|
3
|
+
"version": "0.1.16",
|
|
4
|
+
"description": "Higgsfield AI CLI — generate images and videos from the terminal.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"higgsfield": "bin/higgsfield.js",
|
|
7
|
+
"higgs": "bin/higgs.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"postinstall": "node install.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"bin/",
|
|
14
|
+
"install.js"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=14"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"homepage": "https://higgsfield.ai",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/higgsfield-ai/cli.git"
|
|
24
|
+
},
|
|
25
|
+
"os": [
|
|
26
|
+
"darwin",
|
|
27
|
+
"linux"
|
|
28
|
+
],
|
|
29
|
+
"cpu": [
|
|
30
|
+
"x64",
|
|
31
|
+
"arm64"
|
|
32
|
+
],
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
}
|
|
36
|
+
}
|