eitri-cli 1.17.0-beta.2 → 1.17.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/.eslintrc.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "root": true,
3
+ "extends": ["eslint:recommended", "google", "plugin:prettier/recommended", "plugin:jest/recommended"],
4
+ "plugins": ["prettier", "jest"],
5
+ "env": {
6
+ "es6": true,
7
+ "node": true
8
+ },
9
+ "globals": {
10
+ "Atomics": "readonly",
11
+ "SharedArrayBuffer": "readonly"
12
+ },
13
+ "parserOptions": {
14
+ "sourceType": "commonjs"
15
+ },
16
+ "rules": {
17
+ "jest/no-conditional-expect": "warn",
18
+ "jest/no-focused-tests": "warn",
19
+ "prefer-const": "warn",
20
+ "prefer-rest-params": "warn",
21
+ "no-unused-expressions": "error",
22
+ "no-undef": "error",
23
+ "prettier/prettier": "error",
24
+ "no-console": "off"
25
+ }
26
+ }
package/.prettierrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "printWidth": 130,
3
+ "tabWidth": 4,
4
+ "singleQuote": false,
5
+ "semi": false
6
+ }
package/package.json CHANGED
@@ -1,93 +1,97 @@
1
1
  {
2
- "name": "eitri-cli",
3
- "version": "1.17.0-beta.2",
4
- "description": "Command Line Interface to make \"Eitri-App\" with code and fire.",
5
- "main": "index.js",
6
- "bin": {
7
- "eitri": "index-eitri.js"
8
- },
9
- "scripts": {
10
- "test-eitri": "NODE_APP_INSTANCE=eitri jest --detectOpenHandles",
11
- "test": "NODE_APP_INSTANCE=eitri jest --detectOpenHandles",
12
- "linter": "./node_modules/.bin/eslint --fix ./src/**/*.js",
13
- "docsify:run": "cd docsify && docsify serve",
14
- "build": "echo \"no build\"",
15
- "release": "semantic-release",
16
- "release:dry": "semantic-release --dry-run"
17
- },
18
- "engines": {
19
- "node": ">=16.0.0",
20
- "npm": ">=3.0.0"
21
- },
22
- "keywords": [],
23
- "author": "Calindra",
24
- "license": "ISC",
25
- "lint-staged": {
26
- "*.js": [
27
- "./node_modules/.bin/eslint --fix",
28
- "git add"
29
- ]
30
- },
31
- "dependencies": {
32
- "adm-zip": "^0.5.9",
33
- "axios": "0.21.3",
34
- "axios-cookiejar-support": "^0.5.1",
35
- "base-64": "^0.1.0",
36
- "base64url": "^3.0.1",
37
- "camelcase": "^6.3.0",
38
- "chalk": "^3.0.0",
39
- "cheerio": "^1.0.0-rc.3",
40
- "cli-progress": "^3.4.0",
41
- "commander": "^9.2.0",
42
- "config": "^3.3.0",
43
- "cors": "^2.8.5",
44
- "emojilib": "^2.4.0",
45
- "express": "^4.17.3",
46
- "express-rate-limit": "^6.3.0",
47
- "figlet": "^1.2.4",
48
- "folder-hash": "^3.3.0",
49
- "form-data": "^4.0.0",
50
- "inquirer": "^7.0.0",
51
- "js-yaml": "^4.1.0",
52
- "jsonwebtoken": "^8.5.1",
53
- "lz-string": "^1.5.0",
54
- "node-watch": "^0.6.3",
55
- "open": "^7.0.0",
56
- "ps-node": "^0.1.6",
57
- "qrcode": "^1.5.3",
58
- "semver": "^7.1.3",
59
- "slugify": "^1.4.0",
60
- "socket.io-client": "^4.5.2",
61
- "standard-version": "^9.5.0",
62
- "temp-dir": "^2.0.0",
63
- "tmp": "^0.1.0",
64
- "tough-cookie": "^3.0.1",
65
- "tough-cookie-file-store": "^2.0.2",
66
- "uuid": "^7.0.2",
67
- "yaml": "^2.4.2"
68
- },
69
- "devDependencies": {
70
- "@commitlint/cli": "^17.7.2",
71
- "@commitlint/config-conventional": "^17.7.0",
72
- "@faker-js/faker": "^7.6.0",
73
- "@semantic-release/changelog": "^6.0.3",
74
- "@semantic-release/git": "^10.0.1",
75
- "docsify-cli": "^4.4.4",
76
- "eslint": "^6.7.2",
77
- "eslint-config-google": "^0.14.0",
78
- "husky": "^8.0.3",
79
- "jest": "^29.7.0",
80
- "lint-staged": "^9.5.0",
81
- "nock": "^13.3.0",
82
- "puppeteer": "^21.4.1",
83
- "semantic-release": "^22.0.8"
84
- },
85
- "resolutions": {
86
- "lodash": "4.17.21",
87
- "minimist": "1.2.6",
88
- "ansi-regex": "5.0.1",
89
- "merge": "2.1.1",
90
- "tar": "6.1.9",
91
- "handlebars": "4.7.7"
92
- }
2
+ "name": "eitri-cli",
3
+ "version": "1.17.0-beta.3",
4
+ "description": "Command Line Interface to make \"Eitri-App\" with code and fire.",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "eitri": "index-eitri.js"
8
+ },
9
+ "scripts": {
10
+ "test-eitri": "NODE_APP_INSTANCE=eitri jest --detectOpenHandles",
11
+ "test": "NODE_APP_INSTANCE=eitri jest --detectOpenHandles",
12
+ "linter": "./node_modules/.bin/eslint --fix ./src/**/*.js",
13
+ "docsify:run": "cd docsify && docsify serve",
14
+ "build": "echo \"no build\"",
15
+ "release": "semantic-release",
16
+ "release:dry": "semantic-release --dry-run"
17
+ },
18
+ "engines": {
19
+ "node": ">=16.0.0",
20
+ "npm": ">=3.0.0"
21
+ },
22
+ "keywords": [],
23
+ "author": "Calindra",
24
+ "license": "ISC",
25
+ "lint-staged": {
26
+ "*.js": [
27
+ "./node_modules/.bin/eslint --fix",
28
+ "git add"
29
+ ]
30
+ },
31
+ "dependencies": {
32
+ "adm-zip": "^0.5.9",
33
+ "axios": "^1.7.2",
34
+ "axios-cookiejar-support": "^5.0.2",
35
+ "base-64": "^0.1.0",
36
+ "base64url": "^3.0.1",
37
+ "camelcase": "^6.3.0",
38
+ "chalk": "^3.0.0",
39
+ "cheerio": "^1.0.0-rc.3",
40
+ "cli-progress": "^3.4.0",
41
+ "commander": "^9.2.0",
42
+ "config": "^3.3.0",
43
+ "cors": "^2.8.5",
44
+ "emojilib": "^2.4.0",
45
+ "express": "^4.17.3",
46
+ "express-rate-limit": "^6.3.0",
47
+ "figlet": "^1.2.4",
48
+ "folder-hash": "^3.3.0",
49
+ "form-data": "^4.0.0",
50
+ "get-folder-size": "^2.0.1",
51
+ "inquirer": "^7.0.0",
52
+ "js-yaml": "^4.1.0",
53
+ "jsonwebtoken": "^9.0.2",
54
+ "lz-string": "^1.5.0",
55
+ "node-watch": "^0.6.3",
56
+ "open": "^7.0.0",
57
+ "ps-node": "^0.1.6",
58
+ "qrcode": "^1.5.3",
59
+ "semver": "^7.1.3",
60
+ "slugify": "^1.4.0",
61
+ "socket.io-client": "^4.5.2",
62
+ "standard-version": "^9.5.0",
63
+ "temp-dir": "^2.0.0",
64
+ "tmp": "^0.1.0",
65
+ "tough-cookie": "^4.1.4",
66
+ "tough-cookie-file-store": "^2.0.2",
67
+ "uuid": "^7.0.2",
68
+ "yaml": "^2.4.2"
69
+ },
70
+ "devDependencies": {
71
+ "@commitlint/cli": "^17.7.2",
72
+ "@commitlint/config-conventional": "^17.7.0",
73
+ "@faker-js/faker": "^7.6.0",
74
+ "@semantic-release/changelog": "^6.0.3",
75
+ "@semantic-release/git": "^10.0.1",
76
+ "docsify-cli": "^4.4.2",
77
+ "eslint": "^9.5.0",
78
+ "eslint-config-google": "^0.14.0",
79
+ "eslint-plugin-jest": "^28.6.0",
80
+ "eslint-plugin-prettier": "^5.1.3",
81
+ "husky": "^8.0.3",
82
+ "jest": "^29.7.0",
83
+ "lint-staged": "^9.5.0",
84
+ "nock": "^13.3.0",
85
+ "prettier": "^3.3.2",
86
+ "puppeteer": "^22.11.2",
87
+ "semantic-release": "^22.0.8"
88
+ },
89
+ "resolutions": {
90
+ "lodash": "4.17.21",
91
+ "minimist": "1.2.6",
92
+ "ansi-regex": "5.0.1",
93
+ "merge": "2.1.1",
94
+ "tar": "6.1.9",
95
+ "handlebars": "4.7.7"
96
+ }
93
97
  }
