#
# Copyright (c) 2019-2022 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
#   Red Hat, Inc. - initial API and implementation
#

apiVersion: 1.0.0

metadata:
  name: dsc-dev

projects:

  - name: dsc
    source:
      type: git
      location: 'https://github.com/redhat-developer/devspaces-chectl.git'

components:

  - alias: dev
    type: dockerimage
    image: quay.io/devspaces/theia-dev-rhel8:next
    mountSources: true
    memoryLimit: 1G

  - id: redhat/vscode-yaml/latest
    type: chePlugin
    memoryLimit: 128M

  - id: che-incubator/typescript/latest
    type: chePlugin
    memoryLimit: 1G

commands:

  - name: Build
    actions:
      - type: exec
        component: dev
        command: >
                 yarn
        workdir: /projects/dsc

  - name: Test
    actions:
      - type: exec
        component: dev
        command: >
                 yarn test
        workdir: /projects/dsc

  - name: Run
    actions:
      - type: exec
        component: dev
        command: >
                 ./run --help
        workdir: /projects/dsc/bin

  - name: Generate Devfile
    actions:
      - type: exec
        component: dev
        command: >
                 ./run devfile:generate \
                     --name=dsc-test \
                     --language=typescript \
                     --dockerimage=quay.io/devspaces/theia-dev-rhel8:next \
                     --git-repo=https://github.com/redhat-developer/devspaces-chectl.git \
                     --command="yarn" > /projects/sample.devfile;
                  cat /projects/sample.devfile
        workdir: /projects/dsc/bin

  - name: Create Workspace
    actions:
      - type: exec
        component: dev
        command: >
                 cat /projects/sample.devfile | curl -F 'clbin=<-' https://clbin.com > /projects/clbin;
                 uri=$(cat /projects/clbin); ./run workspace:start -f=$uri
        workdir: /projects/dsc/bin

  - name: Package Binaries
    actions:
      - type: exec
        component: dev
        command: >
                 yarn pack-binaries
        workdir: /projects/dsc

  - name: Format Sources
    actions:
      - type: exec
        component: dev
        command: >
                 yarn format
        workdir: /projects/dsc
  - name: Attach remote debugger
    actions:
      - referenceContent: |
          {
            "version": "0.2.0",
            "configurations": [
              {
                "type": "node",
                "request": "attach",
                "name": "Attach to Remote",
                "address": "localhost",
                "port": 9229,
                "localRoot": "${workspaceFolder}",
                "remoteRoot": "${workspaceFolder}"
              }
            ]
          }
        type: vscode-launch
