Gruntfile.js revision 5003b4008868032decd27b09f87bc1222ce1b783
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * The contents of this file are subject to the terms of the Common Development and
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Distribution License (the License). You may not use this file except in compliance with the
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * specific language governing permission and limitations under the License.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * When distributing Covered Software, include this CDDL Header Notice in each file and include
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Header, with the fields enclosed by brackets [] replaced by your own identifying
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * information: "Portions copyright [year] [name of copyright owner]".
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Copyright 2015 ForgeRock AS.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg/* global module, require, process */
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburgfunction mavenProjectTestSource (projectDir) {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg var compositionDirectory = "target/composed",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg forgeRockCommonsDirectory = process.env.FORGEROCK_UI_SRC + "/forgerock-ui-commons",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg forgeRockUiDirectory = process.env.FORGEROCK_UI_SRC + "/forgerock-ui-user",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg targetVersion = grunt.option("target-version") || "dev",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg // When building, dependencies are downloaded and expanded by Maven
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg "target/dependencies-expanded/forgerock-ui-user",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg "target/dependencies-expanded/openam-ui-common",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg // This must come last so that it overwrites any conflicting files!
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg // When watching, we want to get the dependencies directly from the source
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg mavenProjectSource(forgeRockCommonsDirectory),
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg // This must come last so that it overwrites any conflicting files!
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg "**/*.woff2",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg serverDeployDirectory = process.env.OPENAM_HOME + "/XUI",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg testDeployDirectory = process.env.OPENAM_HOME + "/../openam-test";
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Copy all the sources and resources from this project and all dependencies into the composition directory.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * TODO: This copying shouldn't really be necessary, but is required because the dependencies are all over
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * the place. If we move to using npm for our dependencies, this can be greatly simplified.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg files: buildCompositionDirs.map(function (dir) {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Copy files that do not need to be compiled into the compiled directory.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg "!index.html" // Output by grunt-text-replace
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Check the JavaScript source code for common mistakes and style issues.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg format: require.resolve("eslint-formatter-warning-summary")
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Compile LESS source code into minified CSS files.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg src: compositionDirectory + "/css/styles.less",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Run qunit tests.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Include the version of AM in the index file.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * This is needed to force the browser to refetch JavaScript files when a new version of AM is deployed.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Concatenate and uglify the JavaScript.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg mainConfigFile: compositionDirectory + "/main.js",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg // These files are excluded from optimization so that the UI can be customized without having to
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg // repackage it.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Sync is used when watching to speed up the build.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Copy all the sources and resources from this project and all dependencies into the composition directory.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg files: watchCompositionDirs.map(function (dir) {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Copy files that do not need to be compiled into the compiled directory.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Note that this also copies main.js because the requirejs step is not being performed when watching (it
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * is too slow).
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg "!index.html" // Output by grunt-text-replace
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Copy the compiled files to the server deploy directory.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg compareUsing: "md5" // Avoids spurious syncs of touched, but otherwise unchanged, files (e.g. CSS)
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Copy the compiled files, along with the test source files and dependencies, to the server deploy
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg files: testInputDirectory.map(function (inputDirectory) {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg compareUsing: "md5" // Avoids spurious syncs of touched, but otherwise unchanged, files (e.g. CSS)
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Redeploy whenever any source files change.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg files: watchCompositionDirs.map(function (dir) {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Deploy and run the tests whenever any source files change.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg files: watchCompositionDirs.map(function (dir) {
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Generates OS notifications when the watch passes or fails.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg grunt.loadNpmTasks("grunt-contrib-requirejs");
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Resync the compiled directory and deploy and run the tests.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg "sync:compose",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg "sync:compiled",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg "sync:testServer",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Resync the compiled directory and deploy to the web server.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg "sync:compose",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg "sync:compiled",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg "sync:server"
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg * Rebuild the compiled directory. Maven then packs this directory into the final archive artefact.
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg "copy:compose",
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg "copy:compiled"
5003b4008868032decd27b09f87bc1222ce1b783Joe Bandenburg grunt.registerTask("dev", ["copy:compose", "deploy", "watch"]);