@@ -940,16 +940,28 @@ module.exports = NodeHelper.create({
940940 self . sendResponse ( res , error ) ;
941941 } else {
942942 const workDir = path . resolve ( `${ __dirname } /../${ path . basename ( url ) } ` ) ;
943- exec ( "npm ci --omit=dev" , { cwd : workDir , timeout : 120000 } , ( error , stdout , stderr ) => {
944- if ( error ) {
945- Log . error ( "[MMM-Remote-Control]" , error ) ;
946- self . sendResponse ( res , error , { stdout, stderr, ...data } ) ;
947- } else {
948- // success part
949- self . readModuleData ( ) ;
950- self . sendResponse ( res , undefined , { stdout, ...data } ) ;
943+ const packageJsonExists = fs . existsSync ( `${ workDir } /package.json` ) ;
944+ if ( packageJsonExists ) {
945+ const packageJson = JSON . parse ( fs . readFileSync ( `${ workDir } /package.json` , "utf8" ) ) ;
946+ const installNecessary = packageJson . dependencies || packageJson . scripts ?. preinstall || packageJson . scripts ?. postinstall ;
947+ if ( installNecessary ) {
948+ const packageLockExists = fs . existsSync ( `${ workDir } /package-lock.json` ) ;
949+ const command = packageLockExists
950+ ? "npm ci --omit=dev"
951+ : "npm install --omit=dev" ;
952+
953+ exec ( command , { cwd : workDir , timeout : 120000 } , ( error , stdout , stderr ) => {
954+ if ( error ) {
955+ Log . error ( "[MMM-Remote-Control]" , error ) ;
956+ self . sendResponse ( res , error , { stdout, stderr, ...data } ) ;
957+ } else {
958+ // success part
959+ self . readModuleData ( ) ;
960+ self . sendResponse ( res , undefined , { stdout, ...data } ) ;
961+ }
962+ } ) ;
951963 }
952- } ) ;
964+ }
953965 }
954966 } ) ;
955967 } ,
@@ -986,30 +998,37 @@ module.exports = NodeHelper.create({
986998 return ;
987999 }
9881000 if ( result . summary . changes ) {
989- exec ( "npm ci --omit=dev" , { cwd : path , timeout : 120000 } , ( error , stdout , stderr ) => {
990- if ( error ) {
991- Log . error ( "[MMM-Remote-Control]" , error ) ;
992- self . sendResponse ( res , error , { stdout, stderr} ) ;
993- } else {
994- // success part
995- self . readModuleData ( ) ;
996- fs . readdir ( path , ( err , files ) => {
997- if ( files . includes ( "CHANGELOG.md" ) ) {
998- const chlog = fs . readFileSync ( `${ path } /CHANGELOG.md` , "utf-8" ) ;
999- self . sendResponse ( res , undefined , { code : "restart" , info : `${ name } updated.` , chlog} ) ;
1001+ const packageJsonExists = fs . existsSync ( `${ path } /package.json` ) ;
1002+ if ( packageJsonExists ) {
1003+ const packageJson = JSON . parse ( fs . readFileSync ( `${ path } /package.json` , "utf8" ) ) ;
1004+ const installNecessary = packageJson . dependencies || packageJson . scripts ?. preinstall || packageJson . scripts ?. postinstall ;
1005+ if ( installNecessary ) {
1006+ const packageLockExists = fs . existsSync ( `${ path } /package-lock.json` ) ;
1007+ const command = packageLockExists
1008+ ? "npm ci --omit=dev"
1009+ : "npm install --omit=dev" ;
1010+
1011+ exec ( command , { cwd : path , timeout : 120000 } , ( error , stdout , stderr ) => {
1012+ if ( error ) {
1013+ Log . error ( "[MMM-Remote-Control]" , error ) ;
1014+ self . sendResponse ( res , error , { stdout, stderr} ) ;
10001015 } else {
1001- self . sendResponse ( res , undefined , { code : "restart" , info : `${ name } updated.` } ) ;
1016+ // success part
1017+ self . readModuleData ( ) ;
1018+
1019+ const changelogExists = fs . existsSync ( `${ path } /CHANGELOG.md` ) ;
1020+ if ( changelogExists ) {
1021+ const changelog = fs . readFileSync ( `${ path } /CHANGELOG.md` , "utf-8" ) ;
1022+ self . sendResponse ( res , undefined , { code : "restart" , info : `${ name } updated.` , chlog : changelog } ) ;
1023+ } else {
1024+ self . sendResponse ( res , undefined , { code : "restart" , info : `${ name } updated.` } ) ;
1025+ }
10021026 }
10031027 } ) ;
1004-
1005- /*
1006- * let chlog = fs.readFileSync(path+"/CHANGELOG.md")
1007- * self.sendResponse(res, undefined, { code: "restart", info: name + " updated.", chlog: "" });
1008- */
1028+ } else {
1029+ self . sendResponse ( res , undefined , { code : "up-to-date" , info : `${ name } already up to date.` } ) ;
10091030 }
1010- } ) ;
1011- } else {
1012- self . sendResponse ( res , undefined , { code : "up-to-date" , info : `${ name } already up to date.` } ) ;
1031+ }
10131032 }
10141033 } ) ;
10151034 } ) ;
0 commit comments