diff --git a/examples/installers/nodejs.vsh b/examples/installers/nodejs.vsh new file mode 100755 index 00000000..3c33017a --- /dev/null +++ b/examples/installers/nodejs.vsh @@ -0,0 +1,7 @@ +#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run + +import freeflowuniverse.herolib.installers.lang.nodejs + +mut nodejs_installer := nodejs.get()! +// nodejs_installer.install()! +nodejs_installer.destroy()! diff --git a/lib/installers/lang/nodejs/.heroscript b/lib/installers/lang/nodejs/.heroscript index 78c781fc..655603a1 100644 --- a/lib/installers/lang/nodejs/.heroscript +++ b/lib/installers/lang/nodejs/.heroscript @@ -9,4 +9,3 @@ build: false startupmanager: false supported_platforms: "" - diff --git a/lib/installers/lang/nodejs/nodejs.v b/lib/installers/lang/nodejs/nodejs.v deleted file mode 100644 index 07530b75..00000000 --- a/lib/installers/lang/nodejs/nodejs.v +++ /dev/null @@ -1,22 +0,0 @@ -module nodejs - -import freeflowuniverse.herolib.osal -// import freeflowuniverse.herolib.ui.console -// import freeflowuniverse.herolib.core.texttools -// import freeflowuniverse.herolib.installers.base - -// @[params] -// pub struct InstallArgs { -// pub mut: -// reset bool -// } - -// pub fn install_(args_ InstallArgs) ! { -// _ := args_ -// pl := core.platform()! -// if pl == .arch { -// osal.package_install('npm')! -// } else { -// return error('only support arch for now') -// } -// } diff --git a/lib/installers/lang/nodejs/nodejs_actions.v b/lib/installers/lang/nodejs/nodejs_actions.v index 55898a7f..b746b9e6 100644 --- a/lib/installers/lang/nodejs/nodejs_actions.v +++ b/lib/installers/lang/nodejs/nodejs_actions.v @@ -1,28 +1,18 @@ module nodejs -import freeflowuniverse.herolib.osal import freeflowuniverse.herolib.ui.console -import freeflowuniverse.herolib.core.texttools -import freeflowuniverse.herolib.core.pathlib import freeflowuniverse.herolib.installers.ulist -import freeflowuniverse.herolib.installers.base import os //////////////////// following actions are not specific to instance of the object -fn installed_() !bool { - res := os.execute('pnpm -v') +// checks if a certain version or above is installed +fn installed() !bool { + res := os.execute('node -v') if res.exit_code != 0 { return false } - r := res.output.split_into_lines().filter(it.trim_space().len > 0) - if r.len != 1 { - return error("couldn't parse pnpm version.\n${res.output}") - } - if texttools.version(r[0]) >= texttools.version(version) { - return true - } - return false + return true } // get the Upload List of the files @@ -32,38 +22,19 @@ fn ulist_get() !ulist.UList { } // uploads to S3 server if configured -fn upload_() ! { +fn upload() ! {} + +fn install() ! { + console.print_header('Installing Node.js...') + os.execute('curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -') + os.execute('sudo apt install -y nodejs') + console.print_header('Node.js installation complete.') } -fn install_() ! { - console.print_header('install nodejs') - osal.package_install('pnpm')! -} - -fn destroy_() ! { - // mut systemdfactory := systemd.new()! - // systemdfactory.destroy("zinit")! - - // osal.process_kill_recursive(name:'zinit')! - // osal.cmd_delete('zinit')! - - osal.package_remove(' - pnpm - ')! - - // //will remove all paths where go/bin is found - // osal.profile_path_add_remove(paths2delete:"go/bin")! - - // osal.rm(" - // podman - // conmon - // buildah - // skopeo - // runc - // /var/lib/containers - // /var/lib/podman - // /var/lib/buildah - // /tmp/podman - // /tmp/conmon - // ")! +fn destroy() ! { + console.print_header('Uninstalling Node.js and NVM...') + os.execute('sudo apt remove -y nodejs') + os.execute('sudo apt autoremove -y') + os.rm('~/.nvm') or {} + console.print_header('Node.js and NVM have been uninstalled.') } diff --git a/lib/installers/lang/nodejs/nodejs_factory_.v b/lib/installers/lang/nodejs/nodejs_factory_.v index 89e1f052..a8951515 100644 --- a/lib/installers/lang/nodejs/nodejs_factory_.v +++ b/lib/installers/lang/nodejs/nodejs_factory_.v @@ -1,12 +1,9 @@ module nodejs -import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console -import freeflowuniverse.herolib.data.paramsparser import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit -import time __global ( nodejs_global map[string]&NodeJS @@ -45,11 +42,11 @@ pub fn play(args_ PlayArgs) ! { reset := p.get_default_false('reset') if other_action.name == 'destroy' || reset { console.print_debug('install action nodejs.destroy') - // destroy()! + destroy()! } if other_action.name == 'install' { console.print_debug('install action nodejs.install') - // install()! + install()! } } } @@ -89,14 +86,14 @@ pub mut: pub fn (mut self NodeJS) install(args InstallArgs) ! { switch(self.name) - // if args.reset || (!installed()!) { - // install()! - // } + if args.reset || (!installed()!) { + install()! + } } pub fn (mut self NodeJS) destroy() ! { switch(self.name) - // destroy()! + destroy()! } // switch instance to be used for nodejs diff --git a/lib/installers/lang/nodejs/nodejs_model.v b/lib/installers/lang/nodejs/nodejs_model.v index e9fbd94e..e01acd6a 100644 --- a/lib/installers/lang/nodejs/nodejs_model.v +++ b/lib/installers/lang/nodejs/nodejs_model.v @@ -1,27 +1,33 @@ module nodejs -import freeflowuniverse.herolib.data.paramsparser -import os +import freeflowuniverse.herolib.data.encoderhero pub const version = '9.15.2' const singleton = true const default = true -// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED @[heap] pub struct NodeJS { pub mut: name string = 'default' } -fn obj_init(obj_ NodeJS) !NodeJS { - // never call get here, only thing we can do here is work on object itself - mut obj := obj_ - panic('implement') - return obj +// your checking & initialization code if needed +fn obj_init(mycfg_ NodeJS) !NodeJS { + mut mycfg := mycfg_ + return mycfg } // called before start if done fn configure() ! { // mut installer := get()! } + +pub fn heroscript_dumps(obj NodeJS) !string { + return encoderhero.encode[NodeJS](obj)! +} + +pub fn heroscript_loads(heroscript string) !NodeJS { + mut obj := encoderhero.decode[NodeJS](heroscript)! + return obj +}