1- const semver = require ( ' semver' ) ;
2- const engines = require ( ' ./package.json' ) . engines ;
3- const fs = require ( 'fs' ) ;
4- const os = require ( 'os' ) ;
5- const path = require ( ' path' ) ;
6- const { exec} = require ( ' child_process' ) ;
7- require ( ' source-map-support' ) . install ( ) ;
1+ const semver = require ( " semver" ) ;
2+ const engines = require ( " ./package.json" ) . engines ;
3+ const fs = require ( "node:fs" ) ;
4+ const os = require ( "node:os" ) ;
5+ const path = require ( "node: path" ) ;
6+ const { exec} = require ( "node: child_process" ) ;
7+ require ( " source-map-support" ) . install ( ) ;
88
99let controller ;
1010let stopping = false ;
11- let watchdog = process . env . Z2M_WATCHDOG != undefined ;
11+ const watchdog = process . env . Z2M_WATCHDOG != null ;
1212let watchdogCount = 0 ;
1313let unsolicitedStop = false ;
1414// csv in minutes, default: 1min, 5min, 15min, 30min, 60min
1515let watchdogDelays = [ 2000 , 60000 , 300000 , 900000 , 1800000 , 3600000 ] ;
1616
17- if ( watchdog && process . env . Z2M_WATCHDOG !== ' default' ) {
17+ if ( watchdog && process . env . Z2M_WATCHDOG !== " default" ) {
1818 if ( / ^ \d + ( .\d + ) ? ( , \d + ( .\d + ) ? ) * $ / . test ( process . env . Z2M_WATCHDOG ) ) {
19- watchdogDelays = process . env . Z2M_WATCHDOG . split ( ',' ) . map ( ( v ) => parseFloat ( v ) * 60000 ) ;
19+ watchdogDelays = process . env . Z2M_WATCHDOG . split ( "," ) . map ( ( v ) => Number . parseFloat ( v ) * 60000 ) ;
2020 } else {
2121 console . log ( `Invalid watchdog delays (must use number-only CSV format representing minutes, example: 'Z2M_WATCHDOG=1,5,15,30,60'.` ) ;
2222 process . exit ( 1 ) ;
2323 }
2424}
2525
26- const hashFile = path . join ( __dirname , ' dist' , ' .hash' ) ;
26+ const hashFile = path . join ( __dirname , " dist" , " .hash" ) ;
2727
2828async function triggerWatchdog ( code ) {
2929 const delay = watchdogDelays [ watchdogCount ] ;
@@ -58,11 +58,11 @@ async function exit(code, restart = false) {
5858
5959async function currentHash ( ) {
6060 return await new Promise ( ( resolve ) => {
61- exec ( ' git rev-parse --short=8 HEAD' , ( error , stdout ) => {
61+ exec ( " git rev-parse --short=8 HEAD" , ( error , stdout ) => {
6262 const commitHash = stdout . trim ( ) ;
6363
64- if ( error || commitHash === '' ) {
65- resolve ( ' unknown' ) ;
64+ if ( error || commitHash === "" ) {
65+ resolve ( " unknown" ) ;
6666 } else {
6767 resolve ( commitHash ) ;
6868 }
@@ -81,26 +81,26 @@ async function build(reason) {
8181
8282 return await new Promise ( ( resolve , reject ) => {
8383 const env = { ...process . env } ;
84- const _600mb = 629145600 ;
84+ const mb600 = 629145600 ;
8585
86- if ( _600mb > os . totalmem ( ) && ! env . NODE_OPTIONS ) {
86+ if ( mb600 > os . totalmem ( ) && ! env . NODE_OPTIONS ) {
8787 // Prevent OOM on tsc compile for system with low memory
8888 // https://github.com/Koenkk/zigbee2mqtt/issues/12034
89- env . NODE_OPTIONS = ' --max_old_space_size=256' ;
89+ env . NODE_OPTIONS = " --max_old_space_size=256" ;
9090 }
9191
9292 // clean build, prevent failures due to tsc incremental building
93- exec ( ' pnpm run prepack' , { env, cwd : __dirname } , async ( err , stdout , stderr ) => {
93+ exec ( " pnpm run prepack" , { env, cwd : __dirname } , ( err ) => {
9494 if ( err ) {
95- process . stdout . write ( ' , failed\n' ) ;
95+ process . stdout . write ( " , failed\n" ) ;
9696
9797 if ( err . code === 134 ) {
98- process . stderr . write ( ' \n\nBuild failed; ran out-of-memory, free some memory (RAM) and start again\n\n' ) ;
98+ process . stderr . write ( " \n\nBuild failed; ran out-of-memory, free some memory (RAM) and start again\n\n" ) ;
9999 }
100100
101101 reject ( err ) ;
102102 } else {
103- process . stdout . write ( ' , finished\n' ) ;
103+ process . stdout . write ( " , finished\n" ) ;
104104 resolve ( ) ;
105105 }
106106 } ) ;
@@ -109,19 +109,19 @@ async function build(reason) {
109109
110110async function checkDist ( ) {
111111 if ( ! fs . existsSync ( hashFile ) ) {
112- await build ( ' initial build' ) ;
112+ await build ( " initial build" ) ;
113113 }
114114
115- const distHash = fs . readFileSync ( hashFile , ' utf8' ) ;
115+ const distHash = fs . readFileSync ( hashFile , " utf8" ) ;
116116 const hash = await currentHash ( ) ;
117117
118- if ( hash !== ' unknown' && distHash !== hash ) {
119- await build ( ' hash changed' ) ;
118+ if ( hash !== " unknown" && distHash !== hash ) {
119+ await build ( " hash changed" ) ;
120120 }
121121}
122122
123123async function start ( ) {
124- console . log ( `Starting Zigbee2MQTT ${ watchdog ? `with watchdog (${ watchdogDelays } )` : ` without watchdog` } .` ) ;
124+ console . log ( `Starting Zigbee2MQTT ${ watchdog ? `with watchdog (${ watchdogDelays } )` : " without watchdog" } .` ) ;
125125 await checkDist ( ) ;
126126
127127 // gc
@@ -132,7 +132,7 @@ async function start() {
132132 console . log ( `\t\tZigbee2MQTT requires node version ${ version } , you are running ${ process . version } !\n` ) ;
133133 }
134134
135- const { onboard} = require ( ' ./dist/util/onboarding' ) ;
135+ const { onboard} = require ( " ./dist/util/onboarding" ) ;
136136
137137 const success = await onboard ( ) ;
138138
@@ -143,7 +143,7 @@ async function start() {
143143 }
144144 }
145145
146- const { Controller} = require ( ' ./dist/controller' ) ;
146+ const { Controller} = require ( " ./dist/controller" ) ;
147147 controller = new Controller ( restart , exit ) ;
148148
149149 await controller . start ( ) ;
@@ -172,17 +172,17 @@ async function handleQuit() {
172172 }
173173}
174174
175- if ( require . main === module || require . main . filename . endsWith ( path . sep + ' cli.js' ) ) {
176- if ( process . argv . length === 3 && process . argv [ 2 ] === ' writehash' ) {
175+ if ( require . main === module || require . main . filename . endsWith ( ` ${ path . sep } cli.js` ) ) {
176+ if ( process . argv . length === 3 && process . argv [ 2 ] === " writehash" ) {
177177 writeHash ( ) ;
178178 } else {
179- process . on ( ' SIGINT' , handleQuit ) ;
180- process . on ( ' SIGTERM' , handleQuit ) ;
179+ process . on ( " SIGINT" , handleQuit ) ;
180+ process . on ( " SIGTERM" , handleQuit ) ;
181181 start ( ) ;
182182 }
183183} else {
184- process . on ( ' SIGINT' , handleQuit ) ;
185- process . on ( ' SIGTERM' , handleQuit ) ;
184+ process . on ( " SIGINT" , handleQuit ) ;
185+ process . on ( " SIGTERM" , handleQuit ) ;
186186
187187 module . exports = { start} ;
188188}
0 commit comments