<?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>
        <artifactId>keycloak-parent</artifactId>
        <groupId>org.keycloak</groupId>
        <version>23.0.2</version>
        <relativePath>../../../pom.xml</relativePath>
    </parent>

    <artifactId>keycloak-js-adapter-jar</artifactId>

    <name>Keycloak JavaScript Adapter (JAR)</name>
    <description>A build of the Keycloak JavaScript adapter that puts the compiled result in a JAR (for inclusion in the Keycloak server).</description>

    <properties>
        <js.projectDir>../../../js</js.projectDir>
        <js.adapter.projectDir>${js.projectDir}/libs/keycloak-js</js.adapter.projectDir>
        <js.adapter.distDir>${js.adapter.projectDir}/dist</js.adapter.distDir>
        <!-- as the frontend-maven-plugin depends on workingDirectory, list all parts which should be ignored from the checksum -->
        <maven.build.cache.exclude.1>${maven.multiModuleProjectDirectory}/js/libs/keycloak-js/node_modules</maven.build.cache.exclude.1>
        <!-- TODO: this is almost correct, as the DIST folder includes also two source files -->
        <maven.build.cache.exclude.2>${maven.multiModuleProjectDirectory}/js/libs/keycloak-js/dist</maven.build.cache.exclude.2>
    </properties>

    <build>
        <resources>
            <resource>
                <directory>${js.adapter.distDir}</directory>
                <includes>
                    <include>*.js</include>
                </includes>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>${js.adapter.distDir}</directory>
                            <excludes>
                                <exclude>*.d.ts</exclude>
                            </excludes>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>install-node-and-pnpm</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>pnpm-install</id>
                        <goals>
                            <goal>pnpm</goal>
                        </goals>
                        <configuration>
                            <arguments>${pnpm.args.install}</arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>run-build</id>
                        <goals>
                            <goal>pnpm</goal>
                        </goals>
                        <configuration>
                            <arguments>run build</arguments>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <workingDirectory>${js.projectDir}/libs/keycloak-js</workingDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>