Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[add] devコマンドからサーバー起動とelectron起動を同時に行うことができる
- Loading branch information
1 parent
e4f3468
commit 6c12ce4
Showing
5 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
react: yarn start | ||
electron: node dev_env/electron-wait-react.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const net = require('net'); | ||
const port = process.env.PORT ? process.env.PORT - 100 : 3000; | ||
|
||
process.env.ELECTRON_START_URL = `http://localhost:${port}`; | ||
|
||
const client = new net.Socket(); | ||
|
||
let startedElectron = false; | ||
const tryConnection = () => | ||
client.connect({ port: port }, () => { | ||
client.end(); | ||
if (!startedElectron) { | ||
console.log('starting electron'); | ||
startedElectron = true; | ||
const exec = require('child_process').exec; | ||
exec('yarn electron'); | ||
} | ||
}); | ||
|
||
tryConnection(); | ||
|
||
client.on('error', error => { | ||
setTimeout(tryConnection, 1000); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters