2019-02-10 15:26:50 +03:00
import execa from 'execa'
2022-09-26 16:29:56 +03:00
import { LogHelper } from '@/helpers/log-helper'
2022-11-20 18:21:06 +03:00
import { SystemHelper } from '@/helpers/system-helper'
2019-02-10 15:26:50 +03:00
/ * *
* Check OS environment
* /
2022-09-03 14:12:41 +03:00
export default ( ) =>
new Promise ( async ( resolve , reject ) => {
2022-09-26 16:29:56 +03:00
LogHelper . info ( 'Checking OS environment...' )
2022-09-03 14:12:41 +03:00
2022-11-20 18:21:06 +03:00
const info = SystemHelper . getInformation ( )
2022-09-03 14:12:41 +03:00
if ( info . type === 'windows' ) {
2022-09-26 16:29:56 +03:00
LogHelper . error ( 'Voice offline mode is not available on Windows' )
2022-09-03 14:12:41 +03:00
reject ( )
} else if ( info . type === 'unknown' ) {
2022-09-26 16:29:56 +03:00
LogHelper . error (
2022-09-03 14:12:41 +03:00
'This OS is unknown, please open an issue to let us know about it'
)
reject ( )
} else {
try {
2022-09-26 16:29:56 +03:00
LogHelper . success ( ` You are running ${ info . name } ` )
LogHelper . info ( 'Checking tools...' )
2022-09-03 14:12:41 +03:00
await execa ( 'tar' , [ '--version' ] )
2022-09-26 16:29:56 +03:00
LogHelper . success ( '"tar" found' )
2022-09-03 14:12:41 +03:00
await execa ( 'make' , [ '--version' ] )
2022-09-26 16:29:56 +03:00
LogHelper . success ( '"make" found' )
2022-09-03 14:12:41 +03:00
if ( info . type === 'macos' ) {
await execa ( 'brew' , [ '--version' ] )
2022-09-26 16:29:56 +03:00
LogHelper . success ( '"brew" found' )
2022-09-03 14:12:41 +03:00
await execa ( 'curl' , [ '--version' ] )
2022-09-26 16:29:56 +03:00
LogHelper . success ( '"curl" found' )
2022-09-03 14:12:41 +03:00
} else if ( info . type === 'linux' ) {
await execa ( 'apt-get' , [ '--version' ] )
2022-09-26 16:29:56 +03:00
LogHelper . success ( '"apt-get" found' )
2022-09-03 14:12:41 +03:00
await execa ( 'wget' , [ '--version' ] )
2022-09-26 16:29:56 +03:00
LogHelper . success ( '"wget" found' )
2022-09-03 14:12:41 +03:00
}
resolve ( )
} catch ( e ) {
if ( e . cmd ) {
const cmd = e . cmd . substr ( 0 , e . cmd . indexOf ( ' ' ) )
2022-09-26 16:29:56 +03:00
LogHelper . error (
2022-09-03 14:12:41 +03:00
` The following command has failed: " ${ e . cmd } ". " ${ cmd } " is maybe missing. To continue this setup, please install the required tool. More details about the failure: ${ e } `
)
} else {
2022-09-26 16:29:56 +03:00
LogHelper . error ( ` Failed to prepare the environment: ${ e } ` )
2022-09-03 14:12:41 +03:00
}
reject ( e )
2019-02-10 15:26:50 +03:00
}
}
2022-09-03 14:12:41 +03:00
} )