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

  <parent>
    <groupId>org.kie.kogito</groupId>
    <artifactId>kogito-apps</artifactId>
    <version>1.0.0.Final</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <packaging>pom</packaging>
  
  <artifactId>kogito-apps-ui-packages</artifactId>
  <name>Kogito Apps :: UI Packages</name>

  <properties>
    <path.to.root>${project.basedir}</path.to.root> <!-- package.json in root dir-->
    <path.to.packages>${path.to.root}/packages</path.to.packages>
    <sonar.sources>
      ${path.to.packages}/common/src,
      ${path.to.packages}/management-console/src,
      ${path.to.packages}/task-console/src,
      ${path.to.packages}/trusty/src
    </sonar.sources>
    <sonar.exclusions>**/__mocks__/**,**/mocks/**,**/tests/utils/**,**/*.stories.tsx</sonar.exclusions>
    <sonar.test.inclusions>**/*test.ts,**/*test.tsx</sonar.test.inclusions>
    <sonar.javascript.lcov.reportPaths>
      ${path.to.packages}/common/coverage/lcov.info,
      ${path.to.packages}/management-console/coverage/lcov.info,
      ${path.to.packages}/task-console/coverage/lcov.info,
      ${path.to.packages}/trusty/coverage/lcov.info
    </sonar.javascript.lcov.reportPaths>
  </properties>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <configuration>
          <filesets>
            <fileset>
              <directory>node_modules</directory>
            </fileset>
            <fileset>
              <directory>packages/common/node_modules</directory>
            </fileset>
            <fileset>
              <directory>packages/management-console/node_modules</directory>
            </fileset>
            <fileset>
              <directory>packages/task-console/node_modules</directory>
            </fileset>
            <fileset>
              <directory>packages/trusty/node_modules</directory>
            </fileset>
          </filesets>
        </configuration>
      </plugin>
      <!-- frontend related plugins-->
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <configuration>
          <workingDirectory>${path.to.root}</workingDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <!--
        Installs node and yarn in the webapp's node and node_modules folders.
        Run 'mvn package':
          * the first time you have checked out the source.
          * whenever the dependencies have been changed in package.json (delete the webapp's node_modules folder first!)
        If you want to skip installation of the packages, turn the profile off by setting property `-Dskip.ui.deps`.
      -->
      <id>install-node-yarn</id>
      <activation>
        <property><name>!skip.ui.deps</name></property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>install-node-and-npm</id>
                <goals>
                  <goal>install-node-and-npm</goal>
                </goals>
                <configuration>
                  <nodeVersion>${version.node}</nodeVersion>
                  <npmVersion>${version.npm}</npmVersion>
                </configuration>
              </execution>
              <execution>
                <id>install-node-and-yarn</id>
                <goals>
                  <goal>install-node-and-yarn</goal>
                </goals>
                <configuration>
                  <nodeVersion>${version.node}</nodeVersion>
                  <yarnVersion>${version.yarn}</yarnVersion>
                </configuration>
              </execution>
              <execution>
                <id>npm install lock-treatment-tool</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <configuration>
                  <npmRegistryURL>${env.NPM_REGISTRY_URL}</npmRegistryURL>
                  <arguments>install lock-treatment-tool --global-style --no-package-lock --no-save</arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>install-ui-deps</id>
      <activation>
        <property><name>!skip.ui.deps</name></property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>lock-treatment-tool execution</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <configuration>
                  <npmRegistryURL>${env.NPM_REGISTRY_URL}</npmRegistryURL>
                  <arguments>run locktt -- --skipIntegrity</arguments>
                </configuration>
              </execution>
              <execution>
                <id>yarn install</id>
                <goals>
                  <goal>yarn</goal>
                </goals>
                <configuration>
                  <npmRegistryURL>${env.NPM_REGISTRY_URL}</npmRegistryURL>
                  <arguments>install --fetch-retry-mintimeout=100000 --fetch-retries=10 --frozen-lockfile</arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <!--
        Builds the UI package. Can be skipped by using property `-Dskip.ui.build`.
      -->
      <id>build-ui</id>
      <activation>
        <property><name>!skip.ui.build</name></property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>yarn build</id>
                <goals>
                  <goal>yarn</goal>
                </goals>
                <configuration>
                  <npmRegistryURL>${env.NPM_REGISTRY_URL}</npmRegistryURL>
                  <arguments>run build:prod</arguments>
                  <environmentVariables>
                    <KOGITO_APP_VERSION>${project.version}</KOGITO_APP_VERSION>
                </environmentVariables>
                </configuration>
              </execution>
              <execution>
                <id>yarn test</id>
                <goals>
                  <goal>yarn</goal>
                </goals>
                <phase>test</phase>
                <configuration>
                  <npmRegistryURL>${env.NPM_REGISTRY_URL}</npmRegistryURL>
                  <arguments>run test</arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
