eitri-cli 1.10.1-beta.1 → 1.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.
Files changed (67) hide show
  1. package/eitri-cli-v2/eitri-cli-v2.win32-x64-msvc.node +0 -0
  2. package/eitri-cli-v2/src/commands/mod.rs +2 -0
  3. package/eitri-cli-v2/src/commands/publish.rs +35 -0
  4. package/eitri-cli-v2/src/commands/run_test.rs +41 -0
  5. package/eitri-cli-v2/src/config/mod.rs +1 -0
  6. package/eitri-cli-v2/src/config/user_credentials.rs +38 -0
  7. package/eitri-cli-v2/src/infra/http_client.rs +493 -0
  8. package/eitri-cli-v2/src/infra/mod.rs +1 -0
  9. package/eitri-cli-v2/src/lib.rs +30 -0
  10. package/eitri-cli-v2/src/model/auth_response.rs +8 -0
  11. package/eitri-cli-v2/src/model/credentials.rs +8 -0
  12. package/eitri-cli-v2/src/model/eitri_conf.rs +43 -0
  13. package/eitri-cli-v2/src/model/mod.rs +8 -0
  14. package/eitri-cli-v2/src/model/process_output.rs +8 -0
  15. package/eitri-cli-v2/src/model/revision.rs +14 -0
  16. package/eitri-cli-v2/src/model/test_config.rs +7 -0
  17. package/eitri-cli-v2/src/model/url.rs +11 -0
  18. package/eitri-cli-v2/src/model/workspace_auth.rs +4 -0
  19. package/eitri-cli-v2/src/services/blind_guardian.rs +87 -0
  20. package/eitri-cli-v2/src/services/eitri_foundry.rs +84 -0
  21. package/eitri-cli-v2/src/services/eitri_manager.rs +78 -0
  22. package/eitri-cli-v2/src/services/mod.rs +4 -0
  23. package/eitri-cli-v2/src/services/workspace.rs +49 -0
  24. package/eitri-cli-v2/src/utils/convert_eitri_conf.rs +98 -0
  25. package/eitri-cli-v2/src/utils/mod.rs +1 -0
  26. package/package.json +1 -1
  27. package/src/modules/vegvisir/VegvisirService.js +1 -1
  28. package/src/service/Emulator/AndroidEmulatorService.js +3 -25
  29. package/src/service/MiniLog.js +46 -5
  30. package/test/Executor.js +60 -0
  31. package/test/Factory.js +13 -0
  32. package/test/Helper.js +15 -0
  33. package/test/_fixtures/factory.js +30 -0
  34. package/test/_fixtures/miniWebApp/miniapp.conf.js +4 -0
  35. package/test/_fixtures/miniapp.conf.js +5 -0
  36. package/test/_fixtures/server/HelloWorldBackend.js +7 -0
  37. package/test/_fixtures/src/Home.js +5 -0
  38. package/test/_fixtures/src/Home2.js +5 -0
  39. package/test/_fixtures/src/commons/util.js +3 -0
  40. package/test/_fixtures/src/components/TagA.jsx +4 -0
  41. package/test/_fixtures/src/components/TagB.jsx +4 -0
  42. package/test/_fixtures/src/components/TagC.jsx +3 -0
  43. package/test/_fixtures/src/components/TagD.jsx +3 -0
  44. package/test/_fixtures/src/server/foo.js +7 -0
  45. package/test/_fixtures/src/views/AboutTemplate.jsx +14 -0
  46. package/test/_fixtures/woodcoffee/miniapp.conf.js +5 -0
  47. package/test/ame.conf.js +3 -0
  48. package/test/cmd/clean.test.js +66 -0
  49. package/test/cmd/create.test.js +252 -0
  50. package/test/cmd/list.test.js +74 -0
  51. package/test/cmd/manage-env.test.js +168 -0
  52. package/test/e2e/cli.test.js +473 -0
  53. package/test/miniapp.conf.js +3 -0
  54. package/test/model/Payload.test.js +35 -0
  55. package/test/modules/vegvisir/VegvisirService.test.js +37 -0
  56. package/test/service/BlindGuardian.test.js +84 -0
  57. package/test/service/CheckAmeConf.test.js +313 -0
  58. package/test/service/Http.test.js +312 -0
  59. package/test/service/InviteService.test.js +117 -0
  60. package/test/service/MiniWebAppFactory.test.js +40 -0
  61. package/test/service/TagTree.test.js +81 -0
  62. package/test/service/TargetService.test.js +48 -0
  63. package/test/service/TrackingService.test.js +105 -0
  64. package/test/service/UserAmeConf.test.js +47 -0
  65. package/test/service/WoodCoffeeFactory.test.js +148 -0
  66. package/test/service/Workspace.test.js +211 -0
  67. package/test/utils/getWorkspaceId.test.js +17 -0
