@ahqstore/cli 0.7.0 → 0.10.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,98 +0,0 @@
1
- macro_rules! f {
2
- ($($x:tt)*) => {
3
- format!($($x)*)
4
- };
5
- }
6
-
7
- macro_rules! s {
8
- ($($x:tt)*) => {
9
- stringify!($($x)*)
10
- };
11
- }
12
-
13
- #[macro_export]
14
- macro_rules! windowsPlatform {
15
- ($num: ident, $win: ident, $config: ident, $gh_r: ident, $final_config: ident, $platform: ident, $options: ident, $finder: ident) => {
16
- $num += 1;
17
- if let Some(platform) = $config.platform.$platform {
18
- if matches!(&platform, &InstallerFormat::LinuxAppImage | &InstallerFormat::AndroidApkZip) {
19
- ERR.println(&"Invalid File Format, expected a valid windows format");
20
- process::exit(1);
21
- }
22
-
23
- let Some(options) = $config.platform.$options else {
24
- ERR.println(&f!("{} Options not found!", s!($win)));
25
- process::exit(1);
26
- };
27
- let Some(finder) = $config.finder.$finder else {
28
- ERR.println(&f!("{} Finder config not found!", s!($win)));
29
- process::exit(1);
30
- };
31
-
32
- let assets = crate::app::build::find_assets(&$gh_r, &finder);
33
-
34
- if assets.len() > 1 {
35
- ERR.println(&f!("Multiple assets found while parsing {}", s!($win)));
36
- process::exit(1);
37
- }
38
- if assets.len() == 0 {
39
- ERR.println(&f!("No assets found while parsing {}", s!($win)));
40
- process::exit(1);
41
- }
42
-
43
- $final_config.downloadUrls.insert(
44
- $num,
45
- DownloadUrl {
46
- installerType: platform,
47
- asset: assets[0].name.clone(),
48
- url: "".into(),
49
- },
50
- );
51
-
52
- $final_config.install.$win = Some(InstallerOptionsWindows {
53
- assetId: $num,
54
- exec: options.zip_file_exec.map_or(None, |a| Some(a.to_string())),
55
- installerArgs: options
56
- .exe_installer_args
57
- .map_or(None, |a| Some(a.iter().map(|x| x.to_string()).collect())),
58
- });
59
- }
60
- };
61
- }
62
-
63
- #[macro_export]
64
- macro_rules! linuxPlatform {
65
- ($num: ident, $linux: ident, $config: ident, $gh_r: ident, $final_config: ident, $platform: ident, $finder: ident) => {
66
- $num += 1;
67
- if let Some(platform) = $config.platform.$platform {
68
- if !matches!(&platform, &InstallerFormat::LinuxAppImage) {
69
- ERR.println(&"Invalid File Format, expected LinuxAppImage");
70
- }
71
-
72
- let Some(finder) = $config.finder.$finder else {
73
- ERR.println(&f!("{} Finder Config not found!", s!($linux)));
74
- process::exit(1);
75
- };
76
-
77
- let assets = find_assets(&$gh_r, &finder);
78
-
79
- if assets.len() > 1 {
80
- ERR.println(&f!("Multiple assets found while parsing {}", s!($linux)));
81
- process::exit(1);
82
- }
83
-
84
- $final_config.downloadUrls.insert(
85
- $num,
86
- DownloadUrl {
87
- installerType: platform,
88
- asset: assets[0].name.clone(),
89
- url: "".into()
90
- },
91
- );
92
-
93
- $final_config.install.$linux = Some(InstallerOptionsLinux {
94
- assetId: $num
95
- });
96
- }
97
- };
98
- }
@@ -1,219 +0,0 @@
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
- license_or_tos: config.license_or_tos,
108
- install: InstallerOptions {
109
- linux: None,
110
- android: None,
111
- linuxArm64: None,
112
- linuxArm7: None,
113
- winarm: None,
114
- win32: None,
115
- },
116
- repo: config.repo,
117
- version,
118
- site: config.site,
119
- source: config.redistributed,
120
- verified: false
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 +0,0 @@
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
- }
Binary file
@@ -1,114 +0,0 @@
1
- use std::process;
2
-
3
- use ahqstore_types::AppRepo;
4
- use inquire::{
5
- validator::{ErrorMessage, Validation},
6
- Editor, Text,
7
- };
8
- use serde::{Deserialize, Serialize};
9
-
10
- use crate::app::{
11
- shared::{Config, IMetadata, IPlatform},
12
- ERR, INFO,
13
- };
14
-
15
- #[derive(Serialize, Deserialize)]
16
- struct ServerUserResp {
17
- pub linked_acc: Vec<String>,
18
- }
19
-
20
- pub fn inquire<'a>() -> (String, Config<'a>) {
21
- INFO.println(&"Generating a random Application ID");
22
- let Ok(app_id) = Text::new("Application ID:")
23
- .with_default(&gen_appid())
24
- .prompt()
25
- else {
26
- ERR.println(&"Must Enter an ID");
27
- process::exit(1);
28
- };
29
-
30
- let Ok(app_name) = Text::new("Start menu entry name:")
31
- .with_default("Application")
32
- .prompt()
33
- else {
34
- ERR.println(&"Must Enter a name");
35
- process::exit(1);
36
- };
37
-
38
- let Ok(display_name) = Text::new("Application Display Name:")
39
- .with_default("My Cool App")
40
- .prompt()
41
- else {
42
- ERR.println(&"Must Enter a name");
43
- process::exit(1);
44
- };
45
-
46
- let Ok(user_id) = Text::new("Your AHQ Store Author ID:").prompt() else {
47
- ERR.println(&"Must Enter an ID");
48
- process::exit(1);
49
- };
50
-
51
- let Ok(desc) = Editor::new("Enter your app description").prompt() else {
52
- ERR.println(&"Must Enter a description");
53
- process::exit(1);
54
- };
55
-
56
- let Ok(repo) = Text::new("Enter your app repository:")
57
- .with_default("owner/repoName")
58
- .with_validator(|string: &str| {
59
- if string.split("/").collect::<Vec<_>>().len() == 2 {
60
- Ok(Validation::Valid)
61
- } else {
62
- Ok(Validation::Invalid(ErrorMessage::Custom(
63
- "Must be in the format owner/repoName".into(),
64
- )))
65
- }
66
- })
67
- .prompt()
68
- else {
69
- ERR.println(&"Must Enter a repository");
70
- process::exit(1);
71
- };
72
-
73
- let [owner, repo] = repo.split("/").collect::<Vec<_>>()[..] else {
74
- panic!("Repo Parsing Failed")
75
- };
76
-
77
- INFO.println(&"Validating author id & repo");
78
-
79
- (
80
- app_id.clone(),
81
- IMetadata::new(
82
- app_id,
83
- app_name,
84
- display_name,
85
- user_id,
86
- desc,
87
- AppRepo {
88
- author: owner.into(),
89
- repo: repo.into(),
90
- },
91
- IPlatform::new()
92
- ),
93
- )
94
- }
95
-
96
- fn gen_appid() -> String {
97
- let mut string = String::new();
98
-
99
- use rand::seq::SliceRandom;
100
-
101
- let val = vec![
102
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
103
- "t", "u", "v", "w", "s", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
104
- "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "S", "Y", "Z", "0", "1", "2", "3", "4",
105
- "5", "6", "7", "8", "9"
106
- ];
107
-
108
- for _ in 0..40 {
109
- let val = val.choose(&mut rand::thread_rng()).unwrap();
110
- string.push_str(val);
111
- }
112
-
113
- string
114
- }
@@ -1,74 +0,0 @@
1
- mod inquire;
2
- use std::{fs, process};
3
-
4
- use inquire::*;
5
- use serde_json::to_string_pretty;
6
-
7
- use super::{ERR, INFO, WARN};
8
-
9
- pub fn create(force: bool) {
10
- let (id, config) = inquire();
11
-
12
- create_dir(force);
13
-
14
- let succ = (|| {
15
- let config_file = to_string_pretty(&config).ok()?;
16
- fs::write("./.ahqstore/config.json", config_file).ok()?;
17
-
18
- let base_img = format!("./.ahqstore/images/{}", &id);
19
-
20
- fs::create_dir_all(&base_img).ok()?;
21
-
22
- let icon = include_bytes!("./icon.png");
23
- fs::write(format!("{}/icon.png", &base_img), icon).ok()?;
24
-
25
- let readme = include_str!("./readme.md");
26
- fs::write("./.ahqstore/README.md", readme).ok()
27
- })()
28
- .is_some();
29
-
30
- if !succ {
31
- ERR.println(&"Failed to populate .ahqstore");
32
- process::exit(1);
33
- } else {
34
- println!("🇩​​​​​🇴​​​​​🇳​​​​​🇪​​​​​");
35
- println!(
36
- r#"████████████████████████████████████████████████████████████████▀█
37
- █─█─██▀▄─██▄─▄▄─█▄─▄▄─█▄─█─▄███─▄▄▄─█─▄▄─█▄─▄▄▀█▄─▄█▄─▀█▄─▄█─▄▄▄▄█
38
- █─▄─██─▀─███─▄▄▄██─▄▄▄██▄─▄████─███▀█─██─██─██─██─███─█▄▀─██─██▄─█
39
- ▀▄▀▄▀▄▄▀▄▄▀▄▄▄▀▀▀▄▄▄▀▀▀▀▄▄▄▀▀▀▀▄▄▄▄▄▀▄▄▄▄▀▄▄▄▄▀▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀
40
- "#
41
- );
42
- INFO.println(&"Do not forget to edit config.json and finder.json\nMore details about all the files is present in README.md");
43
- }
44
- }
45
-
46
- pub fn create_dir(force: bool) {
47
- if let Err(_) = fs::create_dir("./.ahqstore") {
48
- if force {
49
- WARN.println(&"--force detected\nRemoving dir .ahqstore");
50
-
51
- let succ = (|| {
52
- fs::remove_dir_all("./.ahqstore").ok()?;
53
- fs::create_dir_all("./.ahqstore").ok()?;
54
-
55
- Some(())
56
- })()
57
- .is_some();
58
-
59
- if succ {
60
- INFO.println(&".ahqstore directory created, initializing data...");
61
- } else {
62
- ERR.println(&"Failed to create .ahqstore directory");
63
- process::exit(1);
64
- }
65
- } else {
66
- ERR.println(
67
- &"Failed to create .ahqstore directory\nHint: Use --force option to ignore this error",
68
- );
69
- process::exit(1);
70
- }
71
- } else {
72
- INFO.println(&"Created .ahqstore directory, initializing data...");
73
- }
74
- }
@@ -1,13 +0,0 @@
1
- # AHQ Store Cli
2
-
3
- ## config.json
4
-
5
- Follows the schema as presented [here](https://docs.rs/ahqstore_cli_rs/latest/ahqstore_cli_rs/shared/struct.IMetadata.html)
6
-
7
- ## images/<app-id>/icon.png
8
-
9
- Your application icon that'll be bundled in the app metadata file
10
-
11
- ## images/<app-id>/\*
12
-
13
- Place any image(s) [upto 10] that will be placed in the app modal in AHQ Store
package/src/app/help.rs DELETED
@@ -1,77 +0,0 @@
1
- use chalk_rs::Chalk;
2
-
3
- pub fn main_help() -> String {
4
- let mut chalk = Chalk::new();
5
-
6
- let cli = chalk.blue().bold().string(&"AHQ Store CLI");
7
-
8
- let usage = chalk.green().bold().string(&"Usage:");
9
-
10
- let cmds = chalk.green().bold().string(&"Commands:");
11
- let help = chalk.cyan().bold().string(&"help");
12
- let create = chalk.cyan().bold().string(&"create");
13
- let build = chalk.cyan().bold().string(&"build");
14
- let upload = chalk.cyan().bold().string(&"build");
15
-
16
- let opt = chalk.yellow().bold().string(&"Options:");
17
- let force = chalk.cyan().bold().string(&"--force, -f");
18
-
19
- let env = chalk.yellow().bold().string(&"Required ENV:");
20
- let app_id = chalk.cyan().bold().string(&"APP_ID");
21
- let gh_token = chalk.cyan().bold().string(&"GH_TOKEN");
22
- let gh_repo = chalk.cyan().bold().string(&"GITHUB_REPOSITORY");
23
- let gh_action = chalk.cyan().bold().string(&"GITHUB_ACTION");
24
- let r_id = chalk.cyan().bold().string(&"RELEASE_ID");
25
-
26
- let optional = chalk.yellow().bold().string(&"(Optional)");
27
-
28
- format!(
29
- r#"{cli}
30
- Ship your apps to the ahq store quickly and efficiently
31
-
32
- {usage}
33
- ahqstore (command) [options]
34
- {cmds}
35
- {help}
36
- Shows the help menu
37
- {create}
38
- Generates AHQ Store config files required to ship your apps
39
- {opt}
40
- {force} Override Existing contents if .ahqstore dir isn't empty
41
- {upload}
42
- Build & Upload ahqstore config file
43
- {env}
44
- {app_id} {optional} Application Id (required if your config has more than 1 appIds)
45
- {r_id} GitHub Release Id
46
- {gh_token} GitHub Token
47
- {gh_repo} GitHub owner & repo name, eg ahqstore/app
48
- (Equivalent to GITHUB_REPOSITORY variable in GitHub actions)
49
- {gh_action} {optional} Set this env to anything to specify that it is running in an GitHub Action
50
- (Outputs AHQ_STORE_FILE_URL=<url>)
51
- {build}
52
- Build the ahqstore config file
53
- {env}
54
- {app_id} {optional} Application Id (required if your config has more than 1 appIds)
55
- {r_id} GitHub Release Id
56
- {gh_token} GitHub Token
57
- {gh_repo} GitHub owner & repo name, eg ahqstore/app
58
- (Equivalent to GITHUB_REPOSITORY variable in GitHub actions)
59
- {gh_action} {optional} Set this env to anything to specify that it is running in an GitHub Action
60
- (Outputs AHQ_STORE_FILE_URL=<url>)"#
61
- )
62
- }
63
-
64
- pub fn not_found(name: &str) -> String {
65
- let mut chalk = Chalk::new();
66
-
67
- let cmd = chalk.red().bold().string(&"Command not found:");
68
- let tip = chalk.green().bold().string(&"Tip:");
69
- let astore = chalk.cyan().bold().string(&"ahqstore");
70
-
71
- format!(
72
- r#"{cmd} {name}
73
-
74
- {tip}
75
- Write {astore} to view the help menu"#
76
- )
77
- }
package/src/app/mod.rs DELETED
@@ -1,39 +0,0 @@
1
- use chalk_rs::Chalk;
2
- use lazy_static::lazy_static;
3
-
4
- mod build;
5
- mod create;
6
- mod help;
7
- pub mod shared;
8
-
9
- lazy_static! {
10
- static ref INFO: Chalk = {
11
- let mut chalk = Chalk::new();
12
- chalk.blue().bold();
13
- chalk
14
- };
15
- static ref WARN: Chalk = {
16
- let mut chalk = Chalk::new();
17
- chalk.yellow().bold();
18
- chalk
19
- };
20
- static ref ERR: Chalk = {
21
- let mut chalk = Chalk::new();
22
- chalk.red().bold();
23
- chalk
24
- };
25
- }
26
-
27
- pub fn start(args: Vec<String>, gh: bool) {
28
- if args.len() >= 1 {
29
- match args[0].as_str() {
30
- "create" => create::create(args.len() > 1 && (&args[1] == "--force" || &args[1] == "-f")),
31
- "build" => build::build_config(false, false),
32
- "upload" => build::build_config(true, gh),
33
- "help" => println!("{}", help::main_help()),
34
- a => println!("{}", help::not_found(a)),
35
- }
36
- } else {
37
- println!("{}", help::main_help());
38
- }
39
- }