Files
herolib/lib/installers/lang/herolib/herolib.v
Mahmoud-Emad f5c2b306b8 test: Update test and script URL
- Remove frontmatter test due to disabled parsing
- Update install script URL
2025-11-17 15:23:08 +02:00

123 lines
3.4 KiB
V

module herolib
import incubaid.herolib.osal.core as osal
import incubaid.herolib.ui.console
import incubaid.herolib.installers.base
import incubaid.herolib.installers.lang.vlang
import incubaid.herolib.core.pathlib
import incubaid.herolib.develop.gittools
import os
// install herolib will return true if it was already installed
@[params]
pub struct InstallArgs {
pub mut:
git_pull bool
git_reset bool
reset bool // means reinstall
}
fn install0(args InstallArgs) ! {
// install herolib if it was already done will return true
console.print_header('install herolib (reset: ${args.reset})')
// osal.package_refresh()!
if args.reset {
osal.done_reset()!
}
base.develop()!
vlang.install(reset: args.reset)!
// vlang.v_analyzer_install(reset: args.reset)!
mut gs := gittools.new()!
gs.config()!.light = true // means we clone depth 1
mut repo := gs.get_repo(
pull: args.git_pull
reset: args.git_reset
url: 'https://github.com/incubaid/herolib/tree/development/lib'
)!
// mut repo2 := gs.get_repo(
// pull: args.git_pull
// reset: args.git_reset
// url: 'https://github.com/incubaid/webcomponents/tree/main/webcomponents'
// )!
mut path1 := repo.path()
// mut path2 := repo2.get_path()!
mut path1p := pathlib.get_dir(path: path1, create: false)!
// mut path2p := pathlib.get_dir(path: path2, create: false)!
path1p.link('${os.home_dir()}/.vmodules/incubaid/herolib', true)!
// path2p.link('${os.home_dir()}/.vmodules/incubaid/webcomponents', true)!
// hero_compile()!
osal.done_set('install_herolib', 'OK')!
return
}
// remove hero, crystal, ...
pub fn uninstall() ! {
console.print_debug('uninstall hero & herolib')
cmd := '
rm -rf ${os.home_dir()}/hero
rm -rf ${os.home_dir()}/_code
rm -f /usr/local/bin/hero
rm -f /tmp/hero
rm -f /tmp/install*
rm -f /tmp/build_hero*
rm -rf /tmp/execscripts
'
osal.execute_stdout(cmd) or { return error('Cannot uninstall herolib/hero.\n${err}') }
}
pub fn install(args InstallArgs) ! {
if args.reset == false && osal.done_exists('install_hero') {
console.print_debug('hero already installed')
return
}
console.print_header('install hero')
base.install()!
cmd := '
cd /tmp
export TERM=xterm
curl https://raw.githubusercontent.com/incubaid/herolib/refs/heads/development/scripts/install_hero.sh | bash
'
osal.execute_stdout(cmd) or { return error('Cannot install hero.\n${err}') }
osal.done_set('install_hero', 'OK')!
return
}
pub fn compile(args InstallArgs) ! {
if args.reset == false && osal.done_exists('compile_hero') {
console.print_debug('hero already compiled')
return
}
console.print_header('compile hero')
install(args)!
cmd := "
cd /tmp
export TERM=xterm
curl 'https://raw.githubusercontent.com/incubaid/herolib/refs/heads/development/scripts/install_v.sh' > /tmp/install_v.sh
bash /tmp/install_v.sh --herolib
"
osal.execute_stdout(cmd) or { return error('Cannot install hero.\n${err}') }
osal.done_set('install_hero', 'OK')!
return
}
// pub fn update() ! {
// console.print_header('package_install update herolib')
// if !(i.state == .reset) && osal.done_exists('install_crystaltools') {
// console.print_debug(' package_install was already done')
// return
// }
// osal.execute_silent('cd /tmp && export TERM=xterm && source /root/env.sh && ct_upgrade') or {
// return error('Cannot update crystal tools.\n${err}')
// }
// osal.done_set('update_crystaltools', 'OK')!
// }