|
1 | 1 | /* eslint-disable no-console */ |
2 | 2 |
|
3 | 3 | import type { AddressInfo } from "node:net"; |
| 4 | +import { readFileSync } from "node:fs"; |
| 5 | +import { fileURLToPath } from "node:url"; |
| 6 | +import { dirname, join } from "node:path"; |
4 | 7 | import chalk from "chalk"; |
5 | 8 | import open from "open"; |
6 | 9 | import os from "node:os"; |
| 10 | +import semver from "semver"; |
7 | 11 |
|
8 | 12 | import { |
9 | 13 | PrismicUserProfile, |
@@ -70,6 +74,8 @@ export class StartSliceMachineProcess { |
70 | 74 | * Runs the process. |
71 | 75 | */ |
72 | 76 | async run(): Promise<void> { |
| 77 | + this._checkNodeVersion(); |
| 78 | + |
73 | 79 | // This migration needs to run before the plugins are initialised |
74 | 80 | // Nothing can start without the config file |
75 | 81 | await migrateSMJSON(this._sliceMachineManager); |
@@ -165,6 +171,34 @@ export class StartSliceMachineProcess { |
165 | 171 | } |
166 | 172 | } |
167 | 173 |
|
| 174 | + /** |
| 175 | + * Checks if the current Node.js version satisfies the required version and |
| 176 | + * displays a warning if it doesn't. |
| 177 | + */ |
| 178 | + private _checkNodeVersion(): void { |
| 179 | + const __dirname = dirname(fileURLToPath(import.meta.url)); |
| 180 | + const pkg = JSON.parse( |
| 181 | + readFileSync(join(__dirname, "../package.json"), "utf8"), |
| 182 | + ); |
| 183 | + |
| 184 | + const requiredVersion = pkg.engines?.node; |
| 185 | + |
| 186 | + if (!requiredVersion) { |
| 187 | + return; |
| 188 | + } |
| 189 | + |
| 190 | + const currentVersion = process.version; |
| 191 | + |
| 192 | + if (!semver.satisfies(currentVersion, requiredVersion)) { |
| 193 | + console.warn( |
| 194 | + chalk.yellow( |
| 195 | + `⚠️ Warning: You are using Node.js ${currentVersion}, but this tool requires ${requiredVersion}.\n` + |
| 196 | + ` Some features may not work correctly. Please upgrade your Node.js version.\n`, |
| 197 | + ), |
| 198 | + ); |
| 199 | + } |
| 200 | + } |
| 201 | + |
168 | 202 | /** |
169 | 203 | * Returns a string with Slice Machine info formatted for the console. |
170 | 204 | * |
|
0 commit comments