@ahqstore/cli 0.2.6 → 0.3.4

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.
Files changed (43) hide show
  1. package/Cargo.toml +48 -0
  2. package/README.md +0 -43
  3. package/build.rs +8 -0
  4. package/cli-rs/Cargo.toml +45 -0
  5. package/cli-rs/README.md +41 -0
  6. package/cli-rs/build.rs +4 -0
  7. package/cli-rs/finalize.js +25 -0
  8. package/cli-rs/rust-toolchain.toml +2 -0
  9. package/cli-rs/src/app/build/config.rs +54 -0
  10. package/cli-rs/src/app/build/icon.rs +48 -0
  11. package/cli-rs/src/app/build/mod.rs +217 -0
  12. package/cli-rs/src/app/build/release.rs +50 -0
  13. package/cli-rs/src/app/create/icon.png +0 -0
  14. package/cli-rs/src/app/create/inquire.rs +189 -0
  15. package/cli-rs/src/app/create/mod.rs +74 -0
  16. package/cli-rs/src/app/create/readme.md +71 -0
  17. package/cli-rs/src/app/help.rs +77 -0
  18. package/cli-rs/src/app/mod.rs +39 -0
  19. package/cli-rs/src/app/shared/file_sorter.rs +34 -0
  20. package/cli-rs/src/app/shared/mod.rs +62 -0
  21. package/cli-rs/src/app/shared/platforms.rs +69 -0
  22. package/cli-rs/src/lib.rs +13 -0
  23. package/cli-rs/src/main.rs +10 -0
  24. package/cli-rs/tslink.toml +2 -0
  25. package/index.js +259 -0
  26. package/package.json +45 -29
  27. package/src/app/build/config.rs +54 -0
  28. package/src/app/build/icon.rs +48 -0
  29. package/src/app/build/mod.rs +217 -0
  30. package/src/app/build/release.rs +50 -0
  31. package/src/app/create/icon.png +0 -0
  32. package/src/app/create/inquire.rs +189 -0
  33. package/src/app/create/mod.rs +74 -0
  34. package/src/app/create/readme.md +71 -0
  35. package/src/app/help.rs +77 -0
  36. package/src/app/mod.rs +39 -0
  37. package/src/app/shared/file_sorter.rs +34 -0
  38. package/src/app/shared/mod.rs +62 -0
  39. package/src/app/shared/platforms.rs +69 -0
  40. package/src/lib.rs +12 -0
  41. package/src/main.rs +10 -0
  42. package/install.js +0 -44
  43. package/src/cli.js +0 -24
