@ahqstore/cli 0.2.6 → 0.3.5
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/Cargo.toml +53 -0
- package/README.md +0 -43
- package/build.rs +8 -0
- package/index.js +182 -0
- package/package.json +43 -29
- package/src/app/build/config.rs +54 -0
- package/src/app/build/icon.rs +48 -0
- package/src/app/build/mod.rs +217 -0
- package/src/app/build/release.rs +50 -0
- package/src/app/create/icon.png +0 -0
- package/src/app/create/inquire.rs +189 -0
- package/src/app/create/mod.rs +74 -0
- package/src/app/create/readme.md +71 -0
- package/src/app/help.rs +77 -0
- package/src/app/mod.rs +39 -0
- package/src/app/shared/file_sorter.rs +34 -0
- package/src/app/shared/mod.rs +62 -0
- package/src/app/shared/platforms.rs +69 -0
- package/src/lib.rs +12 -0
- package/src/main.rs +10 -0
- package/install.js +0 -44
- package/src/cli.js +0 -24
package/Cargo.toml
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
edition = "2021"
|
|
3
|
+
name = "ahqstore_cli_rs"
|
|
4
|
+
version = "0.3.5"
|
|
5
|
+
description = "AHQ Store CLI"
|
|
6
|
+
repository = "https://github.com/ahqstore/cli"
|
|
7
|
+
homepage = "https://github.com/ahqstore/cli"
|
|
8
|
+
license = "MIT"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
|
|
11
|
+
[lib]
|
|
12
|
+
name = "ahqstore_cli_rs"
|
|
13
|
+
crate-type = ["cdylib"]
|
|
14
|
+
path = "src/lib.rs"
|
|
15
|
+
|
|
16
|
+
[[bin]]
|
|
17
|
+
name = "ahqstore"
|
|
18
|
+
path = "src/main.rs"
|
|
19
|
+
|
|
20
|
+
[dependencies]
|
|
21
|
+
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
|
|
22
|
+
napi = { version = "2.12.2", default-features = false, features = [
|
|
23
|
+
"napi4",
|
|
24
|
+
], optional = true }
|
|
25
|
+
napi-derive = { version = "2.12.2", optional = true }
|
|
26
|
+
inquire = { version = "0.7.5", features = ["editor"] }
|
|
27
|
+
chalk_rs = "1.0.1"
|
|
28
|
+
lazy_static = "1.4.0"
|
|
29
|
+
serde = { version = "1.0.203", features = ["derive"] }
|
|
30
|
+
serde_json = "1.0.117"
|
|
31
|
+
ahqstore-types = "2.0.0"
|
|
32
|
+
reqwest = { version = "0.12", features = ["json", "blocking"] }
|
|
33
|
+
sha2 = "0.10.8"
|
|
34
|
+
base64 = "0.22.1"
|
|
35
|
+
image = { version = "0.25", default-features = false, features = [
|
|
36
|
+
"rayon",
|
|
37
|
+
"png",
|
|
38
|
+
] }
|
|
39
|
+
rand = "0.8.5"
|
|
40
|
+
|
|
41
|
+
[target.'cfg(unix)'.dependencies]
|
|
42
|
+
openssl-sys = { version = "0.9.102", features = ["vendored"] }
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
[build-dependencies]
|
|
46
|
+
napi-build = { version = "2.0.1", optional = true }
|
|
47
|
+
|
|
48
|
+
[profile.release]
|
|
49
|
+
lto = true
|
|
50
|
+
strip = "symbols"
|
|
51
|
+
|
|
52
|
+
[features]
|
|
53
|
+
node = ["dep:napi", "dep:napi-build", "dep:napi-derive"]
|
package/README.md
CHANGED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# AHQ Store CLI
|
|
2
|
-
|
|
3
|
-
The CLI for devs making AHQ Store Apps
|
|
4
|
-
|
|
5
|
-
This version: NPMJS-PREBUILT-BINARIES
|
|
6
|
-
|
|
7
|
-
Install
|
|
8
|
-
|
|
9
|
-
```sh
|
|
10
|
-
$ npm i -g @ahqstore/cli
|
|
11
|
-
$ yarn global add @ahqstore/cli
|
|
12
|
-
$ pnpm add -g @ahqstore/cli
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Help Command
|
|
16
|
-
|
|
17
|
-
The help command shows all available commands
|
|
18
|
-
|
|
19
|
-
```sh
|
|
20
|
-
$ ahqstore --help
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Create .ahqstore config
|
|
24
|
-
|
|
25
|
-
Creates the .ahqstore/\* config files to make your app ready to be built
|
|
26
|
-
|
|
27
|
-
```sh
|
|
28
|
-
$ ahqstore --create {--force}
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Build a project
|
|
32
|
-
|
|
33
|
-
Builds your app based on the config files and environment variables
|
|
34
|
-
ENV:
|
|
35
|
-
|
|
36
|
-
> `APP_ID` (Optional) Application Id (only required if your config has more than 1 appIds)
|
|
37
|
-
> `RELEASE_ID` GitHub Release Id
|
|
38
|
-
> `GH_TOKEN` GitHub Personal Access Token / GitHub Actions Token
|
|
39
|
-
> `GITHUB_REPOSITORY` GitHub owner & repo name, eg ahqstore/app
|
|
40
|
-
|
|
41
|
-
```sh
|
|
42
|
-
$ ahqstore build
|
|
43
|
-
```
|
package/build.rs
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
/* prettier-ignore */
|
|
6
|
+
|
|
7
|
+
/* auto-generated by NAPI-RS */
|
|
8
|
+
/* and modified by @ahqsoftwares */
|
|
9
|
+
|
|
10
|
+
const { existsSync, readFileSync } = require('fs')
|
|
11
|
+
const { join } = require("path");
|
|
12
|
+
|
|
13
|
+
const { platform, arch } = process;
|
|
14
|
+
|
|
15
|
+
let nativeBinding = null;
|
|
16
|
+
let localFileExisted = false;
|
|
17
|
+
let loadError = null;
|
|
18
|
+
|
|
19
|
+
function isMusl() {
|
|
20
|
+
// For Node 10
|
|
21
|
+
if (!process.report || typeof process.report.getReport !== "function") {
|
|
22
|
+
try {
|
|
23
|
+
const lddPath = require("child_process")
|
|
24
|
+
.execSync("which ldd")
|
|
25
|
+
.toString()
|
|
26
|
+
.trim();
|
|
27
|
+
return readFileSync(lddPath, "utf8").includes("musl");
|
|
28
|
+
} catch (e) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
const { glibcVersionRuntime } = process.report.getReport().header;
|
|
33
|
+
return !glibcVersionRuntime;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
switch (platform) {
|
|
38
|
+
case "win32":
|
|
39
|
+
switch (arch) {
|
|
40
|
+
case "x64":
|
|
41
|
+
localFileExisted = existsSync(
|
|
42
|
+
join(__dirname, "cli.win32-x64-msvc.node")
|
|
43
|
+
);
|
|
44
|
+
try {
|
|
45
|
+
if (localFileExisted) {
|
|
46
|
+
nativeBinding = require("./cli.win32-x64-msvc.node");
|
|
47
|
+
} else {
|
|
48
|
+
nativeBinding = require("@ahqstore/cli-win32-x64-msvc");
|
|
49
|
+
}
|
|
50
|
+
} catch (e) {
|
|
51
|
+
loadError = e;
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
case "ia32":
|
|
55
|
+
localFileExisted = existsSync(
|
|
56
|
+
join(__dirname, "cli.win32-ia32-msvc.node")
|
|
57
|
+
);
|
|
58
|
+
try {
|
|
59
|
+
if (localFileExisted) {
|
|
60
|
+
nativeBinding = require("./cli.win32-ia32-msvc.node");
|
|
61
|
+
} else {
|
|
62
|
+
nativeBinding = require("@ahqstore/cli-win32-ia32-msvc");
|
|
63
|
+
}
|
|
64
|
+
} catch (e) {
|
|
65
|
+
loadError = e;
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
case "arm64":
|
|
69
|
+
localFileExisted = existsSync(
|
|
70
|
+
join(__dirname, "cli.win32-arm64-msvc.node")
|
|
71
|
+
);
|
|
72
|
+
try {
|
|
73
|
+
if (localFileExisted) {
|
|
74
|
+
nativeBinding = require("./cli.win32-arm64-msvc.node");
|
|
75
|
+
} else {
|
|
76
|
+
nativeBinding = require("@ahqstore/cli-win32-arm64-msvc");
|
|
77
|
+
}
|
|
78
|
+
} catch (e) {
|
|
79
|
+
loadError = e;
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
default:
|
|
83
|
+
throw new Error(`Unsupported architecture on Windows: ${arch}`);
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
case "darwin":
|
|
87
|
+
localFileExisted = existsSync(join(__dirname, "cli.darwin-universal.node"));
|
|
88
|
+
try {
|
|
89
|
+
if (localFileExisted) {
|
|
90
|
+
nativeBinding = require("./cli.darwin-universal.node");
|
|
91
|
+
} else {
|
|
92
|
+
nativeBinding = require("@ahqstore/cli-darwin-universal");
|
|
93
|
+
}
|
|
94
|
+
break;
|
|
95
|
+
} catch {}
|
|
96
|
+
switch (arch) {
|
|
97
|
+
case "x64":
|
|
98
|
+
localFileExisted = existsSync(join(__dirname, "cli.darwin-x64.node"));
|
|
99
|
+
try {
|
|
100
|
+
if (localFileExisted) {
|
|
101
|
+
nativeBinding = require("./cli.darwin-x64.node");
|
|
102
|
+
} else {
|
|
103
|
+
nativeBinding = require("@ahqstore/cli-darwin-x64");
|
|
104
|
+
}
|
|
105
|
+
} catch (e) {
|
|
106
|
+
loadError = e;
|
|
107
|
+
}
|
|
108
|
+
break;
|
|
109
|
+
case "arm64":
|
|
110
|
+
localFileExisted = existsSync(join(__dirname, "cli.darwin-arm64.node"));
|
|
111
|
+
try {
|
|
112
|
+
if (localFileExisted) {
|
|
113
|
+
nativeBinding = require("./cli.darwin-arm64.node");
|
|
114
|
+
} else {
|
|
115
|
+
nativeBinding = require("@ahqstore/cli-darwin-arm64");
|
|
116
|
+
}
|
|
117
|
+
} catch (e) {
|
|
118
|
+
loadError = e;
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
default:
|
|
122
|
+
throw new Error(`Unsupported architecture on macOS: ${arch}`);
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
case "linux":
|
|
126
|
+
switch (arch) {
|
|
127
|
+
case "x64":
|
|
128
|
+
if (isMusl()) {
|
|
129
|
+
throw new Error("MUSL Bindings are not supported!");
|
|
130
|
+
} else {
|
|
131
|
+
localFileExisted = existsSync(
|
|
132
|
+
join(__dirname, "cli.linux-x64-gnu.node")
|
|
133
|
+
);
|
|
134
|
+
try {
|
|
135
|
+
if (localFileExisted) {
|
|
136
|
+
nativeBinding = require("./cli.linux-x64-gnu.node");
|
|
137
|
+
} else {
|
|
138
|
+
nativeBinding = require("@ahqstore/cli-linux-x64-gnu");
|
|
139
|
+
}
|
|
140
|
+
} catch (e) {
|
|
141
|
+
loadError = e;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
case "arm64":
|
|
146
|
+
if (isMusl()) {
|
|
147
|
+
throw new Error("MUSL Bindings are not supported!");
|
|
148
|
+
} else {
|
|
149
|
+
localFileExisted = existsSync(
|
|
150
|
+
join(__dirname, "cli.linux-arm64-gnu.node")
|
|
151
|
+
);
|
|
152
|
+
try {
|
|
153
|
+
if (localFileExisted) {
|
|
154
|
+
nativeBinding = require("./cli.linux-arm64-gnu.node");
|
|
155
|
+
} else {
|
|
156
|
+
nativeBinding = require("@ahqstore/cli-linux-arm64-gnu");
|
|
157
|
+
}
|
|
158
|
+
} catch (e) {
|
|
159
|
+
loadError = e;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
default:
|
|
164
|
+
throw new Error(`Unsupported architecture on Linux: ${arch}`);
|
|
165
|
+
}
|
|
166
|
+
break;
|
|
167
|
+
default:
|
|
168
|
+
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (!nativeBinding) {
|
|
172
|
+
if (loadError) {
|
|
173
|
+
throw loadError;
|
|
174
|
+
}
|
|
175
|
+
throw new Error(`Failed to load native binding`);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const { nodeEntrypoint } = nativeBinding;
|
|
179
|
+
|
|
180
|
+
const args = process.argv.slice(2) || [];
|
|
181
|
+
|
|
182
|
+
nodeEntrypoint(args, process.env["GH_ACTION"] != null);
|
package/package.json
CHANGED
|
@@ -1,38 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ahqstore/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
"version": "0.3.5",
|
|
4
|
+
"napi": {
|
|
5
|
+
"name": "cli",
|
|
6
|
+
"triples": {
|
|
7
|
+
"additional": [
|
|
8
|
+
"aarch64-apple-darwin",
|
|
9
|
+
"aarch64-unknown-linux-gnu",
|
|
10
|
+
"aarch64-pc-windows-msvc",
|
|
11
|
+
"i686-pc-windows-msvc",
|
|
12
|
+
"universal-apple-darwin",
|
|
13
|
+
"riscv64gc-unknown-linux-gnu"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
10
16
|
},
|
|
11
|
-
"
|
|
12
|
-
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@napi-rs/cli": "^2.18.3"
|
|
13
20
|
},
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
"ava": {
|
|
22
|
+
"timeout": "3m"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">= 10"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"url": "https://github.com/ahqstore/cli"
|
|
21
29
|
},
|
|
22
|
-
"keywords": [
|
|
23
|
-
"Cli",
|
|
24
|
-
"DeveloperTool"
|
|
25
|
-
],
|
|
26
|
-
"author": "AHQ Softwares",
|
|
27
|
-
"license": "MIT",
|
|
28
30
|
"bin": {
|
|
29
|
-
"ahqstore": "
|
|
31
|
+
"ahqstore": "./index.js"
|
|
30
32
|
},
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
+
"scripts": {
|
|
34
|
+
"artifacts": "napi artifacts",
|
|
35
|
+
"build": "napi build --platform --release --features node",
|
|
36
|
+
"build:debug": "napi build --platform --features node",
|
|
37
|
+
"prepublishOnly": "napi prepublish -t npm",
|
|
38
|
+
"universal": "napi universal",
|
|
39
|
+
"version": "napi version"
|
|
33
40
|
},
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
"
|
|
41
|
+
"optionalDependencies": {
|
|
42
|
+
"@ahqstore/cli-win32-x64-msvc": "0.3.5",
|
|
43
|
+
"@ahqstore/cli-darwin-x64": "0.3.5",
|
|
44
|
+
"@ahqstore/cli-linux-x64-gnu": "0.3.5",
|
|
45
|
+
"@ahqstore/cli-darwin-arm64": "0.3.5",
|
|
46
|
+
"@ahqstore/cli-linux-arm64-gnu": "0.3.5",
|
|
47
|
+
"@ahqstore/cli-win32-arm64-msvc": "0.3.5",
|
|
48
|
+
"@ahqstore/cli-win32-ia32-msvc": "0.3.5",
|
|
49
|
+
"@ahqstore/cli-darwin-universal": "0.3.5",
|
|
50
|
+
"@ahqstore/cli-linux-riscv64-gnu": "0.3.5"
|
|
37
51
|
}
|
|
38
|
-
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
use std::{env, fs, process};
|
|
2
|
+
|
|
3
|
+
use serde_json::from_str;
|
|
4
|
+
|
|
5
|
+
use crate::app::{
|
|
6
|
+
shared::{Config, Finder, IMetadata},
|
|
7
|
+
ERR,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
use super::{GHAsset, GHRelease};
|
|
11
|
+
|
|
12
|
+
pub fn get_config<'a>() -> IMetadata<'a> {
|
|
13
|
+
let Ok(config) = fs::read_to_string("./.ahqstore/config.json") else {
|
|
14
|
+
ERR.println(&"Unable to read config file!");
|
|
15
|
+
process::exit(1);
|
|
16
|
+
};
|
|
17
|
+
let config = config.leak();
|
|
18
|
+
let Ok(mut config) = from_str::<'a, Config>(config) else {
|
|
19
|
+
ERR.println(&"Unable to read config file!");
|
|
20
|
+
process::exit(1);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
if let Ok(app_id) = env::var("APP_ID") {
|
|
24
|
+
config.remove(&app_id).expect("Key not present in JSON")
|
|
25
|
+
} else {
|
|
26
|
+
config.into_values().nth(0).expect("No Key present in JSON")
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
pub fn find_assets<'a>(gh_r: &'a GHRelease, finder: &'a Finder) -> Vec<&'a GHAsset> {
|
|
31
|
+
gh_r
|
|
32
|
+
.assets
|
|
33
|
+
.iter()
|
|
34
|
+
.filter(|a| {
|
|
35
|
+
if let Some(x) = finder.startsWith {
|
|
36
|
+
if !a.name.starts_with(&x) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if let Some(x) = finder.contains {
|
|
41
|
+
if !a.name.contains(&x) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if let Some(x) = finder.endsWith {
|
|
46
|
+
if !a.name.ends_with(&x) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
true
|
|
52
|
+
})
|
|
53
|
+
.collect::<Vec<_>>()
|
|
54
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
use crate::app::ERR;
|
|
2
|
+
use base64::engine::{general_purpose::STANDARD, Engine};
|
|
3
|
+
use image::{load_from_memory_with_format as load_img, ImageFormat};
|
|
4
|
+
use std::fs;
|
|
5
|
+
use std::process;
|
|
6
|
+
|
|
7
|
+
pub fn get_icon(uid: &str) -> String {
|
|
8
|
+
let base_img = format!("./.ahqstore/images/{uid}/icon.png");
|
|
9
|
+
|
|
10
|
+
let Ok(icon) = fs::read(&base_img) else {
|
|
11
|
+
ERR.println(&"Unable to read icon file!");
|
|
12
|
+
process::exit(1);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
validate_png(&icon);
|
|
16
|
+
|
|
17
|
+
STANDARD.encode(&icon)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
pub fn get_images(uid: &str) -> Vec<String> {
|
|
21
|
+
let base_img = format!("./.ahqstore/images/{uid}");
|
|
22
|
+
|
|
23
|
+
let Ok(image_dir) = fs::read_dir(&base_img) else {
|
|
24
|
+
ERR.println(&"Unable to read image dir!");
|
|
25
|
+
process::exit(1);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
let mut entries = image_dir
|
|
29
|
+
.map(|res| res.expect("Unable to unwrap dir entry").path())
|
|
30
|
+
.filter(|f| !f.ends_with("icon.png"))
|
|
31
|
+
.map(|res| fs::read(res).expect("Unable to read bytes"))
|
|
32
|
+
.map(|img| {
|
|
33
|
+
validate_png(&img);
|
|
34
|
+
return STANDARD.encode(&img);
|
|
35
|
+
})
|
|
36
|
+
.collect::<Vec<_>>();
|
|
37
|
+
|
|
38
|
+
entries.truncate(10);
|
|
39
|
+
|
|
40
|
+
entries
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
pub fn validate_png(data: &Vec<u8>) {
|
|
44
|
+
let Ok(_) = load_img(&data, ImageFormat::Png) else {
|
|
45
|
+
ERR.println(&"Invalid PNG");
|
|
46
|
+
process::exit(1);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
use ahqstore_types::{
|
|
2
|
+
AHQStoreApplication, DownloadUrl, InstallType, InstallerFormat, InstallerOptions,
|
|
3
|
+
InstallerOptionsLinux, InstallerOptionsWin32, Str,
|
|
4
|
+
};
|
|
5
|
+
use lazy_static::lazy_static;
|
|
6
|
+
use reqwest::blocking::{Client, ClientBuilder};
|
|
7
|
+
use serde::{Deserialize, Serialize};
|
|
8
|
+
use serde_json::{from_str, to_string, to_string_pretty};
|
|
9
|
+
use std::{collections::HashMap, env, fs, process};
|
|
10
|
+
|
|
11
|
+
use crate::app::{ERR, WARN};
|
|
12
|
+
|
|
13
|
+
use super::INFO;
|
|
14
|
+
|
|
15
|
+
mod config;
|
|
16
|
+
mod icon;
|
|
17
|
+
mod release;
|
|
18
|
+
use config::*;
|
|
19
|
+
use icon::*;
|
|
20
|
+
use release::*;
|
|
21
|
+
|
|
22
|
+
lazy_static! {
|
|
23
|
+
pub static ref CLIENT: Client = ClientBuilder::new()
|
|
24
|
+
.user_agent("AHQ Store / App Builder")
|
|
25
|
+
.build()
|
|
26
|
+
.unwrap();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
#[derive(Debug, Deserialize, Serialize)]
|
|
30
|
+
struct GHRelease {
|
|
31
|
+
pub upload_url: String,
|
|
32
|
+
pub assets: Vec<GHAsset>,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#[derive(Debug, Deserialize, Serialize)]
|
|
36
|
+
struct GHAsset {
|
|
37
|
+
pub name: String,
|
|
38
|
+
pub browser_download_url: String,
|
|
39
|
+
}
|
|
40
|
+
pub fn build_config(upload: bool, gh_action: bool) {
|
|
41
|
+
let Some(_) = fs::read_dir("./.ahqstore").ok() else {
|
|
42
|
+
ERR.println(&".ahqstore dir couldn't be accessed!");
|
|
43
|
+
process::exit(1);
|
|
44
|
+
};
|
|
45
|
+
if !gh_action {
|
|
46
|
+
INFO.print(&"INFO ");
|
|
47
|
+
println!("Checking .ahqstore");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let config = get_config();
|
|
51
|
+
|
|
52
|
+
let repo = env::var("GITHUB_REPOSITORY").unwrap_or("%NUL".into());
|
|
53
|
+
|
|
54
|
+
if &repo == "%NUL" {
|
|
55
|
+
ERR.println(&"GITHUB_REPOSITORY not set");
|
|
56
|
+
process::exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let r_id = env::var("RELEASE_ID").unwrap_or("latest".into());
|
|
60
|
+
|
|
61
|
+
if &r_id == "latest" && upload {
|
|
62
|
+
ERR.println(&"RELEASE_ID variable not present");
|
|
63
|
+
process::exit(1);
|
|
64
|
+
};
|
|
65
|
+
if &r_id == "latest" {
|
|
66
|
+
INFO.print(&"INFO ");
|
|
67
|
+
println!("Getting latest release");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let gh_token = env::var("GH_TOKEN").unwrap_or("".into());
|
|
71
|
+
|
|
72
|
+
if &gh_token == "" && upload {
|
|
73
|
+
ERR.println(&"GH_TOKEN variable not present");
|
|
74
|
+
process::exit(1);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
let (version, gh_r) = fetch_release(&repo, &r_id, &gh_token);
|
|
78
|
+
|
|
79
|
+
let icon = get_icon(&config.appId);
|
|
80
|
+
#[allow(non_snake_case)]
|
|
81
|
+
let displayImages = get_images(&config.appId);
|
|
82
|
+
|
|
83
|
+
let app_id = config.appId.clone();
|
|
84
|
+
|
|
85
|
+
let mut final_config: AHQStoreApplication = AHQStoreApplication {
|
|
86
|
+
appDisplayName: config.appDisplayName,
|
|
87
|
+
appId: config.appId,
|
|
88
|
+
appShortcutName: config.appShortcutName,
|
|
89
|
+
authorId: config.authorId,
|
|
90
|
+
description: config.description,
|
|
91
|
+
downloadUrls: HashMap::default(),
|
|
92
|
+
icon,
|
|
93
|
+
displayImages,
|
|
94
|
+
install: InstallerOptions {
|
|
95
|
+
installType: config.platform.installType,
|
|
96
|
+
linux: None,
|
|
97
|
+
win32: None,
|
|
98
|
+
},
|
|
99
|
+
repo: config.repo,
|
|
100
|
+
version,
|
|
101
|
+
site: None,
|
|
102
|
+
source: None
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
if let Some(platform) = config.platform.win32Platform {
|
|
106
|
+
match (&platform, &final_config.install.installType) {
|
|
107
|
+
(&InstallerFormat::WindowsZip, _) => {}
|
|
108
|
+
(_, &InstallType::PerUser | &InstallType::Computer) => {
|
|
109
|
+
WARN.println(
|
|
110
|
+
&"Setting PerUser or Computer in a non WindowsZip install type does not have any effect",
|
|
111
|
+
);
|
|
112
|
+
process::exit(1);
|
|
113
|
+
}
|
|
114
|
+
_ => {}
|
|
115
|
+
};
|
|
116
|
+
let Some(options) = config.platform.win32Options else {
|
|
117
|
+
ERR.println(&"Win32 Options not found!");
|
|
118
|
+
process::exit(1);
|
|
119
|
+
};
|
|
120
|
+
let Some(finder) = config.finder.windowsFinder else {
|
|
121
|
+
ERR.println(&"Win32 Finder Config not found!");
|
|
122
|
+
process::exit(1);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
let assets = find_assets(&gh_r, &finder);
|
|
126
|
+
|
|
127
|
+
if assets.len() > 1 {
|
|
128
|
+
ERR.println(&"Multiple assets found");
|
|
129
|
+
process::exit(1);
|
|
130
|
+
}
|
|
131
|
+
if assets.len() == 0 {
|
|
132
|
+
ERR.println(&"No assets found");
|
|
133
|
+
process::exit(1);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
final_config.downloadUrls.insert(
|
|
137
|
+
1,
|
|
138
|
+
DownloadUrl {
|
|
139
|
+
installerType: platform,
|
|
140
|
+
url: assets[0].browser_download_url.clone(),
|
|
141
|
+
},
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
final_config.install.win32 = Some(InstallerOptionsWin32 {
|
|
145
|
+
assetId: 1,
|
|
146
|
+
deps: Some(options.deps),
|
|
147
|
+
exec: options.zip_file_exec.map_or(None, |a| Some(a.to_string())),
|
|
148
|
+
installerArgs: options
|
|
149
|
+
.exe_installer_args
|
|
150
|
+
.map_or(None, |a| Some(a.iter().map(|x| x.to_string()).collect())),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if let Some(platform) = config.platform.linuxPlatform {
|
|
155
|
+
let Some(finder) = config.finder.linuxFinder else {
|
|
156
|
+
ERR.println(&"Linux Finder Config not found!");
|
|
157
|
+
process::exit(1);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
let assets = find_assets(&gh_r, &finder);
|
|
161
|
+
|
|
162
|
+
if assets.len() > 1 {
|
|
163
|
+
ERR.println(&"Multiple assets found");
|
|
164
|
+
process::exit(1);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
final_config.downloadUrls.insert(
|
|
168
|
+
2,
|
|
169
|
+
DownloadUrl {
|
|
170
|
+
installerType: platform,
|
|
171
|
+
url: assets[0].browser_download_url.clone(),
|
|
172
|
+
},
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
final_config.install.linux = Some(InstallerOptionsLinux {
|
|
176
|
+
assetId: 2
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
final_config.site = config.site;
|
|
181
|
+
final_config.source = config.redistributed;
|
|
182
|
+
|
|
183
|
+
let config_file = to_string_pretty(&final_config).unwrap();
|
|
184
|
+
let config_file = to_string(config_file.as_bytes()).unwrap();
|
|
185
|
+
|
|
186
|
+
if !gh_action {
|
|
187
|
+
println!("Bytes: ahqstore.json");
|
|
188
|
+
println!("{}", &config_file);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if upload {
|
|
192
|
+
let uup = gh_r
|
|
193
|
+
.upload_url
|
|
194
|
+
.replace("{?name,label}", &format!("?name={app_id}.txt"));
|
|
195
|
+
|
|
196
|
+
let resp = CLIENT
|
|
197
|
+
.post(uup)
|
|
198
|
+
.header("Content-Length", config_file.len())
|
|
199
|
+
.header("Content-Type", "text/plain")
|
|
200
|
+
.header("Accept", "application/json")
|
|
201
|
+
.body(config_file)
|
|
202
|
+
.bearer_auth(&gh_token)
|
|
203
|
+
.send()
|
|
204
|
+
.unwrap()
|
|
205
|
+
.text()
|
|
206
|
+
.unwrap();
|
|
207
|
+
|
|
208
|
+
if gh_action {
|
|
209
|
+
let val: GHAsset = from_str(&resp).unwrap();
|
|
210
|
+
|
|
211
|
+
println!("AHQ_STORE_FILE_URL={}", &val.browser_download_url);
|
|
212
|
+
} else {
|
|
213
|
+
INFO.println(&"GitHub Response");
|
|
214
|
+
println!("{resp}");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|