feat: Improved the nodejs installer, added an example
This commit is contained in:
7
examples/installers/nodejs.vsh
Executable file
7
examples/installers/nodejs.vsh
Executable file
@@ -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()!
|
||||
@@ -9,4 +9,3 @@
|
||||
build: false
|
||||
startupmanager: false
|
||||
supported_platforms: ""
|
||||
|
||||
|
||||
@@ -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')
|
||||
// }
|
||||
// }
|
||||
@@ -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.')
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user