apiVersion: 1.0.0

metadata:
  name: crwctl-dev

projects:

  - name: crwctl
    source:
      type: git
      location: 'https://github.com/redhat-developer/codeready-workspaces-chectl.git'

components:

  - alias: dev
    type: dockerimage
    image: quay.io/crw/theia-dev-rhel8:2.1
    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/crwctl

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

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

  - name: Generate Devfile
    actions:
      - type: exec
        component: dev
        command: >
                 ./run devfile:generate \
                     --name=crwctl-test \
                     --language=typescript \
                     --dockerimage=quay.io/crw/theia-dev-rhel8:2.1 \
                     --git-repo=https://github.com/redhat-developer/codeready-workspaces-chectl.git \
                     --command="yarn" > /projects/sample.devfile;
                  cat /projects/sample.devfile
        workdir: /projects/crwctl/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/crwctl/bin

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

  - name: Format Sources
    actions:
      - type: exec
        component: dev
        command: >
                 yarn format
        workdir: /projects/crwctl

        - 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
