eitri-cli 1.1.0-beta.2 → 1.1.0-beta.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eitri-cli",
3
- "version": "1.1.0-beta.2",
3
+ "version": "1.1.0-beta.3",
4
4
  "description": "Command Line Interface to make \"eitri app\" with code and fire.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -3,6 +3,7 @@ const BlindGuardian = require("../../service/BlindGuardian");
3
3
  const Http = require("../../service/Http");
4
4
  const config = require("config");
5
5
  const getWorkspace = require("../../util/getWorkspace");
6
+ const writeGlobalWorkspaceConfig = require("./utils/writeGlobalWorkspaceConfig");
6
7
 
7
8
  module.exports = class VegvisirService {
8
9
  constructor() {
@@ -19,9 +20,15 @@ module.exports = class VegvisirService {
19
20
  } catch (error) {
20
21
  if (axios.isAxiosError(error)) {
21
22
  if (error.response.status === 404) {
22
- console.error(
23
- "Você não possui workspaces cadastrados, utilize o comando 'eitri workspace create' para cadastrar"
23
+ console.log(
24
+ "Você não possui nenhum workspace criado, estamos criando um default para você!"
24
25
  );
26
+ const createdWorkspace = await this.create({
27
+ name: 'DEFAULT'
28
+ })
29
+
30
+ return [createdWorkspace]
31
+
25
32
  }
26
33
  } else {
27
34
  console.error("Houve um erro inesperado ao listar workspaces");
@@ -31,16 +38,19 @@ module.exports = class VegvisirService {
31
38
 
32
39
  async create(createData) {
33
40
  const url = `${this.config.url}${this.config.basePath}${this.config.workspace}`;
34
- await this.http.post(url, createData);
41
+ const response = await this.http.post(url, createData);
42
+ return response.data;
35
43
  }
36
44
 
37
45
  async check(slug) {
38
46
  try {
39
- const workspace = await getWorkspace()
47
+ let workspace = await getWorkspace()
40
48
  if(!workspace) {
41
- console.log("É necessário ter um workspace definido para realizar essa ação, certifique-se de estar em um workspace.")
42
- console.log("Execute o comando 'eitri workspace current' para checar você está em um workspace.")
43
- return process.exit(0)
49
+ const workspaces = await this.listMyWorkspaces();
50
+ const defaultWorkspace = await workspaces.find(w => w.name === 'DEFAULT')
51
+ await writeGlobalWorkspaceConfig(defaultWorkspace)
52
+ workspace = defaultWorkspace;
53
+ return;
44
54
  }
45
55
 
46
56
  const data = {
@@ -3,6 +3,10 @@ const getWorkspace = require("../../../util/getWorkspace");
3
3
  module.exports = async function current(cmdObj) {
4
4
  try {
5
5
  const workspace = await getWorkspace()
6
+ if(!workspace) {
7
+ console.log("Você não possui workspace selecionado para desenvolvimento.")
8
+ return;
9
+ }
6
10
  console.log("====================================================")
7
11
  console.log('\t Workspace Atual: ', workspace.name)
8
12
  console.log("====================================================")
@@ -4,6 +4,7 @@ const VegvisirService = require("../VegvisirService");
4
4
  const path = require("path");
5
5
  const { mkdir, writeFile } = require("fs/promises");
6
6
  const { existsSync } = require("fs");
7
+ const writeGlobalWorkspaceConfig = require("../utils/writeGlobalWorkspaceConfig");
7
8
  const vegvisirService = new VegvisirService();
8
9
 
9
10
  module.exports = async function use(cmdArgs) {
@@ -30,28 +31,13 @@ module.exports = async function use(cmdArgs) {
30
31
  await writeGlobalWorkspaceConfig(selectedWorkspace);
31
32
  };
32
33
 
33
- async function writeGlobalWorkspaceConfig(selectedWorkspace) {
34
- const eitriFolderPath = path.resolve(os.homedir(), ".eitri");
35
- const workspaceFolderPath = path.resolve(eitriFolderPath, "workspaces");
36
- const workspaceFilePath = path.resolve(workspaceFolderPath, "workspace");
37
-
38
- await mkdir(workspaceFolderPath, { recursive: true });
39
-
40
- const workspaceConfig = JSON.stringify({
41
- name: selectedWorkspace.name,
42
- id: selectedWorkspace.id,
43
- });
44
-
45
- await writeFile(workspaceFilePath, workspaceConfig, { encoding: "utf8" });
46
-
47
- console.log("\nWorkspace configurado com sucesso!");
48
- }
49
-
50
34
  async function writeLocalWorkspaceConfig(selectedWorkspace) {
51
- const miniAppConfPath = path.resolve(process.cwd(), "eitri-app.conf.js");
52
- if (!existsSync(miniAppConfPath)) {
35
+ const eitriAppConfPath = path.resolve(process.cwd(), "eitri-app.conf.js");
36
+ const oldConfPath = path.resolve(process.cwd(), "miniapp.conf.js");
37
+
38
+ if (!existsSync(oldConfPath) && !existsSync(eitriAppConfPath)) {
53
39
  console.error(
54
- "Você só pode selecionar um workspace como local dentro de um eitri-app"
40
+ "Você só pode selecionar um workspace como local dentro de um projeto de eitri-app"
55
41
  );
56
42
  return;
57
43
  }
@@ -0,0 +1,20 @@
1
+ const os = require("os");
2
+ const path = require("path");
3
+ const { mkdir, writeFile } = require("fs/promises");
4
+
5
+ module.exports = async function writeGlobalWorkspaceConfig(selectedWorkspace) {
6
+ const eitriFolderPath = path.resolve(os.homedir(), ".eitri");
7
+ const workspaceFolderPath = path.resolve(eitriFolderPath, "workspaces");
8
+ const workspaceFilePath = path.resolve(workspaceFolderPath, "workspace");
9
+
10
+ await mkdir(workspaceFolderPath, { recursive: true });
11
+
12
+ const workspaceConfig = JSON.stringify({
13
+ name: selectedWorkspace.name,
14
+ id: selectedWorkspace.id,
15
+ });
16
+
17
+ await writeFile(workspaceFilePath, workspaceConfig, { encoding: "utf8" });
18
+
19
+ console.log(`Workspace configurado com sucesso! (${selectedWorkspace.name})`);
20
+ }
@@ -29,8 +29,7 @@ module.exports = async function getWorkspace() {
29
29
  return workspace;
30
30
  } catch (error) {
31
31
  if(error.code === "ENOENT") {
32
- console.error("Você não tem nenhum workspace definido para desenvolvimento, execute o comando 'eitri workspace use' para definir um workspace.")
33
- return process.exit(1)
32
+ return;
34
33
  }
35
34
  console.error("Houve um erro inesperado ao tentar ler o workspace atual.")
36
35
  return process.exit(1)