@@ -1,141 +1,124 @@
1
- const { default: axios } = require("../../../node_modules/axios/index");
2
- const BlindGuardian = require("../../service/BlindGuardian");
3
- const Http = require("../../service/Http");
4
- const configService = require("../../service/ConfigService");
5
- const writeGlobalWorkspaceConfig = require("./utils/writeGlobalWorkspaceConfig");
6
- const { readFile } = require("fs/promises");
7
- const os = require("os");
8
- const {validateUUID} = require("../../util/GenericUtils");
9
- const path = require("path");
10
- const fs = require('fs')
11
- const debug = require('debug')('eitri:VegvisirService')
12
- const inquirer = require("inquirer");
13
- const chalk = require("chalk");
1
+ // const { default: axios } = require("../../../node_modules/axios/index");
2
+ const axios = require("axios")
3
+ const BlindGuardian = require("../../service/BlindGuardian")
4
+ const Http = require("../../service/Http")
5
+ const configService = require("../../service/ConfigService")
6
+ const writeGlobalWorkspaceConfig = require("./utils/writeGlobalWorkspaceConfig")
7
+ const { readFile } = require("fs/promises")
8
+ const os = require("os")
9
+ const { validateUUID } = require("../../util/GenericUtils")
10
+ const path = require("path")
11
+ const fs = require("fs")
12
+ const debug = require("debug")("eitri:VegvisirService")
13
+ const inquirer = require("inquirer")
14
+ const chalk = require("chalk")
14
15
 
