@@ -4,7 +4,6 @@ const fs = require('fs');
4
4
const os = require ( 'os' ) ;
5
5
const path = require ( 'path' ) ;
6
6
const { exec} = require ( 'child_process' ) ;
7
- const { rimrafSync} = require ( 'rimraf' ) ;
8
7
require ( 'source-map-support' ) . install ( ) ;
9
8
10
9
let controller ;
@@ -16,7 +15,7 @@ let unsolicitedStop = false;
16
15
let watchdogDelays = [ 2000 , 60000 , 300000 , 900000 , 1800000 , 3600000 ] ;
17
16
18
17
if ( watchdog && process . env . Z2M_WATCHDOG !== 'default' ) {
19
- if ( / ^ (?: (?: [ 0 - 9 ] * [ . ] ) ? [ 0 - 9 ] + ) + (?: , ? (?: [ 0 - 9 ] * [ . ] ) ? [ 0 - 9 ] + ) * $ / . test ( process . env . Z2M_WATCHDOG ) ) {
18
+ if ( / ^ \d + ( . \d + ) ? ( , \d + ( . \d + ) ? ) * $ / . test ( process . env . Z2M_WATCHDOG ) ) {
20
19
watchdogDelays = process . env . Z2M_WATCHDOG . split ( ',' ) . map ( ( v ) => parseFloat ( v ) * 60000 ) ;
21
20
} else {
22
21
console . log ( `Invalid watchdog delays (must use number-only CSV format representing minutes, example: 'Z2M_WATCHDOG=1,5,15,30,60'.` ) ;
@@ -58,10 +57,16 @@ async function exit(code, restart = false) {
58
57
}
59
58
60
59
async function currentHash ( ) {
61
- const git = require ( 'git-last-commit' ) ;
60
+ return await new Promise ( ( resolve ) => {
61
+ exec ( 'git rev-parse --short=8 HEAD' , ( error , stdout ) => {
62
+ const commitHash = stdout . trim ( ) ;
62
63
63
- return new Promise ( ( resolve ) => {
64
- git . getLastCommit ( ( err , commit ) => ( err ? resolve ( 'unknown' ) : resolve ( commit . shortHash ) ) ) ;
64
+ if ( error || commitHash === '' ) {
65
+ resolve ( 'unknown' ) ;
66
+ } else {
67
+ resolve ( commitHash ) ;
68
+ }
69
+ } ) ;
65
70
} ) ;
66
71
}
67
72
@@ -72,10 +77,9 @@ async function writeHash() {
72
77
}
73
78
74
79
async function build ( reason ) {
75
- return new Promise ( ( resolve , reject ) => {
76
- process . stdout . write ( `Building Zigbee2MQTT... (${ reason } )` ) ;
77
- rimrafSync ( 'dist' ) ;
80
+ process . stdout . write ( `Building Zigbee2MQTT... (${ reason } )` ) ;
78
81
82
+ return await new Promise ( ( resolve , reject ) => {
79
83
const env = { ...process . env } ;
80
84
const _600mb = 629145600 ;
81
85
@@ -85,7 +89,8 @@ async function build(reason) {
85
89
env . NODE_OPTIONS = '--max_old_space_size=256' ;
86
90
}
87
91
88
- exec ( 'pnpm run build' , { env, cwd : __dirname } , async ( err , stdout , stderr ) => {
92
+ // clean build, prevent failures due to tsc incremental building
93
+ exec ( 'pnpm run prepack' , { env, cwd : __dirname } , async ( err , stdout , stderr ) => {
89
94
if ( err ) {
90
95
process . stdout . write ( ', failed\n' ) ;
91
96
@@ -107,8 +112,9 @@ async function checkDist() {
107
112
await build ( 'initial build' ) ;
108
113
}
109
114
110
- const distHash = fs . readFileSync ( hashFile , 'utf-8 ' ) ;
115
+ const distHash = fs . readFileSync ( hashFile , 'utf8 ' ) ;
111
116
const hash = await currentHash ( ) ;
117
+
112
118
if ( hash !== 'unknown' && distHash !== hash ) {
113
119
await build ( 'hash changed' ) ;
114
120
}
@@ -118,41 +124,41 @@ async function start() {
118
124
console . log ( `Starting Zigbee2MQTT ${ watchdog ? `with watchdog (${ watchdogDelays } )` : `without watchdog` } .` ) ;
119
125
await checkDist ( ) ;
120
126
121
- const version = engines . node ;
127
+ // gc
128
+ {
129
+ const version = engines . node ;
122
130
123
- if ( ! semver . satisfies ( process . version , version ) ) {
124
- console . log ( `\t\tZigbee2MQTT requires node version ${ version } , you are running ${ process . version } !\n` ) ;
125
- }
131
+ if ( ! semver . satisfies ( process . version , version ) ) {
132
+ console . log ( `\t\tZigbee2MQTT requires node version ${ version } , you are running ${ process . version } !\n` ) ;
133
+ }
126
134
127
- // Validate settings
128
- const settings = require ( './dist/util/settings' ) ;
135
+ // Validate settings
136
+ const settings = require ( './dist/util/settings' ) ;
129
137
130
- settings . reRead ( ) ;
138
+ settings . reRead ( ) ;
131
139
132
- // gc
133
- {
134
140
const settingsMigration = require ( './dist/util/settingsMigration' ) ;
135
141
136
142
settingsMigration . migrateIfNecessary ( ) ;
137
- }
138
143
139
- const errors = settings . validate ( ) ;
144
+ const errors = settings . validate ( ) ;
140
145
141
- if ( errors . length > 0 ) {
142
- unsolicitedStop = false ;
146
+ if ( errors . length > 0 ) {
147
+ unsolicitedStop = false ;
143
148
144
- console . log ( `\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!` ) ;
145
- console . log ( ' READ THIS CAREFULLY\n' ) ;
146
- console . log ( `Refusing to start because configuration is not valid, found the following errors:` ) ;
149
+ console . log ( `\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!` ) ;
150
+ console . log ( ' READ THIS CAREFULLY\n' ) ;
151
+ console . log ( `Refusing to start because configuration is not valid, found the following errors:` ) ;
147
152
148
- for ( const error of errors ) {
149
- console . log ( `- ${ error } ` ) ;
150
- }
153
+ for ( const error of errors ) {
154
+ console . log ( `- ${ error } ` ) ;
155
+ }
151
156
152
- console . log ( `\nIf you don't know how to solve this, read https://www.zigbee2mqtt.io/guide/configuration` ) ;
153
- console . log ( `\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n` ) ;
157
+ console . log ( `\nIf you don't know how to solve this, read https://www.zigbee2mqtt.io/guide/configuration` ) ;
158
+ console . log ( `\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n` ) ;
154
159
155
- return exit ( 1 ) ;
160
+ return await exit ( 1 ) ;
161
+ }
156
162
}
157
163
158
164
const { Controller} = require ( './dist/controller' ) ;
0 commit comments