eitri-cli 1.3.0 → 1.4.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/package.json +1 -2
- package/src/cmd/create.js +1 -1
- package/src/cmd/start.js +5 -1
- package/src/modules/vegvisir/VegvisirCommand.js +4 -0
- package/src/modules/vegvisir/cmd/use.js +19 -9
- package/src/service/StarterService.js +1 -1
- package/src/service/factories/QRCodeStarterFactory.js +38 -27
- package/test/e2e/cli.test.js +21 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eitri-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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": {
|
|
@@ -61,7 +61,6 @@
|
|
|
61
61
|
"tmp": "^0.1.0",
|
|
62
62
|
"tough-cookie": "^3.0.1",
|
|
63
63
|
"tough-cookie-file-store": "^2.0.2",
|
|
64
|
-
"uri-scheme": "^1.1.0",
|
|
65
64
|
"uuid": "^7.0.2"
|
|
66
65
|
},
|
|
67
66
|
"devDependencies": {
|
package/src/cmd/create.js
CHANGED
package/src/cmd/start.js
CHANGED
|
@@ -80,7 +80,11 @@ module.exports = async function start(args) {
|
|
|
80
80
|
|
|
81
81
|
const loadedTarget = await workspace.getTarget()
|
|
82
82
|
const platform = loadedTarget.platform
|
|
83
|
-
|
|
83
|
+
const argsWithDeeplinks = {
|
|
84
|
+
...args,
|
|
85
|
+
deepLinks: loadedTarget?.deepLinks || []
|
|
86
|
+
}
|
|
87
|
+
await handleStartServer(argsWithDeeplinks, trackingService, watcher, workspace, target, targetConfig, platform)
|
|
84
88
|
|
|
85
89
|
TrackingEitriAnalytics.sendEvent({
|
|
86
90
|
eventName:"start",
|
|
@@ -18,6 +18,10 @@ module.exports = function VegvisirCommand() {
|
|
|
18
18
|
"--local",
|
|
19
19
|
"Seleciona um workspace para um diretório de Eitri-App específico"
|
|
20
20
|
)
|
|
21
|
+
.option(
|
|
22
|
+
"--name <workspace-name>",
|
|
23
|
+
"Permite selecionar um workspace previamente criado pelo nome"
|
|
24
|
+
)
|
|
21
25
|
.action(async (cmdObj) => {
|
|
22
26
|
require("./cmd/use.js")(cmdObj);
|
|
23
27
|
});
|
|
@@ -11,18 +11,28 @@ module.exports = async function use(cmdArgs) {
|
|
|
11
11
|
const workspaces = await vegvisirService.listMyWorkspaces();
|
|
12
12
|
if (!workspaces) return;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
let workspaceNameSelected = cmdArgs?.name
|
|
15
|
+
|
|
16
|
+
if(!cmdArgs?.name){
|
|
17
|
+
const { workspaceName } = await inquirer.prompt([
|
|
18
|
+
{
|
|
19
|
+
name: "workspaceName",
|
|
20
|
+
type: "rawlist",
|
|
21
|
+
message: "Selecione qual workspace você deseja utilizar:",
|
|
22
|
+
choices: workspaces,
|
|
23
|
+
},
|
|
24
|
+
]);
|
|
25
|
+
workspaceNameSelected = workspaceName
|
|
26
|
+
}
|
|
22
27
|
|
|
23
28
|
const selectedWorkspace = workspaces.find(
|
|
24
|
-
(work) => work
|
|
29
|
+
(work) => work?.name === workspaceNameSelected
|
|
25
30
|
);
|
|
31
|
+
if(!selectedWorkspace){
|
|
32
|
+
const workspacesNames = Array.isArray(workspaces) && workspaces?.length > 0 ? workspaces?.map(w => w.name) : [];
|
|
33
|
+
console.warn(`O workspace [${cmdArgs?.name}] não existe. Workspaces existentes: `, JSON.stringify(workspacesNames));
|
|
34
|
+
return;
|
|
35
|
+
};
|
|
26
36
|
|
|
27
37
|
if (cmdArgs.local) {
|
|
28
38
|
await writeLocalWorkspaceConfig(selectedWorkspace);
|
|
@@ -24,7 +24,7 @@ async function handleStartServer(args, trackingService, watcher, workspace, fact
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
const starter = factory.create(args, trackingService, watcher, workspace, targetConfig)
|
|
27
|
+
const starter = await factory.create(args, trackingService, watcher, workspace, targetConfig)
|
|
28
28
|
await starter.startServer()
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const QRCodeFactory = require("../QRCodeFactory");
|
|
2
|
-
const { Ios, Android } = require("uri-scheme");
|
|
3
2
|
const readline = require("readline");
|
|
4
3
|
const chalk = require("chalk");
|
|
5
4
|
const os = require("os");
|
|
5
|
+
const util = require('util')
|
|
6
|
+
const exec = util.promisify(require("child_process").exec)
|
|
7
|
+
|
|
6
8
|
function QRCodeStarter(
|
|
7
9
|
args,
|
|
8
10
|
trackingService,
|
|
@@ -56,35 +58,48 @@ function QRCodeStarter(
|
|
|
56
58
|
_QRCodeFactory.generate({ ...this.args, qrCodePath, fullUrl });
|
|
57
59
|
|
|
58
60
|
if (this.args.emulator) {
|
|
59
|
-
tryOpenEmulator(fullUrl, args);
|
|
61
|
+
await tryOpenEmulator(fullUrl, args);
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
listenerKeyPressToOpenEmulator(fullUrl);
|
|
64
|
+
await listenerKeyPressToOpenEmulator(fullUrl, args.deepLinks);
|
|
63
65
|
};
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
function tryOpenEmulator(fullUrl, args) {
|
|
68
|
+
async function tryOpenEmulator(fullUrl, args) {
|
|
67
69
|
const shareId = extractShareId(fullUrl);
|
|
68
|
-
const { emulator } = args;
|
|
69
|
-
if
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
70
|
+
const { emulator, deepLinks } = args;
|
|
71
|
+
if(!deepLinks || deepLinks?.length < 1) {
|
|
72
|
+
console.log("Seu application não contém deep links configurados.")
|
|
73
|
+
return
|
|
74
|
+
};
|
|
75
|
+
for (const deepLink of deepLinks) {
|
|
76
|
+
if (emulator === "ios") {
|
|
77
|
+
const cmd = `xcrun simctl openurl booted ${deepLink}/${shareId}`
|
|
78
|
+
const opened = await openDeepLink(cmd)
|
|
79
|
+
if(opened) return;
|
|
80
|
+
} else {
|
|
81
|
+
const cmd = `adb shell am start -a android.intent.action.VIEW -d ${deepLink}/${shareId}`
|
|
82
|
+
const opened = await openDeepLink(cmd)
|
|
83
|
+
if(opened) return;
|
|
84
|
+
}
|
|
77
85
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function openDeepLink(cmd) {
|
|
89
|
+
try {
|
|
90
|
+
const {stderr} = await exec(cmd)
|
|
91
|
+
if(stderr) {
|
|
92
|
+
return false
|
|
83
93
|
}
|
|
84
|
-
|
|
94
|
+
return true
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.log(`Houve um erro ao tentar abrir o Eitri-App via deep link`)
|
|
97
|
+
return process.exit(1)
|
|
98
|
+
}
|
|
85
99
|
}
|
|
86
100
|
|
|
87
|
-
function listenerKeyPressToOpenEmulator(url) {
|
|
101
|
+
async function listenerKeyPressToOpenEmulator(url, deepLinks) {
|
|
102
|
+
if(!deepLinks || deepLinks?.length < 1) return;
|
|
88
103
|
const enterText = chalk.blue.bold("Enter");
|
|
89
104
|
console.log("================================================");
|
|
90
105
|
console.log(`\t${chalk.green.bold("Abertura de Eitri-App automática")}`);
|
|
@@ -104,20 +119,16 @@ function listenerKeyPressToOpenEmulator(url) {
|
|
|
104
119
|
console.log("================================================");
|
|
105
120
|
readline.emitKeypressEvents(process.stdin);
|
|
106
121
|
|
|
107
|
-
process.stdin.on("keypress", (chunk, key) => {
|
|
122
|
+
process.stdin.on("keypress", async (chunk, key) => {
|
|
108
123
|
if (key && key.name == "a") {
|
|
109
124
|
const emulator = "android";
|
|
110
125
|
console.log(`Abrindo Eitri-App no ${chalk.blue.bold("Android")}`);
|
|
111
|
-
tryOpenEmulator(url, { emulator });
|
|
126
|
+
await tryOpenEmulator(url, { emulator, deepLinks });
|
|
112
127
|
}
|
|
113
128
|
if (os.platform() === "darwin" && key && key.name == "i") {
|
|
114
129
|
const emulator = "ios";
|
|
115
130
|
console.log(`Abrindo Eitri-App no ${chalk.blue.bold("iOS")}`);
|
|
116
|
-
tryOpenEmulator(url, { emulator });
|
|
117
|
-
}
|
|
118
|
-
if (key && key.name == "q") {
|
|
119
|
-
console.log("Parando execução do Eitri-App");
|
|
120
|
-
process.exit(0);
|
|
131
|
+
await tryOpenEmulator(url, { emulator, deepLinks });
|
|
121
132
|
}
|
|
122
133
|
});
|
|
123
134
|
}
|
package/test/e2e/cli.test.js
CHANGED
|
@@ -190,6 +190,27 @@ describe("eitri-cli", () => {
|
|
|
190
190
|
2 * minutes
|
|
191
191
|
);
|
|
192
192
|
|
|
193
|
+
it(
|
|
194
|
+
"should select workspace by name",
|
|
195
|
+
async () => {
|
|
196
|
+
try {
|
|
197
|
+
await execAsync(
|
|
198
|
+
`cd ${EITRI_WORK_DIR} && rm -rf ./eitri-test-*`,
|
|
199
|
+
{ env: process.env }
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
const executor = new Executor({ env: devEnv });
|
|
203
|
+
await executor
|
|
204
|
+
.exec("eitri workspace use --name DEFAULT")
|
|
205
|
+
.waitFor(/Workspace configurado com sucesso!/);
|
|
206
|
+
} catch (e) {
|
|
207
|
+
console.error(e);
|
|
208
|
+
throw e;
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
2 * minutes
|
|
212
|
+
);
|
|
213
|
+
|
|
193
214
|
const getPublishedVersion = async (version, eitriAppId) => {
|
|
194
215
|
const blindGuardian = new BlindGuardian();
|
|
195
216
|
const http = new Http(blindGuardian);
|