Skip to content

Commit

Permalink
feat: add node version validation script
Browse files Browse the repository at this point in the history
  • Loading branch information
nmsn authored and ourai committed Jan 25, 2025
1 parent 2c5d175 commit c0848ea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
24 changes: 24 additions & 0 deletions .knosys/scripts/command/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const fs = require('fs');
const path = require('path');
const semver = require('semver');
const { resolveRootPath } = require('../helper');

module.exports = {
execute: () => {
const packageJsonPath = path.join(resolveRootPath(), 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const requiredNodeVersion = packageJson?.engines?.node;
const currentNodeVersion = process.version;

if (!requiredNodeVersion) {
console.error('No engines.node configuration found in package.json');
process.exit(1);
}

if (!semver.satisfies(currentNodeVersion, requiredNodeVersion)) {
console.error(`\nCurrent Node.js version ${currentNodeVersion} does not meet requirements!`);
console.error(`Please use Node.js version ${requiredNodeVersion}\n`);
process.exit(1);
}
},
};
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
},
"packageManager": "[email protected]",
"scripts": {
"env": "node .knosys/scripts env",
"presetup": "npm run env",
"setup": "cross-env cp .env.example .env.local && npx auth secret",
"predev": "npm run env",
"dev": "cross-env NEXT_PUBLIC_DOMAIN_ENV=development next dev -p 3000",
"build": "next build",
"build:test": "NODE_ENV=test NEXT_PUBLIC_DOMAIN_ENV=test next build",
"prestart": "npm run env",
"start": "cross-env NEXT_PUBLIC_DOMAIN_ENV=development next dev -p 3000",
"start:test": "NODE_ENV=test NEXT_PUBLIC_DOMAIN_ENV=test next start -p 3001",
"analyze": "cross-env ANALYZE=true next build",
Expand Down Expand Up @@ -134,6 +138,7 @@
"lint-staged": "15.3.0",
"postcss": "^8.4.18",
"prettier": "^2.5.1",
"semver": "^7.6.3",
"tailwindcss": "3.4.16"
}
}
}

0 comments on commit c0848ea

Please sign in to comment.