<?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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>io.hawt</groupId>
    <artifactId>project</artifactId>
    <version>4.0.0</version>
    <relativePath>../../pom.xml</relativePath>
  </parent>

  <groupId>io.hawt.examples</groupId>
  <artifactId>hawtio-example-sample-plugin</artifactId>
  <name>${project.artifactId}</name>
  <description>Hawtio :: Sample Hawtio plugin TypeScript project</description>

  <properties>
    <!--
      Path to the Hawtio plugin TS project. You can specify the path if it's placed
      differently from the project root.
    -->
    <plugin.path>${project.basedir}</plugin.path>
  </properties>

  <build>
    <!-- Include the build output of the TS project as the resources to JAR -->
    <resources>
      <resource>
        <directory>${plugin.path}/build</directory>
        <targetPath>META-INF/resources</targetPath>
        <excludes>
          <exclude>index.html</exclude>
        </excludes>
      </resource>
    </resources>

    <plugins>
      <!-- Build the TS plugin project from Maven -->
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <configuration>
          <workingDirectory>${plugin.path}</workingDirectory>
        </configuration>
        <executions>
          <execution>
            <id>install node and yarn</id>
            <goals>
              <goal>install-node-and-yarn</goal>
            </goals>
            <configuration>
              <nodeVersion>${node-version}</nodeVersion>
              <yarnVersion>${yarn-version}</yarnVersion>
            </configuration>
          </execution>
          <execution>
            <id>yarn npm audit</id>
            <goals>
              <goal>yarn</goal>
            </goals>
            <configuration>
              <arguments>npm audit --all</arguments>
            </configuration>
          </execution>
          <execution>
            <id>yarn install</id>
            <goals>
              <goal>yarn</goal>
            </goals>
            <configuration>
              <arguments>install</arguments>
            </configuration>
          </execution>
          <execution>
            <id>yarn build</id>
            <goals>
              <goal>yarn</goal>
            </goals>
            <configuration>
              <arguments>build</arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Clean up the plugin's 'build/' and 'node_modules/' directories as well -->
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <configuration>
          <filesets>
            <fileset>
              <directory>${plugin.path}/build</directory>
              <includes>
                <include>**/*</include>
              </includes>
              <followSymlinks>false</followSymlinks>
            </fileset>
            <fileset>
              <directory>${plugin.path}/node_modules</directory>
              <includes>
                <include>**/*</include>
              </includes>
              <followSymlinks>false</followSymlinks>
            </fileset>
          </filesets>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>
