@ -7,10 +7,12 @@ import { detectOS, updateSoftware, isInstalled } from './system.js'
import { isFolder , isFile } from './files.js'
import { isFolder , isFile } from './files.js'
import { aoIsInstalled } from './features/ao-server.js'
import { aoIsInstalled } from './features/ao-server.js'
import { asciiArt } from './console.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 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 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' ]
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)
// 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 ( ) {
export async function checkAo ( ) {
const width = 24
const width = 19
const columnize = ( status ) => styledStatus ( status , width )
// Print status of each required package individually
// Print status of each required package individually
console . log ( ` \n ${ heading2 ( 'Required Software Packages' ) } ` )
console . log ( ` \n ${ heading2 ( 'Required Software Packages' ) } ` )
const summary = checkRequired ( )
const summary = Object . entries ( checkRequired ( ) )
Object . entries ( summary ) . forEach ( ( [ packageName , isInstalled ] ) => {
let installedRequirementCount = 0
console . log ( packageName . padEnd ( width ) + ( isInstalled ? 'Installed' : 'Missing' ) )
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
// Check for existence of required directories
console . log ( ` \n ${ heading2 ( 'Folders & Config File' ) } ` )
console . log ( ` \n ${ heading2 ( 'Folders & Config File' ) } ` )
const requiredDirectoriesExist = checkAoDirectories ( )
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
// Check for .env file
const aoEnvFilePath = path . join ( process . env . HOME , '.ao/.env' )
const aoEnvFilePath = path . join ( process . env . HOME , '.ao/.env' )
const hasEnvFile = isFile ( aoEnvFilePath )
const hasEnvFile = isFile ( aoEnvFilePath )
console . log ( '~/.ao/.env' . padEnd ( width ) + ( hasEnvFile ? 'Initialized' : 'Blank' ) , '\n' )
console . log ( '~/.ao/.env' . padEnd ( width ) + columnize ( hasEnvFile ? 'Initialized' : 'Blank' ) )
// Check for ao-server folder with node_modules folder (can do a better check?)
console . log ( '~/.ao/memes' . padEnd ( width ) + columnize ( requiredDirectoriesExist ? 'Created' : 'Missing' ) )
// Check for node project folders and locally installed packages (npm i)
console . log ( ` \n ${ heading2 ( 'AO Server + Client Version Installed' ) } ` )
console . log ( ` \n ${ heading2 ( 'AO Server + Client Version Installed' ) } ` )
const homePathsToCheck = [ 'ao-server' , 'ao-svelte' , 'ao-3' ]
const homePathsToCheck = [ 'ao-server' , 'ao-svelte' , 'ao-3' ]
let homePathsExist = [ ]
let homePathsExist = [ ]
let npmInstalled = [ ]
homePathsToCheck . forEach ( folderName => {
homePathsToCheck . forEach ( folderName => {
const nodeModules Path = path . join ( process . env . HOME , folderName , 'node_modules' )
const folder Path = path . join ( process . env . HOME , folderName )
const exists = isFolder ( nodeModules Path)
const exists = isFolder ( folder Path)
console . log ( folderName . padEnd ( width ) + ( exists ? 'Installed' : 'Not Installed' ) )
let npmI = false
if ( exists ) {
if ( exists ) {
homePathsExist . push ( folderName )
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' )
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 name = feature ? . name || shortname
const isInstalled = feature . hasOwnProperty ( 'isInstalled' ) ? feature . isInstalled ( ) : [ 'installed' , 'enabled' , 'running' , 'synced' ] . includes ( feature . status ( ) )
const isInstalled = feature . hasOwnProperty ( 'isInstalled' ) ? feature . isInstalled ( ) : [ 'installed' , 'enabled' , 'running' , 'synced' ] . includes ( feature . status ( ) )
if ( isInstalled ) optionalInstalls . push ( shortname )
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' ) } ` )
console . log ( ` \n ${ heading2 ( 'Summary' ) } ` )
@ -239,15 +261,23 @@ export function checkAo() {
if ( installAttained === 'Standard' && fullFeatures . every ( shortname => optionalInstalls . includes ( shortname ) ) ) {
if ( installAttained === 'Standard' && fullFeatures . every ( shortname => optionalInstalls . includes ( shortname ) ) ) {
installAttained = 'Full'
installAttained = 'Full'
}
}
console . log ( installedRequirementCount + '/' + summary . length , 'required packages installed.' )
console . log ( optionalInstalls . length + '/' + Object . keys ( features ) . length , 'optional features installed.' )
console . log ( optionalInstalls . length + '/' + Object . keys ( features ) . length , 'optional features installed.' )
if ( ! installAttained ) {
if ( ! installAttained ) {
console . log ( "You have not installed the AO; the required packages were not detected." )
console . log ( "You have not installed the AO; the required packages were not detected." )
} else {
} 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
// Installs core dependencies required by Alchemy and the AO