forked from facebook/create-react-app
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Open the player instead of the browser (#3)
* Open the player instead of the browser * Remove async, change order of checks and return the rejections
- Loading branch information
1 parent
0830331
commit 85de8bc
Showing
5 changed files
with
39 additions
and
4 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
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 @@ | ||
PLAYER_PATH = "./" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const path = require('path'); | ||
const chalk = require('react-dev-utils/chalk'); | ||
const fs = require('fs'); | ||
const { execFile } = require('child_process'); | ||
|
||
function openPlayer(url) { | ||
return new Promise((_, reject) => { | ||
if (!process.env.PLAYER_PATH) { | ||
console.error(chalk.red('PLAYER_PATH environment variable not set. Set it in the ".env" file to run the player.')); | ||
return reject(); | ||
} | ||
|
||
const playerPath = path.resolve(__dirname, process.env.PLAYER_PATH); | ||
if (!fs.existsSync(playerPath)) { | ||
console.error(chalk.red(`Player not found at ${playerPath}. Set the PLAYER_PATH environment variable in the ".env" file to run the player.`)); | ||
return reject(); | ||
} | ||
|
||
if (path.extname(process.env.PLAYER_PATH) !== '.exe') { | ||
console.error(chalk.red('PLAYER_PATH environment variable should point to the player executable. Set it in the ".env" file to run the player.')); | ||
return reject(); | ||
} | ||
|
||
|
||
execFile(playerPath, ['--player', `--url=${url}`, '--root'], { stdio: 'inherit' }); | ||
}); | ||
} | ||
|
||
module.exports = openPlayer; |
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