@@ -0,0 +1,43 @@
1
+ use serde_derive::{Deserialize, Serialize};
2
+
3
+ #[derive(Debug, Serialize, Deserialize)]
4
+ pub struct EitriConf {
5
+ #[serde(rename = "name")]
6
+ pub name: String,
7
+
8
+ #[serde(rename = "title")]
9
+ pub title: String,
10
+
11
+ #[serde(rename = "slug")]
12
+ pub slug: String,
13
+
14
+ #[serde(rename = "eitri-app-components")]
15
+ pub eitri_app_components: Option<String>,
16
+
17
+ #[serde(rename = "eitri-app-client")]
18
+ pub eitri_app_client: Option<String>,
19
+
20
+ #[serde(rename = "eitri-luminus")]
21
+ pub eitri_luminus: Option<String>,
22
+
23
+ #[serde(rename = "eitri-bifrost")]
24
+ pub eitri_bifrost: Option<String>,
25
+
26
+ #[serde(rename = "eitri-commons")]
27
+ pub eitri_commons: Option<String>,
28
+
29
+ #[serde(rename = "version")]
30
+ pub version: String,
31
+
32
+ #[serde(rename = "public-key")]
33
+ pub public_key: String,
34
+
35
+ #[serde(rename = "applicationId")]
36
+ pub application_id: String,
37
+
38
+ #[serde(rename = "id")]
39
+ pub id: String,
40
+
41
+ #[serde(rename = "organizationId")]
42
+ pub organization_id: String,
43
+ }
@@ -0,0 +1,8 @@
1
+ pub mod auth_response;
2
+ pub mod credentials;
3
+ pub mod eitri_conf;
4
+ pub mod revision;
5
+ pub mod process_output;
6
+ pub mod test_config;
7
+ pub mod workspace_auth;
8
+ pub mod url;
@@ -0,0 +1,8 @@
1
+ use serde::{Serialize, Deserialize};
2
+
3
+ #[derive(Serialize, Deserialize)]
4
+ #[serde(rename_all = "camelCase")]
5
+ pub struct ProcessOutput {
6
+ pub stdout: String,
7
+ pub stderr: String,
8
+ }
@@ -0,0 +1,14 @@
1
+ use serde::{Deserialize, Serialize};
2
+
3
+ #[derive(Debug, Deserialize, Serialize, Clone)]
4
+ #[serde(rename_all = "camelCase")]
5
+ pub struct Revision {
6
+ pub id: String,
7
+
8
+ pub version: String,
9
+ }
10
+
11
+ #[derive(Debug, Deserialize, Serialize)]
12
+ pub struct GetRevisionsResult {
13
+ pub revisions: Vec<Revision>,
14
+ }
@@ -0,0 +1,7 @@
1
+ use serde::{Serialize, Deserialize};
2
+
3
+ #[derive(Serialize, Deserialize)]
4
+ #[serde(rename_all = "camelCase")]
5
+ pub struct TestConfig {
6
+ pub test_path: String
7
+ }
@@ -0,0 +1,11 @@
1
+ pub struct Url {
2
+ pub host: String,
3
+ pub path: String
4
+ }
5
+
6
+ impl Url {
7
+ pub fn get_full_url(&self) -> String{
8
+ let full_url = format!("{}{}", self.host, self.path);
9
+ full_url
10
+ }
11
+ }
@@ -0,0 +1,4 @@
1
+ pub struct WorkspaceAuth {
2
+ pub access_token: String,
3
+ pub user_workspace_id: String
4
+ }
@@ -0,0 +1,87 @@
1
+ use std::{env, process::exit};
2
+
3
+ use reqwest::header::HeaderMap;
4
+ use serde_derive::{Deserialize, Serialize};
5
+
6
+ use crate::{
7
+ config::user_credentials,
8
+ infra::http_client::{self, HttpError},
9
+ model::{auth_response::AuthResponse, credentials::Credentials},
10
+ };
11
+
12
+ #[derive(Serialize, Deserialize)]
13
+ struct AuthenticationDTO {
14
+ client_id: String,
15
+ client_secret: String,
16
+ grant_type: String,
17
+ }
18
+
19
+ #[allow(dead_code)]
20
+ pub async fn get_access_token(host: &str, uri: &str) -> Result<String, HttpError> {
21
+ let mut headers = HeaderMap::new();
22
+ headers.append("user-agent", "eitri".parse().unwrap());
23
+
24
+ let client_id = env::var("EITRI_CLI_CLIENT_ID").unwrap_or_else(|_| String::from(""));
25
+ let client_secret = env::var("EITRI_CLI_CLIENT_SECRET").unwrap_or_else(|_| String::from(""));
26
+
27
+ let credentials = if !client_id.is_empty() && !client_secret.is_empty() {
28
+ let credentials = Credentials {
29
+ dev_key: client_secret,
30
+ dev_user: client_id,
31
+ };
32
+ credentials
33
+ } else {
34
+ let credentials = match user_credentials::get_credentials() {
35
+ Ok(credential) => credential,
36
+ Err(_) => {
37
+ eprintln!("Erro ao ler credenciais");
38
+ exit(1)
39
+ }
40
+ };
41
+ credentials
42
+ };
43
+
44
+ let data = AuthenticationDTO {
45
+ client_id: credentials.dev_user,
46
+ client_secret: credentials.dev_key,
47
+ grant_type: String::from("client_credentials"),
48
+ };
49
+
50
+ let url = &format!("{}/{}", host, uri);
51
+
52
+ let response = http_client::post::<AuthResponse, AuthenticationDTO>(url, data, headers).await?;
53
+
54
+ Ok(response.access_token)
55
+ }
56
+
57
+ #[cfg(test)]
58
+ mod tests {
59
+
60
+ use super::*;
61
+ use httpmock::prelude::*;
62
+ use serde_json::json;
63
+
64
+ #[tokio::test]
65
+ async fn should_get_access_token() {
66
+ let server = MockServer::start();
67
+
68
+ server.mock(|when, then| {
69
+ when.method(POST).path("/blind-guardian-api/v2/o/auth");
70
+ then.status(200)
71
+ .header("content-type", "application/json; charset=UTF-8")
72
+ .body(
73
+ json!({
74
+ "accessToken": "123.123.123"
75
+ })
76
+ .to_string()
77
+ .as_bytes(),
78
+ );
79
+ });
80
+
81
+ let token = get_access_token(&server.url(""), "blind-guardian-api/v2/o/auth")
82
+ .await
83
+ .unwrap();
84
+
85
+ assert_eq!(token, "123.123.123")
86
+ }
87
+ }
@@ -0,0 +1,84 @@
1
+ use crate::{
2
+ infra::http_client::{self, HttpError},
3
+ model::{
4
+ process_output::ProcessOutput, test_config::TestConfig, url::Url, workspace_auth::WorkspaceAuth,
5
+ },
6
+ };
7
+
8
+ pub async fn run_test(
9
+ workspace_auth: WorkspaceAuth,
10
+ test_path: String,
11
+ url: Url,
12
+ ) -> Result<ProcessOutput, HttpError> {
13
+ let access_token: String = workspace_auth.access_token;
14
+ let user_workspace_id: String = workspace_auth.user_workspace_id;
15
+ let mut headers = http_client::get_default_headers(access_token).await;
16
+ let url = url.get_full_url();
17
+ let data = TestConfig {
18
+ test_path: test_path,
19
+ };
20
+
21
+
22
+ headers.append("workspace-id", user_workspace_id.parse().unwrap());
23
+ let result = http_client::post::<ProcessOutput, TestConfig>(&url, data, headers).await?;
24
+
25
+ Ok(result)
26
+ }
27
+
28
+ #[cfg(test)]
29
+ mod tests {
30
+ use httpmock::prelude::*;
31
+ use serde_json::json;
32
+
33
+ use crate::{
34
+ model::{url::Url, workspace_auth::WorkspaceAuth},
35
+ services::eitri_foundry::run_test,
36
+ };
37
+
38
+ #[tokio::test]
39
+ async fn should_return_test_status() {
40
+ let server = MockServer::start();
41
+
42
+ let result = String::from("'PASS ../storage/ad24ec72-90b0-4511-b836-e217183e31c7/react-proj/src/test/Service.test.js\n' +
43
+ ' ✓ teste soma agora (2 ms)\n' +
44
+ ' ✓ teste multiplicao agora\n' +
45
+ '\n' +
46
+ 'Test Suites: 1 passed, 1 total\n' +
47
+ 'Tests: 2 passed, 2 total\n' +
48
+ 'Snapshots: 0 total\n' +
49
+ 'Time: 0.162 s, estimated 1 s\n' +
50
+ 'Ran all test suites'");
51
+
52
+ let mock = server.mock(|when, then| {
53
+ when.method(POST).path("/runes-foundry/run-test");
54
+ then
55
+ .status(200)
56
+ .header("content-type", "application/json; charset=UTF-8")
57
+ .body(
58
+ json!({
59
+ "stderr": result,
60
+ "stdout":"aaaaaa"
61
+ })
62
+ .to_string()
63
+ .as_bytes(),
64
+ );
65
+ });
66
+
67
+ let workspace_auth = WorkspaceAuth {
68
+ access_token: String::from("123.123.123"),
69
+ user_workspace_id: String::from("xxxx"),
70
+ };
71
+
72
+ let path = String::from("");
73
+ let url = Url {
74
+ host: server.url(""),
75
+ path: String::from("/runes-foundry/run-test"),
76
+ };
77
+
78
+ let response = run_test(workspace_auth, path, url).await.unwrap();
79
+
80
+ assert_eq!(mock.hits(), 1);
81
+ assert_eq!(response.stderr, result);
82
+
83
+ }
84
+ }
@@ -0,0 +1,78 @@
1
+ use std::process::exit;
2
+
3
+ use serde_json::json;
4
+
5
+ use crate::{
6
+ infra::http_client::{self, HttpError},
7
+ model::revision::{GetRevisionsResult, Revision},
8
+ };
9
+
10
+ use super::blind_guardian;
11
+
12
+ pub async fn get_revision(eitri_app_id: &str, version: &str) -> Result<Revision, HttpError> {
13
+ let access_token = match blind_guardian::get_access_token(
14
+ "https://api.eitri.tech",
15
+ "blind-guardian-api/v2/o/auth",
16
+ )
17
+ .await
18
+ {
19
+ Ok(token) => token,
20
+ Err(_err) => {
21
+ eprintln!("Houve um erro ao autenticar-se no Eitri");
22
+ exit(1)
23
+ }
24
+ };
25
+
26
+ let headers = http_client::get_default_headers(access_token).await;
27
+
28
+ let url = format!(
29
+ "https://api.eitri.tech/eitri-manager-api/v2/revisions?eitriAppId={}&version={}",
30
+ eitri_app_id, version
31
+ );
32
+
33
+ let result = http_client::get::<GetRevisionsResult>(&url, headers).await?;
34
+
35
+ let revision = match result.revisions.first() {
36
+ Some(revision) => revision.clone(),
37
+ None => {
38
+ eprintln!("Versão não encontrada, certifique-se de que foi feito push-version antes de publicar a versão.");
39
+ exit(1)
40
+ }
41
+ };
42
+ Ok(revision)
43
+ }
44
+
45
+ pub async fn publish_revision(
46
+ eitri_app_id: &str,
47
+ environment_id: &str,
48
+ message: &str,
49
+ ) -> Result<String, HttpError> {
50
+ let access_token = match blind_guardian::get_access_token(
51
+ "https://api.eitri.tech",
52
+ "blind-guardian-api/v2/o/auth",
53
+ )
54
+ .await
55
+ {
56
+ Ok(token) => token,
57
+ Err(_err) => {
58
+ eprintln!("Houve um erro ao autenticar-se no Eitri");
59
+ exit(1)
60
+ }
61
+ };
62
+
63
+ let headers = http_client::get_default_headers(access_token).await;
64
+
65
+ let url = format!(
66
+ "https://api.eitri.tech/eitri-manager-api/revisions/{}/publish",
67
+ eitri_app_id
68
+ );
69
+
70
+ let data = json!({
71
+ "envId": environment_id,
72
+ "message": message
73
+ });
74
+
75
+ let result = http_client::put(&url, data, headers).await?;
76
+
77
+ Ok(result)
78
+ }
@@ -0,0 +1,4 @@
1
+ pub mod blind_guardian;
2
+ pub mod eitri_manager;
3
+ pub mod workspace;
4
+ pub mod eitri_foundry;
@@ -0,0 +1,49 @@
1
+ use std::{env, fs, path::Path, process::exit};
2
+
3
+ use crate::model::eitri_conf::EitriConf;
4
+ use crate::utils::convert_eitri_conf;
5
+
6
+ pub async fn read_eitri_conf() -> EitriConf {
7
+ let current_dir = match env::current_dir().ok() {
8
+ Some(it) => it,
9
+ None => {
10
+ eprintln!("Houve um erro o tentar ler o diretório atual");
11
+ exit(1)
12
+ }
13
+ };
14
+
15
+ let current_dir_str = current_dir.display().to_string();
16
+ let file_path = Path::new(&current_dir_str);
17
+ let file_path = file_path.join("eitri-app.conf.json");
18
+
19
+ convert_eitri_conf::convert();
20
+
21
+ let content = match fs::read_to_string(file_path.display().to_string()).ok() {
22
+ Some(it) => it,
23
+ None => {
24
+ eprintln!("Houve um erro ao tentar ler o eitri-app.conf do projeto. Certifique-se de estar no diretório de um Eitri-App");
25
+ exit(1)
26
+ }
27
+ };
28
+
29
+ let eitri_conf: EitriConf = match serde_json::from_str(&content).ok() {
30
+ Some(it) => {
31
+ match fs::remove_file(file_path.display().to_string()) {
32
+ Ok(()) => (),
33
+ Err(_err) => {
34
+ eprintln!(
35
+ "Houve um erro ao tentar ler o eitri-app.conf do projeto. Tente novamente."
36
+ );
37
+ exit(1)
38
+ }
39
+ };
40
+ it
41
+ }
42
+ None => {
43
+ eprintln!("Houve um erro ao fazer parse do json");
44
+ exit(1)
45
+ }
46
+ };
47
+
48
+ eitri_conf
49
+ }
@@ -0,0 +1,98 @@
1
+ use std::env::current_dir;
2
+ use std::fs;
3
+ use std::io::Write;
4
+ use std::process::exit;
5
+ use std::{fs::File, process::Command};
6
+
7
+ static BASH_SCRIPT: &str = r#"
8
+ #!/bin/bash
9
+
10
+ # Atribua os argumentos a variáveis
11
+ js_file="eitri-app.conf.js"
12
+ json_file="eitri-app.conf.json"
13
+
14
+ # Verifique se o arquivo JavaScript existe
15
+ if [ ! -f "$js_file" ]; then
16
+ echo "Erro: Arquivo JavaScript não encontrado: $js_file"
17
+ exit 1
18
+ fi
19
+
20
+ # Execute o script JavaScript para converter o objeto para JSON e redirecione a saída para o arquivo JSON
21
+ node -e "console.log(JSON.stringify(require('./$js_file'), null, 2))" > "$json_file"
22
+
23
+ echo "Conversão concluída. O JSON foi salvo em: $json_file"
24
+ "#;
25
+
26
+ static BAT_SCRIPT: &str = r#"
27
+ @echo off
28
+
29
+ rem Atribua os argumentos a variáveis
30
+ set "js_file=eitri-app.conf.js"
31
+ set "json_file=eitri-app.conf.json"
32
+
33
+ rem Verifique se o arquivo JavaScript existe
34
+ if not exist "%js_file%" (
35
+ echo Erro: Arquivo JavaScript não encontrado: %js_file%
36
+ exit /b 1
37
+ )
38
+
39
+ rem Execute o script JavaScript para converter o objeto para JSON e redirecione a saída para o arquivo JSON
40
+ node -e "console.log(JSON.stringify(require('./%js_file%'), null, 2))" > "%json_file%"
41
+
42
+ echo Conversão concluída. O JSON foi salvo em: %json_file%
43
+ "#;
44
+
45
+ #[allow(dead_code)]
46
+ pub fn convert() {
47
+ if cfg!(target_os = "windows") {
48
+ let temp_script = temp_bat_script();
49
+ println!("{temp_script}");
50
+ let out = Command::new("cmd")
51
+ .args(&["/C", &temp_script])
52
+ .output()
53
+ .expect("Falha ao converter arquivo .js e .json");
54
+ println!("\x1b[33mArquivo eitri-app.conf.json gerado com sucesso\x1b[0m");
55
+ match fs::remove_file(temp_script) {
56
+ Ok(it) => it,
57
+ Err(_err) => {
58
+ eprintln!("Houve um remover script temporário");
59
+ exit(1)
60
+ }
61
+ };
62
+ out
63
+ } else {
64
+ Command::new("sh")
65
+ .arg("-c")
66
+ .arg(BASH_SCRIPT)
67
+ .output()
68
+ .expect("Falha ao converter arquivo .js e .json")
69
+ };
70
+ }
71
+
72
+ fn temp_bat_script() -> String {
73
+ let dir = match current_dir() {
74
+ Ok(dir_path) => dir_path,
75
+ Err(_) => {
76
+ eprintln!("Houve um erro o tentar ler o diretório atual");
77
+ exit(1)
78
+ }
79
+ };
80
+
81
+ let file_path = dir.join("convert.bat");
82
+ let file = match File::create(file_path.to_owned()) {
83
+ Ok(it) => it,
84
+ Err(_err) => {
85
+ eprintln!("Houve um criar script temporário");
86
+ exit(1)
87
+ }
88
+ };
89
+ match writeln!(&file, "{BAT_SCRIPT}") {
90
+ Ok(it) => it,
91
+ Err(_err) => {
92
+ eprintln!("Houve um salvar script temporário");
93
+ exit(1)
94
+ }
95
+ };
96
+
97
+ file_path.to_owned().display().to_string()
98
+ }
@@ -0,0 +1 @@
1
+ pub mod convert_eitri_conf;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eitri-cli",
3
- "version": "1.10.1-beta.1",
3
+ "version": "1.10.1",
4
4
  "description": "Command Line Interface to make \"Eitri-App\" with code and fire.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -125,7 +125,7 @@ module.exports = class VegvisirService {
125
125
  );
