<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.sterl.spring</groupId>
        <artifactId>spring-persistent-tasks-root</artifactId>
        <version>2.2.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>spring-persistent-tasks-ui</artifactId>
    <name>UI for spring persistent tasks</name>
    <description>React ui lib and the default UI web-app for sprint persistent tasks</description>

    <url>https://github.com/sterlp/spring-persistent-tasks/wiki/Admin-Dashbaord-UI-and-CSRF</url>
    <scm>
        <url>https://github.com/sterlp/spring-persistent-tasks</url>
    </scm>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.sterl.spring</groupId>
            <artifactId>spring-persistent-tasks-core</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>web-app/dist</directory>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.4.0</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>${project.basedir}/ui-lib/node_modules</directory>
                        </fileset>
                        <fileset>
                            <directory>${project.basedir}/ui-lib/dist</directory>
                        </fileset>

                        <fileset>
                            <directory>${project.basedir}/web-app/node_modules</directory>
                        </fileset>
                        <fileset>
                            <directory>${project.basedir}/web-app/dist</directory>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.5.0</version>
                <executions>
                    <execution>
                        <id>pnpm install</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <executable>pnpm</executable>
                            <arguments>
                                <argument>install</argument>
                            </arguments>
                        </configuration>
                    </execution>

                    <execution>
                        <id>pnpm build</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <executable>pnpm</executable>
                            <arguments>
                                <argument>recursive</argument>
                                <argument>run</argument>
                                <argument>build</argument>
                            </arguments>
                        </configuration>
                    </execution>

                    <execution>
                        <id>pnpm test</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <executable>pnpm</executable>
                            <arguments>
                                <argument>recursive</argument>
                                <argument>run</argument>
                                <argument>test</argument>
                                <argument>--</argument>
                                <argument>run</argument>
                            </arguments>
                            <skip>${skipTests}</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.3.1</version>
                <executions>
                    <execution>
                        <id>copy-index-html</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>web-app/dist/templates/task-ui</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>web-app/dist/static/task-ui</directory>
                                    <includes>
                                        <include>index.html</include>
                                    </includes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>