eitri-cli 1.3.0-beta.2 → 1.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eitri-cli",
3
- "version": "1.3.0-beta.2",
3
+ "version": "1.3.0",
4
4
  "description": "Command Line Interface to make \"Eitri-App\" with code and fire.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -86,22 +86,14 @@ ${await targetService.getAppConfExampleSnippet()}
86
86
  const userWorkspace = await getWorkspace()
87
87
  await miniLog.connect(userWorkspace.id)
88
88
  console.log(separator)
89
- console.log('Analisando versões')
89
+ console.log("Analisando versões...");
90
90
 
91
- // Verificar se precisamos dessa parte
92
- const {target} = await workspace.checkVersions()
93
- // const {addedPermissions, removedPermissions} = await workspace.comparePermissions(target)
94
- // await logPermissionsAndOpenPrompt(addedPermissions, removedPermissions, cmdObj)
95
- // console.log(separator)
91
+ const { target } = await workspace.checkVersions();
96
92
 
97
- console.log('Preparando os arquivos do seu Eitri-App')
98
-
99
- await workspace.uploadAll()
100
- const webhooks = workspace.getWebhooks()
101
- printAvailableWebhooks(webhooks)
102
- console.log('')
103
- console.log(separator)
104
- console.log('Gerando Eitri-App')
93
+ console.log("\nPreparando os arquivos do seu Eitri-App...");
94
+ await workspace.uploadZip();
95
+ console.log(separator);
96
+ console.log("Gerando versão do Eitri-App");
105
97
 
106
98
  const start = Date.now()
107
99
  let pushVersionPromise = miniLog.awaitForPushVersion()
