eitri-cli 1.10.0-beta.4 → 1.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.
@@ -21,6 +21,7 @@ serde = { version = "1.0.197", features = ["derive"] }
21
21
  serde_derive = "1.0.197"
22
22
  serde_json = "1.0.114"
23
23
  tokio = { version = "1.36.0", features = ["full"] }
24
+ colored = "2.0"
24
25
 
25
26
  [target.x86_64-unknown-linux-gnu]
26
27
  openssl = { version = "0.9", features = ["vendored"] }
@@ -1,4 +1,5 @@
1
1
  use std::{env, process::exit};
2
+ use colored::*;
2
3
 
3
4
  use crate::{
4
5
  model::{url::Url, workspace_auth::WorkspaceAuth},
@@ -28,8 +29,12 @@ pub async fn execute(_workspace_auth: WorkspaceAuth, _path: String) {
28
29
  let output_str = output.stderr;
29
30
  eprint!("{output_str}");
30
31
  }
31
- Err(_) => {
32
- eprintln!("Houve um erro ao executar os testes.");
32
+ Err(http_error) => {
33
+ if let Some(message) = http_error.get_message() {
34
+ eprintln!("{}", message.red().bold());
35
+ } else {
36
+ eprintln!("Houve um erro ao executar os testes.");
37
+ }
33
38
  exit(1)
34
39
  }
35
40
  }
@@ -22,6 +22,15 @@ pub enum HttpError {
22
22
  Deserialize(reqwest::Error),
23
23
  }
24
24
 
25
+ impl HttpError {
26
+ pub fn get_message(&self) -> Option<&String> {
27
+ match self {
28
+ HttpError::HttpError(_, api_error) => Some(&api_error.message),
29
+ _ => None,
30
+ }
31
+ }
32
+ }
33
+
25
34
  #[allow(dead_code)]
26
35
  pub async fn post<T, U>(url: &str, data: U, headers: HeaderMap) -> Result<T, HttpError>
27
36
  where
@@ -18,6 +18,7 @@ pub async fn run_test(
18
18
  test_path: test_path,
19
19
  };
20
20
 
21
+
21
22
  headers.append("workspace-id", user_workspace_id.parse().unwrap());
22
23
  let result = http_client::post::<ProcessOutput, TestConfig>(&url, data, headers).await?;
23
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eitri-cli",
3
- "version": "1.10.0-beta.4",
3
+ "version": "1.10.0",
4
4
  "description": "Command Line Interface to make \"Eitri-App\" with code and fire.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -26,6 +26,21 @@ module.exports = async function runTests(args) {
26
26
  const miniConf = workspace.getMiniConf()
27
27
  let testPath = ""
28
28
 
29
+ if (!Object.prototype.hasOwnProperty.call(miniConf, 'type')) {
30
+ const message = "Erro no arquivo eitri-app.conf.js: A propriedade 'type' não está presente."
31
+ console.log(`\x1b[1m\x1b[31m${message}\x1b[0m`);
32
+ process.exit(1)
33
+ }
34
+
35
+ if (
36
+ Object.prototype.hasOwnProperty.call(miniConf, 'type') &&
37
+ miniConf.type !== 'module'
38
+ ) {
39
+ const message = " Os testes não podem ser executados devido à ausência do tipo 'module' no arquivo 'eitri-app.conf.js'. Certifique-se de incluir o atributo 'type' com o valor 'module' no arquivo de configuração para permitir a execução dos testes com sucesso."
40
+ console.log(`\x1b[1m\x1b[31m${message}\x1b[0m`);
41
+ process.exit(1)
42
+ }
43
+
29
44
  await vegvisirService.isCurrentWorkspaceOwnedByUser(miniConf.slug)
30
45
 
31
46
  const separator = '======================================================================='
@@ -187,35 +187,43 @@ class Workspace {
187
187
  const headers = {
188
188
  accept: this.config.libs.updateLibsEndpointVersion,
189
189
  };
190
- const setupResponse = await this.http.post(
191
- `${this.serverUrl}/${this.basePath}/setup`,
192
- miniConf,
193
- headers
194
- ); // somente para garantir que a pasta do usuario existe
190
+ try {
191
+ const setupResponse = await this.http.post(
192
+ `${this.serverUrl}/${this.basePath}/setup`,
193
+ miniConf,
194
+ headers
195
+ ); // somente para garantir que a pasta do usuario existe
195
196
 
196
- console.log("Preparando compilador");
197
- await this.http.put(
198
- `${this.serverUrl}/${this.basePath}/version`,
199
- miniConf,
200
- headers
201
- ); // TODO PDV Setup fara isso aqui
202
- console.log("Compilador pronto para uso contínuo");
197
+ console.log("Preparando compilador");
198
+ await this.http.put(
199
+ `${this.serverUrl}/${this.basePath}/version`,
200
+ miniConf,
201
+ headers
202
+ ); // TODO PDV Setup fara isso aqui
203
+ console.log("Compilador pronto para uso contínuo");
203
204
 
204
- const setupData = setupResponse.data;
205
+ const setupData = setupResponse.data;
205
206
 
206
- const { state, target: remoteTarget, eitriConf: remoteEitriConf } = setupData;
207
+ const { state, target: remoteTarget, eitriConf: remoteEitriConf } = setupData;
207
208
 
208
- if (!this.eitriAppService.validEitriConf(miniConf)) {
209
- await this.eitriAppService.writeEitriConf(remoteEitriConf, miniConf, this.folder2watch);
210
- }
209
+ if (!this.eitriAppService.validEitriConf(miniConf)) {
210
+ await this.eitriAppService.writeEitriConf(remoteEitriConf, miniConf, this.folder2watch);
211
+ }
211
212
 
212
- await LibsService.validateLibsVersions({ libs: state.libs, eitriAppConf: miniConf });
213
+ await LibsService.validateLibsVersions({ libs: state.libs, eitriAppConf: miniConf });
213
214
 
214
- this.printLibsVersion(state);
215
+ this.printLibsVersion(state);
215
216
 
216
- await this.loadTarget(remoteTarget);
217
+ await this.loadTarget(remoteTarget);
217
218
 
218
- return setupData;
219
+ return setupData;
220
+ } catch (e) {
221
+ if (e.response && e.response.data && e.response.data.name === "WorkspaceService.setup.mismatchAppType") {
222
+ console.error(`\x1b[1m\x1b[31m${e.response.data.message}\x1b[0m`);
223
+ process.exit(1)
224
+ }
225
+ throw Error(e)
226
+ }
219
227
  }
220
228
 
221
229
  async loadTarget(remoteTarget) {