Gruntfile.js revision 81452d62e7f0eb940448ac113ef1a09004982e57
/**
* 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-2016 ForgeRock AS.
*/
/* global module, require, process */
var _ = require("lodash"),
mavenSrcPath = "/src/main/js",
mavenTestPath = "/src/test/js";
function mavenProjectSource (projectDir) {
return [
projectDir + "/src/main/resources"
];
}
function mavenProjectTestSource (projectDir) {
return [
projectDir + "/src/test/resources"
];
}
var compositionDirectory = "target/XUI",
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([
]),
testInputDirs = _.flatten([
]),
nonCompiledFiles = [
"**/*.html",
"**/*.ico",
"**/*.json",
"**/*.png",
"**/*.eot",
"**/*.svg",
"**/*.woff",
"**/*.woff2",
"**/*.otf",
"themes/**/*.*"
],
babel: {
options: {
babelrc: false,
env: {
development: {
sourceMaps: true
}
},
presets: ["es2015"],
plugins: [["transform-es2015-classes", {
"loose": true
}]]
},
transpile: {
files: [{
expand: true,
src: ["**/*.js"],
}],
options: {
only: [
"main.js",
"config/**/*.js",
]
}
},
files: [{
expand: true,
src: "**/*.jsm",
}
}],
options: {
plugins: [["transform-es2015-classes", {
"loose": true
}], "transform-es2015-modules-amd"]
}
}
},
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
]),
}]
},
/**
* Copy files that have been transpiled into the compiled directory.
*/
transpiled: {
files: [{
expand: true,
src: [
"**/*.js",
],
}]
}
},
eslint: {
/**
* Check the JavaScript source code for common mistakes and style issues.
*/
lint: {
src: [
],
options: {
}
}
},
karma: {
options: {
},
build: {
singleRun: true,
reporters: "progress"
},
dev: {
}
},
less: {
/**
* Compile LESS source code into minified CSS files.
*/
compile: {
files: [{
}, {
}, {
}],
options: {
compress: true,
plugins: [
new (require("less-plugin-clean-css"))({})
],
relativeUrls: true
}
}
},
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 files that have been transpiled (with their source maps) into the compiled directory.
*/
transpiled: {
files: [{
src: [
"**/*.js",
"**/*.js.map"
],
}],
compareUsing: "md5"
},
/**
* Copy the test source files into the test-classes target directory.
*/
test: {
return {
src: ["**"],
};
}),
verbose: true,
},
/**
* Copy the compiled files to the server deploy directory.
*/
server: {
files: [{
src: ["**"],
}],
verbose: true,
}
},
watch: {
/**
* Redeploy whenever any source files change.
*/
source: {
return dir + "/**";
}),
tasks: ["deploy"]
}
}
});
/**
* Resync the compiled directory and deploy to the web server.
*/
"sync:compose",
"newer:babel",
"less",
"replace",
"sync:compiled",
"sync:transpiled",
"sync:test",
"sync:server"
]);
/**
* Rebuild the compiled directory. Maven then packs this directory into the final archive artefact.
*/
"copy:compose",
"eslint",
"babel",
"requirejs",
"less",
"replace",
"copy:compiled",
"copy:transpiled",
"karma:build"
]);
};