[buildout]
extends =
  ../java-jdk/buildout.cfg
  ../libsecret/buildout.cfg
  ../pkgconfig/buildout.cfg
  ../patchelf/buildout.cfg
  ../python3/buildout.cfg
  ../yarn/buildout.cfg
  download-plugins.cfg
  buildout.hash.cfg


[preloadTemplate.html]
recipe = slapos.recipe.build:download
shared = true
url = ${:_profile_base_location_}/${:_buildout_section_name_}

[yarn.lock]
recipe = slapos.recipe.build:download
shared = true
url = ${:_profile_base_location_}/${:_buildout_section_name_}

[theia]
recipe = slapos.recipe.cmmi
shared = true
path = ${yarn.lock:location}
# To regenerate yarn.lock, use package.json instead
# path = ${package.json:location}
environment =
  TMPDIR=@@LOCATION@@/tmp
  PATH=${nodejs:location}/bin:${pkgconfig:location}/bin:${python3:location}/bin:%(PATH)s
  PKG_CONFIG_PATH=${libsecret:pkg-config-path}
  LDFLAGS=-Wl,-rpath=${libsecret:location}/lib -L${gettext:location}/lib -Wl,-rpath=${gettext:location}/lib -Wl,-rpath=${glib:location}/lib
pre-configure =
  mkdir -p $TMPDIR
  echo '${package.json:content}' > %(location)s/package.json
  # To regenerate yarn.lock, comment the line below
  cp yarn.lock %(location)s
configure-command = true
make-binary = cd %(location)s && ${yarn:location}/bin/yarn
make-targets = theia build
post-install =
  # On Debian 9 the -rpath are not taken into account by yarn build for unknown reasons
  cd %(location)s/node_modules/keytar/build/Release
  ${patchelf:location}/bin/patchelf --set-rpath \
    ${libsecret:location}/lib:${gettext:location}/lib:${glib:location}/lib \
    keytar.node

[theia-wrapper]
recipe = slapos.recipe.template
output = ${buildout:bin-directory}/${:_buildout_section_name_}
inline =
  #!/bin/sh
  cd ${theia:location}
  exec ${yarn:location}/bin/yarn theia start "$@"

[theia-open]
recipe = slapos.recipe.template
output = ${buildout:bin-directory}/${:_buildout_section_name_}
inline =
  #!/bin/sh
  exec ${nodejs:location}/bin/node ${theia:location}/node_modules/.bin/theia-open "$@"

[theia-plugins]
recipe = slapos.recipe.build
urls = ${theia-download-plugins:urls}
install =
  import os
  for line in options['urls'].splitlines():
    extension_name, url, md5sum = line.split()
    extract_dir = self.extract(self.download(url, md5sum))
    destination_dir = os.path.join(options['location'], extension_name)
    self.copyTree(guessworkdir(extract_dir), destination_dir)
    os.chmod(destination_dir, 0o750)

[package.json]
content =
  {
      "private": true,
      "theia": {
          "backend": {
              "config": {
                  "warnOnPotentiallyInsecureHostPattern": false
              }
          },
          "frontend": {
              "config": {
                  "applicationName": "Theia SlapOS",
                  "preferences": {
                      "application.confirmExit": "always",
                      "files.associations": {
                          "*.cfg": "zc-buildout"
                      },
                      "files.enableTrash": false,
                      "files.exclude": {
                          "**.pyc": true,
                          "**.egg-info": true,
                          "__pycache__": true,
                          ".git": true,
                          ".env": true,
                          "**/node_modules/**": true
                      },
                      "files.watcherExclude": {
                          "**/.eggs/**": true,
                          "**/.env/**": true,
                          "**/.git/**": true,
                          "**/node_modules/**": true
                      },
                      "editor.multiCursorModifier": "ctrlCmd",
                      "editor.tabSize": 2,
                      "plantuml.server": "https://plantuml.host.vifib.net/svg/",
                      "plantuml.render": "PlantUMLServer",
                      "gitlens.remotes": [{ "domain": "lab.nexedi.com", "type": "GitLab" }],
                      "java.home": "${java-jdk:location}"
                  },
                  "warnOnPotentiallyInsecureHostPattern": false
              }
          },
          "generator": {
              "config": {
                  "preloadTemplate": "${preloadTemplate.html:target}"
              }
          }
      },
      "dependencies": {
          "@theia/bulk-edit": "latest",
          "@theia/callhierarchy": "latest",
          "@theia/console": "latest",
          "@theia/core": "latest",
          "@theia/debug": "latest",
          "@theia/editor": "latest",
          "@theia/editor-preview": "latest",
          "@theia/file-search": "latest",
          "@theia/filesystem": "latest",
          "@theia/getting-started": "latest",
          "@theia/keymaps": "latest",
          "@theia/markers": "latest",
          "@theia/messages": "latest",
          "@theia/metrics": "latest",
          "@theia/mini-browser": "latest",
          "@theia/monaco": "latest",
          "@theia/navigator": "latest",
          "@theia/outline-view": "latest",
          "@theia/output": "latest",
          "@theia/plugin-dev": "latest",
          "@theia/plugin-ext": "latest",
          "@theia/plugin-ext-vscode": "latest",
          "@theia/preferences": "latest",
          "@theia/preview": "latest",
          "@theia/process": "latest",
          "@theia/property-view": "latest",
          "@theia/scm": "latest",
          "@theia/scm-extra": "latest",
          "@theia/search-in-workspace": "latest",
          "@theia/task": "latest",
          "@theia/terminal": "latest",
          "@theia/timeline": "latest",
          "@theia/typehierarchy": "latest",
          "@theia/userstorage": "latest",
          "@theia/variable-resolver": "latest",
          "@theia/vsx-registry": "latest",
          "@theia/workspace": "latest",
          "@perrinjerome/theia-open": "latest",
          "@perrinjerome/theia-open-cli": "latest"
      },
      "devDependencies": {
          "@theia/cli": "latest"
      }
  }
