@ahqstore/cli 0.7.0 → 0.10.1

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.
@@ -0,0 +1,4 @@
1
+ {
2
+ "python-envs.defaultEnvManager": "ms-python.python:system",
3
+ "python-envs.pythonProjects": []
4
+ }
package/Cargo.toml CHANGED
@@ -1,7 +1,7 @@
1
1
  [package]
2
2
  edition = "2021"
3
3
  name = "ahqstore_cli_rs"
4
- version = "0.7.0"
4
+ version = "0.10.1"
5
5
  description = "AHQ Store CLI"
6
6
  repository = "https://github.com/ahqstore/cli"
7
7
  homepage = "https://github.com/ahqstore/cli"
@@ -22,11 +22,6 @@ pkg-url = "{ repo }/releases/download/{ version }/{ name }-{ target }.zip"
22
22
  pkg-fmt = "zip"
23
23
 
24
24
  [dependencies]
25
- # Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
26
- napi = { version = "2", default-features = false, features = [
27
- "napi4",
28
- ], optional = true }
29
- napi-derive = { version = "2", optional = true }
30
25
  inquire = { version = "0", features = ["editor"] }
31
26
  chalk_rs = "1"
32
27
  lazy_static = "1"
@@ -39,17 +34,11 @@ image = { version = "0.25", default-features = false, features = [
39
34
  "rayon",
40
35
  "png",
41
36
  ] }
42
- rand = "0.8"
37
+ rand = "0.9"
43
38
 
44
39
  [target.'cfg(unix)'.dependencies]
45
40
  openssl-sys = { version = "0.9", features = ["vendored"] }
46
41
 
47
- [build-dependencies]
48
- napi-build = { version = "2", optional = true }
49
-
50
42
  [profile.release]
51
43
  lto = true
52
44
  strip = "symbols"
53
-
54
- [features]
55
- node = ["dep:napi", "dep:napi-build", "dep:napi-derive"]
package/build.rs CHANGED
@@ -1,8 +1,4 @@
1
- #[cfg(feature = "node")]
2
- extern crate napi_build;
3
-
1
+ // Checking for targets
4
2
  fn main() {
5
- // Ensures that users can download it too
6
- #[cfg(feature = "node")]
7
- napi_build::setup();
8
- }
3
+
4
+ }
package/bundle.ps1 CHANGED
@@ -1,4 +1,13 @@
1
1
  mkdir dist
