From 6a99b0053dbb868499f67020ec08da65bac90718 Mon Sep 17 00:00:00 2001 From: deicidus <> Date: Thu, 16 Jun 2022 07:18:20 -0700 Subject: [PATCH] fixed startup infinite loop due to AO version checking ao-cli, now it gets from global npm package.json --- README.md | 5 +++-- scripts/features/ao-cli.js | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c280884..bd417cf 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ These features work right now: * Browse the [AO User Manual](https://git.coalitionofinvisiblecolleges.org/autonomousorganization/ao-manual) and automatically download and keep it updated * Interactive install wizard installs the AO for you * Operate essential AO client features (view, create, and organize priorities) +* Easily monitor your AO server status and start/stop the service * Easily view installed/running status of optional AO features (soon all features) * Easily install/uninstall and turn on/off optional AO features * Manages your AO configuration (.env) file for you @@ -32,8 +33,7 @@ These features work right now: * Wraps the functionality of (some of) Zen's Alchemy suite of scripts (system configuration, AO installation) * Add `ao` alias for `ao-cli` (under Features→ao-cli) * Enchant your 'cd' command to narrate your travels through the UNIX filesystem (under Features→ao-cli) (less annoying than it sounds, easy to disable) -* Easily monitor your AO server status and start/stop the service -* Easily add your existing systemctl services the Features list so you can start and stop them from the AO Features menu +* Easily add your existing systemctl services to the Features list so you can start and stop them from the AO Features menu ## Upcoming Features @@ -63,6 +63,7 @@ These features are planned and many are mocked up in the menus: ## Version History +* 0.1.6 Fixed AO version number crash on startup * 0.1.5 Added support for feature submodules and adding system services to AO's features menu * 0.1.4 Added fantasy hook feature to bring the AO MUD aesthetic into the terminal * 0.1.2 AO install wizard partway done, reorganized project repos, 'Check AO install' feature diff --git a/scripts/features/ao-cli.js b/scripts/features/ao-cli.js index 7a3931e..4cab634 100644 --- a/scripts/features/ao-cli.js +++ b/scripts/features/ao-cli.js @@ -1,6 +1,7 @@ import { execSync } from 'child_process' import { fileURLToPath } from 'url' import path from 'path' +import fs from 'fs' import { loadJsonFile } from '../files.js' // Can't include .json files without adding an experimental node flag, but we can use this workaround to use require, which works, instead @@ -34,7 +35,24 @@ function installAoCli() { } async function getAoCliVersion() { - return execSync('ao-cli --version').toString().replace(/\n$/, '') + const npmGlobalPackagesPath = execSync('npm root -g').toString().replace(/\n/, '') + const aoGlobalPackagePath = path.join(npmGlobalPackagesPath, '@autonomousorganization/ao-cli/package.json') + let jsonFileContents + try { + const contents = fs.readFileSync(aoGlobalPackagePath) + jsonFileContents = JSON.parse(contents) + } catch(err) { + if(err.code === 'ENOENT') { + console.log('The global ao-cli package.json file does not exist.') + } else { + console.log('Unknown error loading global ao-cli package.json file, aborting.', err) + } + return null + } + if(!jsonFileContents.hasOwnProperty('version')) { + return null + } + return jsonFileContents.version } // Updates the globally-installed version of this package, ao-cli, using npm