@sanity/codegen
Version:
Codegen toolkit for Sanity.io
52 lines (45 loc) • 1.51 kB
JavaScript
import {execute} from '@oclif/core'
import {CLI_TELEMETRY_SYMBOL} from '@sanity/cli-core'
const err = '\u001B[31m\u001B[1mERROR:\u001B[22m\u001B[39m '
const nodeVersionParts = process.version.replace(/^v/i, '').split('.').map(Number)
const majorVersion = nodeVersionParts[0]
const minorVersion = nodeVersionParts[1]
const patchVersion = nodeVersionParts[2]
function isSupportedNodeVersion(major, minor, patch) {
if (major === 20) {
if (minor > 19) return true
if (minor === 19 && patch >= 1) return true
return false
}
if (major === 21) return true
if (major === 22 && minor >= 12) return true
if (major > 22) return true
return false
}
if (!isSupportedNodeVersion(majorVersion, minorVersion, patchVersion)) {
// eslint-disable-next-line no-console
console.error(
`${err}Node.js version >=20.19.1 <22 or >=22.12 required. You are running ${process.version}`,
)
// eslint-disable-next-line no-console
console.error('')
process.exit(1)
}
if (process.env.NODE_ENV !== 'production') {
/**
* Telemetry is added via a plugin in the main CLI.
* This adds a mock implementation of the telemetry API to allow running this CLI for testing.
*
* We won't be exposing this API to the public, so it's ok to use a globalThis assignment.
*/
globalThis[CLI_TELEMETRY_SYMBOL] = {
trace: () => ({
complete: () => {},
error: () => {},
log: () => {},
start: () => {},
}),
}
}
await execute({dir: import.meta.url})