2013-05-27 21:57:39 +00:00
|
|
|
/**
|
|
|
|
* How to run grunt tasks:
|
|
|
|
* - At project root, run 'npm install' - It will install nodedependencies declared in package,json in <root>/.node_modules
|
|
|
|
* - install grunt CLI tools globally, run 'npm install -g grunt-cli'
|
|
|
|
* - run a grunt target defined in Gruntfiles.js, ex: 'grunt lint'
|
|
|
|
*
|
|
|
|
* Note: The 'ghost' grunt task have special deps on CasperJS and phantomjs.
|
2013-08-04 16:27:32 +00:00
|
|
|
* For now, It's configured to run only on TravisCI where these deps are
|
2013-05-27 21:57:39 +00:00
|
|
|
* correctly defined.
|
2013-08-04 16:27:32 +00:00
|
|
|
* If you run this task locally, it may require some env set up first.
|
2013-05-27 21:57:39 +00:00
|
|
|
*/
|
|
|
|
|
2014-03-16 20:15:34 +00:00
|
|
|
var SOURCE_FOLDER = "src";
|
|
|
|
|
2013-05-26 22:02:48 +00:00
|
|
|
module.exports = function(grunt) {
|
2014-03-16 20:15:34 +00:00
|
|
|
var mapToSrcFolder = function (path) {return [SOURCE_FOLDER, path].join('/');};
|
|
|
|
|
|
|
|
var piskelScripts = require('./src/piskel-script-list.js').scripts.map(mapToSrcFolder);
|
|
|
|
var piskelStyles = require('./src/piskel-style-list.js').styles.map(mapToSrcFolder);
|
|
|
|
|
2013-08-11 11:37:23 +00:00
|
|
|
var getGhostConfig = function (delay) {
|
|
|
|
return {
|
2014-03-16 20:15:34 +00:00
|
|
|
filesSrc : ['test/integration/casperjs/*_test.js'],
|
2013-08-11 11:37:23 +00:00
|
|
|
options : {
|
|
|
|
args : {
|
2014-03-16 20:15:34 +00:00
|
|
|
baseUrl : 'http://localhost:' + '<%= connect.test.options.port %>/src/',
|
2013-08-11 11:37:23 +00:00
|
|
|
mode : '?debug',
|
|
|
|
delay : delay
|
|
|
|
},
|
|
|
|
direct : false,
|
|
|
|
logLevel : 'info',
|
|
|
|
printCommand : false,
|
|
|
|
printFilePaths : true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-08-04 16:27:32 +00:00
|
|
|
grunt.initConfig({
|
2014-05-05 20:36:34 +00:00
|
|
|
clean: {
|
|
|
|
before: ['dest'],
|
|
|
|
after: ['build/closure/closure_compiled_binary.js']
|
|
|
|
},
|
2013-08-10 10:11:16 +00:00
|
|
|
jshint: {
|
|
|
|
options: {
|
2013-08-10 12:28:10 +00:00
|
|
|
indent:2,
|
|
|
|
undef : true,
|
|
|
|
latedef : true,
|
|
|
|
browser : true,
|
2013-09-29 20:50:24 +00:00
|
|
|
trailing : true,
|
2013-09-28 21:52:51 +00:00
|
|
|
curly : true,
|
|
|
|
es3 : true,
|
2013-09-07 15:50:43 +00:00
|
|
|
globals : {'$':true, 'jQuery' : true, 'pskl':true, 'Events':true, 'Constants':true, 'console' : true, 'module':true, 'require':true}
|
2013-08-10 10:11:16 +00:00
|
|
|
},
|
|
|
|
files: [
|
2013-08-04 16:27:32 +00:00
|
|
|
'Gruntfile.js',
|
|
|
|
'package.json',
|
2014-03-16 20:15:34 +00:00
|
|
|
'src/js/**/*.js',
|
|
|
|
'!src/js/lib/**/*.js' // Exclude lib folder (note the leading !)
|
2013-08-04 16:27:32 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
connect : {
|
2013-08-11 18:51:04 +00:00
|
|
|
test : {
|
2013-08-04 16:27:32 +00:00
|
|
|
options : {
|
|
|
|
base : '.',
|
2013-08-11 18:51:04 +00:00
|
|
|
port : 4321
|
|
|
|
}
|
2014-05-05 21:08:11 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
express: {
|
|
|
|
server: {
|
|
|
|
options: {
|
|
|
|
port: 9001,
|
|
|
|
hostname : 'localhost',
|
|
|
|
bases: ['dest']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
open : {
|
|
|
|
server : {
|
|
|
|
path : 'http://localhost:9001/'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
scripts: {
|
|
|
|
files: ['src/**/*.*'],
|
|
|
|
tasks: ['merge'],
|
|
|
|
options: {
|
|
|
|
spawn: false
|
2013-08-04 16:27:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ghost : {
|
2014-02-11 23:14:24 +00:00
|
|
|
'default' : getGhostConfig(5000),
|
2013-08-11 11:37:23 +00:00
|
|
|
local : getGhostConfig(50)
|
2013-08-04 16:27:32 +00:00
|
|
|
},
|
|
|
|
concat : {
|
2013-12-18 22:22:25 +00:00
|
|
|
js : {
|
|
|
|
options : {
|
|
|
|
separator : ';'
|
|
|
|
},
|
2013-08-11 11:37:23 +00:00
|
|
|
src : piskelScripts,
|
2014-05-05 20:36:34 +00:00
|
|
|
dest : 'dest/js/piskel-packaged.js'
|
2013-12-18 22:22:25 +00:00
|
|
|
},
|
|
|
|
css : {
|
|
|
|
src : piskelStyles,
|
2014-05-05 20:36:34 +00:00
|
|
|
dest : 'dest/css/piskel-style-packaged.css'
|
2013-09-28 21:52:51 +00:00
|
|
|
}
|
2013-08-04 16:27:32 +00:00
|
|
|
},
|
|
|
|
uglify : {
|
|
|
|
options : {
|
|
|
|
mangle : true
|
|
|
|
},
|
|
|
|
my_target : {
|
|
|
|
files : {
|
2014-05-05 20:36:34 +00:00
|
|
|
'dest/js/piskel-packaged-min.js' : ['dest/js/piskel-packaged.js']
|
2013-08-04 16:27:32 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-28 16:51:10 +00:00
|
|
|
},
|
2014-05-05 20:36:34 +00:00
|
|
|
copy: {
|
|
|
|
main: {
|
|
|
|
files: [
|
|
|
|
{src: ['src/piskel-boot.js'], dest: 'dest/piskel-boot.js'},
|
|
|
|
{src: ['src/js/lib/iframeLoader.js'], dest: 'dest/js/lib/iframeLoader.js'},
|
|
|
|
{expand: true, src: ['img/**'], cwd: 'src/', dest: 'dest/', filter: 'isFile'},
|
|
|
|
{expand: true, src: ['**/*.html'], cwd: 'src/', dest: 'dest/', filter: 'isFile'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2013-09-28 16:51:10 +00:00
|
|
|
closureCompiler: {
|
|
|
|
options: {
|
|
|
|
// [REQUIRED] Path to closure compiler
|
2014-03-16 20:15:34 +00:00
|
|
|
compilerFile: 'build/closure/closure_compiler_20130823.jar',
|
2013-09-28 16:51:10 +00:00
|
|
|
|
|
|
|
// [OPTIONAL] set to true if you want to check if files were modified
|
|
|
|
// before starting compilation (can save some time in large sourcebases)
|
2013-09-28 19:28:45 +00:00
|
|
|
//checkModified: true,
|
2013-09-28 16:51:10 +00:00
|
|
|
|
|
|
|
// [OPTIONAL] Set Closure Compiler Directives here
|
|
|
|
compilerOpts: {
|
|
|
|
/**
|
|
|
|
* Keys will be used as directives for the compiler
|
|
|
|
* values can be strings or arrays.
|
|
|
|
* If no value is required use null
|
|
|
|
*/
|
2013-09-28 19:10:12 +00:00
|
|
|
//compilation_level: 'ADVANCED_OPTIMIZATIONS',
|
2013-09-28 17:06:35 +00:00
|
|
|
compilation_level: 'SIMPLE_OPTIMIZATIONS',
|
2014-03-16 20:15:34 +00:00
|
|
|
externs: ['build/closure/piskel-closure-externs.js'],
|
2013-09-28 19:28:45 +00:00
|
|
|
// Inject some constants in JS code, could we use that for appengine wiring ?
|
|
|
|
//define: ["'goog.DEBUG=false'"],
|
2013-09-28 17:06:35 +00:00
|
|
|
warning_level: 'verbose',
|
|
|
|
jscomp_off: ['checkTypes', 'fileoverviewTags'],
|
|
|
|
summary_detail_level: 1,
|
2013-09-28 19:10:12 +00:00
|
|
|
language_in: 'ECMASCRIPT3'
|
|
|
|
//output_wrapper: '"(function(){%output%}).call(this);"'
|
2013-09-28 16:51:10 +00:00
|
|
|
},
|
|
|
|
execOpts: { // [OPTIONAL] Set exec method options
|
2013-09-28 17:06:35 +00:00
|
|
|
maxBuffer: 999999 * 1024
|
2013-09-28 16:51:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
compile: {
|
|
|
|
|
|
|
|
/**
|
|
|
|
*[OPTIONAL] Here you can add new or override previous option of the Closure Compiler Directives.
|
|
|
|
* IMPORTANT! The feature is enabled as a temporary solution to [#738](https://github.com/gruntjs/grunt/issues/738).
|
|
|
|
* As soon as issue will be fixed this feature will be removed.
|
|
|
|
*/
|
|
|
|
TEMPcompilerOpts: {
|
|
|
|
},
|
|
|
|
src: [
|
2014-03-16 20:15:34 +00:00
|
|
|
'src/js/**/*.js',
|
|
|
|
'src/piskel-boot.js',
|
|
|
|
'src/piskel-script-list.js',
|
|
|
|
'!src/js/lib/**/*.js'
|
2013-09-28 19:28:45 +00:00
|
|
|
],
|
2013-09-28 16:51:10 +00:00
|
|
|
|
2013-09-28 19:28:45 +00:00
|
|
|
// This generated JS binary is currently not used and even excluded from source control using .gitignore.
|
2014-03-16 20:15:34 +00:00
|
|
|
dest: 'build/closure/closure_compiled_binary.js'
|
2013-09-28 16:51:10 +00:00
|
|
|
}
|
2013-08-04 16:27:32 +00:00
|
|
|
}
|
|
|
|
});
|
2013-05-26 21:58:59 +00:00
|
|
|
|
2013-08-10 10:11:16 +00:00
|
|
|
grunt.config.set('leadingIndent.indentation', 'spaces');
|
|
|
|
grunt.config.set('leadingIndent.jsFiles', {
|
2014-03-16 20:15:34 +00:00
|
|
|
src: [
|
|
|
|
'src/js/**/*.js',
|
|
|
|
'!src/js/lib/**/*.js'
|
|
|
|
]
|
2013-08-10 10:11:16 +00:00
|
|
|
});
|
|
|
|
grunt.config.set('leadingIndent.cssFiles', {
|
2014-03-16 20:15:34 +00:00
|
|
|
src: ['src/css/**/*.css']
|
2013-08-10 10:11:16 +00:00
|
|
|
});
|
2013-05-26 21:58:59 +00:00
|
|
|
|
2014-05-05 21:08:11 +00:00
|
|
|
grunt.loadNpmTasks('grunt-closure-tools');
|
2014-05-05 20:36:34 +00:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-clean');
|
2014-05-05 21:08:11 +00:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-concat');
|
2013-08-04 16:27:32 +00:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-connect');
|
2014-05-05 20:36:34 +00:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
2013-08-04 16:27:32 +00:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-uglify');
|
2014-05-05 21:08:11 +00:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
|
|
|
grunt.loadNpmTasks('grunt-express');
|
2013-08-04 16:27:32 +00:00
|
|
|
grunt.loadNpmTasks('grunt-ghost');
|
2014-05-05 21:08:11 +00:00
|
|
|
grunt.loadNpmTasks('grunt-open');
|
2013-08-10 12:47:26 +00:00
|
|
|
grunt.loadNpmTasks('grunt-leading-indent');
|
2013-08-10 10:11:16 +00:00
|
|
|
|
2013-08-11 18:51:04 +00:00
|
|
|
// Validate
|
2013-08-10 12:47:26 +00:00
|
|
|
grunt.registerTask('lint', ['leadingIndent:jsFiles', 'leadingIndent:cssFiles', 'jshint']);
|
2013-05-26 21:58:59 +00:00
|
|
|
|
2013-09-28 21:52:51 +00:00
|
|
|
// Validate & Test
|
2014-05-05 20:36:34 +00:00
|
|
|
grunt.registerTask('test', ['lint', 'compile', 'connect:test', 'ghost:default']);
|
2013-08-11 18:51:04 +00:00
|
|
|
|
|
|
|
// Validate & Test (faster version) will NOT work on travis !!
|
2014-05-05 20:36:34 +00:00
|
|
|
grunt.registerTask('precommit', ['lint', 'compile', 'connect:test', 'ghost:local']);
|
2013-08-11 18:51:04 +00:00
|
|
|
|
2013-09-28 16:51:10 +00:00
|
|
|
// Compile JS code (eg verify JSDoc annotation and types, no actual minified code generated).
|
2014-05-05 20:36:34 +00:00
|
|
|
grunt.registerTask('compile', ['closureCompiler:compile', 'clean:after']);
|
2013-08-11 18:51:04 +00:00
|
|
|
|
2014-05-05 20:36:34 +00:00
|
|
|
grunt.registerTask('merge', ['concat:js', 'concat:css', 'uglify', 'copy']);
|
2013-12-18 22:22:25 +00:00
|
|
|
|
2013-08-11 18:51:04 +00:00
|
|
|
// Validate & Build
|
2014-05-05 20:36:34 +00:00
|
|
|
grunt.registerTask('default', ['clean:before', 'lint', 'compile', 'merge']);
|
2013-08-11 18:51:04 +00:00
|
|
|
|
2014-05-05 21:08:11 +00:00
|
|
|
// Start webserver and watch for changes
|
|
|
|
grunt.registerTask('server', ['express', 'open', 'watch']);
|
2013-05-26 22:02:48 +00:00
|
|
|
};
|