<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (C) 2017/2021 e-voyageurs technologies
  ~
  ~ 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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>ai.tock</groupId>
    <artifactId>tock-bot-admin</artifactId>
    <version>23.3.1</version>
  </parent>

  <artifactId>tock-bot-admin-web</artifactId>
  <packaging>pom</packaging>
  <name>Tock Bot Admin Front</name>
  <description>Web app front for Tock Bot Admin</description>

  <properties>
    <project.build.frontend.directory>${project.build.directory}/frontend</project.build.frontend.directory>
  </properties>

  <dependencies>
    <dependency>
      <groupId>ai.tock</groupId>
      <artifactId>tock-nlp-admin-web</artifactId>
      <version>${project.version}</version>
      <type>zip</type>
      <classifier>sources</classifier>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>pl.project13.maven</groupId>
        <artifactId>git-commit-id-plugin</artifactId>
        <executions>
          <execution>
            <id>generate-source-info</id>
            <phase>initialize</phase>
            <goals>
              <goal>revision</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>import-nlp-admin-sources</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <includeClassifiers>sources</includeClassifiers>
              <outputDirectory>${project.build.frontend.directory}/src</outputDirectory>
              <excludes>app/nlp-admin-app.*.*</excludes>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>merge-bot-admin-sources</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <resources>
                <resource>
                  <directory>.</directory>
                  <includes>
                    <include>src/**</include>
                    <include>*.json</include>
                  </includes>
                  <excludes>
                    <exclude>**/manifest.ts</exclude>
                  </excludes>
                  <filtering>false</filtering>
                </resource>
              </resources>
              <outputDirectory>${project.build.frontend.directory}</outputDirectory>
              <overwrite>true</overwrite>
            </configuration>
          </execution>
          <execution>
            <id>merge-tock-info</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <resources>
                <resource>
                  <directory>.</directory>
                  <includes>
                    <include>**/manifest.ts</include>
                  </includes>
                  <filtering>true</filtering>
                </resource>
              </resources>
              <outputDirectory>${project.build.frontend.directory}</outputDirectory>
              <overwrite>true</overwrite>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <configuration>
          <workingDirectory>${project.build.frontend.directory}</workingDirectory>
        </configuration>
        <executions>
          <execution>
            <id>install node and npm</id>
            <phase>process-resources</phase>
            <goals>
              <goal>install-node-and-npm</goal>
            </goals>
            <configuration>
              <nodeVersion>${node}</nodeVersion>
            </configuration>
          </execution>
          <execution>
            <id>npm ci</id>
            <phase>process-resources</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>ci -d --loglevel warn --force</arguments>
            </configuration>
          </execution>
          <execution>
            <id>npm run-script mavenbuild</id>
            <phase>compile</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run-script mavenbuild --loglevel warn --force</arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptors>
            <descriptor>src/main/assembly/assembly.xml</descriptor>
          </descriptors>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>