package/Cargo.toml ADDED
@@ -0,0 +1,48 @@
1
+ [package]
2
+ edition = "2021"
3
+ name = "ahqstore_cli_rs"
4
+ version = "0.3.4"
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 = ["napi4"], optional = true }
23
+ napi-derive = { version = "2.12.2", optional = true }
24
+ inquire = { version = "0.7.5", features = ["editor"] }
25
+ chalk_rs = "1.0.1"
26
+ lazy_static = "1.4.0"
27
+ serde = { version = "1.0.203", features = ["derive"] }
28
+ serde_json = "1.0.117"
29
+ ahqstore-types = "2.0.0"
30
+ reqwest = { version = "0.12", features = ["json", "blocking"] }
31
+ sha2 = "0.10.8"
32
+ base64 = "0.22.1"
33
+ image = { version = "0.25", default-features = false, features = ["rayon", "png"]}
34
+ rand = "0.8.5"
35
+
36
+ [target.'cfg(unix)'.dependencies]
37
+ openssl-sys = { version = "0.9.102", features = ["vendored"] }
38
+
39
+
40
+ [build-dependencies]
41
+ napi-build = {version = "2.0.1", optional = true}
42
+
43
+ [profile.release]
44
+ lto = true
45
+ strip = "symbols"
46
+
47
+ [features]
48
+ 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
@@ -0,0 +1,8 @@
1
+ #[cfg(feature = "node")]
2
+ extern crate napi_build;
3
+
4
+ fn main() {
5
+ // Ensures that users can download it too
6
+ #[cfg(feature = "node")]
7
+ napi_build::setup();
8
+ }
@@ -0,0 +1,45 @@
1
+ [package]
2
+ name = "ahqstore_cli_rs"
3
+ version = "0.2.8"
4
+ edition = "2021"
5
+ description = "AHQ Store CLI"
6
+ repository = "https://github.com/ahqstore/cli"
7
+ homepage = "https://github.com/ahqstore/cli"
8
+ license = "MIT"
9
+ exclude = ["dist/**", ".ahqstore/**", "finalize.js", "tslink.toml"]
10
+ readme = "README.md"
11
+
12
+ [lib]
13
+ name = "ahqstore_cli_rs"
14
+ crate-type = ["cdylib"]
15
+ path = "src/lib.rs"
16
+
17
+ [[bin]]
18
+ name = "ahqstore"
19
+ path = "src/main.rs"
20
+
21
+ [dependencies]
22
+ node-bindgen = { version = "6.0.1", optional = true }
23
+ tslink = { version = "0.1.3", optional = true }
24
+ inquire = { version = "0.7.5", features = ["editor"] }
25
+ chalk_rs = "1.0.1"
26
+ lazy_static = "1.4.0"
27
+ serde = { version = "1.0.203", features = ["derive"] }
28
+ serde_json = "1.0.117"
29
+ ahqstore-types = "2.0.0"
30
+ reqwest = { version = "0.12", features = ["json", "blocking"] }
31
+ sha2 = "0.10.8"
32
+ base64 = "0.22.1"
33
+ image = "0.25"
34
+ rand = "0.8.5"
35
+
36
+ [target.aarch64-unknown-linux-gnu.dependencies]
37
+ openssl = { version = "0.10.64", features = ["vendored"] }
38
+
39
+ [build-dependencies]
40
+ node-bindgen = { version = "6.0.1", default-features = false, features = [
41
+ "build",
42
+ ], optional = true }
43
+
44
+ [features]
45
+ node = ["dep:node-bindgen", "dep:tslink"]
@@ -0,0 +1,41 @@
1
+ # AHQ Store CLI
2
+
3
+ The CLI for devs making AHQ Store Apps
4
+
5
+ This version: CARGO
6
+
7
+ Install
8
+
9
+ ```sh
10
+ $ cargo install ahqstore_cli_rs
11
+ ```
12
+
13
+ ## Help Command
14
+
15
+ The help command shows all available commands
16
+
17
+ ```sh
18
+ $ ahqstore --help
19
+ ```
20
+
21
+ ## Create .ahqstore config
22
+
23
+ Creates the .ahqstore/\* config files to make your app ready to be built
24
+
25
+ ```sh
26
+ $ ahqstore --create {--force}
27
+ ```
28
+
29
+ ## Build a project
30
+
31
+ Builds your app based on the config files and environment variables
32
+ ENV:
33
+
34
+ > `APP_ID` (Optional) Application Id (only required if your config has more than 1 appIds)
35
+ > `RELEASE_ID` GitHub Release Id
36
+ > `GH_TOKEN` GitHub Personal Access Token / GitHub Actions Token
37
+ > `GITHUB_REPOSITORY` GitHub owner & repo name, eg ahqstore/app
38
+
39
+ ```sh
40
+ $ ahqstore build
41
+ ```
@@ -0,0 +1,4 @@
1
+ fn main() {
2
+ #[cfg(feature = "node")]
3
+ node_bindgen::build::configure();
4
+ }
@@ -0,0 +1,25 @@
1
+ const { writeFileSync, readFileSync } = require("fs");
2
+ const { join } = require("path");
3
+ let arch = process.env.arch || require("process").arch;
4
+
5
+ if (arch == "arm64" && process.platform == "win32") {
6
+ arch = "ia32";
7
+ }
8
+
9
+ const packageJson = join(__dirname, "dist", "package.json");
10
+
11
+ let json = JSON.parse(readFileSync(packageJson));
12
+
13
+ json.name = `@ahqstore/cli-rs-${process.platform}-${arch}`;
14
+
15
+ json.description = `AHQ Store CLI Binaries for ${process.platform}-${arch}`;
16
+ json.repository = {
17
+ type: "git",
18
+ url: "git+https://github.com/ahqstore/cli.git",
19
+ };
20
+ json.bugs = {
21
+ url: "https://github.com/ahqstore/cli/issues",
22
+ };
23
+ json.homepage = "https://github.com/ahqstore/cli#readme";
24
+
25
+ writeFileSync(packageJson, JSON.stringify(json, null, 2));
@@ -0,0 +1,2 @@
1
+ [toolchain]
2
+ channel = "nightly"
@@ -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
+ }
@@ -0,0 +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
+ }
Binary file