@ -7,10 +7,12 @@ import { detectOS, updateSoftware, isInstalled } from './system.js'
import { isFolder , isFile } from './files.js'
import { aoIsInstalled } from './features/ao-server.js'
import { asciiArt } from './console.js'
import { headerStyle , heading2 } from './styles.js'
import { headerStyle , heading2 , styledStatus } from './styles.js'
import features from './features/index.js'
import { yesOrNo } from './welcome.js'
const AO _MEMES _PATH = path . join ( process . env . HOME , '.ao/memes' )
const AO _PATH = path . join ( process . env . HOME , '.ao' )
const AO _MEMES _PATH = path . join ( AO _PATH , 'memes' )
const commonPackages = [ 'curl' , 'wget' , 'git' , 'make' , 'sqlite3' , 'python' , 'autoconf-archive' ]
const debianPackages = [ 'build-essential' , 'zlib1g-dev' , 'libtool-bin' , 'autoconf' , 'automake autotools-dev' , 'libgmp-dev' , 'libsqlite3-dev' , 'python3' , 'python3-mako' , 'libsodium-dev' , 'pkg-config' , 'libev-dev' , 'libcurl4-gnutls-dev' , 'libssl-dev' , 'fakeroot' , 'devscripts' ]
@ -183,37 +185,57 @@ export function checkRequired() {
}
// Prints out a summary of the AO's installation status. Returns true if the AO is installed (Standard + ao-svelte or ao-3, not ao-cli-only)
export function checkAo ( ) {
const width = 24
export async function checkAo ( ) {
const width = 19
const columnize = ( status ) => styledStatus ( status , width )
// Print status of each required package individually
console . log ( ` \n ${ heading2 ( 'Required Software Packages' ) } ` )
const summary = checkRequired ( )
Object . entries ( summary ) . forEach ( ( [ packageName , isInstalled ] ) => {
console . log ( packageName . padEnd ( width ) + ( isInstalled ? 'Installed' : 'Missing' ) )
const summary = Object . entries ( checkRequired ( ) )
let installedRequirementCount = 0
summary . forEach ( ( [ packageName , isInstalled ] ) => {
if ( isInstalled ) installedRequirementCount ++
console . log ( packageName . padEnd ( width ) + columnize ( isInstalled ? 'Installed' : 'Missing' ) )
} )
const prerequisitesInstalled = Object . entries ( summary ) . every ( ( [ packageName , isInstalled ] ) => isInstalled )
const prerequisitesInstalled = summary . every ( ( [ packageName , isInstalled ] ) => isInstalled )
// Check for existence of required directories
console . log ( ` \n ${ heading2 ( 'Folders & Config File' ) } ` )
const requiredDirectoriesExist = checkAoDirectories ( )
console . log ( '~/.ao & ~/.ao/memes ' . padEnd ( width ) + ( requiredDirectoriesExist ? ' Created ' : 'Missing' ) )
console . log ( '~/.ao' . padEnd ( width ) + ( isFolder ( AO _PATH ) ? columnize ( 'Created' ) : columnize ( 'Missing' ) ) )
// Check for .env file
const aoEnvFilePath = path . join ( process . env . HOME , '.ao/.env' )
const hasEnvFile = isFile ( aoEnvFilePath )
console . log ( '~/.ao/.env' . padEnd ( width ) + ( hasEnvFile ? 'Initialized' : 'Blank' ) , '\n' )
console . log ( '~/.ao/.env' . padEnd ( width ) + columnize ( hasEnvFile ? 'Initialized' : 'Blank' ) )
console . log ( '~/.ao/memes' . padEnd ( width ) + columnize ( requiredDirectoriesExist ? 'Created' : 'Missing' ) )
// Check for ao-server folder with node_modules folder (can do a better check?)
// Check for node project folders and locally installed packages (npm i )
console . log ( ` \n ${ heading2 ( 'AO Server + Client Version Installed' ) } ` )
const homePathsToCheck = [ 'ao-server' , 'ao-svelte' , 'ao-3' ]
let homePathsExist = [ ]
let npmInstalled = [ ]
homePathsToCheck . forEach ( folderName => {
const nodeModules Path = path . join ( process . env . HOME , folderName , 'node_modules' )
const exists = isFolder ( nodeModules Path)
console . log ( folderName . padEnd ( width ) + ( exists ? 'Installed' : 'Not Installed' ) )
const folder Path = path . join ( process . env . HOME , folderName )
const exists = isFolder ( folder Path)
let npmI = false
if ( exists ) {
homePathsExist . push ( folderName )
try {
const stdout = execSync ( 'cd ' + folderPath + ' && npm list 2>&1' )
npmInstalled . push ( folderName )
npmI = true
} catch ( error ) {
const missingLocalPackagesCount = error . output . toString ( ) . match ( /npm ERR! missing:/g ) . length || 0
if ( missingLocalPackagesCount ) {
// Confirmation that not all dependencies have been installed
//console.log(folderName, 'has', missingLocalPackagesCount, 'npm packages left to install.')
} else {
// Unknown error
}
}
}
console . log ( folderName . padEnd ( width ) + columnize ( exists ? npmI ? 'Installed' : 'Downloaded' : 'Not Installed' ) )
} )
const hasAnAo = ( homePathsExist . includes ( 'ao-server' ) && homePathsExist . includes ( 'ao-svelte' ) ) || homePathsExist . includes ( 'ao-3' )
@ -224,7 +246,7 @@ export function checkAo() {
const name = feature ? . name || shortname
const isInstalled = feature . hasOwnProperty ( 'isInstalled' ) ? feature . isInstalled ( ) : [ 'installed' , 'enabled' , 'running' , 'synced' ] . includes ( feature . status ( ) )
if ( isInstalled ) optionalInstalls . push ( shortname )
console . log ( name . padEnd ( width ) + ( isInstalled ? 'Installed' : 'Not Installed' ) )
console . log ( name . padEnd ( width ) + columnize ( isInstalled ? 'Installed' : 'Not Installed' ) )
} )
console . log ( ` \n ${ heading2 ( 'Summary' ) } ` )
@ -239,15 +261,23 @@ export function checkAo() {
if ( installAttained === 'Standard' && fullFeatures . every ( shortname => optionalInstalls . includes ( shortname ) ) ) {
installAttained = 'Full'
}
console . log ( installedRequirementCount + '/' + summary . length , 'required packages installed.' )
console . log ( optionalInstalls . length + '/' + Object . keys ( features ) . length , 'optional features installed.' )
if ( ! installAttained ) {
console . log ( "You have not installed the AO; the required packages were not detected." )
} else {
console . log ( 'You have the packages installed for a' , installAttained , 'install.' )
console . log ( 'Recognized this set of packages as a' , installAttained , 'install.' )
}
console . log ( 'Selected AO_VERSION is' , aoEnv ( 'AO_VERSION' ) )
console . log ( 'Selected AO_VERSION is' , aoEnv ( 'AO_VERSION' ) + '\n' )
// Is it possible to check if npm i has already been called in all the node project folders?
if ( installAttained ) console . log ( 'The AO is installed.' )
else {
console . log ( 'The AO is not installed yet. Would you like to install it now?' )
const answer = await yesOrNo ( 'Start AO install wizard?' , true )
if ( answer ) {
await aoInstallWizard ( )
}
}
}
// Installs core dependencies required by Alchemy and the AO