2013-05-27 02:02:48 +04:00
|
|
|
module.exports = function(grunt) {
|
2015-12-01 02:28:41 +03:00
|
|
|
|
|
|
|
// Update this variable if you don't want or can't serve on localhost
|
|
|
|
var hostname = 'localhost';
|
|
|
|
|
2015-12-10 00:38:58 +03:00
|
|
|
var PORT = {
|
|
|
|
PROD : 9001,
|
|
|
|
DEV : 9901,
|
|
|
|
TEST : 9991
|
|
|
|
};
|
|
|
|
|
|
|
|
var DEV_MODE = '?debug';
|
|
|
|
|
2015-12-01 02:28:41 +03:00
|
|
|
// create a version based on the build timestamp
|
2014-07-06 18:17:14 +04:00
|
|
|
var dateFormat = require('dateformat');
|
2015-12-01 02:28:41 +03:00
|
|
|
var version = '-' + dateFormat(new Date(), "yyyy-mm-dd-hh-MM");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to prefix all strings in provided array with the provided path
|
|
|
|
*/
|
|
|
|
var prefixPaths = function (paths, prefix) {
|
|
|
|
return paths.map(function (path) {
|
|
|
|
return prefix + path;
|
|
|
|
});
|
|
|
|
};
|
2014-07-06 18:17:14 +04:00
|
|
|
|
2015-11-30 03:29:59 +03:00
|
|
|
// get the list of scripts paths to include
|
2015-12-01 02:28:41 +03:00
|
|
|
var scriptPaths = require('./src/piskel-script-list.js').scripts;
|
|
|
|
var piskelScripts = prefixPaths(scriptPaths, "src/").filter(function (path) {
|
2014-08-24 00:45:52 +04:00
|
|
|
return path.indexOf('devtools') === -1;
|
|
|
|
});
|
2015-12-01 02:28:41 +03:00
|
|
|
|
2015-11-30 03:29:59 +03:00
|
|
|
// get the list of styles paths to include
|
2015-12-01 02:28:41 +03:00
|
|
|
var stylePaths = require('./src/piskel-style-list.js').styles;
|
|
|
|
var piskelStyles = prefixPaths(stylePaths, "src/");
|
2014-08-22 02:37:35 +04:00
|
|
|
|
2015-12-01 02:28:41 +03:00
|
|
|
var getCasperConfig = function (suiteName, delay, host) {
|
|
|
|
var testPaths = require('./test/casperjs/' + suiteName).tests;
|
|
|
|
var tests = prefixPaths(testPaths, "test/casperjs/");
|
2014-08-24 00:45:52 +04:00
|
|
|
|
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 : {
|
2015-12-10 00:38:58 +03:00
|
|
|
baseUrl : 'http://' + host + ':' + PORT.TEST,
|
|
|
|
mode : DEV_MODE,
|
2015-12-01 02:28:41 +03:00
|
|
|
delay : 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
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-12-10 00:38:58 +03:00
|
|
|
var getConnectConfig = function (base, port, host) {
|
|
|
|
if (typeof base === 'string') {
|
|
|
|
base = [base];
|
2014-08-22 02:37:35 +04:00
|
|
|
}
|
|
|
|
|
2014-07-21 01:55:10 +04:00
|
|
|
return {
|
|
|
|
options: {
|
|
|
|
port: port,
|
2015-12-01 02:28:41 +03:00
|
|
|
hostname : host,
|
2015-12-10 00:38:58 +03:00
|
|
|
base: base
|
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);
|
|
|
|
|
2013-08-04 20:27:32 +04:00
|
|
|
grunt.initConfig({
|
2014-05-06 00:36:34 +04:00
|
|
|
clean: {
|
2015-12-01 02:35:26 +03:00
|
|
|
all: ['dest', 'src/img/icons.png', 'src/css/icons.css'],
|
2015-12-01 02:28:41 +03:00
|
|
|
prod: ['dest/prod', 'dest/tmp'],
|
|
|
|
desktop: ['dest/desktop', 'dest/tmp'],
|
|
|
|
dev: ['dest/dev', 'dest/tmp']
|
2014-05-06 00:36:34 +04:00
|
|
|
},
|
2015-11-30 02:08:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* STYLE CHECKS
|
|
|
|
*/
|
|
|
|
|
2015-04-15 00:08:53 +03:00
|
|
|
leadingIndent : {
|
|
|
|
options: {
|
|
|
|
indentation : "spaces"
|
|
|
|
},
|
|
|
|
css : ['src/css/**/*.css']
|
|
|
|
},
|
2015-11-30 02:08:50 +03:00
|
|
|
|
2015-04-15 00:08:53 +03:00
|
|
|
jscs : {
|
|
|
|
options : {
|
2015-12-10 00:38:58 +03:00
|
|
|
"config": ".jscsrc",
|
2015-04-15 00:08:53 +03:00
|
|
|
"maximumLineLength": 120,
|
|
|
|
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
|
|
|
|
"validateQuoteMarks": { "mark": "'", "escape": true },
|
|
|
|
"disallowMultipleVarDecl": "exceptUndefined",
|
|
|
|
"disallowSpacesInAnonymousFunctionExpression": null
|
|
|
|
},
|
|
|
|
js : [ 'src/js/**/*.js' , '!src/js/**/lib/**/*.js' ]
|
|
|
|
},
|
2015-11-30 02:08:50 +03:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
jshint: {
|
|
|
|
options: {
|
2013-08-10 16:28:10 +04:00
|
|
|
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,
|
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}
|
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',
|
2015-04-15 00:08:53 +03:00
|
|
|
'!src/js/**/lib/**/*.js' // Exclude lib folder (note the leading !)
|
2013-08-04 20:27:32 +04:00
|
|
|
]
|
|
|
|
},
|
2015-11-30 02:08:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SERVERS, BROWSER LAUNCHERS
|
|
|
|
*/
|
|
|
|
|
2015-12-10 00:38:58 +03:00
|
|
|
connect: {
|
|
|
|
prod: getConnectConfig('dest/prod', PORT.PROD, hostname),
|
|
|
|
test: getConnectConfig(['dest/dev', 'test'], PORT.TEST, hostname),
|
|
|
|
dev: getConnectConfig(['dest/dev', 'test'], PORT.DEV, hostname)
|
2014-05-06 01:08:11 +04:00
|
|
|
},
|
2015-11-30 02:08:50 +03:00
|
|
|
|
2014-05-06 01:08:11 +04:00
|
|
|
open : {
|
2015-12-10 00:38:58 +03:00
|
|
|
prod : {
|
|
|
|
path : 'http://' + hostname + ':' + PORT.PROD + '/'
|
2014-05-06 01:20:00 +04:00
|
|
|
},
|
2015-12-10 00:38:58 +03:00
|
|
|
dev : {
|
|
|
|
path : 'http://' + hostname + ':' + PORT.DEV + '/' + DEV_MODE
|
2014-05-06 01:08:11 +04:00
|
|
|
}
|
|
|
|
},
|
2015-11-30 02:08:50 +03:00
|
|
|
|
2014-05-06 01:08:11 +04:00
|
|
|
watch: {
|
2015-11-30 00:05:41 +03:00
|
|
|
prod: {
|
2014-05-06 01:08:11 +04:00
|
|
|
files: ['src/**/*.*'],
|
2015-11-30 00:05:41 +03:00
|
|
|
tasks: ['build'],
|
|
|
|
options: {
|
|
|
|
spawn: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
dev: {
|
2015-11-30 02:08:50 +03:00
|
|
|
files: ['src/**/*.*'],
|
|
|
|
tasks: ['build-dev'],
|
2014-05-06 01:08:11 +04:00
|
|
|
options: {
|
|
|
|
spawn: false
|
2013-08-04 20:27:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-11-30 02:08:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* BUILD STEPS
|
|
|
|
*/
|
|
|
|
|
|
|
|
sprite:{
|
|
|
|
all : {
|
|
|
|
src: 'src/img/icons/**/*.png',
|
|
|
|
dest: 'src/img/icons.png',
|
|
|
|
destCss: 'src/css/icons.css'
|
|
|
|
}
|
2013-08-04 20:27:32 +04:00
|
|
|
},
|
2015-11-30 02:08:50 +03:00
|
|
|
|
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,
|
2015-12-01 02:28:41 +03:00
|
|
|
dest : 'dest/prod/js/piskel-packaged' + version + '.js'
|
2013-12-19 02:22:25 +04:00
|
|
|
},
|
|
|
|
css : {
|
|
|
|
src : piskelStyles,
|
2015-12-01 02:28:41 +03:00
|
|
|
dest : 'dest/prod/css/piskel-style-packaged' + version + '.css'
|
2013-09-29 01:52:51 +04:00
|
|
|
}
|
2013-08-04 20:27:32 +04:00
|
|
|
},
|
2015-11-30 02:08:50 +03:00
|
|
|
|
2013-08-04 20:27:32 +04:00
|
|
|
uglify : {
|
|
|
|
options : {
|
|
|
|
mangle : true
|
|
|
|
},
|
2015-04-13 17:30:30 +03:00
|
|
|
js : {
|
2013-08-04 20:27:32 +04:00
|
|
|
files : {
|
2015-12-01 02:28:41 +03:00
|
|
|
'dest/tmp/js/piskel-packaged-min.js' : ['dest/prod/js/piskel-packaged' + version + '.js']
|
2013-08-04 20:27:32 +04:00
|
|
|
}
|
|
|
|
}
|
2013-09-28 20:51:10 +04:00
|
|
|
},
|
2015-11-30 02:08:50 +03:00
|
|
|
|
|
|
|
includereplace: {
|
|
|
|
all: {
|
|
|
|
src: 'src/index.html',
|
2015-12-01 02:28:41 +03:00
|
|
|
dest: 'dest/tmp/index.html',
|
2015-11-30 15:36:27 +03:00
|
|
|
options : {
|
|
|
|
globals : {
|
|
|
|
'version' : version
|
|
|
|
}
|
|
|
|
}
|
2015-11-30 02:08:50 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-07-06 18:17:14 +04:00
|
|
|
replace: {
|
2015-11-30 02:08:50 +03:00
|
|
|
// main-partial.html is used when embedded in piskelapp.com
|
|
|
|
mainPartial: {
|
2014-07-06 18:17:14 +04:00
|
|
|
options: {
|
2015-11-30 02:08:50 +03:00
|
|
|
patterns: [{
|
2014-07-06 18:17:14 +04:00
|
|
|
match: /^(.|[\r\n])*<!--body-main-start-->/,
|
2015-11-30 16:22:11 +03:00
|
|
|
replacement: "{% raw %}",
|
2014-07-06 18:17:14 +04:00
|
|
|
description : "Remove everything before body-main-start comment"
|
|
|
|
},{
|
|
|
|
match: /<!--body-main-end-->(.|[\r\n])*$/,
|
2015-11-30 16:22:11 +03:00
|
|
|
replacement: "{% endraw %}",
|
2014-07-06 18:17:14 +04:00
|
|
|
description : "Remove everything after body-main-end comment"
|
|
|
|
},{
|
|
|
|
match: /([\r\n]) /g,
|
|
|
|
replacement: "$1",
|
|
|
|
description : "Decrease indentation by one"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
files: [
|
2015-11-30 02:08:50 +03:00
|
|
|
// src/index.html should already have been moved by the includereplace task
|
2015-12-01 02:28:41 +03:00
|
|
|
{src: ['dest/tmp/index.html'], dest: 'dest/prod/piskelapp-partials/main-partial.html'}
|
2014-07-06 18:17:14 +04:00
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2015-11-30 02:08:50 +03:00
|
|
|
|
2014-05-06 00:36:34 +04:00
|
|
|
copy: {
|
2015-11-30 02:08:50 +03:00
|
|
|
prod: {
|
2014-05-06 00:36:34 +04:00
|
|
|
files: [
|
2015-11-30 02:08:50 +03:00
|
|
|
// dest/js/piskel-packaged-min.js should have been created by the uglify task
|
2015-12-01 02:28:41 +03:00
|
|
|
{src: ['dest/tmp/js/piskel-packaged-min.js'], dest: 'dest/prod/js/piskel-packaged-min' + version + '.js'},
|
|
|
|
{src: ['dest/tmp/index.html'], dest: 'dest/prod/index.html'},
|
|
|
|
{src: ['src/logo.png'], dest: 'dest/prod/logo.png'},
|
|
|
|
{src: ['src/js/lib/gif/gif.ie.worker.js'], dest: 'dest/prod/js/lib/gif/gif.ie.worker.js'},
|
|
|
|
{expand: true, src: ['img/**'], cwd: 'src/', dest: 'dest/prod/', filter: 'isFile'},
|
|
|
|
{expand: true, src: ['css/fonts/**'], cwd: 'src/', dest: 'dest/prod/', filter: 'isFile'}
|
2015-11-30 02:08:50 +03:00
|
|
|
]
|
|
|
|
},
|
|
|
|
dev: {
|
|
|
|
files: [
|
2015-12-01 02:28:41 +03:00
|
|
|
// in dev copy everything to dest/dev
|
|
|
|
{src: ['dest/tmp/index.html'], dest: 'dest/dev/index.html'},
|
|
|
|
{src: ['src/piskel-script-list.js'], dest: 'dest/dev/piskel-script-list.js'},
|
|
|
|
{src: ['src/piskel-style-list.js'], dest: 'dest/dev/piskel-style-list.js'},
|
|
|
|
{expand: true, src: ['js/**'], cwd: 'src/', dest: 'dest/dev/', filter: 'isFile'},
|
|
|
|
{expand: true, src: ['css/**'], cwd: 'src/', dest: 'dest/dev/', filter: 'isFile'},
|
|
|
|
{expand: true, src: ['img/**'], cwd: 'src/', dest: 'dest/dev/', filter: 'isFile'},
|
2014-05-06 00:36:34 +04:00
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2015-11-30 02:08:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* TESTING
|
|
|
|
*/
|
|
|
|
|
2014-08-14 03:50:33 +04:00
|
|
|
karma: {
|
|
|
|
unit: {
|
|
|
|
configFile: 'karma.conf.js'
|
|
|
|
}
|
|
|
|
},
|
2015-11-30 02:08:50 +03:00
|
|
|
|
|
|
|
ghost : {
|
2015-12-01 02:28:41 +03:00
|
|
|
'travis' : getCasperConfig('TravisTestSuite.js', 10000, hostname),
|
|
|
|
'local' : getCasperConfig('LocalTestSuite.js', 50, hostname)
|
2015-11-30 02:08:50 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DESKTOP BUILDS
|
|
|
|
*/
|
|
|
|
|
2015-12-10 01:02:44 +03:00
|
|
|
nwjs: {
|
2015-08-09 02:22:25 +03:00
|
|
|
windows : {
|
|
|
|
options: {
|
2016-03-31 04:42:53 +03:00
|
|
|
version : "0.12.3",
|
2015-08-09 02:22:25 +03:00
|
|
|
build_dir: './dest/desktop/', // destination folder of releases.
|
|
|
|
win: true,
|
|
|
|
linux32: true,
|
|
|
|
linux64: true
|
|
|
|
},
|
2015-12-01 02:28:41 +03:00
|
|
|
src: ['./dest/prod/**/*', "./package.json", "!./dest/desktop/"]
|
2014-05-06 05:53:18 +04:00
|
|
|
},
|
2015-08-09 02:22:25 +03:00
|
|
|
macos : {
|
|
|
|
options: {
|
2015-12-30 01:44:02 +03:00
|
|
|
osx64: true,
|
2016-03-31 04:42:53 +03:00
|
|
|
version : "0.12.3",
|
2015-08-09 02:22:25 +03:00
|
|
|
build_dir: './dest/desktop/'
|
|
|
|
},
|
2015-12-01 02:28:41 +03:00
|
|
|
src: ['./dest/prod/**/*', "./package.json", "!./dest/desktop/"]
|
2015-08-09 02:22:25 +03:00
|
|
|
}
|
2013-08-04 20:27:32 +04:00
|
|
|
}
|
|
|
|
});
|
2013-05-27 01:58:59 +04:00
|
|
|
|
2013-08-11 22:51:04 +04:00
|
|
|
// Validate
|
2015-04-14 19:02:33 +03:00
|
|
|
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']);
|
|
|
|
|
2013-09-29 01:52:51 +04:00
|
|
|
// Validate & Test
|
2015-12-10 00:38:58 +03:00
|
|
|
grunt.registerTask('test-travis', ['lint', 'unit-test', 'build-dev', 'connect:test', 'ghost:travis']);
|
2013-08-11 22:51:04 +04:00
|
|
|
// Validate & Test (faster version) will NOT work on travis !!
|
2015-12-10 00:38:58 +03:00
|
|
|
grunt.registerTask('test-local', ['lint', 'unit-test', 'build-dev', 'connect:test', 'ghost:local']);
|
|
|
|
grunt.registerTask('test-local-nolint', ['unit-test', 'build-dev', 'connect:test', 'ghost:local']);
|
2014-08-24 00:45:52 +04:00
|
|
|
|
|
|
|
grunt.registerTask('test', ['test-travis']);
|
|
|
|
grunt.registerTask('precommit', ['test-local']);
|
|
|
|
|
2015-11-30 02:08:50 +03:00
|
|
|
grunt.registerTask('build-index.html', ['includereplace']);
|
|
|
|
grunt.registerTask('merge-statics', ['concat:js', 'concat:css', 'uglify']);
|
2015-11-30 15:36:27 +03:00
|
|
|
grunt.registerTask('build', ['clean:prod', 'sprite', 'merge-statics', 'build-index.html', 'replace', 'copy:prod']);
|
2015-11-30 02:08:50 +03:00
|
|
|
grunt.registerTask('build-dev', ['clean:dev', 'sprite', 'build-index.html', 'copy:dev']);
|
2013-12-19 02:22:25 +04:00
|
|
|
|
2013-08-11 22:51:04 +04:00
|
|
|
// Validate & Build
|
2015-11-30 02:08:50 +03:00
|
|
|
grunt.registerTask('default', ['lint', 'build']);
|
2013-08-11 22:51:04 +04:00
|
|
|
|
2014-04-29 01:13:44 +04:00
|
|
|
// Build stand alone app with nodewebkit
|
2015-12-10 01:02:44 +03:00
|
|
|
grunt.registerTask('desktop', ['clean:desktop', 'default', 'nwjs:windows']);
|
|
|
|
grunt.registerTask('desktop-mac', ['clean:desktop', 'default', 'nwjs:macos']);
|
2014-05-06 05:53:18 +04:00
|
|
|
|
2014-05-06 01:20:00 +04:00
|
|
|
// Start webserver and watch for changes
|
2015-12-10 00:38:58 +03:00
|
|
|
grunt.registerTask('serve', ['build', 'connect:prod', 'open:prod', 'watch:prod']);
|
2014-05-06 01:43:23 +04:00
|
|
|
// Start webserver on src folder, in debug mode
|
2015-12-10 00:38:58 +03:00
|
|
|
grunt.registerTask('serve-dev', ['build-dev', 'connect:dev', 'open:dev', 'watch:dev']);
|
|
|
|
|
|
|
|
grunt.registerTask('serve-debug', ['serve-dev']);
|
|
|
|
grunt.registerTask('play', ['serve-dev']);
|
2013-05-27 02:02:48 +04:00
|
|
|
};
|