#!/usr/bin/env node // Makes the script crash on unhandled rejections instead of silently // ignoring them. In the future, promise rejections that are not handled will // terminate the Node.js process with a non-zero exit code. process.on('unhandledRejection', (err) => { throw err; }); // Note: we're intentionally using `var` here in case Diez is running on a very old version of Node. var semver = require('semver'); if (semver.gt('7.6.0', process.version)) { console.log('Your Node version is incompatible with Diez. Please upgrade to a newer version.'); process.exit(1); } // Monkey-patch `require()` so the `.diezrc` autodiscovery mechanism can work across monorepos. // TODO: we should have a way to *only* do this while developing across monorepos. const {addPath} = require('app-module-path'); const {Module} = require('module'); for (const requirePath of Module._nodeModulePaths(global.process.cwd())) { addPath(requirePath); } (async () => { const packageJson = require('package-json'); const {Log, diezVersion, loadingMessage} = require('@diez/cli-core'); const {join} = require('path'); const {clearLine} = require('readline'); // Perform a fast DNS resolution check to avoid a hung version check. require('dns').lookup('npmjs.com', async (err) => { if (err) { require('@diez/cli-core/lib/cli').run(join(__dirname, '..')); return; } // Make a simple spinner for our update check. const spinner = loadingMessage('Checking for updates...'); try { const {version: latestVersion} = await packageJson('@diez/cli-core'); if (semver.gt(latestVersion, diezVersion)) { Log.warning('You are using an out-of-date version of Diez. Please upgrade to the latest version:\n'); Log.info('If you are using yarn:'); Log.code('yarn upgrade diez --latest\n\n'); Log.info('If you are using npm:'); Log.code(`npm install diez@${latestVersion} --save\n\n `); } } catch (_) { // Noop. } finally { spinner.stop(); clearLine(process.stdout); require('@diez/cli-core/lib/cli').run(join(__dirname, '..')); } }); })();