* Check the node version and print a warning if it is not the latest LTS. * * @return {Promise }
()
| 101 | * @return {Promise<void>} |
| 102 | **/ |
| 103 | function checkNodeVersion() { |
| 104 | const nodeVersion = getStdout('node --version').trim(); |
| 105 | return new Promise((resolve) => { |
| 106 | https |
| 107 | .get(nodeDistributionsUrl, (res) => { |
| 108 | res.setEncoding('utf8'); |
| 109 | let distributions = ''; |
| 110 | res.on('data', (data) => { |
| 111 | distributions += data; |
| 112 | }); |
| 113 | res.on('end', () => { |
| 114 | const distributionsJson = JSON.parse(distributions); |
| 115 | const latestLtsVersion = getNodeLatestLtsVersion(distributionsJson); |
| 116 | if (latestLtsVersion === '') { |
| 117 | console.log( |
| 118 | yellow( |
| 119 | 'WARNING: Something went wrong. ' + |
| 120 | 'Could not determine the latest LTS version of node.' |
| 121 | ) |
| 122 | ); |
| 123 | } else if (nodeVersion !== latestLtsVersion) { |
| 124 | console.log( |
| 125 | yellow('WARNING: Detected node version'), |
| 126 | cyan(nodeVersion) + |
| 127 | yellow('. Recommended (latest LTS) version is'), |
| 128 | cyan(latestLtsVersion) + yellow('.') |
| 129 | ); |
| 130 | console.log( |
| 131 | yellow('⤷ To fix this, run'), |
| 132 | cyan('"nvm install --lts"'), |
| 133 | yellow('or see'), |
| 134 | cyan('https://nodejs.org/en/download/package-manager'), |
| 135 | yellow('for instructions.') |
| 136 | ); |
| 137 | updatesNeeded.add('node'); |
| 138 | } else { |
| 139 | console.log( |
| 140 | green('Detected'), |
| 141 | cyan('node'), |
| 142 | green('version'), |
| 143 | cyan(nodeVersion + ' (latest LTS)') + green('.') |
| 144 | ); |
| 145 | } |
| 146 | resolve(); |
| 147 | }); |
| 148 | }) |
| 149 | .on('error', () => { |
| 150 | console.log( |
| 151 | yellow( |
| 152 | 'WARNING: Something went wrong. ' + |
| 153 | 'Could not download node version info from ' + |
| 154 | cyan(nodeDistributionsUrl) + |
| 155 | yellow('.') |
| 156 | ) |
| 157 | ); |
| 158 | console.log( |
| 159 | yellow('⤷ Detected node version'), |
| 160 | cyan(nodeVersion) + yellow('.') |