diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8ce73c4..85c7841 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,9 +10,10 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: node-version: 18 + - run: node -v - run: npm i -g yarn - run: yarn - run: yarn build diff --git a/bin.js b/bin.js index 68dc393..f1fd440 100755 --- a/bin.js +++ b/bin.js @@ -1,15 +1,9 @@ -#!/usr/bin/env node -const compareVersions = require("compare-versions") -const MIN_NODE_VERSION = '14.17.6' - -if (compareVersions.compare(process.versions.node, MIN_NODE_VERSION, '<')) { - console.error( - `Bls CLI requires at least node.js v${MIN_NODE_VERSION}.\nYou are using v${process.versions.node}. Please update your version of node.js. Consider using Node.js version manager https://github.com/nvm-sh/nvm.` - ) - process.exit(1) -} else { - const { main } = require("./dist/src/index"); - const { version } = require("./package.json"); - - main(process.argv.slice(2), { version }); -} +#!/usr/bin/env node --no-warnings +const compareVersions = require("compare-versions"); + + +const { main } = require("./dist/src/index"); +const { version } = require("./package.json"); + +main(process.argv.slice(2), { version }); + diff --git a/dev-bin.js b/dev-bin.js index fe63e48..77f5488 100755 --- a/dev-bin.js +++ b/dev-bin.js @@ -1,26 +1,17 @@ -#!/usr/bin/env node +#!/usr/bin/env node --no-warnings require("ts-node/register"); -const compareVersions = require("compare-versions"); -const MIN_NODE_VERSION = "14.17.6"; -if (compareVersions.compare(process.versions.node, MIN_NODE_VERSION, "<")) { - console.error( - `Bls CLI requires at least node.js v${MIN_NODE_VERSION}.\nYou are using v${process.versions.node}. Please update your version of node.js. Consider using Node.js version manager https://github.com/nvm-sh/nvm.`, - ); - process.exit(1); -} else { - const { main } = require("./src/index"); - const { version } = require("./package.json"); +const { main } = require("./src/index"); +const { version } = require("./package.json"); - const runCLI = (args) => { - main(args, { version }); - }; +const runCLI = (args) => { + main(args, { version }); +}; - // Export the runCLI function for testing - module.exports = { runCLI }; +// Export the runCLI function for testing +module.exports = { runCLI }; - // Run the CLI if executed directly - if (require.main === module) { - runCLI(process.argv.slice(2)); - } -} +// Run the CLI if executed directly +if (require.main === module) { + runCLI(process.argv.slice(2)); +} \ No newline at end of file diff --git a/package.json b/package.json index 2480615..1b872c6 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,8 @@ { "name": "@blockless/cli", + "engines": { + "node": ">=18.10.0" + }, "version": "0.0.5-development", "description": "blockless cli client, manage, interact with and deploy blockless applications.", "main": "dist/src/index.js", diff --git a/src/index.ts b/src/index.ts index 70cf3da..a1ebe54 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,10 @@ import { openInBrowser } from './lib/browser' import { getGatewayUrl } from './lib/urls' import { logger } from './lib/logger' import { sitesCli } from './commands/sites' +import * as compareVersions from "compare-versions"; +import { getNodeVersion } from './lib/npm' +const MIN_NODE_VERSION = "18.10"; + /** * Yargs options included in every wrangler command. @@ -166,6 +170,13 @@ export async function main(argv: string[], options: any) { blsCli.version(options.version) blsCli.epilogue(`Blockless CLI v${options.version}`) + if (compareVersions.compare(getNodeVersion(), MIN_NODE_VERSION, "<")) { + console.error( + `Bls CLI requires at least node.js v${MIN_NODE_VERSION}.\nYou are using v${process.versions.node}. Please update your version of node.js. Consider using Node.js version manager https://github.com/nvm-sh/nvm.`, + ); + process.exit(1); + } + if (argv.length > 0) { try { blsCli.parse(argv, parseCliResponse) diff --git a/src/lib/npm.ts b/src/lib/npm.ts index bb021b0..df23161 100644 --- a/src/lib/npm.ts +++ b/src/lib/npm.ts @@ -13,6 +13,10 @@ export const getNpmVersion = (): string => export const getNpmConfigInitVersion = (): string => execSync("npm config get init-version").toString("utf-8") +// Node/npm config +export const getNodeVersion = (): string => + execSync("echo $(node -v)").toString("utf-8").replace('v', '').trim() + /** * Check whether NPM is installed *