<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    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:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         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>
  <properties>
    <frontend-maven-plugin.version>1.8.0</frontend-maven-plugin.version>
    <maven-clean-plugin.version>3.1.0</maven-clean-plugin.version>
    <skiptTests>false</skiptTests>
    <node.version>v14.15.5</node.version>
    <npm.version>6.14.11</npm.version>
  </properties>

  <parent>
    <groupId>io.gravitee.apim</groupId>
    <artifactId>gravitee-api-management</artifactId>
    <version>3.5.21</version>
  </parent>

  <groupId>io.gravitee.apim.ui</groupId>
  <artifactId>gravitee-apim-portal-webui</artifactId>
  <packaging>pom</packaging>
  <name>Gravitee.io APIM - UI Portal</name>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>${maven-clean-plugin.version}</version>
        <configuration>
          <filesets>
            <fileset>
              <directory>dist</directory>
            </fileset>
            <fileset>
              <directory>.tmp</directory>
            </fileset>
            <fileset>
              <directory>node</directory>
            </fileset>
            <fileset>
              <directory>coverage</directory>
            </fileset>
            <fileset>
              <directory>node_modules</directory>
            </fileset>
          </filesets>
        </configuration>
      </plugin>
      <plugin>
        <groupId>com.mycila</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <configuration>
          <mapping>
            <ts>SLASHSTAR_STYLE</ts>
          </mapping>
          <excludes>
            <exclude>*</exclude>
            <exclude>node/**</exclude>
            <exclude>node_modules/**</exclude>
            <exclude>dockerfiles/**</exclude>
            <exclude>projects/**</exclude>
            <exclude>scripts/**</exclude>
            <exclude>coverage/**</exclude>
            <exclude>dist/**</exclude>
            <exclude>tmp/**</exclude>
            <exclude>.*</exclude>
            <exclude>.*/**</exclude>
            <exclude>**/*.scss</exclude>
            <exclude>**/*.woff2</exclude>
            <exclude>.*</exclude>
            <exclude>.*/**</exclude>
            <exclude>**/*.adoc</exclude>
            <exclude>**/*.tmpl</exclude>
            <exclude>**/*.toml</exclude>
          </excludes>
        </configuration>
      </plugin>
      <plugin>
        <groupId>com.hubspot.maven.plugins</groupId>
        <artifactId>prettier-maven-plugin</artifactId>
        <version>0.12</version>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>${frontend-maven-plugin.version}</version>
        <executions>
            <execution>
              <id>install node and npm</id>
              <goals>
                <goal>install-node-and-npm</goal>
              </goals>
              <configuration>
                <nodeVersion>${node.version}</nodeVersion>
                <npmVersion>${npm.version}</npmVersion>
              </configuration>
            </execution>
            <execution>
              <id>npm install</id>
              <goals>
                <goal>npm</goal>
              </goals>
              <phase>process-resources</phase>
            </execution>
            <execution>
              <id>lint</id>
              <goals>
                <goal>npm</goal>
              </goals>
              <phase>test</phase>
              <configuration>
                <arguments>run lint</arguments>
              </configuration>
            </execution>
            <execution>
              <id>test</id>
              <goals>
                <goal>npm</goal>
              </goals>
              <phase>test</phase>
              <configuration>
                <arguments>run test</arguments>
              </configuration>
            </execution>
            <execution>
              <id>build</id>
              <goals>
                <goal>npm</goal>
              </goals>
              <phase>package</phase>
              <configuration>
                <arguments>run build:prod</arguments>
              </configuration>
            </execution>
        </executions>
      </plugin>
      <!--Plugin used to replace version on several files -->
      <plugin>
        <groupId>com.google.code.maven-replacer-plugin</groupId>
        <artifactId>replacer</artifactId>
        <version>1.5.3</version>
        <executions>
          <execution>
            <phase>generate-resources</phase>
            <goals>
              <goal>replace</goal>
            </goals>
            <configuration>
              <includes>
                <include>${project.basedir}/build.json</include>
              </includes>
              <replacements>
                <replacement>
                  <token>"version": "(.*)"</token>
                  <value>"version": "${project.version}"</value>
                </replacement>
              </replacements>
            </configuration>
          </execution>
          <execution>
            <id>replace-base-url</id>
            <phase>package</phase>
            <goals>
              <goal>replace</goal>
            </goals>
            <configuration>
              <file>${project.basedir}/dist/assets/config.json</file>
              <replacements>
                <replacement>
                  <token>"baseURL": "(.*)"</token>
                  <value>"baseURL": "http://localhost:8083/portal/environments/DEFAULT"</value>
                </replacement>
              </replacements>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <appendAssemblyId>false</appendAssemblyId>
              <descriptors>
                <descriptor>assembly.xml</descriptor>
              </descriptors>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
