This commit is contained in:
2025-02-10 13:21:57 +03:00
parent e997946c56
commit abe81190e6
10 changed files with 31 additions and 48 deletions

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env -S v -w -n -enable-globals run #!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.baobab.generator import freeflowuniverse.herolib.baobab.generator
import freeflowuniverse.herolib.baobab.specification import freeflowuniverse.herolib.baobab.specification

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env -S v -w -n -enable-globals run #!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.baobab.generator import freeflowuniverse.herolib.baobab.generator
import freeflowuniverse.herolib.baobab.specification import freeflowuniverse.herolib.baobab.specification

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env -S v -w -n -enable-globals run #!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.baobab.generator import freeflowuniverse.herolib.baobab.generator
import freeflowuniverse.herolib.baobab.specification import freeflowuniverse.herolib.baobab.specification

View File

@@ -1,2 +1,3 @@
methods.v methods.v
meeting_scheduler_actor meeting_scheduler_actor
generate_actor_module

View File

@@ -1,26 +1,30 @@
#!/usr/bin/env -S v -w -n -enable-globals run #!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.baobab.generator import freeflowuniverse.herolib.baobab.generator
import freeflowuniverse.herolib.baobab.specification import freeflowuniverse.herolib.baobab.specification
import freeflowuniverse.herolib.schemas.openapi import freeflowuniverse.herolib.schemas.openapi
import os import os
const example_dir = os.dir(@FILE) const example_dir = os.dir(@FILE)
const openapi_spec_path = os.join_path(example_dir, 'openapi.json') const openapi_spec_path = os.join_path(example_dir, 'openapi.json')
// the actor specification obtained from the OpenRPC Specification // the actor specification obtained from the OpenRPC Specification
openapi_spec := openapi.new(path: openapi_spec_path)! openapi_spec := openapi.new(path: openapi_spec_path)!
actor_spec := specification.from_openapi(openapi_spec)! actor_spec := specification.from_openapi(openapi_spec)!
println(actor_spec)
actor_module := generator.generate_actor_module( actor_module := generator.generate_actor_module(
actor_spec, actor_spec,
interfaces: [.openapi, .http] interfaces: [.openapi, .http]
)! )!
actor_module.write(example_dir, actor_module.write(example_dir,
format: true format: false
overwrite: true overwrite: true
compile: true compile: false
)! )!
os.execvp('bash', ['${example_dir}/meeting_scheduler_actor/scripts/run.sh'])! os.execvp('bash', ['${example_dir}/meeting_scheduler_actor/scripts/run.sh'])!

View File

@@ -1,33 +0,0 @@
import os
import freeflowuniverse.herolib.baobab.stage {IActor, RunParams}
import freeflowuniverse.herolib.schemas.openapi
const openapi_spec_path = '@{dollar}{os.dir(@@FILE)}/specs/openapi.json'
const openapi_spec_json = os.read_file(openapi_spec_path) or { panic(err) }
const openapi_specification = openapi.json_decode(openapi_spec_json)!
struct @{actor_name_pascal}Actor {
stage.Actor
}
fn new() !@{actor_name_pascal}Actor {
return @{actor_name_pascal}Actor {
stage.new_actor('@{actor_name_snake}')
}
}
pub fn run() ! {
mut a_ := new()!
mut a := IActor(a_)
a.run()!
}
pub fn run_server(params RunParams) ! {
mut a := new()!
mut server := actor.new_server(
redis_url: 'localhost:6379'
redis_queue: a.name
openapi_spec: openapi_specification
)!
server.run(params)
}

View File

@@ -2,6 +2,7 @@ import os
import freeflowuniverse.herolib.baobab.stage import freeflowuniverse.herolib.baobab.stage
import freeflowuniverse.herolib.core.redisclient import freeflowuniverse.herolib.core.redisclient
import freeflowuniverse.herolib.schemas.openapi import freeflowuniverse.herolib.schemas.openapi
import time
const name = '@{actor_name_snake}' const name = '@{actor_name_snake}'

View File

