<?xml version="1.0"?>
<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">
    <parent>
        <artifactId>keycloak-parent</artifactId>
        <groupId>org.keycloak</groupId>
        <version>4.7.0.Final-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>keycloak-themes</artifactId>
    <name>Keycloak Themes</name>
    <description/>

    <profiles>
        <profile>
            <id>community</id>
            <activation>
                <property>
                    <name>!product</name>
                </property>
            </activation>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                    </resource>
                    <resource>
                        <directory>src/main/resources-community</directory>
                    </resource>
                </resources>
            </build>
        </profile>
        <profile>
            <id>product</id>
            <activation>
                <property>
                    <name>product</name>
                </property>
            </activation>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                    </resource>
                    <resource>
                        <directory>src/main/resources-product</directory>
                    </resource>
                </resources>
                <plugins>
                    <plugin>
                        <artifactId>maven-jar-plugin</artifactId>
                        <configuration>
                            <excludes>
                                <exclude>**/keycloak-preview/**</exclude>
                            </excludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        
        <profile>
            <id>account2</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.eirslett</groupId>
                        <artifactId>frontend-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>install node and npm</id>
                                <goals>
                                    <goal>install-node-and-npm</goal>
                                </goals>
                                <phase>generate-resources</phase>
                                <configuration>
                                    <nodeVersion>v8.9.4</nodeVersion>
                                </configuration>
                            </execution>
                            <execution>
                                <id>npm install</id>
                                <goals>
                                    <goal>npm</goal>
                                </goals>
                                <phase>generate-resources</phase>
                                <configuration>
                                    <arguments>install</arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>compile typescript</id>
                                <goals>
                                    <goal>npm</goal>
                                </goals>
                                <phase>compile</phase>
                                <configuration>
                                    <arguments>run build</arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>npm remove dev dependencies production=true</id>
                                <goals>
                                    <goal>npm</goal>
                                </goals>
                                <phase>process-classes</phase>
                                <configuration>
                                    <arguments>install --production=true --no-package-lock</arguments>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <workingDirectory>src/main/resources/theme/keycloak-preview/account/resources</workingDirectory>
                        </configuration>
                    </plugin>
                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>
                        <configuration>
                            <filesets>
                                <fileset>
                                    <directory>src/main/resources/theme/keycloak-preview/account/resources/node_modules</directory>
                                </fileset>
                                <fileset>
                                    <directory>src/main/resources/theme/keycloak-preview/account/resources/node</directory>
                                </fileset>
                            </filesets>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>npm-update</id>
            <build>
                <plugins>
                    <!-- Clean downloaded packages from NPM -->
                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>
                        <configuration>
                            <filesets>
                                <fileset>
                                    <directory>src/main/resources/node_modules</directory>
                                </fileset>
                                <fileset>
                                    <directory>src/main/resources/theme/keycloak/common/resources/node_modules</directory>
                                </fileset>
                            </filesets>
                        </configuration>
                    </plugin>
                    <!-- Install NPM and download packages -->
                    <plugin>
                        <groupId>com.github.eirslett</groupId>
                        <artifactId>frontend-maven-plugin</artifactId>
                        <version>1.6</version>
                        <executions>
                            <execution>
                                <id>install-node-and-npm</id>
                                <goals>
                                    <goal>install-node-and-npm</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>npm-install</id>
                                <goals>
                                    <goal>npm</goal>
                                </goals>
                                <configuration>
                                    <arguments>install</arguments>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <nodeVersion>v8.9.4</nodeVersion>
                            <workingDirectory>src/main/resources</workingDirectory>
                        </configuration>
                    </plugin>
                    <!-- Copy files from NPM packages -->
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>3.0.2</version>
                        <executions>
                            <execution>
                                <id>copy-resources</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>

                                <configuration>
                                    <outputDirectory>src/main/resources/theme/keycloak/common/resources/node_modules</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>src/main/node_modules</directory>
                                            <excludes>
                                                <exclude>minimist/**</exclude>
                                                <exclude>mkdirp/**</exclude>
                                                <exclude>**/*.json</exclude>
                                                <exclude>**/*.json</exclude>
                                                <exclude>**/*.markdown</exclude>
                                                <exclude>**/*.swf</exclude>
                                                <exclude>**/*.sh</exclude>
                                                <exclude>**/.bin/**</exclude>
                                                <exclude>**/bin/**</exclude>
                                                <exclude>**/build/**</exclude>
                                                <exclude>**/docs/**</exclude>
                                                <exclude>**/demo/**</exclude>
                                                <exclude>**/devtools/**</exclude>
                                                <exclude>**/example/**</exclude>
                                                <exclude>**/examples/**</exclude>
                                                <exclude>**/grunt/**</exclude>
                                                <exclude>**/less/**</exclude>
                                                <exclude>**/node_modules/**</exclude>
                                                <exclude>**/sass/**</exclude>
                                                <exclude>**/scss/**</exclude>
                                                <exclude>**/src/**</exclude>
                                                <exclude>**/test/**</exclude>
                                                <exclude>**/tests/**</exclude>
                                                <exclude>**/_config.yml</exclude>
                                                <exclude>**/api.md</exclude>
                                                <exclude>**/AUTHORS.txt</exclude>
                                                <exclude>**/CHANGELOG.md</exclude>
                                                <exclude>**/CONTRIBUTING.md</exclude>
                                                <exclude>**/HELP-US-OUT.txt</exclude>
                                                <exclude>**/README.md</exclude>
                                                <exclude>**/Gruntfile.js</exclude>
                                                <exclude>**/Gemfile*</exclude>
                                                <exclude>**/index.js</exclude>
                                                <exclude>**/.*</exclude>
                                            </excludes>
                                        </resource>
                                        <resource>
                                            <directory>src/main/node_modules</directory>
                                            <includes>
                                                <include>angular-ui-select2/src/select2.js</include>
                                                <include>filesaver/src/Filesaver.js</include>
                                                <include>filesaver/src/changename.js</include>
                                            </includes>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
