eitri-cli 1.4.0-beta.2 → 1.4.0-beta.4
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 +1 -1
- package/src/cmd/push-version.js +8 -6
- package/src/cmd/start.js +1 -2
- package/src/modules/vegvisir/VegvisirService.js +51 -3
- package/src/modules/vegvisir/cmd/current.js +3 -2
- package/src/service/Http.js +7 -3
- package/src/service/Workspace.js +10 -2
- package/src/util/GenericUtils.js +5 -0
- package/src/util/getWorkspace.js +5 -5
- package/test/utils/getWorkspaceId.test.js +3 -2
package/package.json
CHANGED
package/src/cmd/push-version.js
CHANGED
|
@@ -8,9 +8,9 @@ const config = require('../service/ConfigService')
|
|
|
8
8
|
const TargetService = require('../service/TargetService')
|
|
9
9
|
const inquirer = require('inquirer')
|
|
10
10
|
const TrackingEitriAnalytics = require('../service/TrackingEitriAnalytics')
|
|
11
|
-
const VegvisirService = require('../modules/vegvisir/VegvisirService')
|
|
12
|
-
const getWorkspace = require('../util/getWorkspace')
|
|
13
11
|
const UserLocalCredential = require('../util/UserLocalCredential')
|
|
12
|
+
const VegvisirService = require('../modules/vegvisir/VegvisirService')
|
|
13
|
+
const {randomUUID} = require('crypto')
|
|
14
14
|
|
|
15
15
|
const blindGuardian = workspace.blindGuardian
|
|
16
16
|
const trackingService = new TrackingService(blindGuardian)
|
|
@@ -39,7 +39,6 @@ module.exports = async function pushVersion(cmdObj) {
|
|
|
39
39
|
}
|
|
40
40
|
workspace.publishing = true
|
|
41
41
|
const miniConf = workspace.getMiniConf()
|
|
42
|
-
await vegvisirService.check(miniConf.slug)
|
|
43
42
|
|
|
44
43
|
let validateResult = checkErros(miniConf)
|
|
45
44
|
|
|
@@ -82,9 +81,12 @@ ${await targetService.getAppConfExampleSnippet()}
|
|
|
82
81
|
blindGuardian.readConf()
|
|
83
82
|
workspace.setServerUrl(config.get('workspace').url)
|
|
84
83
|
console.log('Conectando ao Eitri...')
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
84
|
+
|
|
85
|
+
const tempWorkspaceId = randomUUID()
|
|
86
|
+
vegvisirService.setWorkspaceId(tempWorkspaceId)
|
|
87
|
+
await workspace.initPushVersion(tempWorkspaceId)
|
|
88
|
+
|
|
89
|
+
await miniLog.connect(tempWorkspaceId)
|
|
88
90
|
console.log(separator)
|
|
89
91
|
console.log("Analisando versões...");
|
|
90
92
|
|
package/src/cmd/start.js
CHANGED
|
@@ -10,7 +10,6 @@ const handleStartServer = require('../service/StarterService')
|
|
|
10
10
|
const inquirer = require('inquirer')
|
|
11
11
|
const TrackingEitriAnalytics = require('../service/TrackingEitriAnalytics')
|
|
12
12
|
const VegvisirService = require('../modules/vegvisir/VegvisirService')
|
|
13
|
-
const getWorkspace = require('../util/getWorkspace')
|
|
14
13
|
const UserLocalCredential = require('../util/UserLocalCredential')
|
|
15
14
|
|
|
16
15
|
const blindGuardian = workspace.blindGuardian
|
|
@@ -71,7 +70,7 @@ module.exports = async function start(args) {
|
|
|
71
70
|
workspace.setQrCodeUrl(qrCodeUrl)
|
|
72
71
|
await workspace.init()
|
|
73
72
|
const silentOnConnect = args.verbose ? false : true
|
|
74
|
-
const userWorkspace = await getWorkspace()
|
|
73
|
+
const userWorkspace = await vegvisirService.getWorkspace()
|
|
75
74
|
await miniLog.connect(userWorkspace.id, silentOnConnect)
|
|
76
75
|
|
|
77
76
|
console.log("Construindo...");
|
|
@@ -2,14 +2,26 @@ const { default: axios } = require("../../../node_modules/axios/index");
|
|
|
2
2
|
const BlindGuardian = require("../../service/BlindGuardian");
|
|
3
3
|
const Http = require("../../service/Http");
|
|
4
4
|
const configService = require("../../service/ConfigService");
|
|
5
|
-
const getWorkspace = require("../../util/getWorkspace");
|
|
6
5
|
const writeGlobalWorkspaceConfig = require("./utils/writeGlobalWorkspaceConfig");
|
|
7
|
-
|
|
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')
|
|
8
11
|
module.exports = class VegvisirService {
|
|
9
12
|
constructor() {
|
|
10
13
|
const blindGuardian = new BlindGuardian();
|
|
11
14
|
this.http = new Http(blindGuardian);
|
|
12
15
|
this.config = configService.get("vegvisir");
|
|
16
|
+
this.workspaceId = "";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getWorkspaceId() {
|
|
20
|
+
return this.workspaceId;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
setWorkspaceId(id) {
|
|
24
|
+
this.workspaceId = id;
|
|
13
25
|
}
|
|
14
26
|
|
|
15
27
|
async listMyWorkspaces() {
|
|
@@ -44,7 +56,7 @@ module.exports = class VegvisirService {
|
|
|
44
56
|
|
|
45
57
|
async check(slug) {
|
|
46
58
|
try {
|
|
47
|
-
let workspace = await getWorkspace()
|
|
59
|
+
let workspace = await this.getWorkspace()
|
|
48
60
|
if(!workspace) {
|
|
49
61
|
const workspaces = await this.listMyWorkspaces();
|
|
50
62
|
const defaultWorkspace = await workspaces.find(w => w.name === 'DEFAULT')
|
|
@@ -78,4 +90,40 @@ module.exports = class VegvisirService {
|
|
|
78
90
|
}
|
|
79
91
|
|
|
80
92
|
}
|
|
93
|
+
|
|
94
|
+
async getWorkspace() {
|
|
95
|
+
try {
|
|
96
|
+
const workspaceEitriAppProjectPath = path.resolve(
|
|
97
|
+
process.cwd(),
|
|
98
|
+
".workspaces",
|
|
99
|
+
"workspace"
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
if (fs.existsSync(workspaceEitriAppProjectPath)) {
|
|
103
|
+
const fileContent = await readFile(
|
|
104
|
+
workspaceEitriAppProjectPath,
|
|
105
|
+
"utf8"
|
|
106
|
+
);
|
|
107
|
+
const workspace = JSON.parse(fileContent);
|
|
108
|
+
return workspace;
|
|
109
|
+
}
|
|
110
|
+
const workspaceGlobalPath = path.resolve(
|
|
111
|
+
os.homedir(),
|
|
112
|
+
".eitri",
|
|
113
|
+
"workspaces",
|
|
114
|
+
"workspace"
|
|
115
|
+
);
|
|
116
|
+
const fileContent = await readFile(workspaceGlobalPath, "utf8");
|
|
117
|
+
const workspace = JSON.parse(fileContent);
|
|
118
|
+
console.log("Consutrindo de ", workspace.id)
|
|
119
|
+
workspace.id = validateUUID(this.workspaceId) ? this.workspaceId : workspace.id;
|
|
120
|
+
return workspace;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if(error.code === "ENOENT") {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
console.error("Ocorreu um erro inesperado ao tentar ler o workspace atual.", error?.message)
|
|
126
|
+
return process.exit(1)
|
|
127
|
+
}
|
|
128
|
+
};
|
|
81
129
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
const
|
|
1
|
+
const VegvisirService = require("../../vegvisir/VegvisirService");
|
|
2
|
+
const vegvisirService = new VegvisirService()
|
|
2
3
|
|
|
3
4
|
module.exports = async function current(cmdObj) {
|
|
4
5
|
try {
|
|
5
|
-
const workspace = await getWorkspace()
|
|
6
|
+
const workspace = await vegvisirService.getWorkspace()
|
|
6
7
|
if(!workspace) {
|
|
7
8
|
console.log("Você não possui workspace selecionado para desenvolvimento.")
|
|
8
9
|
return;
|
package/src/service/Http.js
CHANGED
|
@@ -5,12 +5,11 @@ const CookieJar = require('tough-cookie').CookieJar
|
|
|
5
5
|
const os = require('os')
|
|
6
6
|
const path = require('path')
|
|
7
7
|
const getCliVersion = require('../util/getCliVersion')
|
|
8
|
-
const getWorkspace = require('../util/getWorkspace')
|
|
9
8
|
const { randomUUID } = require('crypto')
|
|
9
|
+
const getWorkspace = require('../util/getWorkspace')
|
|
10
10
|
|
|
11
11
|
const filePath = path.join(os.homedir(), './.eitri.cookie.json')
|
|
12
12
|
const jar = new CookieJar(new FileCookieStore(filePath))
|
|
13
|
-
|
|
14
13
|
const axios = require('axios').create({ withCredentials: true, jar })
|
|
15
14
|
|
|
16
15
|
axiosCookieJarSupport(axios)
|
|
@@ -38,6 +37,7 @@ class Http {
|
|
|
38
37
|
constructor(tokenFactory) {
|
|
39
38
|
this.tokenFactory = tokenFactory
|
|
40
39
|
this.newTokenAttempt = 0
|
|
40
|
+
this.workspaceId = ""
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
setTokenFactory(tokenFactory) {
|
|
@@ -48,6 +48,10 @@ class Http {
|
|
|
48
48
|
this.token = token
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
setWorkspaceId(id){
|
|
52
|
+
this.workspaceId = id
|
|
53
|
+
}
|
|
54
|
+
|
|
51
55
|
getCookieSession(url) {
|
|
52
56
|
return new Promise((resolve, reject) => {
|
|
53
57
|
jar.getCookies(url, { allPaths: true }, function (err, cookies) {
|
|
@@ -87,7 +91,7 @@ class Http {
|
|
|
87
91
|
'App-Tools-Version': getCliVersion()
|
|
88
92
|
}
|
|
89
93
|
if (url.includes("foundry") || url.includes("runes-foundry")) {
|
|
90
|
-
headers["Workspace-Id"] = (await getWorkspace()).id;
|
|
94
|
+
headers["Workspace-Id"] = this.workspaceId ? this.workspaceId : (await getWorkspace()).id;
|
|
91
95
|
}
|
|
92
96
|
|
|
93
97
|
return headers
|
package/src/service/Workspace.js
CHANGED
|
@@ -23,8 +23,9 @@ const Buffer = require("buffer");
|
|
|
23
23
|
const DEFAULT_ENV = "dev";
|
|
24
24
|
const cliProgress = require("cli-progress");
|
|
25
25
|
const EitriAppManager = require("./EitriAppManager");
|
|
26
|
-
const getWorkspace = require("../util/getWorkspace");
|
|
27
26
|
const EitriAppService = require("./EitriAppService");
|
|
27
|
+
const VegvisirService = require("../modules/vegvisir/VegvisirService");
|
|
28
|
+
const vegvisirService = new VegvisirService()
|
|
28
29
|
|
|
29
30
|
class Workspace {
|
|
30
31
|
|
|
@@ -96,6 +97,7 @@ class Workspace {
|
|
|
96
97
|
return this.resourceFolders2watch;
|
|
97
98
|
}
|
|
98
99
|
|
|
100
|
+
|
|
99
101
|
async getTargetConfig(id, target) {
|
|
100
102
|
try {
|
|
101
103
|
const configs = await this.getAllTargetConfigs(target);
|
|
@@ -152,6 +154,11 @@ class Workspace {
|
|
|
152
154
|
this.userEmail = token.email;
|
|
153
155
|
}
|
|
154
156
|
|
|
157
|
+
async initPushVersion(workspaceId = "") {
|
|
158
|
+
this.http.setWorkspaceId(workspaceId);
|
|
159
|
+
this.init()
|
|
160
|
+
}
|
|
161
|
+
|
|
155
162
|
getMiniConf() {
|
|
156
163
|
if (!this._miniConf) {
|
|
157
164
|
const eitriAppConfPath = path.resolve(
|
|
@@ -364,7 +371,7 @@ class Workspace {
|
|
|
364
371
|
let miniAppUrl = `${this.getBootstrapURL(
|
|
365
372
|
targetConfig.bootstrapBaseUrl
|
|
366
373
|
)}/${this.config.basePath || "workspace"
|
|
367
|
-
}/user/${(await getWorkspace()).id}/${viewHtml}?data=${encodedData}${paramOrderId}${paramShareId}&devmode=true`;
|
|
374
|
+
}/user/${(await vegvisirService.getWorkspace()).id}/${viewHtml}?data=${encodedData}${paramOrderId}${paramShareId}&devmode=true`;
|
|
368
375
|
|
|
369
376
|
if (cid) {
|
|
370
377
|
miniAppUrl = miniAppUrl + "&cid=" + cid;
|
|
@@ -1043,6 +1050,7 @@ class Workspace {
|
|
|
1043
1050
|
toBase64(content) {
|
|
1044
1051
|
return Buffer.from(content).toString("base64");
|
|
1045
1052
|
}
|
|
1053
|
+
|
|
1046
1054
|
}
|
|
1047
1055
|
|
|
1048
1056
|
module.exports = {
|
package/src/util/GenericUtils.js
CHANGED
|
@@ -14,6 +14,11 @@ class GenericUtils {
|
|
|
14
14
|
return formattedDateTime;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
static validateUUID = (uuid = "") => {
|
|
18
|
+
const regexExp = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi;
|
|
19
|
+
return uuid && typeof uuid === "string" && regexExp.test(uuid)
|
|
20
|
+
}
|
|
21
|
+
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
module.exports = GenericUtils
|
package/src/util/getWorkspace.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const {
|
|
2
|
-
const {
|
|
1
|
+
const {existsSync} = require("fs");
|
|
2
|
+
const {readFile} = require("fs/promises");
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const os = require("os");
|
|
5
5
|
module.exports = async function getWorkspace() {
|
|
@@ -9,7 +9,7 @@ module.exports = async function getWorkspace() {
|
|
|
9
9
|
".workspaces",
|
|
10
10
|
"workspace"
|
|
11
11
|
);
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
if (existsSync(workspaceEitriAppProjectPath)) {
|
|
14
14
|
const fileContent = await readFile(
|
|
15
15
|
workspaceEitriAppProjectPath,
|
|
@@ -28,10 +28,10 @@ module.exports = async function getWorkspace() {
|
|
|
28
28
|
const workspace = JSON.parse(fileContent);
|
|
29
29
|
return workspace;
|
|
30
30
|
} catch (error) {
|
|
31
|
-
if(error.code === "ENOENT") {
|
|
31
|
+
if (error.code === "ENOENT") {
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
console.error("Houve um erro inesperado ao tentar ler o workspace atual.")
|
|
35
35
|
return process.exit(1)
|
|
36
36
|
}
|
|
37
|
-
};
|
|
37
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const VegvisirService = require("../../src/modules/vegvisir/VegvisirService");
|
|
2
2
|
const fs = require('fs/promises')
|
|
3
|
+
const vegvisirService = new VegvisirService()
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
jest.mock('fs', () => ({
|
|
@@ -9,7 +10,7 @@ jest.mock('fs', () => ({
|
|
|
9
10
|
describe('Get WorkspaceID Tests', () => {
|
|
10
11
|
|
|
11
12
|
it('should return error if workspace file not found', async () => {
|
|
12
|
-
const promise = getWorkspace()
|
|
13
|
+
const promise = vegvisirService.getWorkspace()
|
|
13
14
|
await expect(promise).rejects.toThrow("Você não tem nenhum workspace definido para desenvolvimento, execute o comando 'eitri workspace use' para definir um workspace.")
|
|
14
15
|
});
|
|
15
16
|
|