package/src/cmd/start.js CHANGED
@@ -74,11 +74,10 @@ module.exports = async function start(args) {
74
74
  const userWorkspace = await getWorkspace()
75
75
  await miniLog.connect(userWorkspace.id, silentOnConnect)
76
76
 
77
- if (args.unzip) {
78
- await workspace.uploadAll(args)
79
- } else {
80
- await workspace.uploadZip(args)
81
- }
77
+ console.log("Construindo...");
78
+ await workspace.uploadZip(args);
79
+ console.log("Pronto!");
80
+
82
81
  const loadedTarget = await workspace.getTarget()
83
82
  const platform = loadedTarget.platform
84
83
  await handleStartServer(args, trackingService, watcher, workspace, target, targetConfig, platform)
@@ -475,14 +475,7 @@ class Workspace {
475
475
  return !isValidFileName;
476
476
  }
477
477
 
478
- async upsert(filesPath, opts = {}, showProgressBar = false) {
479
- if (showProgressBar) {
480
- return await this.upsertConcurrency(
481
- filesPath,
482
- opts,
483
- showProgressBar
484
- );
485
- }
478
+ async upsert(filesPath, opts = {}) {
486
479
  return await this.upsertSequencial(filesPath, opts);
487
480
  }
488
481
 
@@ -512,54 +505,6 @@ class Workspace {
512
505
  return holder.promise;
513
506
  }
514
507
 
515
- async upsertConcurrency(filesPath, opts = {}, showProgressBar = false) {
516
- const promises = [];
517
- const isSaving = opts.why === WatcherOpts.SAVE;
518
- if (showProgressBar) {
519
- this.createProgressBar(showProgressBar);
520
- this.progressBar.start(filesPath.length, 0);
521
- this.progressBar.update(this.progressBarCounter);
522
- }
523
-
524
- for (const filePath of filesPath) {
525
- const fileName = path.basename(filePath);
526
-
527
- const { isInvalid, promise } = await this.validateFileName(
528
- fileName,
529
- filePath
530
- );
531
- if (isInvalid) return await promise;
532
-
533
- const upsertFile = {
534
- filePath,
535
- opts,
536
- requestNumber: this.requestNumber++,
537
- };
538
- promises.push(
539
- this.execUpsertConcurrency(
540
- upsertFile,
541
- isSaving,
542
- showProgressBar
543
- )
544
- );
545
- }
546
-
547
- const promisesChunks = this.spliceArray(promises, 5);
548
- const data = [];
549
- for (const promiseArray of promisesChunks) {
550
- const result = await Promise.all(promiseArray);
551
- data.push(...result);
552
- }
553
-
554
- if (isSaving) return data[0];
555
-
556
- if (showProgressBar) {
557
- this.progressBar.update(filesPath.length);
558
- this.progressBar.stop();
559
- }
560
- return data;
561
- }
562
-
563
508
  async postFile(filePath, isSaving, opts) {
564
509
  const start = new Date().getTime();
565
510
  const relativePath = this.getRelativePath(filePath);
@@ -584,29 +529,6 @@ class Workspace {
584
529
  fileName,
585
530
  };
586
531
  }
587
-
588
- async execUpsertConcurrency(upsertFile, isSaving, showProgressBar = false) {
589
- const { filePath, opts, requestNumber } = upsertFile;
590
-
591
- const { fileName, relativePath, start } = await this.postFile(
592
- filePath,
593
- isSaving,
594
- opts
595
- );
596
-
597
- if (showProgressBar) {
598
- this.progressBarCounter++;
599
- this.progressBar.update(this.progressBarCounter);
600
- }
601
- return {
602
- filePath,
603
- relativePath,
604
- requestNumber,
605
- time: new Date().getTime() - start,
606
- baseName: fileName,
607
- };
608
- }
609
-
610
532
  async execUpsertSequencial(isSaving) {
611
533
  this.uploading = true;
612
534
  for (let i = 0; i < this.upsertQueue.length; i++) {
@@ -792,37 +714,6 @@ class Workspace {
792
714
  return allFiles;
793
715
  }
794
716
 
795
- async uploadAll() {
796
- await this.mkdirs([this.folder2watch, ...this.resourceFolders2watch]);
797
- await this.rmAllServerFiles();
798
- await this.hashFolder.updateHashFile();
799
-
800
- const srcFiles = await this.listFilesInCorrectOrder();
801
- const filesfromSrc = srcFiles.filter((f) => !f.endsWith("folder.hash"));
802
- const srcFolderHash = srcFiles.filter((f) => f.endsWith("folder.hash"));
803
-
804
- const resourceFiles = await this.getAllResourceFiles(
805
- this.resourceFolders2watch
806
- );
807
-
808
- let files = resourceFiles.concat(filesfromSrc);
809
- const componentFiles = files.filter((file) =>
810
- file.includes("/components")
811
- );
812
-
813
- const opts = {
814
- why: "save",
815
- log: false,
816
- skipCompile: true,
817
- };
818
- const showProgressBar = true;
819
- if (componentFiles && componentFiles.length > 0) {
820
- await this.preUpsert(componentFiles, opts);
821
- }
822
- await this.upsert(files, opts, showProgressBar);
823
- await this.transpile(srcFolderHash);
824
- }
825
-
826
717
  async preUpsert(componentsFiles, opts) {
827
718
  for (const filePath of componentsFiles) {
828
719
  await this.upsertSequencial(filePath, opts);
@@ -869,8 +760,6 @@ class Workspace {
869
760
  );
870
761
  admZip.addLocalFolder("./src");
871
762
 
872
- console.log("Construindo");
873
-
874
763
  const platform = process.platform;
875
764
 
876
765
  const zipPath = await this.resolveOs(platform);
@@ -878,8 +767,6 @@ class Workspace {
878
767
  await this.sendZip(zipPath);
879
768
 
880
769
  await this.transpile(folderHash);
881
-
882
- console.log("Pronto");
883
770
  }
884
771
 
885
772
  async resolveOs(platform) {
@@ -1156,37 +1043,6 @@ class Workspace {
1156
1043
  toBase64(content) {
1157
1044
  return Buffer.from(content).toString("base64");
1158
1045
  }
1159
-
1160
- createProgressBar(showProgressBar) {
1161
- if (showProgressBar) {
1162
- this.progressBar = new cliProgress.SingleBar(
1163
- {
1164
- format: "Sincronizando [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} Arquivos sincronizados...",
1165
- },
1166
- cliProgress.Presets.shades_classic
1167
- );
1168
- }
1169
- }
1170
-
1171
- /**
1172
- *
1173
- * @param {unknown[]} array
1174
- * @param {number} chunkCount
1175
- * @returns {unknown[][]}
1176
- */
1177
- spliceArray(array, chunkCount) {
1178
- var chunks = [],
1179
- iterator,
1180
- auxiliar;
1181
- for (
1182
- iterator = 0, auxiliar = array.length;
1183
- iterator < auxiliar;
1184
- iterator += chunkCount
1185
- ) {
1186
- chunks.push(array.slice(iterator, iterator + chunkCount));
1187
- }
1188
- return chunks;
1189
- }
1190
1046
  }
1191
1047
 
1192
1048
  module.exports = {
@@ -7,6 +7,8 @@ const minutes = 60000;
7
7
  const Executor = require("../Executor.js");
8
8
  const Helper = require("../Helper.js");
9
9
  const ConfigService = require("../../src/service/ConfigService.js");
10
+ const Http = require("../../src/service/Http.js");
11
+ const BlindGuardian = require("../../src/service/BlindGuardian.js");
10
12
 
11
13
  describe("eitri-cli", () => {
12
14
  const EITRI_WORK_DIR = path.join(__dirname, "..", "..", "developer-folder");
@@ -137,6 +139,67 @@ describe("eitri-cli", () => {
137
139
  }
138
140
  });
139
141
 
142
+ it(
143
+ "should do push-version",
144
+ async () => {
145
+ const EITRI_APP_NAME = `eitri-test-${Date.now()}`;
146
+ try {
147
+ await execAsync(
148
+ `cd ${EITRI_WORK_DIR} && rm -rf ./eitri-test-*`,
149
+ { env: process.env }
150
+ );
151
+
152
+ const executor = new Executor({ env: devEnv });
153
+ await executor
154
+ .exec(
155
+ `cd ${EITRI_WORK_DIR} && eitri create ${EITRI_APP_NAME} --yes --application=APPLICATION_CALINDRA`,
156
+ { env: devEnv }
157
+ )
158
+ .waitFor(/Download de template completo/);
159
+ await new Promise((resolve) => setTimeout(resolve, 200));
160
+ const EITRI_APP_FOLDER = path.resolve(
161
+ EITRI_WORK_DIR,
162
+ EITRI_APP_NAME
163
+ );
164
+ const startExecution = new Executor({ env: devEnv });
165
+ await startExecution
166
+ .exec(`cd ${EITRI_APP_FOLDER} && eitri start`)
167
+ .waitFor(/Utilize o QR-Code para iniciar o seu Eitri-App/);
168
+ executor.child.kill();
169
+ startExecution.child.kill();
170
+
171
+ const pushVersion = new Executor({ env: devEnv });
172
+ await pushVersion
173
+ .exec(`cd ${EITRI_APP_FOLDER} && eitri push-version`)
174
+ .waitFor(/disponível no Eitri Console/);
175
+ pushVersion.child.kill();
176
+
177
+ const conf = require(`../../developer-folder/${EITRI_APP_NAME}/eitri-app.conf.js`);
178
+ const data = await getPublishedVersion(conf.version, conf.id);
179
+
180
+ expect(data.length).toBe(1);
181
+ expect(data[0].version).toBe(conf.version);
182
+ expect(data[0].eitriAppId).toBe(conf.id);
183
+
184
+ await Helper.delete(conf.id);
185
+ } catch (e) {
186
+ console.error(e);
187
+ throw e;
188
+ }
189
+ },
190
+ 2 * minutes
191
+ );
192
+
193
+ const getPublishedVersion = async (version, eitriAppId) => {
194
+ const blindGuardian = new BlindGuardian();
195
+ const http = new Http(blindGuardian);
196
+
197
+ const url = `https://api.eitri.tech/eitri-manager-api/revisions?eitriAppId=${eitriAppId}&version=${version}`;
198
+
199
+ const data = await http.get(url);
200
+ return data;
201
+ };
202
+
140
203
  const sleep = (timeInMs) => {
141
204
  return new Promise((resolve) => setTimeout(resolve, timeInMs));
142
205
  };