[buildout]
parts =
  main
  symlink-quickjs-binary
  publish-connection-information

[directory]
recipe = slapos.cookbook:mkdirectory
home = $${buildout:directory}
bin = $${:home}/bin
etc = $${:home}/etc
var = $${:home}/var
log = $${:var}/log

[js-dynamic-template]
recipe = slapos.recipe.template:jinja2
rendered = $${directory:etc}/$${:_buildout_section_name_}.js
template = ${buildout:directory}/$${:_buildout_section_name_}.js
extra-context =
context =
  import json_module json
  raw qjs_wrapper ${qjs-wrapper:location}/lib/libqjswrapper.so
  raw configuration {{ configuration }}
  $${:extra-context}

[main]
<= js-dynamic-template
extra-context =
  key log_dir directory:log
  key pubsub_script pubsub:rendered
  key worker_script worker:rendered

[pubsub]
<= js-dynamic-template

[worker]
<= js-dynamic-template

[symlink-quickjs-binary]
recipe = slapos.recipe.build
binary-path = ${quickjs:location}/bin/qjs
target = $${directory:bin}/qjs
init =
  import os
  if not os.path.exists(options['target']):
    os.symlink(options['binary-path'], options['target'])

[publish-connection-information]
recipe = slapos.cookbook:publish.serialised
instance-path = $${directory:home}
