@ahqstore/cli 0.10.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.
- package/.vscode/settings.json +4 -0
- package/Cargo.toml +1 -1
- package/bundle.ps1 +7 -7
- package/go/go.exe +0 -0
- package/go/go.mod +3 -0
- package/go/main.go +7 -0
- package/js/cli.js +42 -9
- package/js/download.js +70 -12
- package/package.json +1 -1
- package/python/.vscode/settings.json +4 -0
- package/python/cli.py +124 -0
- package/python/pyproject.toml +27 -0
- package/python/setup.py +3 -0
package/Cargo.toml
CHANGED
package/bundle.ps1
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
mkdir dist
|
|
2
2
|
|
|
3
|
-
Copy-Item "./target/$env:TARGET/release/ahqstore.exe" "./dist/ahqstore.exe" -ErrorAction
|
|
4
|
-
Copy-Item "./target/$env:TARGET/release/ahqstore.exe" "./dist/ahqstore_cli_rs.exe" -ErrorAction
|
|
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
5
|
|
|
6
|
-
Copy-Item "./target/$env:TARGET/release/ahqstore" "./dist/ahqstore" -ErrorAction
|
|
7
|
-
Copy-Item "./target/$env:TARGET/release/ahqstore" "./dist/ahqstore_cli_rs" -ErrorAction
|
|
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
8
|
|
|
9
9
|
compress-archive ./dist/* ./ahqstore_cli_rs-$env:TARGET
|
|
10
10
|
|
|
11
|
-
Copy-Item "./target/$env:TARGET/release/ahqstore_cli_rs.dll" "./ahqstore_cli_rs-$env:TARGET.dll" -ErrorAction
|
|
12
|
-
Copy-Item "./target/$env:TARGET/release/libahqstore_cli_rs.so" "./libahqstore_cli_rs-$env:TARGET.so" -ErrorAction
|
|
13
|
-
Copy-Item "./target/$env:TARGET/release/libahqstore_cli_rs.dylib" "./libahqstore_cli_rs-$env:TARGET.dylib" -ErrorAction
|
|
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
package/go/main.go
ADDED
package/js/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
// @ts-check
|
|
3
3
|
|
|
4
|
-
import { existsSync, mkdirSync, rmSync } from "node:fs";
|
|
5
4
|
import { join } from "node:path";
|
|
5
|
+
import { existsSync, mkdirSync, rmSync } from "node:fs";
|
|
6
6
|
import { argv, env, platform } from "node:process";
|
|
7
7
|
|
|
8
8
|
import { downloadModuleWithProgress } from "./download.js";
|
|
@@ -47,23 +47,48 @@ function getLibraryFilename(name) {
|
|
|
47
47
|
return `${prefix}${name}${suffix}`;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
console.log(import.meta.dirname);
|
|
51
|
-
|
|
52
50
|
const dylibDir = join(import.meta.dirname, "lib");
|
|
51
|
+
const dylib = join(dylibDir, getLibraryFilename("ahqstore_cli_rs"));
|
|
53
52
|
|
|
54
|
-
if (!existsSync(dylibDir)) {
|
|
53
|
+
if (!(existsSync(dylibDir) && existsSync(dylib))) {
|
|
55
54
|
console.warn(
|
|
56
55
|
c.red.redBright(
|
|
57
56
|
"Binary not found, downloading AHQ Store CLI Binary for this version",
|
|
58
57
|
),
|
|
59
58
|
);
|
|
60
59
|
|
|
61
|
-
|
|
60
|
+
try {
|
|
61
|
+
rmSync(dylib);
|
|
62
|
+
} catch(_) {}
|
|
63
|
+
try {
|
|
64
|
+
mkdirSync(dylibDir);
|
|
65
|
+
} catch (_) {}
|
|
66
|
+
|
|
67
|
+
await downloadModuleWithProgress(dylib);
|
|
62
68
|
}
|
|
63
69
|
|
|
64
|
-
|
|
70
|
+
let dlib;
|
|
65
71
|
|
|
66
|
-
|
|
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
|
+
}
|
|
67
92
|
|
|
68
93
|
const ver = dlib.func("get_ver", "str", []);
|
|
69
94
|
|
|
@@ -79,10 +104,15 @@ if (output != pkg.version) {
|
|
|
79
104
|
// Unload current one
|
|
80
105
|
dlib.unload();
|
|
81
106
|
|
|
82
|
-
|
|
107
|
+
try {
|
|
108
|
+
rmSync(dylib);
|
|
109
|
+
} catch(_) {}
|
|
110
|
+
try {
|
|
111
|
+
mkdirSync(dylibDir);
|
|
112
|
+
} catch (_) {}
|
|
83
113
|
|
|
84
114
|
/// Download
|
|
85
|
-
|
|
115
|
+
await downloadModuleWithProgress(dylib);
|
|
86
116
|
|
|
87
117
|
// Load newer
|
|
88
118
|
dlib = koffi.load(dylib);
|
|
@@ -96,4 +126,7 @@ argv.slice(2).forEach((a) => {
|
|
|
96
126
|
pushArg(a);
|
|
97
127
|
});
|
|
98
128
|
|
|
129
|
+
// Clear the console output
|
|
130
|
+
console.clear();
|
|
131
|
+
|
|
99
132
|
dlib.func("node_entrypoint", "void", ["bool"])(env["CI"] == "true");
|
package/js/download.js
CHANGED
|
@@ -1,29 +1,87 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
3
|
import { SingleBar } from "cli-progress";
|
|
4
|
-
import c from "ansi-colors";
|
|
5
|
-
|
|
6
|
-
import pkg from "../package.json" with { type: "json" };
|
|
7
4
|
import { getPrefixSuffix } from "./cli.js";
|
|
8
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" };
|
|
9
10
|
|
|
10
11
|
const bar = new SingleBar({
|
|
11
12
|
format:
|
|
12
|
-
"Downloading |" + c.cyan("{bar}") + "| {percentage}%
|
|
13
|
+
"Downloading |" + c.cyan("{bar}") + "| {percentage}% | {value}/{total} KB",
|
|
13
14
|
barCompleteChar: "\u2588",
|
|
14
15
|
barIncompleteChar: "\u2591",
|
|
15
16
|
hideCursor: true,
|
|
16
17
|
});
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
bar.increment();
|
|
21
|
-
bar.update(20);
|
|
22
|
-
|
|
23
|
-
async function getDownload() {
|
|
19
|
+
function getDownload() {
|
|
24
20
|
const { prefix, suffix } = getPrefixSuffix();
|
|
25
21
|
|
|
26
|
-
return `https://github.com/ahqstore/cli/releases/download/${pkg.version}/${prefix}ahqstore_cli_rs-${getRustTarget()}
|
|
22
|
+
return `https://github.com/ahqstore/cli/releases/download/${pkg.version}/${prefix}ahqstore_cli_rs-${getRustTarget()}${suffix}`;
|
|
27
23
|
}
|
|
28
24
|
|
|
29
|
-
|
|
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
|
+
}
|
package/package.json
CHANGED
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"
|
package/python/setup.py
ADDED