Skip to content

Commit 2c92c22

Browse files
authored
Add warning when the browser is not found (#5)
1 parent 3d58cf6 commit 2c92c22

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

create-pull-request.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ const util = require("util");
33
const exec = util.promisify(require("child_process").exec);
44
const gitRemoteOriginUrl = require("git-remote-origin-url");
55
const open = require("open");
6+
const chalk = require('chalk');
7+
const warning = chalk.keyword('orange');
68

79
(async () => {
810
try {
911
const { stdout, stderr } = await exec("git rev-parse --abbrev-ref HEAD");
1012
if (stderr) {
1113
throw stderr;
1214
}
13-
const branchName = stdout.trim();
15+
const branchName = stdout;
1416
const remoteOriginUrl = await gitRemoteOriginUrl();
1517
const newPullRequestUrl = `https://${remoteOriginUrl.replace("git@", "").replace(":", "/").replace(/\.git$/, "")}/pull/new/${branchName}`;
1618
await open(newPullRequestUrl, { app: getBrowser() });
@@ -29,7 +31,12 @@ function getBrowser() {
2931
"opera": "opera"
3032
}
3133

32-
const [, , browser = ""] = process.argv;
34+
const [, , userInput] = process.argv;
35+
const browser = browsers[userInput];
3336

34-
return browsers[browser] || "";
37+
if (userInput && !browser) {
38+
console.log(warning(`Browser "${userInput}" was not found, we will use your default browser.`));
39+
}
40+
41+
return browser || "";
3542
}

package-lock.json

Lines changed: 44 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"url": "https://github.com/DannyFeliz/create-pull-request"
2323
},
2424
"dependencies": {
25+
"chalk": "^4.1.0",
2526
"git-remote-origin-url": "^3.1.0",
2627
"open": "^7.4.0"
2728
},

0 commit comments

Comments
 (0)