2013-05-28 01:57:39 +04: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 20:27:32 +04:00
|
|
|
* For now, It's configured to run only on TravisCI where these deps are
|
2013-05-28 01:57:39 +04:00
|
|
|
* correctly defined.
|
2013-08-04 20:27:32 +04:00
|
|
|
* If you run this task locally, it may require some env set up first.
|
2013-05-28 01:57:39 +04:00
|
|
|
*/
|
|
|
|
|
2014-03-17 00:15:34 +04:00
|
|
|
|
2013-05-27 02:02:48 +04:00
|
|
|
module.exports = function(grunt) {
|
2014-07-06 18:17:14 +04:00
|
|
|
var dateFormat = require('dateformat');
|
|
|
|
var now = new Date();
|
|
|
|
var version = '-' + dateFormat(now, "yyyy-mm-dd-hh-MM");
|
|
|
|
|
2014-08-22 02:37:35 +04:00
|
|
|
var mapToSrcFolder = function (path) {
|
|
|
|
return "src/" + path;
|
|
|
|
};
|
2014-03-17 00:15:34 +04:00
|
|
|
|
2014-08-24 00:45:52 +04:00
|
|
|
var piskelScripts = require('./src/piskel-script-list.js').scripts.map(mapToSrcFolder).filter(function (path) {
|
|
|
|
return path.indexOf('devtools') === -1;
|
|
|
|
});
|
2014-03-17 00:15:34 +04:00
|
|
|
var piskelStyles = require('./src/piskel-style-list.js').styles.map(mapToSrcFolder);
|
|
|
|
|
2014-08-22 02:37:35 +04:00
|
|
|
var mapToCasperFolder = function (path) {
|
2014-08-26 10:21:58 +04:00
|
|
|
return "test/casperjs/" + path;
|
2014-08-22 02:37:35 +04:00
|
|
|
};
|
|
|
|
|
2014-08-24 00:45:52 +04:00
|
|
|
var casperEnvironments = {
|
|
|
|
'local' : {
|
2014-08-26 10:21:58 +04:00
|
|
|
suite : './test/casperjs/LocalTestSuite.js',
|
2014-08-24 00:45:52 +04:00
|
|
|
delay : 50
|
|
|
|
},
|
|
|
|
'travis' : {
|
2014-08-26 10:21:58 +04:00
|
|
|
suite : './test/casperjs/TravisTestSuite.js',
|
2014-09-13 22:32:01 +04:00
|
|
|
delay : 10000
|
2014-08-24 00:45:52 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var getCasperConfig = function (env) {
|
|
|
|
var conf = casperEnvironments[env];
|
|
|
|
var tests = require(conf.suite).tests.map(mapToCasperFolder);
|
2013-08-11 15:37:23 +04:00
|
|
|
return {
|
2014-08-24 00:45:52 +04:00
|
|
|
filesSrc : tests,
|
2013-08-11 15:37:23 +04:00
|
|
|
options : {
|
|
|
|
args : {
|
2014-07-21 01:55:10 +04:00
|
|
|
baseUrl : 'http://localhost:' + '<%= express.test.options.port %>/',
|
2013-08-11 15:37:23 +04:00
|
|
|
mode : '?debug',
|
2014-08-24 00:45:52 +04:00
|
|
|
delay : conf.delay
|
2013-08-11 15:37:23 +04:00
|
|
|
},
|
2014-07-23 21:42:08 +04:00
|
|
|
async : false,
|
2013-08-11 15:37:23 +04:00
|
|
|
direct : false,
|
|
|
|
logLevel : 'info',
|
|
|
|
printCommand : false,
|
|
|
|
printFilePaths : true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-07-21 01:55:10 +04:00
|
|
|
var getExpressConfig = function (source, port, host) {
|
2014-08-22 02:37:35 +04:00
|
|
|
var bases;
|
|
|
|
if (typeof source === 'string') {
|
|
|
|
bases = [source];
|
|
|
|
} else if (Array.isArray(source)) {
|
|
|
|
bases = source;
|
|
|
|
}
|
|
|
|
|
2014-07-21 01:55:10 +04:00
|
|
|
return {
|
|
|
|
options: {
|
|
|
|
port: port,
|
|
|
|
hostname : host || 'localhost',
|
2014-08-22 02:37:35 +04:00
|
|
|
bases: bases
|
2014-07-21 01:55:10 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-08-04 20:27:32 +04:00
|
|
|
grunt.initConfig({
|
2014-05-06 00:36:34 +04:00
|
|
|
clean: {
|
|
|
|
before: ['dest'],
|
|
|
|
after: ['build/closure/closure_compiled_binary.js']
|
|
|
|
},
|
2013-08-10 14:11:16 +04:00
|
|
|
jshint: {
|
|
|
|
options: {
|
2013-08-10 16:28:10 +04:00
|
|
|
indent:2,
|
|
|
|
undef : true,
|
|
|
|
latedef : true,
|
|
|
|
browser : true,
|
2013-09-30 00:50:24 +04:00
|
|
|
trailing : true,
|
2013-09-29 01:52:51 +04:00
|
|
|
curly : true,
|
|
|
|
es3 : true,
|
2013-09-07 19:50:43 +04:00
|
|
|
globals : {'$':true, 'jQuery' : true, 'pskl':true, 'Events':true, 'Constants':true, 'console' : true, 'module':true, 'require':true}
|
2013-08-10 14:11:16 +04:00
|
|
|
},
|
|
|
|
files: [
|
2013-08-04 20:27:32 +04:00
|
|
|
'Gruntfile.js',
|
|
|
|
'package.json',
|
2014-03-17 00:15:34 +04:00
|
|
|
'src/js/**/*.js',
|
|
|
|
'!src/js/lib/**/*.js' // Exclude lib folder (note the leading !)
|
2013-08-04 20:27:32 +04:00
|
|
|
]
|
|
|
|
},
|
2014-05-06 01:08:11 +04:00
|
|
|
express: {
|
2014-08-22 02:37:35 +04:00
|
|
|
test: getExpressConfig(['src', 'test'], 9991),
|
2014-07-21 01:55:10 +04:00
|
|
|
regular: getExpressConfig('dest', 9001),
|
2014-08-22 02:37:35 +04:00
|
|
|
debug: getExpressConfig(['src', 'test'], 9901)
|
2014-05-06 01:08:11 +04:00
|
|
|
},
|
|
|
|
open : {
|
2014-05-06 01:20:00 +04:00
|
|
|
regular : {
|
2014-05-06 01:08:11 +04:00
|
|
|
path : 'http://localhost:9001/'
|
2014-05-06 01:20:00 +04:00
|
|
|
},
|
|
|
|
debug : {
|
|
|
|
path : 'http://localhost:9901/?debug'
|
2014-05-06 01:08:11 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
scripts: {
|
|
|
|
files: ['src/**/*.*'],
|
|
|
|
tasks: ['merge'],
|
|
|
|
options: {
|
|
|
|
spawn: false
|
2013-08-04 20:27:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ghost : {
|
2014-08-24 00:45:52 +04:00
|
|
|
'travis' : getCasperConfig('travis'),
|
|
|
|
'local' : getCasperConfig('local')
|
2013-08-04 20:27:32 +04:00
|
|
|
},
|
|
|
|
concat : {
|
2013-12-19 02:22:25 +04:00
|
|
|
js : {
|
|
|
|
options : {
|
|
|
|
separator : ';'
|
|
|
|
},
|
2013-08-11 15:37:23 +04:00
|
|
|
src : piskelScripts,
|
2014-07-06 18:17:14 +04:00
|
|
|
dest : 'dest/js/piskel-packaged' + version + '.js'
|
2013-12-19 02:22:25 +04:00
|
|
|
},
|
|
|
|
css : {
|
|
|
|
src : piskelStyles,
|
2014-07-06 18:17:14 +04:00
|
|
|
dest : 'dest/css/piskel-style-packaged' + version + '.css'
|
2013-09-29 01:52:51 +04:00
|
|
|
}
|
2013-08-04 20:27:32 +04:00
|
|
|
},
|
|
|
|
uglify : {
|
|
|
|
options : {
|
|
|
|
mangle : true
|
|
|
|
},
|
|
|
|
my_target : {
|
|
|
|
files : {
|
2014-07-06 18:17:14 +04:00
|
|
|
'dest/js/piskel-packaged-min.js' : ['dest/js/piskel-packaged' + version + '.js']
|
2013-08-04 20:27:32 +04:00
|
|
|
}
|
|
|
|
}
|
2013-09-28 20:51:10 +04:00
|
|
|
},
|
2014-07-06 18:17:14 +04:00
|
|
|
replace: {
|
|
|
|
main: {
|
|
|
|
options: {
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
match: 'version',
|
|
|
|
replacement: version
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
files: [
|
2014-07-06 19:15:18 +04:00
|
|
|
{expand: true, flatten: true, src: ['src/piskel-boot-0.1.0.js'], dest: 'dest/'}
|
2014-07-06 18:17:14 +04:00
|
|
|
]
|
|
|
|
},
|
|
|
|
editor: {
|
|
|
|
options: {
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
match: /templates\//g,
|
|
|
|
replacement: "../templates"+version+"/"
|
|
|
|
},{
|
|
|
|
match: /^(.|[\r\n])*<!--body-main-start-->/,
|
|
|
|
replacement: "",
|
|
|
|
description : "Remove everything before body-main-start comment"
|
|
|
|
},{
|
|
|
|
match: /<!--body-main-end-->(.|[\r\n])*$/,
|
|
|
|
replacement: "",
|
|
|
|
description : "Remove everything after body-main-end comment"
|
|
|
|
},{
|
|
|
|
match: /([\r\n]) /g,
|
|
|
|
replacement: "$1",
|
|
|
|
description : "Decrease indentation by one"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
files: [
|
|
|
|
{src: ['src/index.html'], dest: 'dest/piskelapp-partials/main-partial.html'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2014-05-06 00:36:34 +04:00
|
|
|
copy: {
|
|
|
|
main: {
|
|
|
|
files: [
|
2014-07-06 18:17:14 +04:00
|
|
|
{src: ['dest/js/piskel-packaged-min.js'], dest: 'dest/js/piskel-packaged-min' + version + '.js'},
|
2014-06-22 00:39:37 +04:00
|
|
|
{src: ['src/logo.png'], dest: 'dest/logo.png'},
|
2014-07-06 19:15:18 +04:00
|
|
|
{src: ['src/js/lib/iframeLoader-0.1.0.js'], dest: 'dest/js/lib/iframeLoader-0.1.0.js'},
|
2014-07-13 16:02:35 +04:00
|
|
|
{src: ['src/js/lib/gif/gif.ie.worker.js'], dest: 'dest/js/lib/gif/gif.ie.worker.js'},
|
2014-05-06 00:36:34 +04:00
|
|
|
{expand: true, src: ['img/**'], cwd: 'src/', dest: 'dest/', filter: 'isFile'},
|
2014-07-05 13:45:10 +04:00
|
|
|
{expand: true, src: ['css/fonts/**'], cwd: 'src/', dest: 'dest/', filter: 'isFile'},
|
2014-07-12 23:14:07 +04:00
|
|
|
{expand: true, src: ['**/*.html'], cwd: 'src/', dest: 'dest/', filter: 'isFile'}
|
2014-05-06 00:36:34 +04:00
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2013-09-28 20:51:10 +04:00
|
|
|
closureCompiler: {
|
|
|
|
options: {
|
|
|
|
// [REQUIRED] Path to closure compiler
|
2014-03-17 00:15:34 +04:00
|
|
|
compilerFile: 'build/closure/closure_compiler_20130823.jar',
|
2013-09-28 20:51:10 +04: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 23:28:45 +04:00
|
|
|
//checkModified: true,
|
2013-09-28 20:51:10 +04: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 23:10:12 +04:00
|
|
|
//compilation_level: 'ADVANCED_OPTIMIZATIONS',
|
2013-09-28 21:06:35 +04:00
|
|
|
compilation_level: 'SIMPLE_OPTIMIZATIONS',
|
2014-03-17 00:15:34 +04:00
|
|
|
externs: ['build/closure/piskel-closure-externs.js'],
|
2013-09-28 23:28:45 +04:00
|
|
|
// Inject some constants in JS code, could we use that for appengine wiring ?
|
|
|
|
//define: ["'goog.DEBUG=false'"],
|
2013-09-28 21:06:35 +04:00
|
|
|
warning_level: 'verbose',
|
|
|
|
jscomp_off: ['checkTypes', 'fileoverviewTags'],
|
|
|
|
summary_detail_level: 1,
|
2013-09-28 23:10:12 +04:00
|
|
|
language_in: 'ECMASCRIPT3'
|
|
|
|
//output_wrapper: '"(function(){%output%}).call(this);"'
|
2013-09-28 20:51:10 +04:00
|
|
|
},
|
|
|
|
execOpts: { // [OPTIONAL] Set exec method options
|
2013-09-28 21:06:35 +04:00
|
|
|
maxBuffer: 999999 * 1024
|
2013-09-28 20:51:10 +04: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-17 00:15:34 +04:00
|
|
|
'src/js/**/*.js',
|
2014-07-06 19:15:18 +04:00
|
|
|
'src/piskel-boot-0.1.0.js',
|
2014-03-17 00:15:34 +04:00
|
|
|
'src/piskel-script-list.js',
|
|
|
|
'!src/js/lib/**/*.js'
|
2013-09-28 23:28:45 +04:00
|
|
|
],
|
2013-09-28 20:51:10 +04:00
|
|
|
|
2013-09-28 23:28:45 +04:00
|
|
|
// This generated JS binary is currently not used and even excluded from source control using .gitignore.
|
2014-03-17 00:15:34 +04:00
|
|
|
dest: 'build/closure/closure_compiled_binary.js'
|
2013-09-28 20:51:10 +04:00
|
|
|
}
|
2014-04-29 01:13:44 +04:00
|
|
|
},
|
2014-08-14 03:50:33 +04:00
|
|
|
karma: {
|
|
|
|
unit: {
|
|
|
|
configFile: 'karma.conf.js'
|
|
|
|
}
|
|
|
|
},
|
2014-04-29 01:13:44 +04:00
|
|
|
nodewebkit: {
|
2014-05-06 05:53:18 +04:00
|
|
|
options: {
|
2014-05-12 00:16:57 +04:00
|
|
|
build_dir: './dest/desktop/', // destination folder of releases.
|
2014-05-06 05:53:18 +04:00
|
|
|
mac: true,
|
|
|
|
win: true,
|
|
|
|
linux32: true,
|
|
|
|
linux64: true
|
|
|
|
},
|
2014-05-12 00:16:57 +04:00
|
|
|
src: ['./dest/**/*', "./package.json", "!./dest/desktop/"]
|
2013-08-04 20:27:32 +04:00
|
|
|
}
|
|
|
|
});
|
2013-05-27 01:58:59 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
grunt.config.set('leadingIndent.indentation', 'spaces');
|
|
|
|
grunt.config.set('leadingIndent.jsFiles', {
|
2014-03-17 00:15:34 +04:00
|
|
|
src: [
|
|
|
|
'src/js/**/*.js',
|
|
|
|
'!src/js/lib/**/*.js'
|
|
|
|
]
|
2013-08-10 14:11:16 +04:00
|
|
|
});
|
|
|
|
grunt.config.set('leadingIndent.cssFiles', {
|
2014-03-17 00:15:34 +04:00
|
|
|
src: ['src/css/**/*.css']
|
2013-08-10 14:11:16 +04:00
|
|
|
});
|
2013-05-27 01:58:59 +04:00
|
|
|
|
2014-05-06 01:08:11 +04:00
|
|
|
grunt.loadNpmTasks('grunt-closure-tools');
|
2014-05-06 00:36:34 +04:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-clean');
|
2014-05-06 01:08:11 +04:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-concat');
|
2014-05-06 00:36:34 +04:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
2013-08-04 20:27:32 +04:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-uglify');
|
2014-05-06 01:08:11 +04:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
|
|
|
grunt.loadNpmTasks('grunt-express');
|
2014-07-06 18:17:14 +04:00
|
|
|
grunt.loadNpmTasks('grunt-replace');
|
2013-08-04 20:27:32 +04:00
|
|
|
grunt.loadNpmTasks('grunt-ghost');
|
2014-05-06 01:08:11 +04:00
|
|
|
grunt.loadNpmTasks('grunt-open');
|
2014-08-14 03:50:33 +04:00
|
|
|
grunt.loadNpmTasks('grunt-karma');
|
2013-08-10 16:47:26 +04:00
|
|
|
grunt.loadNpmTasks('grunt-leading-indent');
|
2014-04-29 01:13:44 +04:00
|
|
|
grunt.loadNpmTasks('grunt-node-webkit-builder');
|
2014-05-01 04:00:10 +04:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
|
|
|
|
2013-08-11 22:51:04 +04:00
|
|
|
// Validate
|
2013-08-10 16:47:26 +04:00
|
|
|
grunt.registerTask('lint', ['leadingIndent:jsFiles', 'leadingIndent:cssFiles', 'jshint']);
|
2013-05-27 01:58:59 +04:00
|
|
|
|
2014-08-14 03:50:33 +04:00
|
|
|
// karma/unit-tests task
|
|
|
|
grunt.registerTask('unit-test', ['karma']);
|
|
|
|
|
2013-09-29 01:52:51 +04:00
|
|
|
// Validate & Test
|
2014-08-24 00:45:52 +04:00
|
|
|
grunt.registerTask('test-travis', ['lint', 'compile', 'unit-test', 'express:test', 'ghost:travis']);
|
2013-08-11 22:51:04 +04:00
|
|
|
// Validate & Test (faster version) will NOT work on travis !!
|
2014-08-24 00:45:52 +04:00
|
|
|
grunt.registerTask('test-local', ['lint', 'compile', 'unit-test', 'express:test', 'ghost:local']);
|
|
|
|
|
|
|
|
grunt.registerTask('test', ['test-travis']);
|
|
|
|
grunt.registerTask('precommit', ['test-local']);
|
|
|
|
|
2013-08-11 22:51:04 +04:00
|
|
|
|
2013-09-28 20:51:10 +04:00
|
|
|
// Compile JS code (eg verify JSDoc annotation and types, no actual minified code generated).
|
2014-05-06 00:36:34 +04:00
|
|
|
grunt.registerTask('compile', ['closureCompiler:compile', 'clean:after']);
|
2013-08-11 22:51:04 +04:00
|
|
|
|
2014-07-12 23:14:07 +04:00
|
|
|
grunt.registerTask('rep', ['replace:main', 'replace:editor']);
|
2014-07-06 18:17:14 +04:00
|
|
|
|
|
|
|
grunt.registerTask('merge', ['concat:js', 'concat:css', 'uglify', 'rep', 'copy']);
|
2013-12-19 02:22:25 +04:00
|
|
|
|
2013-08-11 22:51:04 +04:00
|
|
|
// Validate & Build
|
2014-05-06 00:36:34 +04:00
|
|
|
grunt.registerTask('default', ['clean:before', 'lint', 'compile', 'merge']);
|
2013-08-11 22:51:04 +04:00
|
|
|
|
2014-04-29 01:13:44 +04:00
|
|
|
// Build stand alone app with nodewebkit
|
2014-05-06 05:53:18 +04:00
|
|
|
grunt.registerTask('desktop', ['default', 'nodewebkit']);
|
|
|
|
|
2014-05-06 01:43:23 +04:00
|
|
|
grunt.registerTask('server', ['merge', 'express:regular', 'open:regular', 'express-keepalive']);
|
2014-05-06 01:20:00 +04:00
|
|
|
|
|
|
|
// Start webserver and watch for changes
|
2014-05-06 01:43:23 +04:00
|
|
|
grunt.registerTask('server:watch', ['server', 'watch']);
|
|
|
|
|
|
|
|
// Start webserver on src folder, in debug mode
|
|
|
|
grunt.registerTask('server:debug', ['express:debug', 'open:debug', 'express-keepalive']);
|
2013-05-27 02:02:48 +04:00
|
|
|
};
|