<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.squashtest.tm</groupId>
    <artifactId>squash-tm-tm</artifactId>
    <version>14.0.0.RELEASE</version>
  </parent>

  <artifactId>tm-front</artifactId>

  <properties>
    <frontend-maven-plugin.version>1.15.4</frontend-maven-plugin.version>
    <frontend-node.version>v22.18.0</frontend-node.version>
    <frontend-yarn.version>v1.22.19</frontend-yarn.version>
    <sonar.sources>.</sonar.sources>
  </properties>

  <build>

    <plugins>

      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>${frontend-maven-plugin.version}</version>
        <executions>
          <execution>
            <id>install node and yarn</id>
            <goals>
              <goal>install-node-and-yarn</goal>
            </goals>
            <configuration>
              <nodeVersion>${frontend-node.version}</nodeVersion>
              <yarnVersion>${frontend-yarn.version}</yarnVersion>
            </configuration>
          </execution>

          <execution>
            <id>yarn install</id>
            <goals>
              <goal>yarn</goal>
            </goals>
            <configuration>
              <arguments>install --frozen-lockfile</arguments>
            </configuration>
          </execution>

          <execution>
            <id>yarn build</id>
            <goals>
              <goal>yarn</goal>
            </goals>
            <configuration>
              <arguments>build</arguments>
              <environmentVariables>
                <NODE_OPTIONS>--max-old-space-size=3072</NODE_OPTIONS>
              </environmentVariables>
            </configuration>
          </execution>

        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>prepare-package</id>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <outputDirectory>${basedir}/target/classes/META-INF/resources</outputDirectory>
              <resources>
                <resource>
                  <directory>${project.basedir}/dist/sqtm-app</directory>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>${maven-jar-plugin.version}</version>
        <executions>
          <execution>
            <id>UT-IT-test-jar</id>
            <goals>
              <goal>test-jar</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <classifier>test-resources</classifier>
              <testClassesDirectory>${basedir}</testClassesDirectory>
              <includes>
                <include>dist/**</include>
              </includes>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>

  <!--  Executing Unit Test only if ng-test profile. so we can build in a chromeless env without tests-->
  <profiles>
    <profile>
      <id>ng-test</id>
      <build>
        <plugins>
          <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <version>${frontend-maven-plugin.version}</version>
            <executions>
              <execution>
                <id>test</id>
                <goals>
                  <goal>yarn</goal>
                </goals>
                <configuration>
                  <arguments>run test-core</arguments>
                  <environmentVariables>
                    <CI>true</CI>
                  </environmentVariables>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>no-front</id>
      <build>
        <plugins>
          <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <version>${frontend-maven-plugin.version}</version>
            <executions>
              <execution>
                <id>install node and yarn</id>
                <phase>none</phase>
              </execution>
              <execution>
                <id>yarn install</id>
                <phase>none</phase>
              </execution>
              <execution>
                <id>yarn build</id>
                <phase>none</phase>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>ci</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>
    </profile>
  </profiles>
</project>
