2013-05-26 22:02:48 +00:00
|
|
|
module.exports = function(grunt) {
|
2014-07-06 14:17:14 +00:00
|
|
|
var dateFormat = require('dateformat');
|
|
|
|
var now = new Date();
|
|
|
|
var version = '-' + dateFormat(now, "yyyy-mm-dd-hh-MM");
|
|
|
|
|
2014-08-21 22:37:35 +00:00
|
|
|
var mapToSrcFolder = function (path) {
|
|
|
|
return "src/" + path;
|
|
|
|
};
|
2014-03-16 20:15:34 +00:00
|
|
|
|
2014-08-23 20:45:52 +00:00
|
|
|
var piskelScripts = require('./src/piskel-script-list.js').scripts.map(mapToSrcFolder).filter(function (path) {
|
|
|
|
return path.indexOf('devtools') === -1;
|
|
|
|
});
|
2014-03-16 20:15:34 +00:00
|
|
|
var piskelStyles = require('./src/piskel-style-list.js').styles.map(mapToSrcFolder);
|
|
|
|
|
2014-08-21 22:37:35 +00:00
|
|
|
var mapToCasperFolder = function (path) {
|
2014-08-26 06:21:58 +00:00
|
|
|
return "test/casperjs/" + path;
|
2014-08-21 22:37:35 +00:00
|
|
|
};
|
|
|
|
|
2014-08-23 20:45:52 +00:00
|
|
|
var casperEnvironments = {
|
|
|
|
'local' : {
|
2014-08-26 06:21:58 +00:00
|
|
|
suite : './test/casperjs/LocalTestSuite.js',
|
2014-08-23 20:45:52 +00:00
|
|
|
delay : 50
|
|
|
|
},
|
|
|
|
'travis' : {
|
2014-08-26 06:21:58 +00:00
|
|
|
suite : './test/casperjs/TravisTestSuite.js',
|
2014-09-13 18:32:01 +00:00
|
|
|
delay : 10000
|
2014-08-23 20:45:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var getCasperConfig = function (env) {
|
|
|
|
var conf = casperEnvironments[env];
|
|
|
|
var tests = require(conf.suite).tests.map(mapToCasperFolder);
|
2013-08-11 11:37:23 +00:00
|
|
|
return {
|
2014-08-23 20:45:52 +00:00
|
|
|
filesSrc : tests,
|
2013-08-11 11:37:23 +00:00
|
|
|
options : {
|
|
|
|
args : {
|
2014-07-20 21:55:10 +00:00
|
|
|
baseUrl : 'http://localhost:' + '<%= express.test.options.port %>/',
|
2013-08-11 11:37:23 +00:00
|
|
|
mode : '?debug',
|
2014-08-23 20:45:52 +00:00
|
|
|
delay : conf.delay
|
2013-08-11 11:37:23 +00:00
|
|
|
},
|
2014-07-23 17:42:08 +00:00
|
|
|
async : false,
|
2013-08-11 11:37:23 +00:00
|
|
|
direct : false,
|
|
|
|
logLevel : 'info',
|
|
|
|
printCommand : false,
|
|
|
|
printFilePaths : true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-07-20 21:55:10 +00:00
|
|
|
var getExpressConfig = function (source, port, host) {
|
2014-08-21 22:37:35 +00:00
|
|
|
var bases;
|
|
|
|
if (typeof source === 'string') {
|
|
|
|
bases = [source];
|
|
|
|
} else if (Array.isArray(source)) {
|
|
|
|
bases = source;
|
|
|
|
}
|
|
|
|
|
2014-07-20 21:55:10 +00:00
|
|
|
return {
|
|
|
|
options: {
|
|
|
|
port: port,
|
|
|
|
hostname : host || 'localhost',
|
2014-08-21 22:37:35 +00:00
|
|
|
bases: bases
|
2014-07-20 21:55:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-04-13 14:30:30 +00:00
|
|
|
// load all grunt tasks
|
|
|
|
require('load-grunt-tasks')(grunt);
|
|
|
|
|
2013-08-04 16:27:32 +00:00
|
|
|
grunt.initConfig({
|
2014-05-05 20:36:34 +00:00
|
|
|
clean: {
|
2015-04-13 14:30:30 +00:00
|
|
|
before: ['dest']
|
2014-05-05 20:36:34 +00:00
|
|
|
},
|
2015-04-14 21:08:53 +00:00
|
|
|
leadingIndent : {
|
|
|
|
options: {
|
|
|
|
indentation : "spaces"
|
|
|
|
},
|
|
|
|
css : ['src/css/**/*.css']
|
|
|
|
},
|
|
|
|
jscs : {
|
|
|
|
options : {
|
|
|
|
"preset": "google",
|
|
|
|
"maximumLineLength": 120,
|
|
|
|
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
|
|
|
|
"validateQuoteMarks": { "mark": "'", "escape": true },
|
|
|
|
"disallowMultipleVarDecl": "exceptUndefined",
|
|
|
|
"disallowSpacesInAnonymousFunctionExpression": null
|
|
|
|
},
|
|
|
|
js : [ 'src/js/**/*.js' , '!src/js/**/lib/**/*.js' ]
|
|
|
|
},
|
2013-08-10 10:11:16 +00:00
|
|
|
jshint: {
|
|
|
|
options: {
|
2013-08-10 12:28:10 +00:00
|
|
|
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,
|
2015-04-09 16:24:34 +00:00
|
|
|
globals : {'$':true, 'jQuery' : true, 'pskl':true, 'Events':true, 'Constants':true, 'console' : true, 'module':true, 'require':true, 'Q':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',
|
2015-04-14 21:08:53 +00:00
|
|
|
'!src/js/**/lib/**/*.js' // Exclude lib folder (note the leading !)
|
2013-08-04 16:27:32 +00:00
|
|
|
]
|
|
|
|
},
|
2014-05-05 21:08:11 +00:00
|
|
|
express: {
|
2014-08-21 22:37:35 +00:00
|
|
|
test: getExpressConfig(['src', 'test'], 9991),
|
2014-07-20 21:55:10 +00:00
|
|
|
regular: getExpressConfig('dest', 9001),
|
2014-08-21 22:37:35 +00:00
|
|
|
debug: getExpressConfig(['src', 'test'], 9901)
|
2014-05-05 21:08:11 +00:00
|
|
|
},
|
|
|
|
open : {
|
2014-05-05 21:20:00 +00:00
|
|
|
regular : {
|
2014-05-05 21:08:11 +00:00
|
|
|
path : 'http://localhost:9001/'
|
2014-05-05 21:20:00 +00:00
|
|
|
},
|
|
|
|
debug : {
|
|
|
|
path : 'http://localhost:9901/?debug'
|
2014-05-05 21:08:11 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
scripts: {
|
|
|
|
files: ['src/**/*.*'],
|
|
|
|
tasks: ['merge'],
|
|
|
|
options: {
|
|
|
|
spawn: false
|
2013-08-04 16:27:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ghost : {
|
2014-08-23 20:45:52 +00:00
|
|
|
'travis' : getCasperConfig('travis'),
|
|
|
|
'local' : getCasperConfig('local')
|
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-07-06 14:17:14 +00:00
|
|
|
dest : 'dest/js/piskel-packaged' + version + '.js'
|
2013-12-18 22:22:25 +00:00
|
|
|
},
|
|
|
|
css : {
|
|
|
|
src : piskelStyles,
|
2014-07-06 14:17:14 +00:00
|
|
|
dest : 'dest/css/piskel-style-packaged' + version + '.css'
|
2013-09-28 21:52:51 +00:00
|
|
|
}
|
2013-08-04 16:27:32 +00:00
|
|
|
},
|
|
|
|
uglify : {
|
|
|
|
options : {
|
|
|
|
mangle : true
|
|
|
|
},
|
2015-04-13 14:30:30 +00:00
|
|
|
js : {
|
2013-08-04 16:27:32 +00:00
|
|
|
files : {
|
2014-07-06 14:17:14 +00:00
|
|
|
'dest/js/piskel-packaged-min.js' : ['dest/js/piskel-packaged' + version + '.js']
|
2013-08-04 16:27:32 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-28 16:51:10 +00:00
|
|
|
},
|
2014-07-06 14:17:14 +00:00
|
|
|
replace: {
|
|
|
|
main: {
|
|
|
|
options: {
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
match: 'version',
|
|
|
|
replacement: version
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
files: [
|
2014-09-29 22:19:54 +00:00
|
|
|
{src: ['src/piskel-boot.js'], dest: 'dest/piskel-boot.js'}
|
2014-07-06 14:17:14 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
editor: {
|
|
|
|
options: {
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
match: /templates\//g,
|
|
|
|
replacement: "../templates"+version+"/"
|
2014-09-29 22:19:54 +00:00
|
|
|
},{
|
|
|
|
match: /piskel-boot.js/g,
|
|
|
|
replacement: "../piskel-boot"+version+".js"
|
2014-07-06 14:17:14 +00:00
|
|
|
},{
|
|
|
|
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-05 20:36:34 +00:00
|
|
|
copy: {
|
|
|
|
main: {
|
|
|
|
files: [
|
2014-07-06 14:17:14 +00:00
|
|
|
{src: ['dest/js/piskel-packaged-min.js'], dest: 'dest/js/piskel-packaged-min' + version + '.js'},
|
2014-09-29 22:19:54 +00:00
|
|
|
{src: ['dest/piskel-boot.js'], dest: 'dest/piskel-boot' + version + '.js'},
|
2014-06-21 20:39:37 +00:00
|
|
|
{src: ['src/logo.png'], dest: 'dest/logo.png'},
|
2014-07-06 15:15:18 +00:00
|
|
|
{src: ['src/js/lib/iframeLoader-0.1.0.js'], dest: 'dest/js/lib/iframeLoader-0.1.0.js'},
|
2014-07-13 12:02:35 +00:00
|
|
|
{src: ['src/js/lib/gif/gif.ie.worker.js'], dest: 'dest/js/lib/gif/gif.ie.worker.js'},
|
2014-05-05 20:36:34 +00:00
|
|
|
{expand: true, src: ['img/**'], cwd: 'src/', dest: 'dest/', filter: 'isFile'},
|
2014-07-05 09:45:10 +00:00
|
|
|
{expand: true, src: ['css/fonts/**'], cwd: 'src/', dest: 'dest/', filter: 'isFile'},
|
2014-07-12 19:14:07 +00:00
|
|
|
{expand: true, src: ['**/*.html'], cwd: 'src/', dest: 'dest/', filter: 'isFile'}
|
2014-05-05 20:36:34 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2014-08-13 23:50:33 +00:00
|
|
|
karma: {
|
|
|
|
unit: {
|
|
|
|
configFile: 'karma.conf.js'
|
|
|
|
}
|
|
|
|
},
|
2014-04-28 21:13:44 +00:00
|
|
|
nodewebkit: {
|
2015-08-08 23:22:25 +00:00
|
|
|
windows : {
|
|
|
|
options: {
|
|
|
|
version : "0.11.5",
|
|
|
|
build_dir: './dest/desktop/', // destination folder of releases.
|
|
|
|
win: true,
|
|
|
|
linux32: true,
|
|
|
|
linux64: true
|
|
|
|
},
|
|
|
|
src: ['./dest/**/*', "./package.json", "!./dest/desktop/"]
|
2014-05-06 01:53:18 +00:00
|
|
|
},
|
2015-08-08 23:22:25 +00:00
|
|
|
macos : {
|
|
|
|
options: {
|
|
|
|
platforms : ['osx64'],
|
|
|
|
version : "0.10.5",
|
|
|
|
build_dir: './dest/desktop/'
|
|
|
|
},
|
|
|
|
src: ['./dest/**/*', "./package.json", "!./dest/desktop/"]
|
|
|
|
}
|
2013-08-04 16:27:32 +00:00
|
|
|
}
|
|
|
|
});
|
2013-05-26 21:58:59 +00:00
|
|
|
|
2013-08-11 18:51:04 +00:00
|
|
|
// Validate
|
2015-04-14 16:02:33 +00:00
|
|
|
grunt.registerTask('lint', ['jscs:js', 'leadingIndent:css', 'jshint']);
|
2013-05-26 21:58:59 +00:00
|
|
|
|
2014-08-13 23:50:33 +00:00
|
|
|
// karma/unit-tests task
|
|
|
|
grunt.registerTask('unit-test', ['karma']);
|
|
|
|
|
2013-09-28 21:52:51 +00:00
|
|
|
// Validate & Test
|
2015-04-13 14:30:30 +00:00
|
|
|
grunt.registerTask('test-travis', ['lint', 'unit-test', 'express:test', 'ghost:travis']);
|
2013-08-11 18:51:04 +00:00
|
|
|
// Validate & Test (faster version) will NOT work on travis !!
|
2015-04-13 14:30:30 +00:00
|
|
|
grunt.registerTask('test-local', ['lint', 'unit-test', 'express:test', 'ghost:local']);
|
2015-04-14 21:08:53 +00:00
|
|
|
grunt.registerTask('test-local-nolint', ['unit-test', 'express:test', 'ghost:local']);
|
2014-08-23 20:45:52 +00:00
|
|
|
|
|
|
|
grunt.registerTask('test', ['test-travis']);
|
|
|
|
grunt.registerTask('precommit', ['test-local']);
|
|
|
|
|
2015-04-13 14:30:30 +00:00
|
|
|
grunt.registerTask('build', ['concat:js', 'concat:css', 'uglify', 'replace:main', 'replace:editor', 'copy']);
|
2013-12-18 22:22:25 +00:00
|
|
|
|
2013-08-11 18:51:04 +00:00
|
|
|
// Validate & Build
|
2015-04-13 14:30:30 +00:00
|
|
|
grunt.registerTask('default', ['clean:before', 'lint', 'build']);
|
2013-08-11 18:51:04 +00:00
|
|
|
|
2014-04-28 21:13:44 +00:00
|
|
|
// Build stand alone app with nodewebkit
|
2015-08-15 14:29:13 +00:00
|
|
|
grunt.registerTask('desktop', ['default', 'nodewebkit:windows']);
|
|
|
|
grunt.registerTask('desktop-mac', ['default', 'nodewebkit:macos']);
|
2014-05-06 01:53:18 +00:00
|
|
|
|
2014-05-05 21:20:00 +00:00
|
|
|
// Start webserver and watch for changes
|
2015-04-13 14:30:30 +00:00
|
|
|
grunt.registerTask('serve', ['build', 'express:regular', 'open:regular', 'express-keepalive', 'watch']);
|
2014-05-05 21:43:23 +00:00
|
|
|
|
|
|
|
// Start webserver on src folder, in debug mode
|
2015-04-13 14:30:30 +00:00
|
|
|
grunt.registerTask('serve-debug', ['express:debug', 'open:debug', 'express-keepalive']);
|
2015-04-26 20:01:06 +00:00
|
|
|
grunt.registerTask('play', ['serve-debug']);
|
2013-05-26 22:02:48 +00:00
|
|
|
};
|