API to get info if updates of palette modules are available and method to update them

Here is 3 flows that can be combined, it is set for my system but the exec commands could be adjusted for most systems.

The first flow check for npm node-red modules that need updating and outputs a js object.

The second can take that object and search and output packages that need updating. It can search on msg.wanted patch or minor or major and update to msg.latest true or false for wanted or latest. (work in progress on versions, still in test phase)

The final flow will take the output of module name and version and run npm install on each.

[{"id":"32853aecedabc3a6","type":"exec","z":"d1395164b4eec73e","command":"cd .node-red && npm outdated --json","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":530,"y":3600,"wires":[["82c08df8c5472cc4"],[],[]]},{"id":"c29555bd4ee9e837","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"wanted","v":"patch","vt":"str"},{"p":"latest","v":"false","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"@flowforge/node-red-dashboard\":{\"current\":\"0.0.9\",\"wanted\":\"0.0.9\",\"latest\":\"0.7.0\",\"dependent\":\".node-red\",\"location\":\"/data/data/com.termux/files/home/.node-red/node_modules/@flowforge/node-red-dashboard\"},\"moment\":{\"current\":\"2.29.4\",\"wanted\":\"2.30.1\",\"latest\":\"2.30.1\",\"dependent\":\".node-red\",\"location\":\"/data/data/com.termux/files/home/.node-red/node_modules/moment\"},\"moment-timezone\":{\"current\":\"0.5.43\",\"wanted\":\"0.5.44\",\"latest\":\"0.5.44\",\"dependent\":\".node-red\",\"location\":\"/data/data/com.termux/files/home/.node-red/node_modules/moment-timezone\"},\"node-red-contrib-telegrambot\":{\"current\":\"15.1.7\",\"wanted\":\"15.1.8\",\"latest\":\"15.1.8\",\"dependent\":\".node-red\",\"location\":\"/data/data/com.termux/files/home/.node-red/node_modules/node-red-contrib-telegrambot\"},\"sqlite3\":{\"current\":\"5.1.6\",\"wanted\":\"5.1.7\",\"latest\":\"5.1.7\",\"dependent\":\".node-red\",\"location\":\"/data/data/com.termux/files/home/.node-red/node_modules/sqlite3\"}}","payloadType":"json","x":330,"y":3720,"wires":[["5462f69b0ba250e6"]]},{"id":"443d58b47b51c375","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"name\":\"dddsdsdmoment-timezone\",\"version\":\"0.5.44\"},{\"name\":\"node-red-contrib-telegrambot\",\"version\":\"15.1.8\"},{\"name\":\"sqlite3\",\"version\":\"5.1.7\"}]","payloadType":"json","x":250,"y":3780,"wires":[["104f9e2dea7d014b"]]},{"id":"104f9e2dea7d014b","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":370,"y":3780,"wires":[["0d05802c058056ea"]]},{"id":"0d05802c058056ea","type":"delay","z":"d1395164b4eec73e","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"120","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":550,"y":3780,"wires":[["0d55d90f55aa7b1f"]]},{"id":"43617bb8073f8f31","type":"function","z":"d1395164b4eec73e","name":"function 151","func":"return {flush: 1};","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":3900,"wires":[["0d05802c058056ea"]]},{"id":"0d55d90f55aa7b1f","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload.name","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"\"cd .node-red && npm install \" & $$.payload.name & \"@\" & $$.payload.version","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":3780,"wires":[["173fc04921fa5fac"]]},{"id":"173fc04921fa5fac","type":"exec","z":"d1395164b4eec73e","command":"","addpay":"payload","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":890,"y":3780,"wires":[["43617bb8073f8f31","153a240649129510"],[],["43617bb8073f8f31","89c70cd5bdf54f72","773a822f16e75e2c"]]},{"id":"153a240649129510","type":"switch","z":"d1395164b4eec73e","name":"","property":"rc.code","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1030,"y":3760,"wires":[["2637eea540660a22"]]},{"id":"89c70cd5bdf54f72","type":"debug","z":"d1395164b4eec73e","name":"debug 2468","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1090,"y":3680,"wires":[]},{"id":"773a822f16e75e2c","type":"switch","z":"d1395164b4eec73e","name":"","property":"rc.code","propertyType":"msg","rules":[{"t":"neq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1030,"y":3800,"wires":[["2637eea540660a22"]]},{"id":"2637eea540660a22","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.result","tot":"msg"},{"t":"set","p":"payload.name","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1200,"y":3780,"wires":[["c96719fc516cad0f"]]},{"id":"c96719fc516cad0f","type":"join","z":"d1395164b4eec73e","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1350,"y":3780,"wires":[["3fe75f47bb18439c"]]},{"id":"3fe75f47bb18439c","type":"debug","z":"d1395164b4eec73e","name":"debug 2467","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1090,"y":3860,"wires":[]},{"id":"6c2b0329d1326a63","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"wanted","v":"patch","vt":"str"},{"p":"latest","v":"false","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":290,"y":3600,"wires":[["32853aecedabc3a6"]]},{"id":"5462f69b0ba250e6","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[$$.payload.*.(\t    $lookfor := $lookup({\t        \"patch\": 2,\t        \"minor\":1,\t        \"major\": 0\t    }, $$.wanted);\t    $current := $split($.current, \".\");\t    $wanted := $split($.wanted, \".\");\t    $latest := $split($.latest, \".\");\t   ($wanted[$lookfor] > $current[$lookfor]) ? (\t        {\t            \"name\": $split($.location, \"node_modules/\")[1],\t            \"version\": $lookup($, ($$.latest ? \"latest\"  : \"wanted\"))\t        }\t    ):(\t        /*$wanted[$lookfor] = $current[$lookfor]  ##false*/\t    )\t)]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":3720,"wires":[["f03c7d1eb0edb07f"]]},{"id":"82c08df8c5472cc4","type":"json","z":"d1395164b4eec73e","name":"","property":"payload","action":"obj","pretty":false,"x":750,"y":3600,"wires":[["0457e87d4ffefaa2"]]},{"id":"0457e87d4ffefaa2","type":"debug","z":"d1395164b4eec73e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":810,"y":3640,"wires":[]},{"id":"f03c7d1eb0edb07f","type":"debug","z":"d1395164b4eec73e","name":"debug 2466","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":690,"y":3720,"wires":[]}]
1 Like