vue-cli-plugin-electron-haunv 1.0.18 → 1.0.19
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/bin/dev-runner.js +25 -11
- package/package.json +2 -3
package/bin/dev-runner.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { spawn } = require("child_process")
|
|
2
|
-
const
|
|
2
|
+
const http = require("http")
|
|
3
3
|
const getPort = require("get-port").default
|
|
4
4
|
const chokidar = require("chokidar")
|
|
5
5
|
const kill = require("tree-kill")
|
|
@@ -8,13 +8,32 @@ const electron = require("electron")
|
|
|
8
8
|
let electronProcess
|
|
9
9
|
let port
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
function waitForServer(url, { interval = 250, timeout = 30000 } = {}) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const deadline = Date.now() + timeout
|
|
14
|
+
|
|
15
|
+
function poll() {
|
|
16
|
+
http.get(url, (res) => {
|
|
17
|
+
res.resume()
|
|
18
|
+
resolve()
|
|
19
|
+
}).on("error", () => {
|
|
20
|
+
if (Date.now() >= deadline) {
|
|
21
|
+
reject(new Error(`Timeout waiting for ${url}`))
|
|
22
|
+
} else {
|
|
23
|
+
setTimeout(poll, interval)
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
poll()
|
|
29
|
+
})
|
|
30
|
+
}
|
|
12
31
|
|
|
32
|
+
async function run() {
|
|
13
33
|
port = await getPort({
|
|
14
34
|
port: [8080, 8081, 8082]
|
|
15
35
|
})
|
|
16
36
|
|
|
17
|
-
// chạy vue dev server
|
|
18
37
|
spawn(
|
|
19
38
|
"npm",
|
|
20
39
|
["run", "serve", "--", "--port", port],
|
|
@@ -24,15 +43,10 @@ async function run() {
|
|
|
24
43
|
}
|
|
25
44
|
)
|
|
26
45
|
|
|
27
|
-
|
|
28
|
-
await waitOn({
|
|
29
|
-
resources: [`http://localhost:${port}`]
|
|
30
|
-
})
|
|
46
|
+
await waitForServer(`http://localhost:${port}`)
|
|
31
47
|
|
|
32
|
-
// chạy electron
|
|
33
48
|
startElectron()
|
|
34
49
|
|
|
35
|
-
// hot reload electron
|
|
36
50
|
chokidar
|
|
37
51
|
.watch(["electron"], { ignoreInitial: true })
|
|
38
52
|
.on("all", () => {
|
|
@@ -42,8 +56,8 @@ async function run() {
|
|
|
42
56
|
|
|
43
57
|
function startElectron() {
|
|
44
58
|
electronProcess = spawn(
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
electron,
|
|
60
|
+
["."],
|
|
47
61
|
{
|
|
48
62
|
stdio: "inherit",
|
|
49
63
|
env: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-cli-plugin-electron-haunv",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -18,8 +18,7 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"chokidar": "latest",
|
|
20
20
|
"get-port": "latest",
|
|
21
|
-
"tree-kill": "latest"
|
|
22
|
-
"wait-on": "latest"
|
|
21
|
+
"tree-kill": "latest"
|
|
23
22
|
},
|
|
24
23
|
"devDependencies": {
|
|
25
24
|
"@tomjs/electron-devtools-installer": "^4.0.1"
|