126
126
  const fileContent = await readFile(workspaceGlobalPath, "utf8");
127
127
  const workspace = JSON.parse(fileContent);
128
- debug(`Construindo para o Workspace [${workspace.id} / Email: ${workspace.userEmail}]`)
128
+ debug(`Construindo para o Workspace [${workspace.id}]`)
129
129
  workspace.id = validateUUID(this.workspaceId) ? this.workspaceId : workspace.id;
130
130
  return workspace;
131
131
  } catch (error) {
@@ -2,7 +2,6 @@ const util = require('util');
2
2
  const inquirer = require("inquirer");
3
3
  const GenericUtils = require('../../util/GenericUtils');
4
4
  const exec = util.promisify(require("child_process").exec)
5
- const debug = require('debug')('eitri:AndroidEmulatorService')
6
5
 
7
6
  module.exports = class AndroidEmulatorService {
8
7
 
@@ -18,30 +17,9 @@ module.exports = class AndroidEmulatorService {
18
17
  try {
19
18
  console.log("Verificando instalação do ABD",)
20
19
  const command = "adb --version"
21
- const {stdout} = await exec(command)
22
- console.log("ADB Instalado. Continuando...\n");
23
-
24
- debug('checkHasInstalledAdb (adb --version):', stdout)
20
+ await exec(command)
21
+ console.log("ADB Instalado. Continuando...")
25
22
  } catch (error) {
26
- console.error("checkHasInstalledAdb: Comando 'adb --version' não executado. Iniciando fallback. \n")
27
- await this.checkHasInstalledAdbFallback(error)
28
- }
29
- }
30
-
31
- static async checkHasInstalledAdbFallback(firstError = {}) {
32
- try {
33
- console.log("Verificação novamente instalação do ADB...");
34
-
35
- const command = "adb devices"
36
- const {stdout} = await exec(command)
37
- console.log("ADB Instalado. Continuando...\n");
38
-
39
- debug('checkHasInstalledAdb (adb devices):', stdout)
40
- } catch (fallbackError) {
41
- console.error("checkHasInstalledAdb: Comando 'adb devices' não executado. \n")
42
- console.error("\n\ncheckHasInstalledAdb error: 'adb --version': \n", {message: firstError?.message || "", error: firstError})
43
- console.error("\n\ncheckHasInstalledAdb error: 'adb devices': \n", {message: fallbackError?.message || "", error: fallbackError})
44
-
45
23
  throw new Error('"adb" não instalado. Saiba mais em https://developer.android.com/tools/adb')
46
24
  }
47
25
  }
@@ -87,7 +65,7 @@ module.exports = class AndroidEmulatorService {
87
65
 
88
66
  static async openDeepLink(cmd) {
89
67
  try {
90
- const { stderr } = await exec(cmd)
68
+ const {stderr} = await exec(cmd)
91
69
  return !(stderr);
92
70
  } catch (error) {
93
71
  console.log(`Houve um erro ao tentar abrir o Eitri-App via deep link`)
@@ -14,12 +14,12 @@ class MiniLog {
14
14
  return new Promise((resolve, reject) => {
15
15
  const socket = this.createSocket()
16
16
  socket.on('connect', () => {
17
- if (!silentOnConnect) console.log('✓ Construindo para Workspace Temporário: ', roomName)
17
+ if(!silentOnConnect) console.log('✓ Construindo para Workspace Temporário: ', roomName)
18
18
  socket.emit('joinRoom', roomName)
19
19
  resolve()
20
20
  })
21
21
  socket.on('connect_error', (e) => {
22
- if (silentOnConnect) console.error('Não foi possível contectar ao compilador', roomName)
22
+ if(silentOnConnect) console.error('Não foi possível contectar ao compilador', roomName)
23
23
  else console.error('Não foi possível contectar ao compilador', roomName, `${this._config.url} ${this._config.path}`)
24
24
  reject(e)
25
25
  })
@@ -29,6 +29,36 @@ class MiniLog {
29
29
  this.socket = socket
30
30
  })
31
31
  }
32
+ //TODO: ESSE MÉTODO DEVE SER APAGADO, QUANDO NÃO EXISTIR MAIS O COMANDO PUBLISH
33
+ awaitForPublish() {
34
+ return new Promise((resolve, reject) => {
35
+ this.socket.on('onLog', (event) => {
36
+ if (!event.publish) {
37
+ return
38
+ }
39
+ if (event.publish.ok) {
40
+ resolve(event)
41
+ } else {
42
+ reject(new Error(event.publish.error))
43
+ }
44
+ })
45
+ })
46
+ }
47
+
48
+ awaitForBuild() {
49
+ return new Promise((resolve, reject) => {
50
+ this.socket.on('onLog', (event) => {
51
+ if (!event.publish) {
52
+ return
53
+ }
54
+ if (event.publish.ok) {
55
+ resolve(event)
56
+ } else {
57
+ reject(new Error(event.publish.error))
58
+ }
59
+ })
60
+ })
61
+ }
32
62
 
33
63
  awaitForPushVersion() {
34
64
  return new Promise((resolve, reject) => {
@@ -39,8 +69,7 @@ class MiniLog {
39
69
  if (event.publish.ok) {
40
70
  resolve(event)
41
71
  } else {
42
- console.error(event.publish.friendlyMessage || event.publish.error)
43
- return process.exit(1)
72
+ reject(new Error(event.publish.error))
44
73
  }
45
74
  })
46
75
  })
@@ -54,6 +83,18 @@ class MiniLog {
54
83
  }
55
84
  }
56
85
 
86
+ format2JSON(str) {
87
+ let parsedToJSON
88
+
89
+ try {
90
+ parsedToJSON = JSON.parse(str)
91
+ } catch (e) {
92
+ return undefined
93
+ }
94
+
95
+ return parsedToJSON
96
+ }
97
+
57
98
  printLog(data) {
58
99
  if (typeof data.msg === 'undefined') {
59
100
  return
@@ -80,7 +121,7 @@ class MiniLog {
80
121
  console.log(chalk.cyan(msg))
81
122
  } else {
82
123
  // A propriedade userFriendlyMessage deve ser tratada pelo Eitri-App. Logaremos da forma como o Eitri-App nos fornecer o objeto.
83
- if (!data.method) {
124
+ if(!data.method) {
84
125
  console.log(`\x1b[34meitri:\x1b[0m\x1b[97m${data.msg}\x1b[0m`);
85
126
  } else {
86
127
  const message = this._colorizeMessage(data.msg, data.method)