@@ -31,45 +31,50 @@ new class {
3131 get_repo_name ( url = this . config . repo ) {
3232 const match = url . match ( / ( h t t p s ? : \/ { 2 } g i t h u b \. c o m \/ .+ ?\/ ( [ ^ \/ ] + ) ) \/ ? / ) ;
3333 if ( match ) return match [ 1 ] ;
34- else throw "Repository not provided or does not match expected format." ;
34+ else throw "[@] Repository not provided or does not match expected format." ;
3535 }
3636
3737 async get_version ( cwd = this . repo_dir , remote = false ) {
38- return this . execute ( `git describe --abbrev=7 --always --long --match v* ${ remote ? "origin/" : "" } ${ this . config . branch } ` , { cwd } ) . catch ( console . warn ) ;
38+ return this . execute ( `git rev-parse --short --verify ${ remote ? "origin/" : "" } ${ this . config . branch } ` , { cwd } ) . catch ( console . warn ) ;
3939 }
4040
4141 async validate_config ( ) {
4242 const repo = this . config . repo . match ( / ( h t t p s ? : \/ { 2 } g i t h u b \. c o m \/ .+ ?\/ ( [ ^ \/ ] + ) ) \/ ? / ) ;
43- if ( ! this . config . repo ) throw "Github repository not provided!" ;
43+ if ( ! this . config . repo ) throw "[@] Github repository not provided!" ;
4444 else this . config . repo = repo [ 1 ] ;
4545
46- if ( ! this . config . branch ) throw "Github branch not provided!" ;
47- if ( ! this . config . start ) throw "Start command not provided!" ;
46+ if ( ! this . config . branch ) throw "[@] Github branch not provided!" ;
47+ if ( ! this . config . start ) throw "[@] Start command not provided!" ;
48+ if ( ! this . config . setup ) console . warn ( "[!] Setup command not provided." ) ;
49+
50+ if ( this . config . frequency > 1000 ) console . warn ( "[!] The scan frequency should be in seconds. The value provided is VERY HIGH!" )
4851 }
4952
5053 match_version ( cwd = this . repo_dir ) {
5154 return new Promise ( async ( resolve , reject ) => {
52- await this . execute ( "git remote update" , { cwd } ) . catch ( console . error )
55+ await this . execute ( "git remote update" , { cwd } ) . catch ( ( res ) => console . log ( "[-] " + res . split ( "\n" ) [ 1 ] . trim ( ) ) )
5356 const remote = await this . get_version ( cwd , true )
5457 const local = await this . get_version ( cwd , false )
55- if ( remote === local ) resolve ( "Remote version matches local repository ." )
56- else reject ( "Remote does not match local repository ." )
58+ if ( remote === local ) resolve ( "[-] Local repository matches origin ." )
59+ else reject ( "[!] Local repository does not match origin ." )
5760 } )
5861 }
5962
6063 match_origin ( cwd = this . repo_dir ) {
6164 return new Promise ( ( resolve , reject ) => {
6265 this . execute ( "git remote get-url origin" , { cwd } ) . catch ( console . error )
6366 . then ( ( origin ) => {
64- if ( origin !== this . config . repo ) reject ( "Origin does not match local repository .")
65- else resolve ( "Origin matches local repository.")
67+ if ( origin === this . config . repo ) resolve ( "[-] Local repository matches origin .")
68+ else reject ( "[!] Local repository does not match origin .")
6669 } )
6770 } )
6871 }
6972
7073 async fork_app ( cwd = this . repo_dir ) {
71- if ( this . app && ! this . app ?. killed ) throw "App already alive!"
74+ if ( this . app && ! this . app ?. killed ) throw "[-] App already alive!"
75+ console . log ( "[.] Preparing environment." )
7276 await this . execute ( "npm install" , { cwd } ) . catch ( console . warn ) ;
77+ console . log ( "[.] Initialising fork." )
7378 return this . app = fork ( cwd , this . config . start . split ( / + / g) ) ;
7479 }
7580
@@ -79,7 +84,7 @@ new class {
7984
8085 async execute ( command , options = { } ) {
8186 return new Promise ( ( resolve , reject ) => {
82- console . log ( `Executing '${ command } '...` ) ;
87+ // console.log(`Executing '${command}'...`);
8388 exec ( command , options , ( err , stdout , stderr ) => {
8489 if ( err ) reject ( err )
8590 else if ( stderr ) reject ( stderr ) ;
@@ -93,10 +98,10 @@ new class {
9398 if ( this . repo_exists ( this . repo_dir ) ) {
9499 rm ( dir , { recursive : true , force : true } , ( err ) => {
95100 if ( err ) reject ( err ) ;
96- else resolve ( "Successfully removed existing repository." )
101+ else resolve ( "[+] Successfully removed existing repository." )
97102 } ) ;
98103 }
99- else resolve ( "Repository not found." )
104+ else resolve ( "[!] Repository folder not found." )
100105 } )
101106 }
102107
@@ -106,25 +111,31 @@ new class {
106111
107112 async reset_app ( ) {
108113 if ( this . app && ! this . app . killed ) {
109- if ( this . app . kill ( ) ) console . log ( "App terminated successfully." )
110- else console . warn ( "Something went wrong while terminating app." )
114+ if ( this . app . kill ( ) ) console . log ( "[+] App terminated successfully." )
115+ else console . warn ( "[!] Something went wrong while terminating app." )
111116 }
112117 await this . remove_dir ( ) . then ( console . log ) . catch ( console . error )
113- console . log ( "Cloning up-to-date repository.. ." )
114- await this . clone ( this . config . repo ) . then ( ( ) => console . log ( "Repository cloned successfully." ) ) . catch ( ( ) => { } ) ;
118+ console . log ( "[.] Cloning up-to-date repository." )
119+ await this . clone ( this . config . repo ) . then ( ( ) => console . log ( "[+] Repository cloned successfully." ) ) . catch ( ( ) => { } ) ;
115120 }
116121
117122 async scan ( ) {
118123 if ( ! this . repo_exists ( ) ) await this . reset_app ( ) ;
119124 else {
120125 await this . match_origin ( this . repo_dir )
121- . catch ( async ( ) => await this . reset_app ( ) )
122- . then ( async ( ) => await this . match_version ( ) . catch ( async ( ) => await this . reset_app ( ) ) )
126+ . catch ( async ( res ) => {
127+ console . log ( res ) ;
128+ await this . reset_app ( ) ;
129+ } )
130+ . then ( async ( ) => await this . match_version ( ) . catch ( async ( res ) => {
131+ console . warn ( res ) ;
132+ await this . reset_app ( ) ;
133+ } ) )
123134 }
124135
125136 await this . fork_app ( ) . catch ( ( ) => { } )
126137
127- return this . sleep ( this . config . frequency ) . then ( ( ) => this . scan ( ) )
138+ return this . sleep ( this . config . frequency * 1000 ) . then ( ( ) => this . scan ( ) )
128139 }
129140
130141} ( )
0 commit comments