15
16
  module.exports = class VegvisirService {
16
17
  constructor() {
17
- const blindGuardian = new BlindGuardian();
18
- this.http = new Http(blindGuardian);
19
- this.config = configService.get("vegvisir");
20
- this.workspaceId = "";
18
+ const blindGuardian = new BlindGuardian()
19
+ this.http = new Http(blindGuardian)
20
+ this.config = configService.get("vegvisir")
21
+ this.workspaceId = ""
21
22
  }
22
23
 
23
24
  getWorkspaceId() {
24
- return this.workspaceId;
25
+ return this.workspaceId
25
26
  }
26
27
 
27
28
  setWorkspaceId(id) {
28
- this.workspaceId = id;
29
+ this.workspaceId = id
29
30
  }
30
31
 
31
32
  async listMyWorkspaces() {
32
33
  try {
33
- const url = `${this.config.url}${this.config.basePath}${this.config.my}`;
34
- const workspaces = await this.http.get(url);
35
- return workspaces;
34
+ const url = `${this.config.url}${this.config.basePath}${this.config.my}`
35
+ const workspaces = await this.http.get(url)
36
+ return workspaces
36
37
  } catch (error) {
37
38
  if (axios.isAxiosError(error)) {
38
39
  if (error.response.status === 404) {
39
- console.log(
40
- "Você não possui nenhum workspace criado, estamos criando um default para você!"
41
- );
40
+ console.log("Você não possui nenhum workspace criado, estamos criando um default para você!")
42
41
  const createdWorkspace = await this.create({
43
- name: 'DEFAULT'
42
+ name: "DEFAULT",
44
43
  })
45
44
 
46
45
  return [createdWorkspace]
47
-
48
46
  }
49
47
  } else {
50
- console.error("Houve um erro inesperado ao listar workspaces: \n", error?.message);
48
+ console.error("Houve um erro inesperado ao listar workspaces: \n", error?.message)
51
49
  }
52
50
  }
53
51
  }
54
52
 
55
53
  async create(createData) {
56
- const url = `${this.config.url}${this.config.basePath}${this.config.workspace}`;
57
- const response = await this.http.post(url, createData);
58
- return response.data;
54
+ const url = `${this.config.url}${this.config.basePath}${this.config.workspace}`
55
+ const response = await this.http.post(url, createData)
56
+ return response.data
59
57
  }
60
58
 
61
59
  async check(slug) {
62
60
  debug("Iniciando check")
63
61
  try {
64
62
  let workspace = await this.getWorkspace()
65
- debug("Workspace carregado", {workspace})
66
- if(!workspace) {
63
+ debug("Workspace carregado", { workspace })
64
+ if (!workspace) {
67
65
  debug("Nenhum workspace obtido. Inciando busca de Workspaces")
68
- const workspaces = await this.listMyWorkspaces();
69
- debug("Lista de Workspaces", {workspaces})
70
- const defaultWorkspace = await workspaces.find(w => w.name === 'DEFAULT')
66
+ const workspaces = await this.listMyWorkspaces()
67
+ debug("Lista de Workspaces", { workspaces })
68
+ const defaultWorkspace = await workspaces.find((w) => w.name === "DEFAULT")
71
69
  await writeGlobalWorkspaceConfig(defaultWorkspace)
72
- workspace = defaultWorkspace;
73
- return;
70
+ workspace = defaultWorkspace
71
+ return
74
72
  }
75
73
 
76
74
  const data = {
77
75
  slug,
78
- id: workspace.id
76
+ id: workspace.id,
79
77
  }
80
78
 
81
- const url =`${this.config.url}${this.config.basePath}${this.config.check}`;
79
+ const url = `${this.config.url}${this.config.basePath}${this.config.check}`
82
80
 
83
81
  await this.http.put(url, data)
84
- debug("Atualização realizada", {url, data})
82
+ debug("Atualização realizada", { url, data })
85
83
  } catch (error) {
86
- debug("Erro na realização do check", {message: error?.message, error})
84
+ debug("Erro na realização do check", { message: error?.message, error })
87
85
  console.error(error.message)
88
86
  if (axios.isAxiosError(error)) {
89
87
  if (error?.response?.status === 404) {
90
- console.error(
91
- "O Workspace atual não foi encontrado."
92
- );
93
- return process.exit(0)
94
- }
95
- console.error("Ocorreu um erro inesperado ao listar workspaces", error?.message);
96
- return process.exit(0)
88
+ console.error("O Workspace atual não foi encontrado.")
89
+ return process.exit(0)
97
90
  }
91
+ console.error("Ocorreu um erro inesperado ao listar workspaces", error?.message)
92
+ return process.exit(0)
93
+ }
98
94
  console.error(error.message)
99
95
  return process.exit(0)
100
96
  }
101
-
102
97
  }
103
98
 
104
99
  async getWorkspace() {
105
100
  try {
106
- const workspaceEitriAppProjectPath = path.resolve(
107
- process.cwd(),
108
- ".workspaces",
109
- "workspace"
110
- );
111
-
101
+ const workspaceEitriAppProjectPath = path.resolve(process.cwd(), ".workspaces", "workspace")
102
+
112
103
  if (fs.existsSync(workspaceEitriAppProjectPath)) {
113
- const fileContent = await readFile(
114
- workspaceEitriAppProjectPath,
115
- "utf8"
116
- );
117
- const workspace = JSON.parse(fileContent);
118
- return workspace;
104
+ const fileContent = await readFile(workspaceEitriAppProjectPath, "utf8")
105
+ const workspace = JSON.parse(fileContent)
106
+ return workspace
119
107
  }
120
- const workspaceGlobalPath = path.resolve(
121
- os.homedir(),
122
- ".eitri",
123
- "workspaces",
124
- "workspace"
125
- );
126
- const fileContent = await readFile(workspaceGlobalPath, "utf8");
127
- const workspace = JSON.parse(fileContent);
108
+ const workspaceGlobalPath = path.resolve(os.homedir(), ".eitri", "workspaces", "workspace")
109
+ const fileContent = await readFile(workspaceGlobalPath, "utf8")
110
+ const workspace = JSON.parse(fileContent)
128
111
  debug(`Construindo para o Workspace [${workspace.id} / Email: ${workspace.userEmail}]`)
129
- workspace.id = validateUUID(this.workspaceId) ? this.workspaceId : workspace.id;
130
- return workspace;
112
+ workspace.id = validateUUID(this.workspaceId) ? this.workspaceId : workspace.id
113
+ return workspace
131
114
  } catch (error) {
132
- if(error.code === "ENOENT") {
133
- return;
115
+ if (error.code === "ENOENT") {
116
+ return
134
117
  }
135
118
  console.error("Ocorreu um erro inesperado ao tentar ler o workspace atual.", error?.message)
136
119
  return process.exit(1)
137
120
  }
138
- };
121
+ }
139
122
 
140
123
  async isCurrentWorkspaceOwnedByUser(slug = "") {
141
124
  const localWorkspace = await this.getWorkspace()
@@ -145,17 +128,21 @@ module.exports = class VegvisirService {
145
128
 
146
129
  const workspacesRemote = await this.listMyWorkspaces()
147
130
 
148
- const isOwner = workspacesRemote && Array.isArray(workspacesRemote) && workspacesRemote.length > 0 && workspacesRemote?.find(w => w?.id === localWorkspace?.id)
131
+ const isOwner =
132
+ workspacesRemote &&
133
+ Array.isArray(workspacesRemote) &&
134
+ workspacesRemote.length > 0 &&
135
+ workspacesRemote?.find((w) => w?.id === localWorkspace?.id)
149
136
  if (isOwner) return
150
137
 
151
- debug("Workspace local é diferente do remoto para esse usuário", {localWorkspace, workspacesRemote})
138
+ debug("Workspace local é diferente do remoto para esse usuário", { localWorkspace, workspacesRemote })
152
139
 
153
140
  const reseted = await this.redefineWorkspace(slug)
154
141
  if (reseted) return debug("Workspace validado com sucesso. Continuando...")
155
142
 
156
143
  console.log("Parece que você está usando um workspace de outro usuário. Como não foi redefinido, não podemos prosseguir.")
157
144
  process.exit(1)
158
- };
145
+ }
159
146
 
160
147
  async redefineWorkspace(slug = "") {
161
148
  const question1 = "\n Deseja redefinir o seu workspace?"
@@ -166,22 +153,16 @@ module.exports = class VegvisirService {
166
153
  {
167
154
  name: "confirm",
168
155
  type: "confirm",
169
- message:
170
- question1 + "\n" + question2 + "\n" + question3 + "\n",
156
+ message: question1 + "\n" + question2 + "\n" + question3 + "\n",
171
157
  default: true,
172
158
  },
173
- ]);
159
+ ])
174
160
 
175
161
  if (res.confirm) {
176
- const workspaceGlobalPath = path.resolve(
177
- os.homedir(),
178
- ".eitri",
179
- "workspaces",
180
- "workspace"
181
- );
162
+ const workspaceGlobalPath = path.resolve(os.homedir(), ".eitri", "workspaces", "workspace")
182
163
 
183
164
  if (fs.existsSync(workspaceGlobalPath)) {
184
- fs.unlinkSync(workspaceGlobalPath);
165
+ fs.unlinkSync(workspaceGlobalPath)
185
166
  }
186
167
 
187
168
  await this.check(slug)
@@ -189,4 +170,4 @@ module.exports = class VegvisirService {
189
170
 
190
171
  return res.confirm
191
172
  }
192
- };
173
+ }