Skip to content

Commit

Permalink
feat: validate node version
Browse files Browse the repository at this point in the history
  • Loading branch information
marsidev committed Sep 4, 2022
1 parent 856b2d9 commit 84d47e1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -84,7 +84,7 @@
}
},
"engines": {
"node": ">=14"
"node": ">=14.6"
},
"publishConfig": {
"access": "public"
Expand Down
6 changes: 6 additions & 0 deletions src/create.ts
Expand Up @@ -8,9 +8,15 @@ import {
validFilename
} from './utils/fs'
import { cli } from './utils/cli'
import { currentVersion, requiredVersion, validNodeVersion } from './utils/node'
import { error, log, success, warn } from './utils/log'

export const init = () => {
if (!validNodeVersion()) {
error(`You are running Node ${currentVersion}.\nThis package requires Node ${requiredVersion} or higher.\nPlease update your version of Node.`)
return
}

if (Object.keys(cli).length <= 3 && cli._.length === 0) {
const cmd = pc.cyan(`${cli.$0} --help`)
warn(`No filenames provided. Use the command "${cmd}" for help`)
Expand Down
9 changes: 9 additions & 0 deletions src/utils/node.ts
@@ -0,0 +1,9 @@
export const currentVersion = process.versions.node

export const requiredVersion = 14

export const validNodeVersion = () => {
const semver = currentVersion.split('.')
const major = semver[0]
return Number(major) >= requiredVersion
}

0 comments on commit 84d47e1

Please sign in to comment.