eitri-cli 1.7.0-beta.1 → 1.7.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.7.0-beta.1",
3
+ "version": "1.7.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": {
@@ -19,6 +19,7 @@ const vegvisirService = new VegvisirService()
19
19
  const standardVersion = require('standard-version')
20
20
  const releaseService = require('../service/ReleaseService')
21
21
  const {isGitRepo} = require('../util/GenericUtils')
22
+ const debug = require('debug')('eitri:pushVersion')
22
23
 
23
24
  module.exports = async function pushVersion(cmdObj) {
24
25
  try {
@@ -29,6 +30,9 @@ module.exports = async function pushVersion(cmdObj) {
29
30
  return
30
31
  }
31
32
 
33
+ const {slug: miniConfSlug} = workspace.getMiniConf()
34
+ await vegvisirService.isCurrentWorkspaceOwnedByUser(miniConfSlug)
35
+
32
36
  const separator = '======================================================================='
33
37
 
34
38
  try {
package/src/cmd/start.js CHANGED
@@ -16,11 +16,14 @@ const blindGuardian = workspace.blindGuardian
16
16
  const hashFolder = workspace.hashFolder
17
17
  const trackingService = new TrackingService(blindGuardian, { ignoreCredentialError: true })
18
18
  const watcher = new Watcher(workspace, hashFolder, trackingService)
19
- const vegvisirService = new VegvisirService()
19
+ const vegvisirService = new VegvisirService(workspace)
20
20
  const debug = require('debug')('eitri:start')
21
21
 
22
22
  module.exports = async function start(args) {
23
23
  debug("Iniciando start()")
24
+ const miniConf = workspace.getMiniConf()
25
+
26
+ await vegvisirService.isCurrentWorkspaceOwnedByUser(miniConf.slug)
24
27
 
25
28
  const separator = '======================================================================='
26
29
  let displayFriendlyErrorAtEnd = ""
@@ -48,7 +51,6 @@ module.exports = async function start(args) {
48
51
  workspace.setResourceFolder2Watch(resourceFolders2watch)
49
52
  }
50
53
 
51
- const miniConf = workspace.getMiniConf()
52
54
  await vegvisirService.check(miniConf.slug)
53
55
  debug("Fim da busca e validação do EitriAppConf", {miniConf})
54
56
 
@@ -106,7 +108,13 @@ module.exports = async function start(args) {
106
108
  const friendlyMessage2 = "Recomendamos que verifique eventuais erros no código. Para mais informações, consulte nossa documentação em: https://docs.eitri.tech/."
107
109
  const friendlyMessage3 = "Se o problema persistir, por favor, entre em contato com o suporte técnico do Eitri."
108
110
  const friendlyMessage4 = "Você pode continuar o desenvolvimento localmente, mesmo que a sincronização não esteja disponível no momento."
109
- displayFriendlyErrorAtEnd = `\x1b[1m\x1b[31m\n${friendlyMessage1}\n${friendlyMessage2} \x1b[0m` + "\n" + `\n${friendlyMessage3}\n${friendlyMessage4}\n \x1b[0m`
111
+ displayFriendlyErrorAtEnd = `\x1b[1m\x1b[31m\n${friendlyMessage1}\n${friendlyMessage2} \x1b[0m` + "\n" + `\n${friendlyMessage3}\n${friendlyMessage4}\n\x1b[0m`
112
+
113
+ const errorData = error.response.data
114
+ const commonStartErrors = ['CodeCompileError', 'TagNotFound']
115
+ if(commonStartErrors.includes(errorData.name)) {
116
+ displayFriendlyErrorAtEnd += `\n\x1b[1m\x1b[31mMotivo: ${errorData.friendlyMessage}\x1b[0m\n`;
117
+ }
110
118
  }
111
119
  console.log("Pronto!");
112
120
 
@@ -161,8 +169,10 @@ module.exports = async function start(args) {
161
169
  await trackingService.sendError(e)
162
170
 
163
171
  process.exit(1)
164
- }finally{
172
+ } finally{
165
173
  if(displayFriendlyErrorAtEnd){
174
+ const folderHash = workspace.getFolderHashPath()
175
+ await workspace.transpile([folderHash])
166
176
  console.log("\n\n" + separator + "\n" + displayFriendlyErrorAtEnd + "\n" + separator + "\n\n")
167
177
  }
168
178
  }
@@ -9,6 +9,8 @@ const {validateUUID} = require("../../util/GenericUtils");
9
9
  const path = require("path");
10
10
  const fs = require('fs')
11
11
  const debug = require('debug')('eitri:VegvisirService')
12
+ const inquirer = require("inquirer");
13
+ const chalk = require("chalk");
12
14
 
13
15
  module.exports = class VegvisirService {
14
16
  constructor() {
@@ -134,4 +136,57 @@ module.exports = class VegvisirService {
134
136
  return process.exit(1)
135
137
  }
136
138
  };
139
+
140
+ async isCurrentWorkspaceOwnedByUser(slug = "") {
141
+ const localWorkspace = await this.getWorkspace()
142
+ if (!localWorkspace?.id) {
143
+ return
144
+ }
145
+
146
+ const workspacesRemote = await this.listMyWorkspaces()
147
+
148
+ const isOwner = workspacesRemote.find(w => w?.id === localWorkspace?.id)
149
+ if (isOwner) return
150
+
151
+ debug("Workspace local é diferente do remoto para esse usuário", {localWorkspace, workspacesRemote})
152
+
153
+ const reseted = await this.redefineWorkspace(slug)
154
+ if (reseted) return debug("Workspace validado com sucesso. Continuando...")
155
+
156
+ console.log("Parece que você está usando um workspace de outro usuário. Como não foi redefinido, não podemos prosseguir.")
157
+ process.exit(1)
158
+ };
159
+
160
+ async redefineWorkspace(slug = "") {
161
+ const question1 = "\n Deseja redefinir o seu workspace?"
162
+ const question2 = chalk.italic(" O workspace atual pertence a outro usuário, portanto, é necessária a redefinição.")
163
+ const question3 = chalk.italic(" Atenção! A redefinição do workspace poderá acarretar na alteração do tema.")
164
+
165
+ const res = await inquirer.prompt([
166
+ {
167
+ name: "confirm",
168
+ type: "confirm",
169
+ message:
170
+ question1 + "\n" + question2 + "\n" + question3 + "\n",
171
+ default: true,
172
+ },
173
+ ]);
174
+
175
+ if (res.confirm) {
176
+ const workspaceGlobalPath = path.resolve(
177
+ os.homedir(),
178
+ ".eitri",
179
+ "workspaces",
180
+ "workspace"
181
+ );
182
+
183
+ if (fs.existsSync(workspaceGlobalPath)) {
184
+ fs.unlinkSync(workspaceGlobalPath);
185
+ }
186
+
187
+ await this.check(slug)
188
+ }
189
+
190
+ return res.confirm
191
+ }
137
192
  };
@@ -1,5 +1,6 @@
1
1
  const util = require('util');
2
2
  const exec = util.promisify(require("child_process").exec)
3
+ const inquirer = require("inquirer");
3
4
 
4
5
  module.exports = class IOSEmulatorService {
5
6
 
@@ -22,8 +22,7 @@ class Watcher {
22
22
  const filePath = name.replace(/\\/g, '/')
23
23
  if (evt === 'remove') {
24
24
  console.log('Apagando', name)
25
- this.workspace.delete(filePath)
26
- return
25
+ return this.workspace.delete(filePath)
27
26
  }
28
27
  fs.stat(filePath, (err, stat) => {
29
28
  if (err) {
@@ -1010,6 +1010,11 @@ class Workspace {
1010
1010
  return Buffer.from(content).toString("base64");
1011
1011
  }
1012
1012
 
1013
+ getFolderHashPath() {
1014
+ const folderHashPath = path.join(this.folder2watch, 'folder.hash');
1015
+ return folderHashPath
1016
+ }
1017
+
1013
1018
  }
1014
1019
 
1015
1020
  module.exports = {