4
4
5
5
const fs = require ( `fs` ) ;
6
6
const getPkgRepo = require ( `../` ) ;
7
- const meow = require ( `meow` ) ;
8
7
const through = require ( `through2` ) ;
9
8
const util = require ( `util` ) ;
10
9
11
- const cli = meow ( {
12
- help :
13
- `Practice writing repository URL or validate the repository in a package.json file.
14
- If used without specifying a package.json file path, you will enter an interactive shell.
15
- Otherwise, the repository info in package.json is printed.
10
+ const yargs = require ( 'yargs/yargs' ) ( process . argv . slice ( 2 ) )
11
+ . usage (
12
+ '\nPractice writing repository URL or validate the repository in a package.json file. If used without specifying a package.json file path, you will enter an interactive shell. Otherwise, the repository info in package.json is printed.'
13
+ )
14
+ . scriptName ( 'get-pkg-repo' )
15
+ . command ( '$0' )
16
+ . command ( '<path> [<path> ...]' )
17
+ . example ( 'get-pkg-repo' )
18
+ . example ( 'get-pkg-repo package.json' )
19
+ . example ( 'cat package.json | get-pkg-repo' )
20
+ . help ( ) . argv ;
16
21
17
- Usage
18
- get-pkg-repo
19
- get-pkg-repo <path> [<path> ...]
20
- cat <path> | get-pkg-repo
21
-
22
- Examples
23
- get-pkg-repo
24
- get-pkg-repo package.json
25
- cat package.json | get-pkg-repo` ,
26
- } ) ;
27
-
28
- const { input} = cli ;
22
+ const input = yargs . _ ;
29
23
30
24
if ( process . stdin . isTTY ) {
31
25
if ( input . length > 0 ) {
32
26
input . forEach ( path => {
33
27
let repo ;
34
- fs . readFile ( path , ` utf8` , ( err , data ) => {
28
+ fs . readFile ( path , ' utf8' , ( err , data ) => {
35
29
if ( err ) {
36
30
console . error ( err ) ;
37
31
return ;
@@ -47,33 +41,37 @@ if (process.stdin.isTTY) {
47
41
} ) ;
48
42
} else {
49
43
process . stdin
50
- . pipe ( through . obj ( ( chunk , enc , cb ) => {
51
- let repo ;
52
- const pkgData = {
53
- repository : chunk . toString ( ) ,
54
- } ;
44
+ . pipe (
45
+ through . obj ( ( chunk , enc , cb ) => {
46
+ let repo ;
47
+ const pkgData = {
48
+ repository : chunk . toString ( ) ,
49
+ } ;
55
50
56
- try {
57
- repo = getPkgRepo ( pkgData ) ;
58
- cb ( null , util . format ( repo ) + `\n` ) ;
59
- } catch ( e ) {
60
- console . error ( e . toString ( ) ) ;
61
- cb ( ) ;
62
- }
63
- } ) )
51
+ try {
52
+ repo = getPkgRepo ( pkgData ) ;
53
+ cb ( null , util . format ( repo ) + '\n' ) ;
54
+ } catch ( e ) {
55
+ console . error ( e . toString ( ) ) ;
56
+ cb ( ) ;
57
+ }
58
+ } )
59
+ )
64
60
. pipe ( process . stdout ) ;
65
61
}
66
62
} else {
67
63
process . stdin
68
- . pipe ( through . obj ( ( chunk , enc , cb ) => {
69
- let repo ;
70
- try {
71
- repo = getPkgRepo ( JSON . parse ( chunk . toString ( ) ) ) ;
72
- } catch ( e ) {
73
- console . error ( e . toString ( ) ) ;
74
- process . exit ( 1 ) ;
75
- }
76
- cb ( null , `${ util . format ( repo ) } \n` ) ;
77
- } ) )
64
+ . pipe (
65
+ through . obj ( ( chunk , enc , cb ) => {
66
+ let repo ;
67
+ try {
68
+ repo = getPkgRepo ( JSON . parse ( chunk . toString ( ) ) ) ;
69
+ } catch ( e ) {
70
+ console . error ( e . toString ( ) ) ;
71
+ process . exit ( 1 ) ;
72
+ }
73
+ cb ( null , util . format ( repo ) + '\n' ) ;
74
+ } )
75
+ )
78
76
. pipe ( process . stdout ) ;
79
77
}
0 commit comments