@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.
@@ -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
- }
@@ -1,42 +0,0 @@
1
- use serde::{Deserialize, Serialize};
2
-
3
- #[derive(Debug, Serialize, Deserialize, Default)]
4
- #[allow(non_snake_case)]
5
- pub struct FileFinder<'a> {
6
- #[serde(borrow)]
7
- pub windowsAmd64Finder: Option<Finder<'a>>,
8
- #[serde(borrow)]
9
- pub windowsArm64Finder: Option<Finder<'a>>,
10
- #[serde(borrow)]
11
- pub linuxAmd64Finder: Option<Finder<'a>>,
12
- #[serde(borrow)]
13
- pub linuxArm64Finder: Option<Finder<'a>>,
14
- #[serde(borrow)]
15
- pub linuxArm32Finder: Option<Finder<'a>>,
16
- #[serde(borrow)]
17
- pub androidUniversalFinder: Option<Finder<'a>>,
18
- }
19
-
20
- #[derive(Debug, Serialize, Deserialize, Default)]
21
- #[allow(non_snake_case)]
22
- pub struct Finder<'a> {
23
- #[serde(borrow)]
24
- pub startsWith: Option<&'a str>,
25
- #[serde(borrow)]
26
- pub contains: Option<&'a str>,
27
- #[serde(borrow)]
28
- pub endsWith: Option<&'a str>,
29
- }
30
-
31
- impl<'a> FileFinder<'a> {
32
- pub fn new() -> Self {
33
- Self {
34
- windowsAmd64Finder: Some(Finder {
35
- startsWith: Some("This-is"),
36
- contains: Some("an"),
37
- endsWith: Some(".example"),
38
- }),
39
- ..Default::default()
40
- }
41
- }
42
- }
@@ -1,64 +0,0 @@
1
- use serde::{Deserialize, Serialize};
2
- use std::collections::HashMap;
3
-
4
- use ahqstore_types::AppRepo;
5
-
6
- pub type Str = String;
7
- pub type Config<'a> = HashMap<String, IMetadata<'a>>;
8
-
9
- mod file_sorter;
10
- mod platforms;
11
- pub use file_sorter::*;
12
- pub use platforms::*;
13
-
14
- #[derive(Debug, Serialize, Deserialize)]
15
- #[allow(non_snake_case)]
16
- pub struct IMetadata<'a> {
17
- pub appId: Str,
18
- pub appShortcutName: Str,
19
- pub appDisplayName: Str,
20
- pub authorId: Str,
21
- pub description: Str,
22
- pub repo: AppRepo,
23
- #[serde[borrow]]
24
- pub platform: IPlatform<'a>,
25
- #[serde[borrow]]
26
- pub finder: FileFinder<'a>,
27
- pub site: Option<Str>,
28
- pub redistributed: Option<Str>,
29
- pub license_or_tos: Option<Str>,
30
- }
31
-
32
- impl<'a> IMetadata<'a> {
33
- #[allow(non_snake_case)]
34
- pub fn new(
35
- appId: Str,
36
- appShortcutName: Str,
37
- appDisplayName: Str,
38
- authorId: Str,
39
- description: Str,
40
- repo: AppRepo,
41
- platform: IPlatform<'a>,
42
- ) -> Config {
43
- let mut config = Config::new();
44
-
45
- config.insert(
46
- appId.clone(),
47
- Self {
48
- appId,
49
- appShortcutName,
50
- appDisplayName,
51
- authorId,
52
- description,
53
- repo,
54
- platform,
55
- finder: FileFinder::new(),
56
- site: None,
57
- redistributed: None,
58
- license_or_tos: None
59
- },
60
- );
61
-
62
- config
63
- }
64
- }
@@ -1,45 +0,0 @@
1
- use ahqstore_types::InstallerFormat;
2
- use serde::{Deserialize, Serialize};
3
-
4
- #[derive(Debug, Serialize, Deserialize)]
5
- #[allow(non_snake_case)]
6
- pub struct IPlatform<'a> {
7
- pub winAmd64Platform: Option<InstallerFormat>,
8
- pub winArm64Platform: Option<InstallerFormat>,
9
- pub linuxAmd64Platform: Option<InstallerFormat>,
10
- pub linuxArm64Platform: Option<InstallerFormat>,
11
- pub linuxArm32Platform: Option<InstallerFormat>,
12
- pub androidUniversal: Option<InstallerFormat>,
13
- #[serde(borrow)]
14
- pub winAmd64Options: Option<IOWin<'a>>,
15
- #[serde(borrow)]
16
- pub winArm64Options: Option<IOWin<'a>>,
17
- }
18
-
19
- #[derive(Debug, Serialize, Deserialize, Clone)]
20
- pub struct IOWin<'a> {
21
- #[serde(borrow)]
22
- pub zip_file_exec: Option<&'a str>,
23
- #[serde(borrow)]
24
- pub exe_installer_args: Option<Vec<&'a str>>,
25
- }
26
-
27
- impl<'a> IPlatform<'a> {
28
- pub fn new() -> Self {
29
- let io_win = IOWin {
30
- exe_installer_args: Some(vec![]),
31
- zip_file_exec: None,
32
- };
33
-
34
- Self {
35
- winAmd64Platform: None,
36
- winArm64Platform: None,
37
- linuxAmd64Platform: None,
38
- linuxArm32Platform: None,
39
- linuxArm64Platform: None,
40
- androidUniversal: None,
41
- winAmd64Options: Some(io_win.clone()),
42
- winArm64Options: Some(io_win)
43
- }
44
- }
45
- }
package/src/lib.rs DELETED
@@ -1,12 +0,0 @@
1
- mod app;
2
-
3
- pub use app::shared;
4
-
5
- #[cfg(feature = "node")]
6
- #[macro_use]
7
- extern crate napi_derive;
8
-
9
- #[cfg_attr(feature = "node", napi)]
10
- pub fn node_entrypoint(args: Vec<String>, gh: bool) {
11
- app::start(args, gh);
12
- }
package/src/main.rs DELETED
@@ -1,10 +0,0 @@
1
- use std::env::args;
2
-
3
- mod app;
4
-
5
- fn main() {
6
- let mut arg = args().collect::<Vec<String>>();
7
- arg.remove(0);
8
-
9
- app::start(arg, std::env::var("GH_ACTION").is_ok());
10
- }