[buildout]
extends =
   ../../component/python3/buildout.cfg
   ../../component/python-2.7/buildout.cfg
   ../../component/nodejs/buildout.cfg
   ../../component/caddy/buildout.cfg
   ../../component/git/buildout.cfg
   ../../component/bash/buildout.cfg
   ../../component/coreutils/buildout.cfg
   ../../stack/slapos.cfg
   ../../stack/monitor/buildout.cfg
   ./gowork.cfg
   ./buildout.hash.cfg
# this gowork.cfg includes the one from caddy, because they share the only gowork
# workspace (not intentionnaly, as far as I see there's only one gowork per SR)
# it is included after caddy, otherwise only caddy is installed. The problem of this
# approach is that caddy's version will be the one pinned here, so we have to update
# here as well.

parts =
  theia-wrapper
  slapos-cookbook
  instance


[nodejs]
<= nodejs-10.6.0

[python3]
<= python3.6.6


[yarn]
# this could become a component, but it needs to be invoked from nodejs explicitly,
# otherwise it uses system's nodejs
# XXX why don't we build a wrapper ?
version = 1.17.3
recipe = slapos.recipe.build:download-unpacked
url = https://github.com/yarnpkg/yarn/releases/download/v${:version}/yarn-v${:version}.tar.gz
md5sum = 4a02e1687a150113ad6b0215f9afdb3e


[python-language-server]
version = 0.19.0
recipe = plone.recipe.command
command =
  bash -c "${python3:executable} -m venv ${:location} && \
    . ${:location}/bin/activate && \
    pip install -r ${python-language-server-requirements.txt:output}"
location = ${buildout:parts-directory}/${:_buildout_section_name_}
stop-on-error = true

[python-language-server-requirements.txt]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/${:filename}
output = ${buildout:parts-directory}/${:_buildout_section_name_}
mode = 0644


[theia]
recipe = plone.recipe.command
command = ${bash:location}/bin/bash -c "
  export PATH=${nodejs:location}/bin/:${python2.7:location}/bin/:$PATH &&
  mkdir -p ${:location} && \
  cd ${:location} && \
  cp ${package.json:rendered} . &&
  cp ${yarn.lock:output} . &&
  ${yarn:location}/bin/yarn && \
  ${yarn:location}/bin/yarn theia build"
location = ${buildout:parts-directory}/${:_buildout_section_name_}
stop-on-error = true
uses = ${yarn.lock:recipe}

[yarn.lock]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/${:filename}
output = ${buildout:parts-directory}/${:_buildout_section_name_}
mode = 0644

[package.json]
recipe = slapos.recipe.template:jinja2
# this comes from https://github.com/theia-ide/theia-apps/blob/def6d29a5fb3739aebc17c6a5b67f1b5c16caacd/theia-full-docker/next.package.json
# but "@theia/php": "next" was removed, because we don't have php/composer component so installation failed
template =
  inline:
    {
      "private": true,
      "theia": {
          "frontend": {
              "config": {
                  "applicationName": "Theia SlapOS",
                  "preferences": {
                      "files.enableTrash": false,
                      "files.exclude": {
                          "**.pyc": true,
                          "**.egg-info": true,
                          "__pycache__": true,
                          ".git": true,
                          ".env": true
                      },
                      "files.watcherExclude": {
                        "**/.eggs/**": true,
                        "**/.env/**": true,
                        "**/.git/**": true,
                        "**/node_modules/**": true
                      },
                      "editor.multiCursorModifier": "ctrlCmd",
                      "plantuml.webservice": "//plantuml.host.vifib.net/svg/",
                      "plantuml.monochrome": false,
                      "editor.tabSize": 2
                  }
              }
          }
      },
      "dependencies": {
          "@theia/callhierarchy": "next",
          "@theia/core": "next",
          "@theia/cpp": "next",
          "@theia/debug": "next",
          "@theia/debug-nodejs": "next",
          "@theia/docker": "next",
          "@theia/editor": "next",
          "@theia/editorconfig": "next",
          "@theia/editor-preview": "next",
          "@theia/file-search": "next",
          "@theia/filesystem": "next",
          "@theia/git": "next",
          "@theia/go": "next",
          "@theia/getting-started": "next",
          "@theia/java": "next",
          "@theia/json": "next",
          "@theia/keymaps": "next",
          "@theia/languages": "next",
          "@theia/markers": "next",
          "@theia/merge-conflicts": "next",
          "@theia/messages": "next",
          "@theia/metrics": "next",
          "@theia/mini-browser": "next",
          "@theia/monaco": "next",
          "@theia/navigator": "next",
          "@theia/outline-view": "next",
          "@theia/output": "next",
          "@theia/plantuml": "next",
          "@theia/plugin": "next",
          "@theia/plugin-ext": "next",
          "@theia/plugin-ext-vscode": "next",
          "@theia/preferences": "next",
          "@theia/preview": "next",
          "@theia/process": "next",
          "@theia/ruby": "next",
          "@theia/rust": "next",
          "@theia/search-in-workspace": "next",
          "@theia/task": "next",
          "@theia/terminal": "next",
          "@theia/textmate-grammars": "next",
          "@theia/tslint": "next",
          "@theia/typescript": "next",
          "@theia/userstorage": "next",
          "@theia/variable-resolver": "next",
          "@theia/workspace": "next",
          "theia-yang-extension": "next",
          "typescript": "latest"
      },
      "devDependencies": {
          "@theia/cli": "next"
      }
  }
rendered = ${buildout:directory}/${:_buildout_section_name_}
mode = 0644


[gowork]
# Install go-language-server in workspace
# Note that this is the same workspace as caddy.
# install list comes from https://github.com/theia-ide/go-language-server/blob/d259749c8f263c4d845055833b03b1d2dbefa5b3/README.md#prerequisites
install +=
  github.com/ramya-rao-a/go-outline
  github.com/acroca/go-symbols
  github.com/nsf/gocode
  github.com/rogpeppe/godef
  golang.org/x/tools/cmd/godoc
  github.com/zmb3/gogetdoc
  golang.org/x/lint/golint
  github.com/fatih/gomodifytags
  github.com/uudashr/gopkgs/cmd/gopkgs
  golang.org/x/tools/cmd/gorename
  sourcegraph.com/sqs/goreturns
  github.com/cweill/gotests/...
  golang.org/x/tools/cmd/guru
  github.com/josharian/impl
  github.com/haya14busa/goplay/cmd/goplay
  github.com/davidrjenni/reftools/cmd/fillstruct


[theia-wrapper]
recipe = slapos.recipe.template:jinja2
rendered = ${buildout:bin-directory}/${:_buildout_section_name_}
mode = 0777
template =
  inline:
  #!/bin/bash
  export PATH=${nodejs:location}/bin/:${python-language-server:location}/bin/:${bash:location}/bin/:${git:location}/bin/:$PATH
  . ${gowork:env.sh}
  export SHELL=bash
  # reset PS1 from gowork
  export PS1='$ '
  cd ${theia:location}
  exec ${yarn:location}/bin/yarn theia start $@


[instance]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/${:filename}
mode = 0644
output = ${buildout:directory}/instance.cfg

[versions]
slapos.recipe.template = 4.3
