@@ -4,6 +4,7 @@ const { command } = require("../../lib/");
4
4
const { exec } = require ( "child_process" ) ;
5
5
const simplegit = require ( "simple-git" ) ;
6
6
const git = simplegit ( ) ;
7
+ var branch = config . BRANCH ;
7
8
8
9
command (
9
10
{
@@ -15,7 +16,7 @@ command(
15
16
async ( message , match ) => {
16
17
prefix = message . prefix ;
17
18
await git . fetch ( ) ;
18
- var branch = config . BRANCH ;
19
+
19
20
var commits = await git . log ( [ branch + "..origin/" + branch ] ) ;
20
21
if ( match === "now" ) {
21
22
if ( commits . total === 0 ) {
@@ -25,13 +26,33 @@ command(
25
26
) ;
26
27
}
27
28
await message . sendMessage ( message . jid , "*Updating...*" ) ;
28
- await exec ( "git pull origin " + config . BRANCH , async ( err , stdout , stderr ) => {
29
- if ( err ) {
30
- return await message . sendMessage ( message . jid , "```" + stderr + "```" ) ;
29
+ await exec (
30
+ "git pull origin " + config . BRANCH ,
31
+ async ( err , stdout , stderr ) => {
32
+ if ( err ) {
33
+ return await message . sendMessage (
34
+ message . jid ,
35
+ "```" + stderr + "```"
36
+ ) ;
37
+ }
38
+ await message . sendMessage ( message . jid , "*Restarting...*" ) ;
39
+ let dependancy = await updatedDependencies ( ) ;
40
+ if ( dependancy ) {
41
+ exec (
42
+ "npm install && pm2 restart " + PROCESSNAME ,
43
+ async ( err , stdout , stderr ) => {
44
+ if ( err ) {
45
+ return await message . sendMessage (
46
+ message . jid ,
47
+ "```" + stderr + "```"
48
+ ) ;
49
+ }
50
+ await message . sendMessage ( message . jid , "*Restarting...*" ) ;
51
+ }
52
+ ) ;
53
+ }
31
54
}
32
- await message . sendMessage ( message . jid , "*Restarting...*" ) ;
33
- await exec ( "pm2 restart " + PROCESSNAME ) ;
34
- } ) ;
55
+ ) ;
35
56
} else {
36
57
if ( commits . total === 0 ) {
37
58
return await message . sendMessage (
@@ -52,3 +73,14 @@ command(
52
73
}
53
74
}
54
75
) ;
76
+
77
+ async function updatedDependencies ( ) {
78
+ try {
79
+ const diff = await git . diff ( [ `${ branch } ..origin/${ branch } ` ] ) ;
80
+ const hasDependencyChanges = diff . includes ( '"dependencies":' ) ;
81
+ return hasDependencyChanges ;
82
+ } catch ( error ) {
83
+ console . error ( "Error occurred while checking package.json:" , error ) ;
84
+ return false ;
85
+ }
86
+ }
0 commit comments