eitri-cli 1.5.1 → 1.6.0-beta.2
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/config/prod-eitri.js +6 -4
- package/package.json +2 -2
- package/src/cmd/clean.js +0 -6
- package/src/cmd/push-version.js +2 -7
- package/src/cmd/start.js +24 -1
- package/src/service/HuginService.js +37 -0
- package/src/service/Workspace.js +34 -104
- package/test/service/Workspace.test.js +0 -33
package/config/prod-eitri.js
CHANGED
|
@@ -43,10 +43,12 @@ const config = {
|
|
|
43
43
|
v1Header: "application/vnd.workspace.api.v1+json",
|
|
44
44
|
v2Header: "application/vnd.workspace.api.v2+json",
|
|
45
45
|
},
|
|
46
|
-
|
|
47
|
-
url: `https://${
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
hugin: {
|
|
47
|
+
url: `https://${API_EITRI_TECH_URL}/eitri-hugin-api`,
|
|
48
|
+
uploadZip: '/uploadAll',
|
|
49
|
+
uploadFile: '/uploadSingle',
|
|
50
|
+
|
|
51
|
+
// pasta do eitriapp dentro de src
|
|
50
52
|
watchUserDir: "/server",
|
|
51
53
|
},
|
|
52
54
|
credentials: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eitri-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0-beta.2",
|
|
4
4
|
"description": "Command Line Interface to make \"Eitri-App\" with code and fire.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"express-rate-limit": "^6.3.0",
|
|
46
46
|
"figlet": "^1.2.4",
|
|
47
47
|
"folder-hash": "^3.3.0",
|
|
48
|
-
"form-data": "^
|
|
48
|
+
"form-data": "^4.0.0",
|
|
49
49
|
"inquirer": "^7.0.0",
|
|
50
50
|
"jsonwebtoken": "^8.5.1",
|
|
51
51
|
"lz-string": "^1.5.0",
|
package/src/cmd/clean.js
CHANGED
|
@@ -100,12 +100,6 @@ module.exports = async function clean(cmdObj) {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
function printAvailableWebhooks(webhooks) {
|
|
104
|
-
if(!webhooks || webhooks.length === 0) return
|
|
105
|
-
console.log('\nWebhooks do Eitri-App.')
|
|
106
|
-
console.table(webhooks)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
103
|
async function track(miniConf, start) {
|
|
110
104
|
let libs = await targetService.getLibs()
|
|
111
105
|
let event = {
|
package/src/cmd/push-version.js
CHANGED
|
@@ -153,7 +153,8 @@ ${await targetService.getAppConfExampleSnippet()}
|
|
|
153
153
|
const { target } = await workspace.checkVersions();
|
|
154
154
|
|
|
155
155
|
console.log("\nPreparando os arquivos do seu Eitri-App...");
|
|
156
|
-
|
|
156
|
+
const isDevMode = false
|
|
157
|
+
await workspace.uploadZip(isDevMode);
|
|
157
158
|
console.log(separator);
|
|
158
159
|
console.log("Gerando versão do Eitri-App");
|
|
159
160
|
|
|
@@ -206,12 +207,6 @@ ${await targetService.getAppConfExampleSnippet()}
|
|
|
206
207
|
}
|
|
207
208
|
}
|
|
208
209
|
|
|
209
|
-
function printAvailableWebhooks(webhooks) {
|
|
210
|
-
if(!webhooks || webhooks.length === 0) return
|
|
211
|
-
console.log('\nWebhooks do Eitri-App.')
|
|
212
|
-
console.table(webhooks)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
210
|
async function track(miniConf, start) {
|
|
216
211
|
// let libs = await targetService.getLibs()
|
|
217
212
|
// let event = {
|
package/src/cmd/start.js
CHANGED
|
@@ -19,6 +19,9 @@ const watcher = new Watcher(workspace, hashFolder, trackingService)
|
|
|
19
19
|
const vegvisirService = new VegvisirService()
|
|
20
20
|
|
|
21
21
|
module.exports = async function start(args) {
|
|
22
|
+
const separator = '======================================================================='
|
|
23
|
+
let displayFriendlyErrorAtEnd = ""
|
|
24
|
+
|
|
22
25
|
try {
|
|
23
26
|
UserLocalCredential.checkForCredentials()
|
|
24
27
|
} catch (error) {
|
|
@@ -74,7 +77,23 @@ module.exports = async function start(args) {
|
|
|
74
77
|
await miniLog.connect(userWorkspace.id, silentOnConnect)
|
|
75
78
|
|
|
76
79
|
console.log("Construindo...");
|
|
77
|
-
|
|
80
|
+
const isDevMode = true
|
|
81
|
+
try {
|
|
82
|
+
await workspace.uploadZip(isDevMode);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if(args.verbose){
|
|
85
|
+
console.error("::uploadZip::", error?.message)
|
|
86
|
+
console.error(":::uploadZip::: ", error)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const friendlyMessage1 = "Desculpe, não foi possível realizar a sincronização dos arquivos."
|
|
90
|
+
const friendlyMessage2 = "Recomendamos que verifique eventuais erros no código. Para mais informações, consulte nossa documentação em: https://docs.eitri.tech/."
|
|
91
|
+
console.log(`\x1b[1m\x1b[31m\n${friendlyMessage1}\n${friendlyMessage2} \x1b[0m`);
|
|
92
|
+
|
|
93
|
+
const friendlyMessage3 = "Se o problema persistir, por favor, entre em contato com o suporte técnico do Eitri."
|
|
94
|
+
const friendlyMessage4 = "Você pode continuar o desenvolvimento localmente, mesmo que a sincronização não esteja disponível no momento."
|
|
95
|
+
displayFriendlyErrorAtEnd = `\n${friendlyMessage3}\n${friendlyMessage4}\n \x1b[0m`
|
|
96
|
+
}
|
|
78
97
|
console.log("Pronto!");
|
|
79
98
|
|
|
80
99
|
const loadedTarget = await workspace.getTarget()
|
|
@@ -123,6 +142,10 @@ module.exports = async function start(args) {
|
|
|
123
142
|
await trackingService.sendError(e)
|
|
124
143
|
|
|
125
144
|
process.exit(1)
|
|
145
|
+
}finally{
|
|
146
|
+
if(displayFriendlyErrorAtEnd){
|
|
147
|
+
console.log("\n\n" + separator + "\n" + displayFriendlyErrorAtEnd + "\n" + separator + "\n\n")
|
|
148
|
+
}
|
|
126
149
|
}
|
|
127
150
|
}
|
|
128
151
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const BlindGuardian = require("./BlindGuardian");
|
|
2
|
+
const Http = require("./Http");
|
|
3
|
+
const configService = require("./ConfigService");
|
|
4
|
+
const VegvisirService = require("../modules/vegvisir/VegvisirService");
|
|
5
|
+
const FormData = require("form-data");
|
|
6
|
+
const fs = require('fs')
|
|
7
|
+
|
|
8
|
+
module.exports = class HuginService {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.config = configService.get("workspace");
|
|
11
|
+
this.blindGuardian = new BlindGuardian();
|
|
12
|
+
this.http = new Http(this.blindGuardian);
|
|
13
|
+
this.vegvisirService = new VegvisirService()
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async postServerless(data, eitriConf) {
|
|
18
|
+
const { filePath, relativePath, isDevMode } = data
|
|
19
|
+
const formData = new FormData();
|
|
20
|
+
const workspace = await this.vegvisirService.getWorkspace();
|
|
21
|
+
formData.append("file", fs.createReadStream(filePath));
|
|
22
|
+
formData.append("organizationId", eitriConf.organizationId);
|
|
23
|
+
formData.append("version", eitriConf.version);
|
|
24
|
+
formData.append("filepath", relativePath);
|
|
25
|
+
formData.append("isDevMode", String(isDevMode));
|
|
26
|
+
formData.append("eitriAppId", eitriConf.id);
|
|
27
|
+
formData.append("workspaceId", workspace.id);
|
|
28
|
+
let url = this.getServerlessUploadUrl(filePath);
|
|
29
|
+
await this.http.postForm(url, formData);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getServerlessUploadUrl(filePath) {
|
|
33
|
+
if (filePath.includes(".zip"))
|
|
34
|
+
return `${this.config.hugin.url}${this.config.hugin.uploadZip}`;
|
|
35
|
+
return `${this.config.hugin.url}${this.config.hugin.uploadFile}`;
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/service/Workspace.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
|
+
const os = require('os')
|
|
2
3
|
const path = require("path");
|
|
3
4
|
const Http = require("./Http");
|
|
4
5
|
const Base64 = require("base-64");
|
|
@@ -25,7 +26,9 @@ const cliProgress = require("cli-progress");
|
|
|
25
26
|
const EitriAppManager = require("./EitriAppManager");
|
|
26
27
|
const EitriAppService = require("./EitriAppService");
|
|
27
28
|
const VegvisirService = require("../modules/vegvisir/VegvisirService");
|
|
29
|
+
const HuginService = require("./HuginService");
|
|
28
30
|
const vegvisirService = new VegvisirService()
|
|
31
|
+
const huginService = new HuginService()
|
|
29
32
|
|
|
30
33
|
class Workspace {
|
|
31
34
|
|
|
@@ -41,11 +44,10 @@ class Workspace {
|
|
|
41
44
|
this.upsertQueue = [];
|
|
42
45
|
this.requestNumber = 0;
|
|
43
46
|
this.publishing = false;
|
|
44
|
-
if (!this.config.
|
|
47
|
+
if (!this.config.hugin) {
|
|
45
48
|
console.warn("Missing colossus config inside workspace.");
|
|
46
49
|
}
|
|
47
50
|
this.shareApi = configService.get("shareApi");
|
|
48
|
-
this.webhooks = [];
|
|
49
51
|
this.targets = [];
|
|
50
52
|
|
|
51
53
|
/**
|
|
@@ -69,14 +71,6 @@ class Workspace {
|
|
|
69
71
|
this.targets = targets;
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
getWebhooks() {
|
|
73
|
-
return this.webhooks;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
setWebhooks(webhooks) {
|
|
77
|
-
this.webhooks = webhooks;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
74
|
setServerUrl(url) {
|
|
81
75
|
this.serverUrl = url;
|
|
82
76
|
}
|
|
@@ -522,30 +516,26 @@ class Workspace {
|
|
|
522
516
|
requestNumber: this.requestNumber++,
|
|
523
517
|
});
|
|
524
518
|
|
|
525
|
-
const
|
|
519
|
+
const isDevMode = opts.why === WatcherOpts.SAVE;
|
|
526
520
|
|
|
527
521
|
if (!this.uploading) {
|
|
528
|
-
await this.execUpsertSequencial(
|
|
522
|
+
await this.execUpsertSequencial(isDevMode);
|
|
529
523
|
}
|
|
530
524
|
|
|
531
525
|
return holder.promise;
|
|
532
526
|
}
|
|
533
527
|
|
|
534
|
-
async postFile(filePath,
|
|
528
|
+
async postFile(filePath, isDevMode, opts) {
|
|
535
529
|
const start = new Date().getTime();
|
|
536
530
|
const relativePath = this.getRelativePath(filePath);
|
|
537
531
|
const fileName = path.basename(filePath);
|
|
538
|
-
if (relativePath.startsWith(this.config.
|
|
539
|
-
const
|
|
540
|
-
const commomModulesPaths = allFiles.filter((f) =>
|
|
541
|
-
f.includes("src/commons")
|
|
542
|
-
);
|
|
543
|
-
await this.postLambda(
|
|
532
|
+
if (relativePath.startsWith(this.config.hugin.watchUserDir)) {
|
|
533
|
+
const data = {
|
|
544
534
|
filePath,
|
|
545
|
-
relativePath,
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
);
|
|
535
|
+
relativePath: relativePath.replace(this.config.hugin.watchUserDir, ""),
|
|
536
|
+
isDevMode,
|
|
537
|
+
}
|
|
538
|
+
await huginService.postServerless(data, this.getMiniConf());
|
|
549
539
|
} else {
|
|
550
540
|
await this.postFormData(filePath, relativePath, opts);
|
|
551
541
|
}
|
|
@@ -555,7 +545,7 @@ class Workspace {
|
|
|
555
545
|
fileName,
|
|
556
546
|
};
|
|
557
547
|
}
|
|
558
|
-
async execUpsertSequencial(
|
|
548
|
+
async execUpsertSequencial(isDevMode) {
|
|
559
549
|
this.uploading = true;
|
|
560
550
|
for (let i = 0; i < this.upsertQueue.length; i++) {
|
|
561
551
|
const { filePath, opts, holder, requestNumber } =
|
|
@@ -564,7 +554,7 @@ class Workspace {
|
|
|
564
554
|
try {
|
|
565
555
|
const { relativePath, start } = await this.postFile(
|
|
566
556
|
filePath,
|
|
567
|
-
|
|
557
|
+
isDevMode,
|
|
568
558
|
opts
|
|
569
559
|
);
|
|
570
560
|
|
|
@@ -638,63 +628,6 @@ class Workspace {
|
|
|
638
628
|
}
|
|
639
629
|
}
|
|
640
630
|
|
|
641
|
-
async postLambda(
|
|
642
|
-
filePath,
|
|
643
|
-
relativePath,
|
|
644
|
-
isSaving,
|
|
645
|
-
commomModulesPaths = []
|
|
646
|
-
) {
|
|
647
|
-
let commomModules = commomModulesPaths.map((commomFilePath) => {
|
|
648
|
-
let code = fs.readFileSync(commomFilePath, "utf8");
|
|
649
|
-
|
|
650
|
-
let name = path.basename(commomFilePath);
|
|
651
|
-
|
|
652
|
-
let compressionResult = this.compressCode(code);
|
|
653
|
-
|
|
654
|
-
return { name, ...compressionResult };
|
|
655
|
-
});
|
|
656
|
-
|
|
657
|
-
let code = fs.readFileSync(filePath, "utf8");
|
|
658
|
-
|
|
659
|
-
let compressionResult = this.compressCode(code);
|
|
660
|
-
|
|
661
|
-
let conf = this.getMiniConf();
|
|
662
|
-
const envCode = this.getEnvCode();
|
|
663
|
-
const fileName = path.basename(relativePath);
|
|
664
|
-
let data = {
|
|
665
|
-
slug: conf.slug,
|
|
666
|
-
envCode: envCode,
|
|
667
|
-
miniAppVersion: conf.version,
|
|
668
|
-
name: fileName,
|
|
669
|
-
code: compressionResult.code,
|
|
670
|
-
compressionType: compressionResult.compressionType,
|
|
671
|
-
publishing: this.publishing,
|
|
672
|
-
isSaving: isSaving,
|
|
673
|
-
restrictedLibs: conf["restricted-libs"],
|
|
674
|
-
webhooks: this.getCandidatedWebhook(fileName, conf),
|
|
675
|
-
commomModules,
|
|
676
|
-
};
|
|
677
|
-
let url = `${this.config.colossus.url}`;
|
|
678
|
-
const { data: responseData } = await this.http.post(url, data);
|
|
679
|
-
|
|
680
|
-
const { hookData } = responseData;
|
|
681
|
-
if (hookData) {
|
|
682
|
-
const _webhooks = [...this.webhooks, hookData];
|
|
683
|
-
this.setWebhooks(_webhooks);
|
|
684
|
-
}
|
|
685
|
-
return responseData;
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
getCandidatedWebhook(fileName, conf) {
|
|
689
|
-
const webhooks = conf["webhooks"];
|
|
690
|
-
if (!webhooks || webhooks.length === 0) return undefined;
|
|
691
|
-
const fileIsCandidatedToWebhook = webhooks.some(
|
|
692
|
-
(hook) => hook.fileName === fileName
|
|
693
|
-
);
|
|
694
|
-
const hook = [{ fileName }];
|
|
695
|
-
return fileIsCandidatedToWebhook ? hook : undefined;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
631
|
async isSynchronized() {
|
|
699
632
|
const res = await Promise.all([
|
|
700
633
|
this.hashFolder.calculate(),
|
|
@@ -746,7 +679,7 @@ class Workspace {
|
|
|
746
679
|
}
|
|
747
680
|
}
|
|
748
681
|
|
|
749
|
-
async uploadZip() {
|
|
682
|
+
async uploadZip(isDevMode) {
|
|
750
683
|
const admZip = new AdmZip();
|
|
751
684
|
await this.mkdirs([this.folder2watch, ...this.resourceFolders2watch]);
|
|
752
685
|
await this.rmAllServerFiles();
|
|
@@ -754,28 +687,25 @@ class Workspace {
|
|
|
754
687
|
const allFiles = await this.listFilesInCorrectOrder();
|
|
755
688
|
const files = allFiles.filter((f) => !f.endsWith("folder.hash"));
|
|
756
689
|
const folderHash = allFiles.filter((f) => f.endsWith("folder.hash"));
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
)
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
filePath,
|
|
774
|
-
relativePath,
|
|
775
|
-
false,
|
|
776
|
-
commomModulesPaths
|
|
777
|
-
);
|
|
690
|
+
|
|
691
|
+
const hasServerless = files.find(file => file.includes(this.config.hugin.watchUserDir))
|
|
692
|
+
if (hasServerless) {
|
|
693
|
+
const serverlessFolderPath = path.join(this.folder2watch, this.config.hugin.watchUserDir)
|
|
694
|
+
|
|
695
|
+
const serverlessZip = new AdmZip()
|
|
696
|
+
serverlessZip.addLocalFolder(serverlessFolderPath, undefined, (fileName) => fileName.includes('.'))
|
|
697
|
+
const now = Date.now()
|
|
698
|
+
const tempZip = path.join(os.tmpdir(), `eitri-serverless-${now}.zip`)
|
|
699
|
+
await serverlessZip.writeZipPromise(tempZip, {overwrite: true, perm: 777})
|
|
700
|
+
|
|
701
|
+
const data = {
|
|
702
|
+
filePath: tempZip,
|
|
703
|
+
// No upload do Zip é ignorado
|
|
704
|
+
relativePath: tempZip,
|
|
705
|
+
isDevMode,
|
|
778
706
|
}
|
|
707
|
+
await huginService.postServerless(data, this.getMiniConf());
|
|
708
|
+
|
|
779
709
|
}
|
|
780
710
|
|
|
781
711
|
admZip.addFile(
|
|
@@ -180,39 +180,6 @@ describe('Workspace', () => {
|
|
|
180
180
|
)
|
|
181
181
|
})
|
|
182
182
|
})
|
|
183
|
-
|
|
184
|
-
describe('.postLambda()', () => {
|
|
185
|
-
const filePath = path.resolve(__dirname, '..', '_fixtures', 'src', 'server', 'foo.js')
|
|
186
|
-
const relativePath = '../_fixtures/src/server/foo.js'
|
|
187
|
-
|
|
188
|
-
beforeEach(() => {
|
|
189
|
-
nock.cleanAll()
|
|
190
|
-
workspace.setWebhooks([])
|
|
191
|
-
})
|
|
192
|
-
it('should on invoke postLambda set webhooks if return hookData', async () => {
|
|
193
|
-
const fakeHookData = {FunctionUrl: 'FakeUrl.com', fileName: 'fakeFileName'}
|
|
194
|
-
nock('https://dev.eitri.calindra.com.br', { allowUnmocked: true })
|
|
195
|
-
.post('/foundry/server', () => {
|
|
196
|
-
return true
|
|
197
|
-
})
|
|
198
|
-
.reply(200, { ok: true, hookData: fakeHookData })
|
|
199
|
-
await workspace.postLambda(filePath, relativePath)
|
|
200
|
-
const webhooks = workspace.getWebhooks()
|
|
201
|
-
expect(webhooks).toContainEqual(fakeHookData)
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
it('should on invoke postLambda ignore set webhooks if no return', async () => {
|
|
205
|
-
nock('https://dev.eitri.calindra.com.br', { allowUnmocked: true })
|
|
206
|
-
.post('/foundry/server', () => {
|
|
207
|
-
return true
|
|
208
|
-
})
|
|
209
|
-
.reply(200, { ok: true })
|
|
210
|
-
await workspace.postLambda(filePath, relativePath)
|
|
211
|
-
const webhooks = workspace.getWebhooks()
|
|
212
|
-
expect(webhooks).toEqual([])
|
|
213
|
-
})
|
|
214
|
-
})
|
|
215
|
-
|
|
216
183
|
describe('.getTargetConfig() & .getAllTargetConfigs()', () => {
|
|
217
184
|
const target = 'CALINDRA_MOBILE'
|
|
218
185
|
const res = [
|