-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#195) Update .nvmrc file with correct Node Version
Closes #195 * Updated `.nvmrc` and `README.md` files with correct Node version * Added `engines` property to `package.json` to specify Node and npm version ranges * Added `.npmrc` file and set `engine-strict` property to `true` * Updated Node version for GitHub actions * Updated `README.md` file `Setup` section * Added validation script file
- Loading branch information
Oluwaseun Longe
authored and
Oluwaseun Longe
committed
Sep 3, 2024
1 parent
c7111fd
commit 1759ae7
Showing
7 changed files
with
121 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
engine-strict=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v20.4.0 | ||
v20.15.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env node | ||
|
||
import chalk from 'chalk'; | ||
import { execSync } from 'child_process'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
async function getRunningVersion() { | ||
const terminalCmd = 'node --version'; | ||
|
||
try { | ||
return execSync(terminalCmd).toString().trim(); | ||
} catch (e) { | ||
console.log(chalk.red(`Node version validation failed while running ${terminalCmd}`), e); | ||
} | ||
} | ||
|
||
async function validateVersion() { | ||
const directory = path.resolve(); | ||
let runningVersion; | ||
|
||
try { | ||
const filePath = path.resolve(directory, '.nvmrc'); | ||
const fileMetadata = await fs.promises.stat(filePath); | ||
const fileContent = fs.readFileSync(filePath, "utf8"); | ||
let specVersion; | ||
|
||
if (fileMetadata) { | ||
specVersion = fileContent.startsWith("v") ? fileContent : `v${fileContent};` | ||
runningVersion = (await getRunningVersion()).trim(); | ||
|
||
if (runningVersion.trim() !== specVersion.trim()) { | ||
console.log(chalk.red(`Your Node version ${runningVersion} does not match the specified version ${specVersion} \rfound in the .nvmrc file in your project root`) ); | ||
console.log('\n-------------\n'); | ||
console.log(chalk.red('Run command "nvm use" in your terminal before running "npm run start" again.\n')); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
|
||
} catch (e) { | ||
if (e.code !== "ENOENT") { | ||
console.log(chalk.red('An unexpected error occurred while validating your Node version.\n')); | ||
console.error(e); | ||
process.exit(1); | ||
} | ||
console.log(chalk.red('Make sure the ".nvmrc" file from the Git repository is present in your project root directory\n')); | ||
console.error(e); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
validateVersion(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters