<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2019 Red Hat, Inc. and/or its affiliates.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.optaweb.employeerostering</groupId>
    <artifactId>optaweb-employee-rostering</artifactId>
    <version>8.4.0.Final</version>
  </parent>

  <artifactId>optaweb-employee-rostering-frontend</artifactId>
  <name>OptaWeb Employee Rostering as a Service React Frontend</name>
  <description>React frontend for Employee Rostering as a Service</description>
  <packaging>pom</packaging>

  <properties>
    <sonar.sources>src</sonar.sources>
    <sonar.exclusions>**/__mocks__/**</sonar.exclusions>
    <sonar.test.inclusions>**/*test.ts,**/*test.tsx</sonar.test.inclusions>
    <sonar.javascript.lcov.reportPaths>coverage/lcov.info</sonar.javascript.lcov.reportPaths>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>install node and npm</id>
            <phase>initialize</phase>
            <goals>
              <goal>install-node-and-npm</goal>
            </goals>
          </execution>
          <execution>
            <id>npm install lock-treatment-tool and run-node</id>
            <phase>initialize</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>install lock-treatment-tool --global-style --no-package-lock --no-save</arguments>
            </configuration>
          </execution>
          <execution>
            <id>lock-treatment-tool execution</id>
            <phase>compile</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run locktt -- </arguments>
            </configuration>
          </execution>
          <execution>
            <id>npm install</id>
            <phase>compile</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>install</arguments>
              <environmentVariables>
                <!--
                  Do not download Cypress binary during `npm install`. It's large (0.5G) and it's only needed locally
                  when running `npm run cypress:run`. When building the project with Maven (e.g. on Jenkins), Cypress
                  tests are executed in a Docker container so the binary downloaded by the npm package is not used.
                 -->
                <CYPRESS_INSTALL_BINARY>0</CYPRESS_INSTALL_BINARY>
              </environmentVariables>
            </configuration>
          </execution>
          <!--
            This is needed to avoid node-sass compilation failure due to missing Node binding
            when Node version used by the frontend plugin is upgraded.
            See https://issues.redhat.com/browse/PLANNER-1751 for details.
          -->
          <execution>
            <id>npm rebuild node-sass</id>
            <phase>compile</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>rebuild node-sass</arguments>
            </configuration>
          </execution>
          <execution>
            <id>npm typecheck</id>
            <phase>compile</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run typecheck</arguments>
            </configuration>
          </execution>
          <execution>
            <id>npm run lint</id>
            <phase>compile</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run lint</arguments>
            </configuration>
          </execution>
          <execution>
            <id>npm test</id>
            <phase>test</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run coverage</arguments>
            </configuration>
          </execution>
          <execution>
            <id>npm run build</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run build</arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <id>package-build</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <descriptors>
                <descriptor>assembly/assembly-optaweb-employee-rostering-frontend-zip.xml</descriptor>
              </descriptors>
              <appendAssemblyId>false</appendAssemblyId>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>productized</id>
      <activation>
        <property>
          <name>productized</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>locktt final cleanup</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>npm</goal>
                </goals>
                <configuration>
                  <arguments>run locktt</arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
