@@ -10,12 +10,28 @@ const querystring = require('querystring');
10
10
const http = require ( 'http' ) ;
11
11
12
12
13
- if ( process . argv [ 2 ] && ValidURL ( process . argv [ 2 ] ) ) {
14
- const customShortcode = process . argv [ 3 ] ;
15
- PostCode ( process . argv [ 2 ] , secret , customShortcode ) ;
16
- }
13
+ if ( process . argv [ 2 ] === '-l' ) {
14
+ const customShortcode = process . argv [ 4 ] ;
15
+ PostCode ( process . argv [ 3 ] , secret , customShortcode ) ;
16
+ } else if ( process . argv [ 2 ] === '-s' ) {
17
+ let remote = null ;
18
+ if ( process . argv [ 3 ] ) {
19
+ remote = process . argv [ 3 ] ;
20
+ } else {
21
+ remote = 'origin' ;
22
+ }
23
+
24
+ exec ( 'git config --get remote.' + remote + '.url' , function ( error , stdout , stderr ) {
25
+ if ( error ) {
26
+ console . error ( `exec error: ${ error } ` ) ;
27
+ return ;
28
+ }
29
+
30
+ let str = `${ stdout } ` ;
31
+ PostCode ( str ) ;
32
+ } ) ;
17
33
18
- else if ( process . argv [ 2 ] !== '-s' ) {
34
+ } else {
19
35
const customShortcode = process . argv [ 5 ] ;
20
36
const directory = process . argv [ 4 ] ;
21
37
let remote = null ;
@@ -48,33 +64,14 @@ else if (process.argv[2] !== '-s') {
48
64
49
65
console . log ( "Pushing code to " + remote + " " + branch ) ;
50
66
exec ( 'git push ' + remote + ' ' + branch , function ( error , stdout , stderr ) {
51
- if ( error ) {
67
+ if ( error ) {
52
68
console . error ( `exec error: ${ error } ` ) ;
53
69
return ;
54
70
}
55
71
} )
56
72
} ) ;
57
73
58
- } else {
59
- let remote = null ;
60
- if ( process . argv [ 3 ] ) {
61
- remote = process . argv [ 3 ] ;
62
- } else {
63
- remote = 'origin' ;
64
- }
65
-
66
- exec ( 'git config --get remote.' + remote + '.url' , function ( error , stdout , stderr ) {
67
- if ( error ) {
68
- console . error ( `exec error: ${ error } ` ) ;
69
- return ;
70
- }
71
-
72
- let str = `${ stdout } ` ;
73
- PostCode ( str ) ;
74
- } ) ;
75
-
76
74
}
77
-
78
75
function PostCode ( url , secret , code ) {
79
76
80
77
url = url . replace ( / ( \r \n | \n | \r ) / gm, "" ) ;
@@ -103,14 +100,4 @@ function PostCode(url, secret, code) {
103
100
104
101
post_req . write ( post_data ) ;
105
102
post_req . end ( ) ;
106
- }
107
-
108
- function ValidURL ( str ) {
109
- var pattern = new RegExp ( '^(https?:\\/\\/)?' + // protocol
110
- '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|' + // domain name
111
- '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
112
- '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
113
- '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
114
- '(\\#[-a-z\\d_]*)?$' , 'i' ) ; // fragment locator
115
- return pattern . test ( str ) ;
116
103
}
0 commit comments