<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2020 Red Hat, Inc. and/or its affiliates.
  ~
  ~ 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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.dashbuilder</groupId>
    <artifactId>dashbuilder-shared</artifactId>
    <version>7.47.0.Final</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <packaging>jar</packaging>
  <artifactId>dashbuilder-js</artifactId>
  <name>Dashbuilder JS</name>
  <description>Dashbuilder JS APIs and internal components for displaying data</description>

  <properties>
    <!-- Comma separated internal components name -->
    <dashbuilder.internal.components.list>logo-provided</dashbuilder.internal.components.list>
    <!-- Components base dir -->
    <dashbuilder.internal.components.root>web/dashbuilder/components</dashbuilder.internal.components.root>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0.0</version>
        <executions>
          <execution>
            <phase>generate-resources</phase>
            <goals>
              <goal>write-project-properties</goal>
            </goals>
            <configuration>
              <outputFile>
                ${project.build.outputDirectory}/dashbuilder-components.properties</outputFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <configuration>
          <installDirectory>${project.build.directory}</installDirectory>
        </configuration>
        <executions>
          <execution>
            <id>install yarn</id>
            <goals>
              <goal>install-node-and-yarn</goal>
            </goals>
          </execution>
          <execution>
            <id>install node and npm</id>
            <phase>initialize</phase>
            <goals>
              <goal>install-node-and-npm</goal>
            </goals>
          </execution>
          <execution>
            <id>yarn run init</id>
            <goals>
              <goal>yarn</goal>
            </goals>
            <configuration>
              <arguments>run init</arguments>
            </configuration>
          </execution>
          <execution>
            <id>npm install lock-treatment-tool and run-node</id>
            <phase>initialize</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>install lock-treatment-tool --global-style
                --no-package-lock --no-save</arguments>
            </configuration>
          </execution>
          <execution>
            <id>lock-treatment-tool execution</id>
            <phase>initialize</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run locktt --</arguments>
            </configuration>
          </execution>

          <execution>
            <id>yarn run build:prod</id>
            <goals>
              <goal>yarn</goal>
            </goals>
            <configuration>
              <arguments>run build:prod</arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-resources</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>
                ${project.build.outputDirectory}/${dashbuilder.internal.components.root}/logo-provided
              </outputDirectory>
              <resources>
                <resource>
                  <directory>packages/logo-component/dist/</directory>
                  <filtering>false</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
