<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2009-2013 Roland Huss
  ~
  ~ 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>

  <artifactId>jolokia-client-javascript-esm</artifactId>
  <version>2.2.4</version>

  <name>jolokia-client-javascript-esm</name>
  <description>Jolokia :: Client :: JavaScript ES Modules</description>

  <parent>
    <groupId>org.jolokia</groupId>
    <artifactId>jolokia-parent</artifactId>
    <version>2.2.4</version>
    <relativePath>../../pom.xml</relativePath>
  </parent>

  <url>https://jolokia.org/</url>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-clean-plugin</artifactId>
        <executions>
          <execution>
            <id>clean-node-data</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
            <inherited>false</inherited>
            <configuration>
              <filesets>
                <fileset>
                  <directory>node_modules</directory>
                </fileset>
                <fileset>
                  <directory>packages</directory>
                  <includes>
                    <include>**/dist/**</include>
                  </includes>
                </fileset>
              </filesets>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-javascript-files</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.outputDirectory}</outputDirectory>
              <resources>
                <resource>
                  <directory>packages/jolokia/dist</directory>
                  <includes>
                    <include>jolokia.cjs</include>
                    <include>jolokia.min.cjs</include>
                  </includes>
                </resource>
                <resource>
                  <directory>packages/jolokia-simple/dist</directory>
                  <includes>
                    <include>jolokia-simple.cjs</include>
                    <include>jolokia-simple.min.cjs</include>
                  </includes>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>prepare-javascript-distribution</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <move todir="${project.build.outputDirectory}">
                  <fileset dir="${project.build.outputDirectory}" />
                  <mapper type="regexp" from="^(.*)\.cjs$" to="\1.js" />
                </move>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <configuration>
          <installDirectory>../../.node</installDirectory>
        </configuration>
        <executions>
          <execution>
            <id>install node and yarn</id>
            <goals>
              <goal>install-node-and-yarn</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
              <nodeVersion>${version.nodejs}</nodeVersion>
              <yarnVersion>${version.yarn}</yarnVersion>
            </configuration>
          </execution>
          <execution>
            <id>yarn install</id>
            <goals>
              <goal>yarn</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
              <arguments>install</arguments>
            </configuration>
          </execution>
          <execution>
            <id>yarn build</id>
            <goals>
              <goal>yarn</goal>
            </goals>
            <phase>compile</phase>
            <configuration>
              <arguments>build</arguments>
            </configuration>
          </execution>
          <execution>
            <id>yarn checks</id>
            <goals>
              <goal>yarn</goal>
            </goals>
            <phase>test</phase>
            <configuration>
              <arguments>eslint --stats packages/</arguments>
            </configuration>
          </execution>
          <execution>
            <id>yarn test</id>
            <goals>
              <goal>yarn</goal>
            </goals>
            <phase>test</phase>
            <configuration>
              <arguments>test</arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>
