Gruntfile.js revision 01f87b9746ac246340e0e98d25e03193d83b071f
0N/A/**
2362N/A * The contents of this file are subject to the terms of the Common Development and
0N/A * Distribution License (the License). You may not use this file except in compliance with the
0N/A * License.
0N/A *
0N/A * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
2362N/A * specific language governing permission and limitations under the License.
0N/A *
2362N/A * When distributing Covered Software, include this CDDL Header Notice in each file and include
0N/A * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
0N/A * Header, with the fields enclosed by brackets [] replaced by your own identifying
0N/A * information: "Portions copyright [year] [name of copyright owner]".
0N/A *
0N/A * Copyright 2015 ForgeRock AS.
0N/A */
0N/A
0N/A/* global module, require, process */
0N/A
0N/Avar _ = require("lodash"),
0N/A mavenSrcPath = "/src/main/js",
2362N/A mavenTestPath = "/src/test/js";
2362N/A
2362N/Afunction mavenProjectSource (projectDir) {
0N/A return [
0N/A projectDir + mavenSrcPath,
0N/A projectDir + "/src/main/resources"
0N/A ];
0N/A}
0N/A
0N/Afunction mavenProjectTestSource (projectDir) {
0N/A return [
0N/A projectDir + mavenTestPath,
0N/A projectDir + "/src/test/resources"
0N/A ];
0N/A}
0N/A
0N/Amodule.exports = function (grunt) {
0N/A var compositionDirectory = "target/composed",
0N/A compiledDirectory = "target/compiled",
0N/A testClassesDirectory = "target/test-classes",
0N/A forgeRockCommonsDirectory = process.env.FORGEROCK_UI_SRC + "/forgerock-ui-commons",
0N/A forgeRockUiDirectory = process.env.FORGEROCK_UI_SRC + "/forgerock-ui-user",
0N/A targetVersion = grunt.option("target-version") || "dev",
0N/A buildCompositionDirs = _.flatten([
0N/A "target/dependencies",
0N/A // When building, dependencies are downloaded and expanded by Maven
0N/A "target/dependencies-expanded/forgerock-ui-user",
0N/A // This must come last so that it overwrites any conflicting files!
0N/A mavenProjectSource(".")
0N/A ]),
0N/A watchCompositionDirs = _.flatten([
0N/A // When watching, we want to get the dependencies directly from the source
0N/A mavenProjectSource(forgeRockCommonsDirectory),
0N/A mavenProjectSource(forgeRockUiDirectory),
0N/A // This must come last so that it overwrites any conflicting files!
0N/A mavenProjectSource(".")
0N/A ]),
0N/A testWatchDirs = _.flatten([
0N/A mavenProjectTestSource(".")
0N/A ]),
0N/A testInputDirs = _.flatten([
0N/A mavenProjectTestSource(".")
0N/A ]),
0N/A nonCompiledFiles = [
0N/A "**/*.html",
0N/A "**/*.ico",
0N/A "**/*.json",
0N/A "**/*.png",
0N/A "**/*.js",
0N/A "**/*.eot",
0N/A "**/*.svg",
0N/A "**/*.woff",
0N/A "**/*.woff2",
0N/A "**/*.otf",
0N/A "css/bootstrap-3.3.5-custom.css"
0N/A ],
0N/A serverDeployDirectory = process.env.OPENAM_HOME + "/XUI";
0N/A
0N/A grunt.initConfig({
0N/A copy: {
0N/A /**
0N/A * Copy all the sources and resources from this project and all dependencies into the composition directory.
0N/A *
0N/A * TODO: This copying shouldn't really be necessary, but is required because the dependencies are all over
0N/A * the place. If we move to using npm for our dependencies, this can be greatly simplified.
0N/A */
0N/A compose: {
0N/A files: buildCompositionDirs.map(function (dir) {
0N/A return {
0N/A expand: true,
0N/A cwd: dir,
0N/A src: ["**"],
0N/A dest: compositionDirectory
0N/A };
0N/A })
0N/A },
0N/A /**
0N/A * Copy files that do not need to be compiled into the compiled directory.
0N/A */
0N/A compiled: {
0N/A files: [{
0N/A expand: true,
0N/A cwd: compositionDirectory,
0N/A src: nonCompiledFiles.concat([
0N/A "!main.js", // Output by r.js
0N/A "!index.html" // Output by grunt-text-replace
0N/A ]),
0N/A dest: compiledDirectory
0N/A }]
0N/A }
0N/A },
0N/A eslint: {
0N/A /**
0N/A * Check the JavaScript source code for common mistakes and style issues.
0N/A */
0N/A lint: {
0N/A src: [
0N/A "." + mavenSrcPath + "/**/*.js",
0N/A "!." + mavenSrcPath + "/libs/**/*.js",
0N/A "." + mavenTestPath + "/**/*.js"
0N/A ],
0N/A options: {
0N/A format: require.resolve("eslint-formatter-warning-summary")
0N/A }
0N/A }
0N/A },
0N/A karma: {
0N/A options: {
0N/A configFile: "karma.conf.js"
0N/A },
0N/A build: {
0N/A singleRun: true,
0N/A reporters: "progress"
0N/A },
0N/A dev: {
0N/A }
0N/A },
0N/A less: {
0N/A /**
0N/A * Compile LESS source code into minified CSS files.
0N/A */
0N/A compile: {
0N/A files: [{
0N/A src: compositionDirectory + "/css/structure.less",
0N/A dest: compiledDirectory + "/css/structure.css"
0N/A }, {
0N/A src: compositionDirectory + "/css/theme.less",
0N/A dest: compiledDirectory + "/css/theme.css"
0N/A }, {
0N/A src: compositionDirectory + "/css/styles-admin.less",
0N/A dest: compiledDirectory + "/css/styles-admin.css"
0N/A }],
0N/A options: {
0N/A compress: true,
0N/A plugins: [
0N/A new (require("less-plugin-clean-css"))({})
0N/A ],
0N/A relativeUrls: true
0N/A }
0N/A }
0N/A },
0N/A replace: {
0N/A /**
0N/A * Include the version of AM in the index file.
0N/A *
0N/A * This is needed to force the browser to refetch JavaScript files when a new version of AM is deployed.
0N/A */
0N/A buildNumber: {
0N/A src: compositionDirectory + "/index.html",
0N/A dest: compiledDirectory + "/index.html",
0N/A replacements: [{
0N/A from: "${version}",
0N/A to: targetVersion
0N/A }]
0N/A }
0N/A },
0N/A requirejs: {
0N/A /**
0N/A * Concatenate and uglify the JavaScript.
0N/A */
0N/A compile: {
0N/A options: {
0N/A baseUrl: compositionDirectory,
0N/A mainConfigFile: compositionDirectory + "/main.js",
0N/A out: compiledDirectory + "/main.js",
0N/A include: ["main"],
0N/A preserveLicenseComments: false,
0N/A generateSourceMaps: true,
0N/A optimize: "uglify2",
0N/A // These files are excluded from optimization so that the UI can be customized without having to
0N/A // repackage it.
0N/A excludeShallow: [
0N/A "config/AppConfiguration",
0N/A "config/ThemeConfiguration"
0N/A ]
0N/A }
0N/A }
0N/A },
0N/A /**
0N/A * Sync is used when watching to speed up the build.
0N/A */
0N/A sync: {
0N/A /**
0N/A * Copy all the sources and resources from this project and all dependencies into the composition directory.
0N/A */
0N/A compose: {
0N/A files: watchCompositionDirs.map(function (dir) {
0N/A return {
0N/A cwd: dir,
0N/A src: ["**"],
0N/A dest: compositionDirectory
0N/A };
0N/A }),
0N/A compareUsing: "md5"
0N/A },
0N/A /**
0N/A * Copy files that do not need to be compiled into the compiled directory.
0N/A *
0N/A * Note that this also copies main.js because the requirejs step is not being performed when watching (it
0N/A * is too slow).
0N/A */
0N/A compiled: {
0N/A files: [{
0N/A cwd: compositionDirectory,
0N/A src: nonCompiledFiles.concat([
0N/A "!index.html" // Output by grunt-text-replace
]),
dest: compiledDirectory
}],
compareUsing: "md5"
},
/**
* Copy the test source files into the test-classes target directory.
*/
test: {
files: testInputDirs.map(function (inputDirectory) {
return {
cwd: inputDirectory,
src: ["**"],
dest: testClassesDirectory
};
}),
verbose: true,
compareUsing: "md5" // Avoids spurious syncs of touched, but otherwise unchanged, files (e.g. CSS)
},
/**
* Copy the compiled files to the server deploy directory.
*/
server: {
files: [{
cwd: compiledDirectory,
src: ["**"],
dest: serverDeployDirectory
}],
verbose: true,
compareUsing: "md5" // Avoids spurious syncs of touched, but otherwise unchanged, files (e.g. CSS)
}
},
watch: {
/**
* Redeploy whenever any source files change.
*/
source: {
files: watchCompositionDirs.concat(testWatchDirs).map(function (dir) {
return dir + "/**";
}),
tasks: ["deploy"]
}
}
});
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-less");
grunt.loadNpmTasks("grunt-contrib-requirejs");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-eslint");
grunt.loadNpmTasks("grunt-karma");
grunt.loadNpmTasks("grunt-sync");
grunt.loadNpmTasks("grunt-text-replace");
/**
* Resync the compiled directory and deploy to the web server.
*/
grunt.registerTask("deploy", [
"sync:compose",
"less",
"replace",
"sync:compiled",
"sync:test",
"sync:server"
]);
/**
* Rebuild the compiled directory. Maven then packs this directory into the final archive artefact.
*/
grunt.registerTask("build", [
"copy:compose",
"eslint",
"requirejs",
"less",
"replace",
"copy:compiled",
"karma:build"
]);
grunt.registerTask("dev", ["copy:compose", "deploy", "watch"]);
grunt.registerTask("prod", ["build"]);
grunt.registerTask("default", ["dev"]);
};