[buildout]
extends =
  ../libsecret/buildout.cfg
  ../pkgconfig/buildout.cfg
  ../patchelf/buildout.cfg
  ../python3/buildout.cfg
  ../tar/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_}

[vscode-uri]
recipe = slapos.recipe.build:download
shared = true
revision = c45342deb98de5c7b391bd2c08431b536b869a04
url = https://github.com/xavth/vscode-uri/archive/${:revision}.tar.gz
md5sum = 877accd4e29d2293ce33815803d998cc

[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:location}/lib/pkgconfig:${libsecret:pkg_config_depends}
  LDFLAGS=-Wl,-rpath=${libsecret:location}/lib -L${gettext:location}/lib -Wl,-rpath=${gettext:location}/lib -Wl,-rpath=${glib:location}/lib
  NODE_OPTIONS=--max_old_space_size=4096
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
  # Workaround https://github.com/microsoft/vscode/issues/154048
  # Once upstream is fixed:
  # - remove [vscode-uri] section
  # - remove the commands below
  # - remove component/tar/buildout.cfg
  # - remove the "resolution" field in package.json
  # - regenerate yarn.lock
  cd %(location)s
  ${tar:location}/bin/tar -xzf ${vscode-uri:target}
  mv vscode-uri-${vscode-uri:revision} vscode-uri
  cd vscode-uri
  ${yarn:location}/bin/yarn
  ${yarn:location}/bin/yarn install
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
  # remove some binaries using musl that are confusing check software
  # and anyway not used once the software is installed
  rm -f %(location)s/node_modules/@msgpackr-extract/*/*.node
  rm -rf $HOME/.cache/yarn/
  # remove "which" command added in $PATH that does not correctly
  # handle executables thanks to a secondary group of the user.
  # https://www.npmjs.com/package/which https://www.npmjs.com/package/isexe
  rm -f %(location)s/node_modules/.bin/which

[theia-wrapper]
recipe = slapos.recipe.template
output = ${buildout:bin-directory}/${:_buildout_section_name_}
inline =
  #!/bin/sh
  cd ${theia:location}
  exec ${nodejs:location}/bin/node ${theia:location}/node_modules/.bin/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)
    patches = options.get(extension_name + '-patches')
    if patches:
      self.applyPatchList(
        patches,
        patch_options=options.get(extension_name + '-patch-options', '-p1'),
        patch_binary=options['patch-binary'],
        cwd=destination_dir,
      )
    os.chmod(destination_dir, 0o750)
patch-binary = ${patch:location}/bin/patch
ms-python-python-patches = ${:_profile_base_location_}/${ms-python-disable-jedi-buildout.patch:_update_hash_filename_} ${ms-python-disable-jedi-buildout.patch:md5sum}

[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.tabSize": 2,
                      "plantuml.server": "https://plantuml.host.vifib.net/svg/",
                      "plantuml.render": "PlantUMLServer",
                      "python.defaultInterpreterPath": "${python:executable}",
                      "gitlens.remotes": [{ "domain": "lab.nexedi.com", "type": "GitLab" }]
                  },
                  "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"
      },
      "resolutions": {
          "**/vscode-uri": "file:./vscode-uri"
      },
      "devDependencies": {
          "@theia/cli": "latest"
      }
  }