Skip to content

Commit

Permalink
Add custom port (#6)
Browse files Browse the repository at this point in the history
Add custom port
  • Loading branch information
JonnyBurger committed May 8, 2019
2 parents 60bef77 + a810871 commit 2c99a48
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -32,6 +32,7 @@ The following options are available:
-a, --android analyse Android bundle
-d, --dev analyse developement bundle
-o, --output [dir] output directory
-p, --port [port] use custom port
-j, --json save output as JSON file instead of HTML
-v, --version print the version number
-h, --help print usage information
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "visualize-bundle",
"version": "1.1.1",
"version": "1.1.2",
"description": "Visualize React Native bundle",
"main": "dist/index.js",
"bin": "dist/index.js",
Expand Down
15 changes: 8 additions & 7 deletions src/index.ts
Expand Up @@ -19,6 +19,7 @@ commander
.option('-d, --dev', 'Analyse developement bundle')
.option('-j, --json', 'Output JSON')
.option('-o, --output [dir]', 'Specify output dir', defaultDir)
.option('-p, --port [port]', 'Specify js package port')
.parse(process.argv);

const sourceMapExplorer = require('source-map-explorer');
Expand All @@ -43,9 +44,9 @@ const start = async () => {
process.stdout.write('Searching for running React Native app... ');
const [expoRunning, rnRunning] = await Promise.all([
isExpoRunning(),
isRnRunning()
isRnRunning(commander.port || 8081)
]);
let port = expoRunning ? 19001 : 8081;
let port = commander.port || (expoRunning ? 19001 : 8081);

if (expoRunning && !rnRunning) {
console.log('Found Expo app.');
Expand All @@ -56,7 +57,7 @@ const start = async () => {
console.log('');
}

if (expoRunning && rnRunning) {
if (expoRunning && rnRunning && !commander.port) {
console.log('Multiple found.');
const prompt = inquirer.createPromptModule();
const {project} = await prompt([
Expand Down Expand Up @@ -89,8 +90,8 @@ const start = async () => {
port === 19001
? [`http://localhost:19001/node_modules/expo/AppEntry.bundle?${query}`]
: [
`http://localhost:8081/index.bundle?${query}`,
`http://localhost:8081/index.${platform}.bundle?${query}`
`http://localhost:${port}/index.bundle?${query}`,
`http://localhost:${port}/index.${platform}.bundle?${query}`
]
);
spinner.text = `Getting map from port ${port}...`;
Expand All @@ -99,8 +100,8 @@ const start = async () => {
port === 19001
? [`http://localhost:19001/node_modules/expo/AppEntry.map?${query}`]
: [
`http://localhost:8081/index.map?${query}`,
`http://localhost:8081/index.${platform}.map?${query}`
`http://localhost:${port}/index.map?${query}`,
`http://localhost:${port}/index.${platform}.map?${query}`
]
);
const outputDir = path.resolve(commander.output);
Expand Down
4 changes: 2 additions & 2 deletions src/is-rn-running.ts
@@ -1,8 +1,8 @@
import getResource from './request-resource';

export default async (): Promise<boolean> => {
export default async (port: number): Promise<boolean> => {
try {
await getResource('http://localhost:8081');
await getResource(`http://localhost:${port}`);
return true;
} catch (err) {
return false;
Expand Down

0 comments on commit 2c99a48

Please sign in to comment.