@@ -1,14 +1,14 @@
#!/bin/bash #!/bin/bash -ex
DIR="@{dollar}(cd "@{dollar}(dirname "@{dollar}{BASH_SOURCE[0]}")" && pwd)" DIR="@{dollar}(cd "@{dollar}(dirname "@{dollar}{BASH_SOURCE[0]}")" && pwd)"
echo "@{dollar}DIR" echo "@{dollar}DIR"
chmod +x @{dollar}{DIR}/run_actor.vsh chmod +x @{dollar}{DIR}/run_actor.vsh
@{dollar}{DIR}/run_actor.vsh > /dev/null 2>&1 & @{dollar}{DIR}/run_actor.vsh &
ACTOR_PID=@{dollar}! ACTOR_PID=@{dollar}!
chmod +x @{dollar}{DIR}/run_http_server.vsh chmod +x @{dollar}{DIR}/run_http_server.vsh
@{dollar}{DIR}/run_http_server.vsh > /dev/null 2>&1 & @{dollar}{DIR}/run_http_server.vsh &
HTTP_SERVER_PID=@{dollar}! HTTP_SERVER_PID=@{dollar}!
# Print desired output # Print desired output

View File

@@ -5,6 +5,7 @@ import os
pub interface IFile { pub interface IFile {
write(string, WriteOptions) ! write(string, WriteOptions) !
name string
} }
pub struct File { pub struct File {
@@ -23,8 +24,7 @@ pub fn (f File) write(path string, params WriteOptions) ! {
} }
pub fn (f File) typescript(path string, params WriteOptions) ! { pub fn (f File) typescript(path string, params WriteOptions) ! {
format := true if params.format {
if format {
os.execute('npx prettier --write ${path}') os.execute('npx prettier --write ${path}')
} }
} }

View File

@@ -1,5 +1,5 @@
module code module code
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.pathlib import freeflowuniverse.herolib.core.pathlib
import os import os
import log import log
@@ -35,38 +35,48 @@ pub fn (mod Module) write(path string, options WriteOptions) ! {
path: if mod.in_src { '${path}/${mod.name}/src' } else { '${path}/${mod.name}' } path: if mod.in_src { '${path}/${mod.name}/src' } else { '${path}/${mod.name}' }
empty: options.overwrite empty: options.overwrite
)! )!
console.print_debug("write ${module_dir.path}")
// pre:="v -n -w -enable-globals"
pre:="v -n -w -gc none -cc tcc -d use_openssl -enable-globals run"
if !options.overwrite && module_dir.exists() { if !options.overwrite && module_dir.exists() {
return return
} }
for file in mod.files { for file in mod.files {
console.print_debug("mod file write ${file.name}")
file.write(module_dir.path, options)! file.write(module_dir.path, options)!
} }
for folder in mod.folders { for folder in mod.folders {
console.print_debug("mod folder write ${folder.name}")
folder.write('${path}/${mod.name}', options)! folder.write('${path}/${mod.name}', options)!
} }
for mod_ in mod.modules { for mod_ in mod.modules {
console.print_debug("mod write ${mod_.name}")
mod_.write('${path}/${mod.name}', options)! mod_.write('${path}/${mod.name}', options)!
} }
if options.format { if options.format {
console.print_debug("format ${module_dir.path}")
os.execute('v fmt -w ${module_dir.path}') os.execute('v fmt -w ${module_dir.path}')
} }
if options.compile { if options.compile {
os.execute_opt('v -n -w -enable-globals -shared ${module_dir.path}') or { console.print_debug("compile shared ${module_dir.path}")
os.execute_opt('${pre} -shared ${module_dir.path}') or {
log.fatal(err.msg()) log.fatal(err.msg())
} }
} }
if options.test { if options.test {
os.execute_opt('v -n -w -enable-globals test ${module_dir.path}') or { console.print_debug("test ${module_dir.path}")
os.execute_opt('${pre} test ${module_dir.path}') or {
log.fatal(err.msg()) log.fatal(err.msg())
} }
} }
if options.document { if options.document {
docs_path := '${path}/${mod.name}/docs' docs_path := '${path}/${mod.name}/docs'
console.print_debug("document ${module_dir.path}")
os.execute('v doc -f html -o ${docs_path} ${module_dir.path}') os.execute('v doc -f html -o ${docs_path} ${module_dir.path}')
} }