diff --git a/index.js b/index.js index 4e0fdad..e9daf8b 100644 --- a/index.js +++ b/index.js @@ -6,16 +6,16 @@ import { detectOS, updateSoftware, installRequired, setNodeVersion } from './scr import { checkAoEnvFile, aoEnv, setAoEnv, AO_ENV_FILE_PATH } from './scripts/settings.js' import { unicornPortal, asciiArt, clearScreen, spinnerWait } from './scripts/console.js' import { welcome, exclaim, roger, farewell } from './scripts/welcome.js' -import { printManualPage, manualFolderAsMenu } from './scripts/manual.js' +import { printManualPage, manualFolderAsMenu, AO_MANUAL_PATH } from './scripts/manual.js' +import { isFolder } from './scripts/files.js' import { sleep } from './scripts/util.js' import { tests } from './scripts/tests.js' import { headerStyle } from './scripts/chalkStyles.js' import './scripts/strings.js' -import { installAoAlias } from './scripts/features.js' +import { installAoAlias, downloadManual, updateManual } from './scripts/features.js' import { startPublicBootstrap } from './scripts/bootstrap.js' // These should become .env variables that are loaded intelligently -const MANUAL_PATH = process.env.HOME + '/.ao/manual' let distro let memberName @@ -66,10 +66,21 @@ async function mainMenu() { while(await testsMenu()) {} break case 'Manual': - await printManualPage(MANUAL_PATH) // Fencepost case - print overview page + if(!isFolder(AO_MANUAL_PATH)) { + console.log("Downloading the AO manual...") + if(downloadManual()) { + console.log("Downloaded the AO Manual from the official git repo via http and saved to", AO_MANUAL_PATH + '.') + } else { + console.log('Failed to download the AO manual, sorry.') + return false + } + } else { + updateManual() + } + await printManualPage(AO_MANUAL_PATH) // Fencepost case - print overview page let previousChoice = 0 do { - previousChoice = await manualFolderAsMenu(MANUAL_PATH, 'AO User Manual', 'Back to Main Menu', previousChoice + 1) + previousChoice = await manualFolderAsMenu(AO_MANUAL_PATH, 'AO User Manual', 'Back to Main Menu', previousChoice + 1) } while(previousChoice !== false) break case 'Log Out': diff --git a/scripts/features.js b/scripts/features.js index 246b8f8..8af0ba6 100644 --- a/scripts/features.js +++ b/scripts/features.js @@ -1,5 +1,6 @@ // Functions to add and remove AO features -import { execSync } from 'child_process' +import { execSync, exec } from 'child_process' +import { AO_MANUAL_PATH } from './manual.js' // Adds a line to .bashrc to make 'ao' an alias for 'ao-cli', to simplify using the AO from the command line export function installAoAlias() { @@ -12,8 +13,28 @@ export function installAoAlias() { } } -// Downloads the ao-manual repo to ~/.ao/manual/ -export function downloadAoManual() { - console.log(execSync('git clone https://git.coalitionofinvisiblecolleges.org:3009/autonomousorganization/ao-manual.git')) +export async function updateManual() { + exec('cd ' + process.env.HOME + '/.ao/manual && git pull origin main 2>&1', (error, stdout, stderr) => { + //console.log('error:', error, 'stdout:', stdout, 'stderr:', stderr) + if(error) { + console.log('git pull failed with error:', error) + } + if(stdout.includes('Already up to date.')) { + return + } + console.log('/nAO User Manual was updated.') + }) } +// Downloads the ao-manual repo to ~/.ao/manual/ +export function downloadManual() { + try { + execSync('git clone http://git.coalitionofinvisiblecolleges.org:3009/autonomousorganization/ao-manual.git ' + AO_MANUAL_PATH + ' 2>&1') + } catch(err) { + switch(err.code) { + case 128: + return false + } + } + return true +} diff --git a/scripts/manual.js b/scripts/manual.js index d75e4f4..ec31f1f 100644 --- a/scripts/manual.js +++ b/scripts/manual.js @@ -5,6 +5,8 @@ import { loadYamlMarkdownFile, lsFolder, isFolder } from './files.js' import { repeatString, centerLines } from './strings.js' import { headerStyle, manualTitleStyle } from './chalkStyles.js' +export const AO_MANUAL_PATH = process.env.HOME + '/.ao/manual' + // Removes numbered prefix such as 12_ and .md suffix, replaces underscores with spaces, and adds titlecase function formatManualTitleString(title) { // Remove .md suffix