Gruntfile.js revision 628399f07dca577d36a0d63146aa093cd2c9c208
/**
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2015 ForgeRock AS.
*/
/* global module, require, process */
var _ = require("lodash"),
mavenSrcPath = "/src/main/js";
function mavenProjectSource (projectDir) {
return [
projectDir + "/src/main/resources"
];
}
function mavenProjectTestSource (projectDir) {
return [
projectDir + "/src/test/js",
projectDir + "/src/test/resources"
];
}
var compositionDirectory = "target/composed",
amCommonsDirectory = "../openam-ui-common",
buildCompositionDirs = _.flatten([
// When building, dependencies are downloaded and expanded by Maven
// This must come last so that it overwrites any conflicting files!
mavenProjectSource(".")
]),
watchCompositionDirs = _.flatten([
// When watching, we want to get the dependencies directly from the source
// This must come last so that it overwrites any conflicting files!
mavenProjectSource(".")
]),
testWatchDirs = _.flatten([
mavenProjectTestSource("."),
]),
testInputDirs = _.flatten([
mavenProjectTestSource("."),
]),
nonCompiledFiles = [
"**/*.html",
"**/*.ico",
"**/*.json",
"**/*.png",
"**/*.js",
"**/*.eot",
"**/*.svg",
"**/*.woff",
"**/*.woff2",
"**/*.otf",
],
copy: {
/**
* Copy all the sources and resources from this project and all dependencies into the composition directory.
*
* TODO: This copying shouldn't really be necessary, but is required because the dependencies are all over
* the place. If we move to using npm for our dependencies, this can be greatly simplified.
*/
compose: {
return {
expand: true,
src: ["**"],
};
})
},
/**
* Copy files that do not need to be compiled into the compiled directory.
*/
compiled: {
files: [{
expand: true,
"!index.html" // Output by grunt-text-replace
]),
}]
}
},
eslint: {
/**
* Check the JavaScript source code for common mistakes and style issues.
*/
lint: {
options: {
}
}
},
less: {
/**
* Compile LESS source code into minified CSS files.
*/
compile: {
files: [{
}, {
}, {
}],
options: {
compress: true,
plugins: [
new (require("less-plugin-clean-css"))({})
],
relativeUrls: true
}
}
},
/**
* Run qunit tests.
*/
qunit: {
},
replace: {
/**
* Include the version of AM in the index file.
*
* This is needed to force the browser to refetch JavaScript files when a new version of AM is deployed.
*/
buildNumber: {
replacements: [{
from: "${version}",
}]
}
},
requirejs: {
/**
* Concatenate and uglify the JavaScript.
*/
compile: {
options: {
include: ["main"],
preserveLicenseComments: false,
generateSourceMaps: true,
optimize: "uglify2",
// These files are excluded from optimization so that the UI can be customized without having to
// repackage it.
]
}
}
},
/**
* Sync is used when watching to speed up the build.
*/
sync: {
/**
* Copy all the sources and resources from this project and all dependencies into the composition directory.
*/
compose: {
return {
src: ["**"],
};
}),
compareUsing: "md5"
},
/**
* Copy files that do not need to be compiled into the compiled directory.
*
* Note that this also copies main.js because the requirejs step is not being performed when watching (it
* is too slow).
*/
compiled: {
files: [{
"!index.html" // Output by grunt-text-replace
]),
}],
compareUsing: "md5"
},
/**
* Copy the compiled files to the server deploy directory.
*/
server: {
files: [{
src: ["**"],
}],
verbose: true,
},
/**
* Copy the compiled files, along with the test source files and dependencies, to the server deploy
* directory.
*/
testServer: {
return {
src: ["**"],
};
}),
verbose: true,
}
},
watch: {
/**
* Redeploy whenever any source files change.
*/
source: {
return dir + "/**";
}),
tasks: ["deploy"]
},
/**
* Deploy and run the tests whenever any source files change.
*/
test: {
return dir + "/**";
}),
tasks: ["test"]
}
},
/**
* Generates OS notifications when the watch passes or fails.
*/
notify_hooks: {
options: {
enabled: true,
title: "OpenAM XUI Tests"
}
}
});
/**
* Resync the compiled directory and deploy and run the tests.
*/
"sync:compose",
"replace",
"sync:compiled",
"sync:testServer",
"qunit"
]);
/**
* Resync the compiled directory and deploy to the web server.
*/
"sync:compose",
"less",
"replace",
"sync:compiled",
"sync:server"
]);
/**
* Rebuild the compiled directory. Maven then packs this directory into the final archive artefact.
*/
"copy:compose",
"eslint",
"requirejs",
"less",
"replace",
"copy:compiled"
]);
};