Browse Source

manual downloads and updates automatically

main
deicidus 2 years ago
parent
commit
608dca49cd
  1. 21
      index.js
  2. 29
      scripts/features.js
  3. 2
      scripts/manual.js

21
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':

29
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
}

2
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

Loading…
Cancel
Save