1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-12-24 09:12:20 +03:00
leon/scripts/check-os.js

60 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-02-10 15:26:50 +03:00
import execa from 'execa'
import { LogHelper } from '@/helpers/log-helper'
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) => {
LogHelper.info('Checking OS environment...')
2022-09-03 14:12:41 +03:00
const info = SystemHelper.getInformation()
2022-09-03 14:12:41 +03:00
if (info.type === 'windows') {
LogHelper.error('Voice offline mode is not available on Windows')
2022-09-03 14:12:41 +03:00
reject()
} else if (info.type === 'unknown') {
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 {
LogHelper.success(`You are running ${info.name}`)
LogHelper.info('Checking tools...')
2022-09-03 14:12:41 +03:00
await execa('tar', ['--version'])
LogHelper.success('"tar" found')
2022-09-03 14:12:41 +03:00
await execa('make', ['--version'])
LogHelper.success('"make" found')
2022-09-03 14:12:41 +03:00
if (info.type === 'macos') {
await execa('brew', ['--version'])
LogHelper.success('"brew" found')
2022-09-03 14:12:41 +03:00
await execa('curl', ['--version'])
LogHelper.success('"curl" found')
2022-09-03 14:12:41 +03:00
} else if (info.type === 'linux') {
await execa('apt-get', ['--version'])
LogHelper.success('"apt-get" found')
2022-09-03 14:12:41 +03:00
await execa('wget', ['--version'])
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(' '))
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 {
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
})