piskel/Gruntfile.js

262 lines
7.4 KiB
JavaScript
Raw Normal View History

2013-05-27 02:02:48 +04:00
module.exports = function(grunt) {
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
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
};
var casperEnvironments = {
'local' : {
2014-08-26 10:21:58 +04:00
suite : './test/casperjs/LocalTestSuite.js',
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
}
};
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 {
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',
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
}
};
};
2015-04-13 17:30:30 +03:00
// load all grunt tasks
require('load-grunt-tasks')(grunt);
grunt.initConfig({
clean: {
2015-04-13 17:30:30 +03:00
before: ['dest']
},
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' ]
},
jshint: {
options: {
undef : true,
latedef : true,
browser : true,
trailing : true,
curly : true,
2015-04-09 19:24:34 +03:00
globals : {'$':true, 'jQuery' : true, 'pskl':true, 'Events':true, 'Constants':true, 'console' : true, 'module':true, 'require':true, 'Q':true}
},
files: [
'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 !)
]
},
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)
},
open : {
regular : {
path : 'http://localhost:9001/'
},
debug : {
path : 'http://localhost:9901/?debug'
}
},
watch: {
scripts: {
files: ['src/**/*.*'],
tasks: ['merge'],
options: {
spawn: false
}
}
},
ghost : {
'travis' : getCasperConfig('travis'),
'local' : getCasperConfig('local')
},
concat : {
2013-12-19 02:22:25 +04:00
js : {
options : {
separator : ';'
},
2013-08-11 15:37:23 +04:00
src : piskelScripts,
dest : 'dest/js/piskel-packaged' + version + '.js'
2013-12-19 02:22:25 +04:00
},
css : {
src : piskelStyles,
dest : 'dest/css/piskel-style-packaged' + version + '.css'
}
},
uglify : {
options : {
mangle : true
},
2015-04-13 17:30:30 +03:00
js : {
files : {
'dest/js/piskel-packaged-min.js' : ['dest/js/piskel-packaged' + version + '.js']
}
}
},
replace: {
main: {
options: {
patterns: [
{
match: 'version',
replacement: version
}
]
},
files: [
{src: ['src/piskel-boot.js'], dest: 'dest/piskel-boot.js'}
]
},
editor: {
options: {
patterns: [
{
match: /templates\//g,
replacement: "../templates"+version+"/"
},{
match: /piskel-boot.js/g,
replacement: "../piskel-boot"+version+".js"
},{
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'}
]
}
},
copy: {
main: {
files: [
{src: ['dest/js/piskel-packaged-min.js'], dest: 'dest/js/piskel-packaged-min' + version + '.js'},
{src: ['dest/piskel-boot.js'], dest: 'dest/piskel-boot' + version + '.js'},
2014-06-22 00:39:37 +04:00
{src: ['src/logo.png'], dest: 'dest/logo.png'},
{src: ['src/js/lib/iframeLoader-0.1.0.js'], dest: 'dest/js/lib/iframeLoader-0.1.0.js'},
{src: ['src/js/lib/gif/gif.ie.worker.js'], dest: 'dest/js/lib/gif/gif.ie.worker.js'},
{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-08-14 03:50:33 +04:00
karma: {
unit: {
configFile: 'karma.conf.js'
}
},
nodewebkit: {
options: {
2015-04-26 23:01:06 +03:00
version : "0.11.5",
build_dir: './dest/desktop/', // destination folder of releases.
mac: true,
win: true,
linux32: true,
linux64: true
},
src: ['./dest/**/*', "./package.json", "!./dest/desktop/"]
}
});
2013-05-27 01:58:59 +04:00
2013-08-11 22:51:04 +04:00
// Validate
grunt.registerTask('lint', ['jscs:js', 'leadingIndent:css', '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']);
// Validate & Test
2015-04-13 17:30:30 +03:00
grunt.registerTask('test-travis', ['lint', 'unit-test', 'express:test', 'ghost:travis']);
2013-08-11 22:51:04 +04:00
// Validate & Test (faster version) will NOT work on travis !!
2015-04-13 17:30:30 +03:00
grunt.registerTask('test-local', ['lint', 'unit-test', 'express:test', 'ghost:local']);
grunt.registerTask('test-local-nolint', ['unit-test', 'express:test', 'ghost:local']);
grunt.registerTask('test', ['test-travis']);
grunt.registerTask('precommit', ['test-local']);
2015-04-13 17:30:30 +03:00
grunt.registerTask('build', ['concat:js', 'concat:css', 'uglify', 'replace:main', 'replace:editor', 'copy']);
2013-12-19 02:22:25 +04:00
2013-08-11 22:51:04 +04:00
// Validate & Build
2015-04-13 17:30:30 +03:00
grunt.registerTask('default', ['clean:before', 'lint', 'build']);
2013-08-11 22:51:04 +04:00
// Build stand alone app with nodewebkit
grunt.registerTask('desktop', ['default', 'nodewebkit']);
// Start webserver and watch for changes
2015-04-13 17:30:30 +03:00
grunt.registerTask('serve', ['build', 'express:regular', 'open:regular', 'express-keepalive', 'watch']);
// Start webserver on src folder, in debug mode
2015-04-13 17:30:30 +03:00
grunt.registerTask('serve-debug', ['express:debug', 'open:debug', 'express-keepalive']);
2015-04-26 23:01:06 +03:00
grunt.registerTask('play', ['serve-debug']);
2013-05-27 02:02:48 +04:00
};