-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.js
46 lines (37 loc) · 869 Bytes
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env node
import meow from 'meow';
import open from 'open';
import chalk from 'chalk';
import isGitRepo from 'is-git-repository';
import gitRemoteOriginUrl from 'git-remote-origin-url';
meow(`
Usage:
$ openup
Flags:
-h, --help Show help message and close
-v, --version View package version
`, {
importMeta: import.meta,
flags: {
help: {
type: 'boolean',
alias: 'h',
},
version: {
type: 'boolean',
alias: 'v',
},
},
});
// Exit if not a git repo
if (!isGitRepo()) {
console.log(chalk.red('Not a git repository'));
// eslint-disable-next-line node/prefer-global/process
process.exit(1);
}
(async () => {
const repoUrl = await gitRemoteOriginUrl();
// Cloned repo with SSH
const url = repoUrl.includes('git@') ? repoUrl.replace(':', '/').replace('git@', 'https://') : repoUrl;
await open(url);
})();