2
- cp ./target/release/ahqstore.exe ./dist/ahqstore.exe
3
- cp ./target/release/ahqstore.exe ./dist/ahqstore_cli_rs.exe
4
- compress-archive ./dist/* ./ahqstore_cli_rs-$env:TARGET
2
+
3
+ Copy-Item "./target/$env:TARGET/release/ahqstore.exe" "./dist/ahqstore.exe" -ErrorAction SilentlyContinue
4
+ Copy-Item "./target/$env:TARGET/release/ahqstore.exe" "./dist/ahqstore_cli_rs.exe" -ErrorAction SilentlyContinue
5
+
6
+ Copy-Item "./target/$env:TARGET/release/ahqstore" "./dist/ahqstore" -ErrorAction SilentlyContinue
7
+ Copy-Item "./target/$env:TARGET/release/ahqstore" "./dist/ahqstore_cli_rs" -ErrorAction SilentlyContinue
8
+
9
+ compress-archive ./dist/* ./ahqstore_cli_rs-$env:TARGET
10
+
11
+ Copy-Item "./target/$env:TARGET/release/ahqstore_cli_rs.dll" "./ahqstore_cli_rs-$env:TARGET.dll" -ErrorAction SilentlyContinue
12
+ Copy-Item "./target/$env:TARGET/release/libahqstore_cli_rs.so" "./libahqstore_cli_rs-$env:TARGET.so" -ErrorAction SilentlyContinue
13
+ Copy-Item "./target/$env:TARGET/release/libahqstore_cli_rs.dylib" "./libahqstore_cli_rs-$env:TARGET.dylib" -ErrorAction SilentlyContinue
package/go/go.exe ADDED
Binary file
package/go/go.mod ADDED
@@ -0,0 +1,3 @@
1
+ module ahqstore/cli/go
2
+
3
+ go 1.25.1
package/go/main.go ADDED
@@ -0,0 +1,7 @@
1
+ package main
2
+
3
+ import "fmt"
4
+
5
+ func main() {
6
+ fmt.Println("Welcome from Go")
7
+ }
package/js/cli.js ADDED
@@ -0,0 +1,132 @@
1
+ #! /usr/bin/env node
2
+ // @ts-check
3
+
4
+ import { join } from "node:path";
5
+ import { existsSync, mkdirSync, rmSync } from "node:fs";
6
+ import { argv, env, platform } from "node:process";
7
+
8
+ import { downloadModuleWithProgress } from "./download.js";
9
+
10
+ import c from "ansi-colors";
11
+
12
+ import koffi from "koffi";
13
+
14
+ import pkg from "../package.json" with { type: "json" };
15
+
16
+ export function getPrefixSuffix() {
17
+ let prefix = "";
18
+ let suffix = "";
19
+
20
+ switch (platform) {
21
+ case "win32":
22
+ suffix = ".dll";
23
+ break;
24
+ case "darwin":
25
+ prefix = "lib";
26
+ suffix = ".dylib";
27
+ break;
28
+ case "linux":
29
+ prefix = "lib";
30
+ suffix = ".so";
31
+ break;
32
+ default:
33
+ prefix = "lib";
34
+ suffix = ".so";
35
+ console.warn(c.yellow("We're guessing a UNIX compatible system."));
36
+ }
37
+
38
+ return { prefix, suffix };
39
+ }
40
+
41
+ /**
42
+ * @param {string} name
43
+ */
44
+ function getLibraryFilename(name) {
45
+ const { prefix, suffix } = getPrefixSuffix();
46
+
47
+ return `${prefix}${name}${suffix}`;
48
+ }
49
+
50
+ const dylibDir = join(import.meta.dirname, "lib");
51
+ const dylib = join(dylibDir, getLibraryFilename("ahqstore_cli_rs"));
52
+
53
+ if (!(existsSync(dylibDir) && existsSync(dylib))) {
54
+ console.warn(
55
+ c.red.redBright(
56
+ "Binary not found, downloading AHQ Store CLI Binary for this version",
57
+ ),
58
+ );
59
+
60
+ try {
61
+ rmSync(dylib);
62
+ } catch(_) {}
63
+ try {
64
+ mkdirSync(dylibDir);
65
+ } catch (_) {}
66
+
67
+ await downloadModuleWithProgress(dylib);
68
+ }
69
+
70
+ let dlib;
71
+
72
+ try {
73
+ dlib = koffi.load(dylib);
74
+ } catch (_) {
75
+ console.warn(
76
+ c.red.redBright(
77
+ "Binary is corrupted, downloading AHQ Store CLI Binary for this version",
78
+ ),
79
+ );
80
+
81
+ try {
82
+ rmSync(dylib);
83
+ } catch(_) {}
84
+ try {
85
+ mkdirSync(dylibDir);
86
+ } catch (_) {}
87
+
88
+ await downloadModuleWithProgress(dylib);
89
+
90
+ dlib = koffi.load(dylib);
91
+ }
92
+
93
+ const ver = dlib.func("get_ver", "str", []);
94
+
95
+ /**
96
+ * Note that we've leaked some memory here
97
+ * @type {string}
98
+ */
99
+ const output = ver();
100
+
101
+ if (output != pkg.version) {
102
+ console.warn(c.red.yellowBright("We need to update binaries..."));
103
+
104
+ // Unload current one
105
+ dlib.unload();
106
+
107
+ try {
108
+ rmSync(dylib);
109
+ } catch(_) {}
110
+ try {
111
+ mkdirSync(dylibDir);
112
+ } catch (_) {}
113
+
114
+ /// Download
115
+ await downloadModuleWithProgress(dylib);
116
+
117
+ // Load newer
118
+ dlib = koffi.load(dylib);
119
+ }
120
+
121
+ dlib.func("init_args", "void", [])();
122
+
123
+ const pushArg = dlib.func("add_arg", "void", ["str"]);
124
+
125
+ argv.slice(2).forEach((a) => {
126
+ pushArg(a);
127
+ });
128
+
129
+ // Clear the console output
130
+ console.clear();
131
+
132
+ dlib.func("node_entrypoint", "void", ["bool"])(env["CI"] == "true");
package/js/download.js ADDED
@@ -0,0 +1,87 @@
1
+ // @ts-check
2
+
3
+ import { SingleBar } from "cli-progress";
4
+ import { getPrefixSuffix } from "./cli.js";
5
+ import { getRustTarget } from "./rust.js";
6
+ import { createWriteStream } from "node:fs";
7
+
8
+ import c from "ansi-colors";
9
+ import pkg from "../package.json" with { type: "json" };
10
+
11
+ const bar = new SingleBar({
12
+ format:
13
+ "Downloading |" + c.cyan("{bar}") + "| {percentage}% | {value}/{total} KB",
14
+ barCompleteChar: "\u2588",
15
+ barIncompleteChar: "\u2591",
16
+ hideCursor: true,
17
+ });
18
+
19
+ function getDownload() {
20
+ const { prefix, suffix } = getPrefixSuffix();
21
+
22
+ return `https://github.com/ahqstore/cli/releases/download/${pkg.version}/${prefix}ahqstore_cli_rs-${getRustTarget()}${suffix}`;
23
+ }
24
+
25
+ /**
26
+ *
27
+ * @param {number} ms
28
+ * @returns {Promise<undefined>}
29
+ */
30
+ const delay = (ms) => new Promise((resolve) => setTimeout(() => resolve(undefined), ms));
31
+
32
+ /**
33
+ *
34
+ * @param {string} file
35
+ * @returns {Promise<undefined>}
36
+ */
37
+ export async function downloadModuleWithProgress(file) {
38
+ const download = getDownload();
39
+
40
+ const stream = createWriteStream(file, {
41
+ autoClose: true,
42
+ flush: true
43
+ });
44
+
45
+ const res = await fetch(
46
+ download,
47
+ {
48
+ headers: {
49
+ "user-agent": "Downloader"
50
+ }
51
+ }
52
+ );
53
+
54
+ const bytes = parseInt(res.headers.get("content-length") || "0");
55
+ const kb = Math.round(bytes / 1024);
56
+
57
+ bar.start(kb, 0);
58
+
59
+ const reader = res.body?.getReader()
60
+
61
+ let curr = 0;
62
+
63
+ while (true) {
64
+ const buf = await reader?.read();
65
+
66
+ if (!buf || !buf.value) {
67
+ bar.update(kb);
68
+ bar.stop();
69
+
70
+ await new Promise((resolve) => {
71
+ stream.on('close', () => resolve(undefined));
72
+ stream.end();
73
+ });
74
+ break;
75
+ }
76
+
77
+ const toAdd = buf.value.length || 0;
78
+
79
+ curr += Math.round(toAdd / 1024);
80
+
81
+ bar.update(curr);
82
+
83
+ stream.write(buf.value);
84
+
85
+ await delay(1);
86
+ }
87
+ }
@@ -0,0 +1,29 @@
1
+ import { getRustTarget } from "./rust.js";
2
+
3
+ import { platform, arch } from "node:process";
4
+
5
+ import c from "ansi-colors";
6
+
7
+ try {
8
+ const target = getRustTarget();
9
+
10
+ console.log(c.green(`Supported Target found: `) + c.yellow(`${target}`));
11
+ console.warn(
12
+ c.yellow(
13
+ "The cli will download the supported binaries the first time it loads."
14
+ )
15
+ );
16
+ } catch (_) {
17
+ console.error(
18
+ c.redBright(
19
+ `ERROR: Your OS is not supported for the cli: ${platform}-${arch} has no binaries available right now`
20
+ )
21
+ );
22
+ console.error(
23
+ c.yellowBright(
24
+ `Want to get support for your target? Head over to https://github.com/ahqstore/cli/issues`
25
+ )
26
+ );
27
+
28
+ process.exit(1);
29
+ }
package/js/rust.js ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Maps the Node.js platform and architecture to a Rust target triple.
3
+ * @returns {string} The Rust target triple (e.g., 'x86_64-pc-windows-msvc').
4
+ * @throws {Error} If the platform/architecture combination is not supported.
5
+ */
6
+ export function getRustTarget() {
7
+ const os = process.platform;
8
+ const arch = process.arch;
9
+
10
+ if (os === "win32") {
11
+ if (arch === "ia32") {
12
+ return "i686-pc-windows-msvc";
13
+ } else if (arch === "x64") {
14
+ return "x86_64-pc-windows-msvc";
15
+ } else if (arch === "arm64") {
16
+ return "aarch64-pc-windows-msvc";
17
+ }
18
+ } else if (os === "darwin") {
19
+ if (arch === "x64") {
20
+ return "x86_64-apple-darwin";
21
+ } else if (arch === "arm64") {
22
+ return "aarch64-apple-darwin";
23
+ }
24
+ } else if (os === "linux") {
25
+ if (arch === "ia32") {
26
+ return "i686-unknown-linux-gnu";
27
+ } else if (arch === "x64") {
28
+ return "x86_64-unknown-linux-gnu";
29
+ } else if (arch === "arm") {
30
+ return "armv7-unknown-linux-gnueabihf";
31
+ } else if (arch === "arm64") {
32
+ return "aarch64-unknown-linux-gnu";
33
+ }
34
+ }
35
+
36
+ throw new Error(`Unsupported platform: ${os} ${arch}`);
37
+ }
package/package.json CHANGED
@@ -1,53 +1,36 @@
1
1
  {
2
2
  "name": "@ahqstore/cli",
3
- "version": "0.7.0",
4
- "readme": "./README.md",
5
- "napi": {
6
- "name": "cli",
7
- "triples": {
8
- "additional": [
9
- "aarch64-apple-darwin",
10
- "aarch64-unknown-linux-gnu",
11
- "aarch64-pc-windows-msvc",
12
- "i686-pc-windows-msvc",
13
- "universal-apple-darwin",
14
- "riscv64gc-unknown-linux-gnu"
15
- ]
16
- }
17
- },
18
- "license": "MIT",
19
- "devDependencies": {
20
- "@napi-rs/cli": "^2.18.4"
21
- },
22
- "ava": {
23
- "timeout": "3m"
24
- },
25
- "engines": {
26
- "node": ">= 10"
3
+ "version": "0.10.1",
4
+ "description": "AHQ Store Official CLI, A port of the rust version to NodeJS",
5
+ "keywords": [
6
+ "cli",
7
+ "ahqstore",
8
+ "management"
9
+ ],
10
+ "homepage": "https://github.com/ahqstore/cli#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/ahqstore/cli/issues"
27
13
  },
28
14
  "repository": {
29
- "url": "https://github.com/ahqstore/cli"
15
+ "type": "git",
16
+ "url": "git+https://github.com/ahqstore/cli.git"
30
17
  },
18
+ "license": "MIT",
19
+ "author": "AHQ Softwares <ahqsecret@gmail.com>",
20
+ "type": "module",
31
21
  "bin": {
32
- "ahqstore": "./index.js"
22
+ "ahqstore": "./js/cli.js"
33
23
  },
24
+ "readme": "README.md",
34
25
  "scripts": {
35
- "artifacts": "napi artifacts",
36
- "build": "napi build --platform --release --features node",
37
- "build:debug": "napi build --platform --features node",
38
- "prepublishOnly": "napi prepublish -t npm",
39
- "universal": "napi universal",
40
- "version": "napi version"
26
+ "postinstall": "node js/postinstall.js"
41
27
  },
42
- "optionalDependencies": {
43
- "@ahqstore/cli-win32-x64-msvc": "0.7.0",
44
- "@ahqstore/cli-darwin-x64": "0.7.0",
45
- "@ahqstore/cli-linux-x64-gnu": "0.7.0",
46
- "@ahqstore/cli-darwin-arm64": "0.7.0",
47
- "@ahqstore/cli-linux-arm64-gnu": "0.7.0",
48
- "@ahqstore/cli-win32-arm64-msvc": "0.7.0",
49
- "@ahqstore/cli-win32-ia32-msvc": "0.7.0",
50
- "@ahqstore/cli-darwin-universal": "0.7.0",
51
- "@ahqstore/cli-linux-riscv64-gnu": "0.7.0"
28
+ "dependencies": {
29
+ "ansi-colors": "^4.1.3",
30
+ "cli-progress": "^3.12.0",
31
+ "koffi": "^2.14.0"
32
+ },
33
+ "engines": {
34
+ "node": ">=22"
52
35
  }
53
- }
36
+ }
@@ -0,0 +1,2 @@
1
+ onlyBuiltDependencies:
2
+ - koffi
@@ -0,0 +1,4 @@
1
+ {
2
+ "python-envs.defaultEnvManager": "ms-python.python:system",
3
+ "python-envs.pythonProjects": []
4
+ }
package/python/cli.py ADDED
@@ -0,0 +1,124 @@
1
+ from cffi import FFI
2
+ from pathlib import Path
3
+ from requests import get
4
+
5
+ import importlib.metadata
6
+
7
+ import os
8
+ import platform
9
+ import sys
10
+
11
+ ffi = FFI()
12
+
13
+ ffi.cdef("""
14
+ char* get_ver();
15
+ void init_args();
16
+ void add_arg(char*);
17
+ void node_entrypoint(bool);
18
+ """)
19
+
20
+ ver = importlib.metadata.version("ahqstore-cli")
21
+
22
+ def rust_target():
23
+ os = platform.system().lower()
24
+ arch = platform.machine().lower()
25
+
26
+ if os == "windows":
27
+ if arch == "i686":
28
+ return "i686-pc-windows-msvc"
29
+ elif arch in ("x86_64", "amd64"):
30
+ return "x86_64-pc-windows-msvc"
31
+ elif arch == "aarch64":
32
+ return "aarch64-pc-windows-msvc"
33
+ elif os == "darwin":
34
+ if arch in ("x86_64", "amd64"):
35
+ return "x86_64-apple-darwin"
36
+ elif arch == "aarch64":
37
+ return "aarch64-apple-darwin"
38
+ elif os == "linux":
39
+ if arch == "i686":
40
+ return "i686-unknown-linux-gnu"
41
+ elif arch in ("x86_64", "amd64"):
42
+ return "x86_64-unknown-linux-gnu"
43
+ elif arch == "armv7l":
44
+ return "armv7-unknown-linux-gnueabihf"
45
+ elif arch == "aarch64":
46
+ return "aarch64-unknown-linux-gnu"
47
+
48
+ # Error out for unsupported systems
49
+ print(f"Error: Unsupported platform: {os} {arch}")
50
+ sys.exit(1)
51
+
52
+ def get_prefix_suffix():
53
+ os = platform.system().lower()
54
+ prefix = ""
55
+ suffix = ""
56
+
57
+ if os == "windows":
58
+ suffix = ".dll"
59
+ elif os == "darwin":
60
+ prefix = "lib"
61
+ suffix = ".dylib"
62
+ elif os == "linux":
63
+ prefix = "lib"
64
+ suffix = ".so"
65
+ else:
66
+ # Default to a generic UNIX-like system
67
+ prefix = "lib"
68
+ suffix = ".so"
69
+
70
+ return (prefix, suffix)
71
+
72
+ def dlib():
73
+ (prefix, suffix) = get_prefix_suffix()
74
+
75
+ return f"{prefix}ahqstore_cli_rs{suffix}"
76
+
77
+ dylib = Path.home().joinpath("ahqstore-py")
78
+
79
+ if not dylib.exists():
80
+ dylib.mkdir()
81
+
82
+ dylib = dylib.joinpath(dlib())
83
+
84
+ def dwnl():
85
+ (prefix, suffix) = get_prefix_suffix()
86
+
87
+ return f"https://github.com/ahqstore/cli/releases/download/{ver}/{prefix}ahqstore_cli_rs-{rust_target()}{suffix}"
88
+
89
+ def dwn():
90
+ url = dwnl()
91
+
92
+ resp = get(url)
93
+
94
+ resp.raise_for_status()
95
+
96
+ with open(dylib, "wb") as f:
97
+ f.write(resp.content)
98
+
99
+ def main():
100
+ C = None
101
+
102
+ try:
103
+ C = ffi.dlopen(str(dylib))
104
+
105
+ ver_ptr = C.get_ver()
106
+
107
+ version = ffi.string(ver_ptr)
108
+
109
+ if not version == bytes(ver, "utf-8"):
110
+ raise BufferError("This was an error comapring them")
111
+ except:
112
+ dwn()
113
+ C = ffi.dlopen(str(dylib))
114
+
115
+ C.init_args()
116
+
117
+ for item in sys.argv[1:]:
118
+ arg = ffi.new("char[]", bytes(item, "ascii"))
119
+
120
+ C.add_arg(arg)
121
+
122
+ C.node_entrypoint(
123
+ os.environ.get("CI") == "true"
124
+ )
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "ahqstore-cli"
7
+ version = "0.10.1"
8
+ authors = [{ name = "AHQ Softwares", email = "ahqsecret@gmail.com" }]
9
+ description = "A modern Python wrapper for the ahqstore CLI"
10
+ readme = "../README.md"
11
+ requires-python = ">=3.8"
12
+ classifiers = [
13
+ "Programming Language :: Python :: 3",
14
+ "License :: OSI Approved :: MIT License",
15
+ "Operating System :: OS Independent",
16
+ ]
17
+ dependencies = [
18
+ # List your Python dependencies here, e.g.,
19
+ "requests>=2.25.1",
20
+ "cffi>=1.17.0",
21
+ ]
22
+
23
+ [tool.hatch.build.targets.wheel]
24
+ packages = ["."]
25
+
26
+ [project.scripts]
27
+ ahqstore = "cli:main"
@@ -0,0 +1,3 @@
1
+ import setuptools
2
+
3
+ setuptools.setup()