eitri-cli 1.12.0-beta.6 → 1.12.0-beta.8

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.12.0-beta.6",
3
+ "version": "1.12.0-beta.8",
4
4
  "description": "Command Line Interface to make \"Eitri-App\" with code and fire.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -34,6 +34,7 @@
34
34
  "axios-cookiejar-support": "^0.5.1",
35
35
  "base-64": "^0.1.0",
36
36
  "base64url": "^3.0.1",
37
+ "camelcase": "^6.3.0",
37
38
  "chalk": "^3.0.0",
38
39
  "cheerio": "^1.0.0-rc.3",
39
40
  "cli-progress": "^3.4.0",
@@ -63,7 +64,8 @@
63
64
  "tmp": "^0.1.0",
64
65
  "tough-cookie": "^3.0.1",
65
66
  "tough-cookie-file-store": "^2.0.2",
66
- "uuid": "^7.0.2"
67
+ "uuid": "^7.0.2",
68
+ "yaml": "^2.4.2"
67
69
  },
68
70
  "devDependencies": {
69
71
  "@commitlint/cli": "^17.7.2",
package/src/cmd/create.js CHANGED
@@ -10,7 +10,7 @@ const { NAME_TITLE_REGEX, SLUG_REGEX } = require("./validate");
10
10
  const handleStartServer = require("../service/StarterService");
11
11
  const getCreateFactory = require("../util/getCreateFactory");
12
12
  const UrlUtils = require("../util/UrlUtils");
13
-
13
+ const open = require("open");
14
14
  // eslint-disable-next-line no-unused-vars
15
15
  const Target = require("../model/Target");
16
16
  const EitriAppManager = require("../service/EitriAppManager");
@@ -54,7 +54,7 @@ module.exports = async function create(projectName, cmdObj) {
54
54
  }
55
55
 
56
56
  console.log(
57
- "\x1b[34mVamos criar o seu Eitri-App. Para isso basta responder algumas perguntas:\x1b[0m"
57
+ "Vamos criar o seu Eitri-App. Carregando configurações..."
58
58
  );
59
59
 
60
60
  try {
@@ -62,6 +62,7 @@ module.exports = async function create(projectName, cmdObj) {
62
62
  workspace.setServerUrl(url);
63
63
  const clientApplication = await askClientApplication(cmdObj.application);
64
64
  if (clientApplication.name === ITEM_DOUBT) {
65
+ open("https://docs.eitri.tech/")
65
66
  handleStartServer(
66
67
  cmdObj,
67
68
  trackingService,
@@ -92,6 +93,11 @@ module.exports = async function create(projectName, cmdObj) {
92
93
 
93
94
  async function askClientApplication(applicationName) {
94
95
  const availableApplications = await eitriAppManager.findAllApplications();
96
+
97
+ console.log(
98
+ "\x1b[34m \nAgora, responda algumas perguntas:\n\x1b[0m"
99
+ );
100
+
95
101
  if (availableApplications.length <= 0) {
96
102
  console.log(
97
103
  "Sua organização não contém nenhuma aplicação disponível para prosseguir com a criação."
@@ -120,9 +126,10 @@ async function askClientApplication(applicationName) {
120
126
  name: "accepted",
121
127
  type: "rawlist",
122
128
  message:
123
- "Selecione a aplicação para qual destina-se seu Eitri-App:",
129
+ "Selecione o Aplicativo para o Eitri-App:",
124
130
  choices: cliOptions.map(createLabel),
125
- pageSize: cliOptions.length + 2,
131
+ pageSize: 10,
132
+ loop: false,
126
133
  },
127
134
  ]);
128
135
  const clientApplication = cliOptions.find(
package/src/cmd/start.js CHANGED
@@ -51,8 +51,7 @@ module.exports = async function start(args) {
51
51
  const setupResult = await workspace.setup(args)
52
52
  debug("Informações do setupResult do workspace", { setupResult })
53
53
 
54
-
55
- const target = setupResult.target.name
54
+ const applicationName = setupResult?.application?.name
56
55
 
57
56
  blindGuardian.readConf()
58
57
  const qrCodeUrl = config.get('qrCode').url
@@ -109,8 +108,8 @@ module.exports = async function start(args) {
109
108
  ...args,
110
109
  deepLinks: loadedTarget?.deepLinks || []
111
110
  }
112
- debug("Iniciando servidor", { argsWithDeeplinks, trackingService, watcher, workspace, target, setupResult, platform })
113
- await handleStartServer(argsWithDeeplinks, trackingService, watcher, workspace, target, setupResult, platform)
111
+ debug("Iniciando servidor", { argsWithDeeplinks, trackingService, watcher, workspace, applicationName, setupResult, platform })
112
+ await handleStartServer(argsWithDeeplinks, trackingService, watcher, workspace, applicationName, setupResult, platform)
114
113
  debug("Servidor iniciado", { loadedTarget })
115
114
 
116
115
  TrackingEitriAnalytics.sendEvent({
@@ -34,6 +34,10 @@ const { LogSuccess } = require("../util/LogUtil");
34
34
  const { extractSlug } = require("../util/LibUtil");
35
35
  const vegvisirService = new VegvisirService()
36
36
  const huginService = new HuginService()
37
+ const YAML = require('yaml');
38
+ const { readFile } = require("fs/promises");
39
+ const convertKeysToCamelCase = require("../util/convertKeysToCamelCase");
40
+ const { exit } = require("process");
37
41
 
38
42
  class Workspace {
39
43
 
@@ -187,39 +191,49 @@ class Workspace {
187
191
  }
188
192
 
189
193
  async setup(args) {
190
- const miniConf = this.getMiniConf();
191
- miniConf.isShared = args.shared
194
+ const eitriConf = this.getMiniConf();
195
+ eitriConf.isShared = args?.shared
192
196
  const headers = {
193
197
  accept: this.config.libs.updateLibsEndpointVersion,
194
198
  };
195
199
  try {
200
+ const appConfig = await this.getAppConfig()
196
201
  const setupResponse = await this.http.post(
197
- `${this.serverUrl}/${this.basePath}/setup`,
198
- miniConf,
202
+ `${this.serverUrl}/${this.basePath}/v2/workspace/setup`,
203
+ {
204
+ eitriConf,
205
+ appConfig
206
+ },
199
207
  headers
200
208
  ); // somente para garantir que a pasta do usuario existe
201
209
 
202
210
  console.log("Preparando compilador");
203
211
  await this.http.put(
204
212
  `${this.serverUrl}/${this.basePath}/version`,
205
- miniConf,
213
+ eitriConf,
206
214
  headers
207
215
  ); // TODO PDV Setup fara isso aqui
208
216
  console.log("Compilador pronto para uso contínuo");
209
217
 
210
218
  const setupData = setupResponse.data;
211
219
 
212
- const { state, target: remoteTarget, eitriConf: remoteEitriConf } = setupData;
220
+ const { state, application, eitriConf: remoteEitriConf } = setupData;
221
+
222
+ if (!application) {
223
+ console.error("O Aplicativo não foi encontrado durante o processo de setup do Eitri-App.");;
224
+ return exit(1);
225
+ }
213
226
 
214
- if (!this.eitriAppService.validEitriConf(miniConf)) {
215
- await this.eitriAppService.writeEitriConf(remoteEitriConf, miniConf, this.folder2watch);
227
+ if (!this.eitriAppService.validEitriConf(eitriConf)) {
228
+ await this.eitriAppService.writeEitriConf(remoteEitriConf, eitriConf, this.folder2watch);
216
229
  }
217
230
 
218
- await LibsService.validateLibsVersions({ libs: state.libs, eitriAppConf: miniConf });
231
+ await LibsService.validateLibsVersions({ libs: state.libs, eitriAppConf: eitriConf });
219
232
 
220
233
  this.printLibsVersion(state);
221
234
 
222
- await this.loadTarget(remoteTarget);
235
+ await this.loadTarget(application);
236
+
223
237
 
224
238
  return setupData;
225
239
  } catch (e) {
@@ -231,6 +245,18 @@ class Workspace {
231
245
  }
232
246
  }
233
247
 
248
+ async getAppConfig() {
249
+ const appConfigPath = path.resolve(
250
+ this.folder2watch,
251
+ "../../app-config.yaml"
252
+ );
253
+ if (!fs.existsSync(appConfigPath)) return
254
+ const content = await readFile(appConfigPath, 'utf8')
255
+ const appConfig = YAML.parse(content);
256
+ return convertKeysToCamelCase(appConfig);
257
+ }
258
+
259
+
234
260
  async loadTarget(remoteTarget) {
235
261
  const targets = await this.availableTargets();
236
262
  this.target = targets.find((t) => t.name === remoteTarget.name);
@@ -0,0 +1,26 @@
1
+ const camelCase = require('camelcase');
2
+
3
+ function convertKeysToCamelCase(obj) {
4
+ const newObj = {};
5
+ for (let key in obj) {
6
+ if (Object.getOwnPropertyNames(obj)) {
7
+ let value = obj[key];
8
+ const camelKey = camelCase(key);
9
+ if (typeof value === 'object' && !Array.isArray(value)) {
10
+ value = convertKeysToCamelCase(value); // Se for um objeto, chama a função recursivamente
11
+ } else if (Array.isArray(value)) {
12
+ // Se for um array, percorre cada item e chama a função recursivamente se for um objeto
13
+ value = value.map(item => {
14
+ if (typeof item === 'object' && !Array.isArray(item)) {
15
+ return convertKeysToCamelCase(item);
16
+ }
17
+ return item;
18
+ });
19
+ }
20
+ newObj[camelKey] = value;
21
+ }
22
+ }
23
+ return newObj;
24
+ }
25
+
26
+ module.exports = convertKeysToCamelCase