@ahqstore/cli 0.5.4 → 0.6.0

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.
@@ -1,232 +1,219 @@
1
- use ahqstore_types::{
2
- AHQStoreApplication, DownloadUrl, InstallerFormat, InstallerOptions, InstallerOptionsAndroid, InstallerOptionsLinux, InstallerOptionsWindows, Str
3
- };
4
- use lazy_static::lazy_static;
5
- use reqwest::blocking::{Client, ClientBuilder};
6
- use serde::{Deserialize, Serialize};
7
- use serde_json::{from_str, to_string, to_string_pretty};
8
- use std::{collections::HashMap, env, fs, process};
9
-
10
- use crate::app::ERR;
11
-
12
- use super::INFO;
13
-
14
- mod config;
15
- mod icon;
16
- mod release;
17
- use config::*;
18
- use icon::*;
19
- use release::*;
20
-
21
- #[macro_use]
22
- mod macros;
23
-
24
- lazy_static! {
25
- pub static ref CLIENT: Client = ClientBuilder::new()
26
- .user_agent("AHQ Store / App Builder")
27
- .build()
28
- .unwrap();
29
- }
30
-
31
- #[derive(Debug, Deserialize, Serialize)]
32
- struct GHRelease {
33
- pub tag_name: String,
34
- pub upload_url: String,
35
- pub assets: Vec<GHAsset>,
36
- }
37
-
38
- #[derive(Debug, Deserialize, Serialize)]
39
- struct GHAsset {
40
- pub name: String,
41
- pub browser_download_url: String,
42
- }
43
- pub fn build_config(upload: bool, gh_action: bool) {
44
- let Some(_) = fs::read_dir("./.ahqstore").ok() else {
45
- ERR.println(&".ahqstore dir couldn't be accessed!");
46
- process::exit(1);
47
- };
48
- if !gh_action {
49
- INFO.print(&"INFO ");
50
- println!("Checking .ahqstore");
51
- }
52
-
53
- let config = get_config();
54
-
55
- let repo = env::var("GITHUB_REPOSITORY").unwrap_or("%NUL".into());
56
-
57
- if &repo == "%NUL" {
58
- ERR.println(&"GITHUB_REPOSITORY not set");
59
- process::exit(1);
60
- }
61
-
62
- let r_id = env::var("RELEASE_ID").unwrap_or("latest".into());
63
-
64
- if &r_id == "latest" && upload {
65
- ERR.println(&"RELEASE_ID variable not present");
66
- process::exit(1);
67
- };
68
- if &r_id == "latest" {
69
- INFO.print(&"INFO ");
70
- println!("Getting latest release");
71
- }
72
-
73
- let gh_token = env::var("GH_TOKEN").unwrap_or("".into());
74
-
75
- if &gh_token == "" && upload {
76
- ERR.println(&"GH_TOKEN variable not present");
77
- process::exit(1);
78
- };
79
-
80
- let (version, gh_r) = fetch_release(&repo, &r_id, &gh_token);
81
-
82
- let icon = get_icon(&config.appId);
83
- let dspl_images = get_images(&config.appId);
84
-
85
- let mut resources = HashMap::new();
86
- resources.insert(0, icon);
87
-
88
- #[allow(non_snake_case)]
89
- let displayImages = dspl_images.into_iter().enumerate().map(|(uid, icon)| {
90
- resources.insert(uid as u8 + 1u8, icon);
91
-
92
- uid as u8
93
- }).collect();
94
-
95
- let app_id = config.appId.clone();
96
-
97
- let mut final_config: AHQStoreApplication = AHQStoreApplication {
98
- releaseTagName: gh_r.tag_name.clone(),
99
- appDisplayName: config.appDisplayName,
100
- appId: config.appId,
101
- appShortcutName: config.appShortcutName,
102
- authorId: config.authorId,
103
- description: config.description,
104
- downloadUrls: HashMap::default(),
105
- displayImages,
106
- resources: Some(resources),
107
- app_page: config.source,
108
- license_or_tos: config.license_or_tos,
109
- install: InstallerOptions {
110
- linux: None,
111
- android: None,
112
- linuxArm64: None,
113
- linuxArm7: None,
114
- winarm: None,
115
- win32: None,
116
- },
117
- repo: config.repo,
118
- version,
119
- site: config.site,
120
- source: config.redistributed,
121
- };
122
-
123
- let mut num = 0;
124
- // Win x86_64
125
- windowsPlatform!(num, win32, config, gh_r, final_config, winAmd64Platform, winAmd64Options, windowsAmd64Finder);
126
-
127
- // Win Arm64
128
- windowsPlatform!(num, winarm, config, gh_r, final_config, winArm64Platform, winArm64Options, windowsArm64Finder);
129
-
130
- // Linux x86_64
131
- linuxPlatform!(num, linux, config, gh_r, final_config, linuxAmd64Platform, linuxAmd64Finder);
132
-
133
- // Linux Arm64
134
- linuxPlatform!(num, linuxArm64, config, gh_r, final_config, linuxArm64Platform, linuxArm64Finder);
135
-
136
- // Linux Armv7
137
- linuxPlatform!(num, linuxArm7, config, gh_r, final_config, linuxArm32Platform, linuxArm32Finder);
138
-
139
- num += 1;
140
-
141
- // Android Universal
142
- if let Some(platform) = config.platform.androidUniversal {
143
- if !matches!(platform, InstallerFormat::AndroidApkZip) {
144
- ERR.println(&"Invalid File Format, expected AndroidApkZip");
145
- }
146
-
147
- let Some(finder) = config.finder.androidUniversalFinder else {
148
- ERR.println(&"Android Finder Config not found!");
149
- process::exit(1);
150
- };
151
-
152
- let assets = find_assets(&gh_r, &finder);
153
-
154
- if assets.len() > 1 {
155
- ERR.println(&"Multiple assets found while parsing android");
156
- process::exit(1);
157
- }
158
-
159
- final_config.downloadUrls.insert(
160
- num,
161
- DownloadUrl {
162
- installerType: platform,
163
- asset: assets[0].name.clone(),
164
- url: "".into()
165
- },
166
- );
167
-
168
- final_config.install.android = Some(InstallerOptionsAndroid {
169
- assetId: num
170
- });
171
- }
172
-
173
- // if let Some(platform) = config.platform.linuxArm64Platform {
174
- // let Some(finder) = config.finder.linuxFinder else {
175
- // ERR.println(&"Linux Finder Config not found!");
176
- // process::exit(1);
177
- // };
178
-
179
- // let assets = find_assets(&gh_r, &finder);
180
-
181
- // if assets.len() > 1 {
182
- // ERR.println(&"Multiple assets found");
183
- // process::exit(1);
184
- // }
185
-
186
- // final_config.downloadUrls.insert(
187
- // 2,
188
- // DownloadUrl {
189
- // installerType: platform,
190
- // url: assets[0].browser_download_url.clone(),
191
- // },
192
- // );
193
-
194
- // final_config.install.linux = Some(InstallerOptionsLinux {
195
- // assetId: 2
196
- // });
197
- // }
198
-
199
- let config_file = to_string_pretty(&final_config).unwrap();
200
-
201
- if !gh_action {
202
- println!("{} {}.json", &*INFO, &app_id);
203
- println!("{}", &config_file);
204
- }
205
-
206
- if upload {
207
- let uup = gh_r
208
- .upload_url
209
- .replace("{?name,label}", &format!("?name={app_id}.json"));
210
-
211
- let resp = CLIENT
212
- .post(uup)
213
- .header("Content-Length", config_file.len())
214
- .header("Content-Type", "text/plain")
215
- .header("Accept", "application/json")
216
- .body(config_file)
217
- .bearer_auth(&gh_token)
218
- .send()
219
- .unwrap()
220
- .text()
221
- .unwrap();
222
-
223
- if gh_action {
224
- let val: GHAsset = from_str(&resp).unwrap();
225
-
226
- println!("AHQ_STORE_FILE_URL={}", &val.browser_download_url);
227
- } else {
228
- INFO.println(&"GitHub Response");
229
- println!("{resp}");
230
- }
231
- }
232
- }
1
+ use ahqstore_types::{
2
+ AHQStoreApplication, DownloadUrl, InstallerFormat, InstallerOptions, InstallerOptionsAndroid, InstallerOptionsLinux, InstallerOptionsWindows, Str
3
+ };
4
+ use lazy_static::lazy_static;
5
+ use reqwest::blocking::{Client, ClientBuilder};
6
+ use serde::{Deserialize, Serialize};
7
+ use serde_json::{from_str, to_string};
8
+ use std::{collections::HashMap, env, fs, process};
9
+
10
+ use crate::app::ERR;
11
+
12
+ use super::INFO;
13
+
14
+ mod config;
15
+ mod icon;
16
+ mod release;
17
+ use config::*;
18
+ use icon::*;
19
+ use release::*;
20
+
21
+ #[macro_use]
22
+ mod macros;
23
+
24
+ lazy_static! {
25
+ pub static ref CLIENT: Client = ClientBuilder::new()
26
+ .user_agent("AHQ Store / App Builder")
27
+ .build()
28
+ .unwrap();
29
+ }
30
+
31
+ #[derive(Debug, Deserialize, Serialize)]
32
+ struct GHRelease {
33
+ pub tag_name: String,
34
+ pub upload_url: String,
35
+ pub assets: Vec<GHAsset>,
36
+ }
37
+
38
+ #[derive(Debug, Deserialize, Serialize)]
39
+ struct GHAsset {
40
+ pub name: String,
41
+ pub browser_download_url: String,
42
+ }
43
+ pub fn build_config(upload: bool, gh_action: bool) {
44
+ let Some(_) = fs::read_dir("./.ahqstore").ok() else {
45
+ ERR.println(&".ahqstore dir couldn't be accessed!");
46
+ process::exit(1);
47
+ };
48
+ if !gh_action {
49
+ INFO.print(&"INFO ");
50
+ println!("Checking .ahqstore");
51
+ }
52
+
53
+ let config = get_config();
54
+
55
+ let repo = env::var("GITHUB_REPOSITORY").unwrap_or("%NUL".into());
56
+
57
+ if &repo == "%NUL" {
58
+ ERR.println(&"GITHUB_REPOSITORY not set");
59
+ process::exit(1);
60
+ }
61
+
62
+ let r_id = env::var("RELEASE_ID").unwrap_or("latest".into());
63
+
64
+ if &r_id == "latest" && upload {
65
+ ERR.println(&"RELEASE_ID variable not present");
66
+ process::exit(1);
67
+ };
68
+ if &r_id == "latest" {
69
+ INFO.print(&"INFO ");
70
+ println!("Getting latest release");
71
+ }
72
+
73
+ let gh_token = env::var("GH_TOKEN").unwrap_or("".into());
74
+
75
+ if &gh_token == "" && upload {
76
+ ERR.println(&"GH_TOKEN variable not present");
77
+ process::exit(1);
78
+ };
79
+
80
+ let (version, gh_r) = fetch_release(&repo, &r_id, &gh_token);
81
+
82
+ let icon = get_icon(&config.appId);
83
+ let dspl_images = get_images(&config.appId);
84
+
85
+ let mut resources = HashMap::new();
86
+ resources.insert(0, icon);
87
+
88
+ #[allow(non_snake_case)]
89
+ let displayImages = dspl_images.into_iter().enumerate().map(|(uid, icon)| {
90
+ resources.insert(uid as u8 + 1u8, icon);
91
+
92
+ uid as u8
93
+ }).collect();
94
+
95
+ let app_id = config.appId.clone();
96
+
97
+ let mut final_config: AHQStoreApplication = AHQStoreApplication {
98
+ releaseTagName: gh_r.tag_name.clone(),
99
+ appDisplayName: config.appDisplayName,
100
+ appId: config.appId,
101
+ appShortcutName: config.appShortcutName,
102
+ authorId: config.authorId,
103
+ description: config.description,
104
+ downloadUrls: HashMap::default(),
105
+ displayImages,
106
+ resources: Some(resources),
107
+ app_page: config.source,
108
+ license_or_tos: config.license_or_tos,
109
+ install: InstallerOptions {
110
+ linux: None,
111
+ android: None,
112
+ linuxArm64: None,
113
+ linuxArm7: None,
114
+ winarm: None,
115
+ win32: None,
116
+ },
117
+ repo: config.repo,
118
+ version,
119
+ site: config.site,
120
+ source: config.redistributed,
121
+ };
122
+
123
+ let mut num = 0;
124
+ // Win x86_64
125
+ windowsPlatform!(num, win32, config, gh_r, final_config, winAmd64Platform, winAmd64Options, windowsAmd64Finder);
126
+
127
+ // Win Arm64
128
+ windowsPlatform!(num, winarm, config, gh_r, final_config, winArm64Platform, winArm64Options, windowsArm64Finder);
129
+
130
+ // Linux x86_64
131
+ linuxPlatform!(num, linux, config, gh_r, final_config, linuxAmd64Platform, linuxAmd64Finder);
132
+
133
+ // Linux Arm64
134
+ linuxPlatform!(num, linuxArm64, config, gh_r, final_config, linuxArm64Platform, linuxArm64Finder);
135
+
136
+ // Linux Armv7
137
+ linuxPlatform!(num, linuxArm7, config, gh_r, final_config, linuxArm32Platform, linuxArm32Finder);
138
+
139
+ num += 1;
140
+
141
+ // Android Universal
142
+ if let Some(platform) = config.platform.androidUniversal {
143
+ if !matches!(platform, InstallerFormat::AndroidApkZip) {
144
+ ERR.println(&"Invalid File Format, expected AndroidApkZip");
145
+ }
146
+
147
+ let Some(finder) = config.finder.androidUniversalFinder else {
148
+ ERR.println(&"Android Finder Config not found!");
149
+ process::exit(1);
150
+ };
151
+
152
+ let assets = find_assets(&gh_r, &finder);
153
+
154
+ if assets.len() > 1 {
155
+ ERR.println(&"Multiple assets found while parsing android");
156
+ process::exit(1);
157
+ }
158
+
159
+ final_config.downloadUrls.insert(
160
+ num,
161
+ DownloadUrl {
162
+ installerType: platform,
163
+ asset: assets[0].name.clone(),
164
+ url: "".into()
165
+ },
166
+ );
167
+
168
+ final_config.install.android = Some(InstallerOptionsAndroid {
169
+ assetId: num
170
+ });
171
+ }
172
+
173
+ INFO.println(&"Validating config");
174
+ match final_config.validate() {
175
+ Ok(x) => {
176
+ println!("{x}");
177
+ },
178
+ Err(x) => {
179
+ ERR.println(&"An error occured!");
180
+ println!("{x}");
181
+
182
+ panic!("👆🏼 Please fix the above issues!");
183
+ }
184
+ }
185
+
186
+ let config_file = to_string(&final_config).unwrap();
187
+
188
+ if !gh_action {
189
+ println!("{} {}.json", &*INFO, &app_id);
190
+ println!("{}", &config_file);
191
+ }
192
+
193
+ if upload {
194
+ let uup = gh_r
195
+ .upload_url
196
+ .replace("{?name,label}", &format!("?name={app_id}.json"));
197
+
198
+ let resp = CLIENT
199
+ .post(uup)
200
+ .header("Content-Length", config_file.len())
201
+ .header("Content-Type", "text/plain")
202
+ .header("Accept", "application/json")
203
+ .body(config_file)
204
+ .bearer_auth(&gh_token)
205
+ .send()
206
+ .unwrap()
207
+ .text()
208
+ .unwrap();
209
+
210
+ if gh_action {
211
+ let val: GHAsset = from_str(&resp).unwrap();
212
+
213
+ println!("AHQ_STORE_FILE_URL={}", &val.browser_download_url);
214
+ } else {
215
+ INFO.println(&"GitHub Response");
216
+ println!("{resp}");
217
+ }
218
+ }
219
+ }
@@ -1,50 +1,50 @@
1
- use std::process;
2
-
3
- use serde_json::{from_str, to_string};
4
- use sha2::{Digest, Sha256};
5
-
6
- use crate::app::{
7
- build::{GHRelease, Str},
8
- ERR, WARN,
9
- };
10
-
11
- use super::CLIENT;
12
-
13
- pub fn fetch_release(repo: &str, r_id: &str, gh_token: &str) -> (Str, GHRelease) {
14
- let Ok(resp) = ({
15
- let mut resp = CLIENT.get(format!(
16
- "https://api.github.com/repos/{repo}/releases/{r_id}"
17
- ));
18
-
19
- if gh_token != "" {
20
- resp = resp.bearer_auth(gh_token);
21
- } else {
22
- WARN.println(&"You may set GH_TOKEN environment variable to load private repos");
23
- }
24
-
25
- resp.send()
26
- }) else {
27
- ERR.println(&"Unable to fetch release");
28
- process::exit(1)
29
- };
30
-
31
- let Ok(release) = resp.text() else {
32
- ERR.println(&"Unable to read release");
33
- process::exit(1);
34
- };
35
-
36
- let Ok(resp) = from_str::<GHRelease>(&release) else {
37
- ERR.println(&"Unable to parse release");
38
- process::exit(1);
39
- };
40
-
41
- let mut hasher = Sha256::new();
42
-
43
- hasher.update(release.as_bytes());
44
-
45
- let hashed = hasher.finalize();
46
- let hashed = hashed.to_vec();
47
- let version = to_string(&hashed).unwrap_or("**UNKNOWN**".to_string());
48
-
49
- (version, resp)
50
- }
1
+ use std::process;
2
+
3
+ use serde_json::{from_str, to_string};
4
+ use sha2::{Digest, Sha256};
5
+
6
+ use crate::app::{
7
+ build::{GHRelease, Str},
8
+ ERR, WARN,
9
+ };
10
+
11
+ use super::CLIENT;
12
+
13
+ pub fn fetch_release(repo: &str, r_id: &str, gh_token: &str) -> (Str, GHRelease) {
14
+ let Ok(resp) = ({
15
+ let mut resp = CLIENT.get(format!(
16
+ "https://api.github.com/repos/{repo}/releases/{r_id}"
17
+ ));
18
+
19
+ if gh_token != "" {
20
+ resp = resp.bearer_auth(gh_token);
21
+ } else {
22
+ WARN.println(&"You may set GH_TOKEN environment variable to load private repos");
23
+ }
24
+
25
+ resp.send()
26
+ }) else {
27
+ ERR.println(&"Unable to fetch release");
28
+ process::exit(1)
29
+ };
30
+
31
+ let Ok(release) = resp.text() else {
32
+ ERR.println(&"Unable to read release");
33
+ process::exit(1);
34
+ };
35
+
36
+ let Ok(resp) = from_str::<GHRelease>(&release) else {
37
+ ERR.println(&"Unable to parse release");
38
+ process::exit(1);
39
+ };
40
+
41
+ let mut hasher = Sha256::new();
42
+
43
+ hasher.update(release.as_bytes());
44
+
45
+ let hashed = hasher.finalize();
46
+ let hashed = hashed.to_vec();
47
+ let version = to_string(&hashed).unwrap_or("**UNKNOWN**".to_string());
48
+
49
+ (version, resp)
50
+ }