2013-05-26 22:02:48 +00:00
|
|
|
module.exports = function(grunt) {
|
2015-11-30 23:28:41 +00:00
|
|
|
|
|
|
|
// Update this variable if you don't want or can't serve on localhost
|
|
|
|
var hostname = 'localhost';
|
|
|
|
|
2015-12-09 21:38:58 +00:00
|
|
|
var PORT = {
|
|
|
|
PROD : 9001,
|
|
|
|
DEV : 9901,
|
|
|
|
TEST : 9991
|
|
|
|
};
|
|
|
|
|
2015-11-30 23:28:41 +00:00
|
|
|
// create a version based on the build timestamp
|
2014-07-06 14:17:14 +00:00
|
|
|
var dateFormat = require('dateformat');
|
2015-11-30 23:28:41 +00:00
|
|
|
var version = '-' + dateFormat(new Date(), "yyyy-mm-dd-hh-MM");
|
2017-05-14 15:16:24 +00:00
|
|
|
var releaseVersion = require('./package.json').version;
|
2015-11-30 23:28:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 14:17:14 +00:00
|
|
|
|
2015-11-30 00:29:59 +00:00
|
|
|
// get the list of scripts paths to include
|
2015-11-30 23:28:41 +00:00
|
|
|
var scriptPaths = require('./src/piskel-script-list.js').scripts;
|
|
|
|
var piskelScripts = prefixPaths(scriptPaths, "src/").filter(function (path) {
|
2014-08-23 20:45:52 +00:00
|
|
|
return path.indexOf('devtools') === -1;
|
|
|
|
});
|
2015-11-30 23:28:41 +00:00
|
|
|
|
2015-11-30 00:29:59 +00:00
|
|
|
// get the list of styles paths to include
|
2015-11-30 23:28:41 +00:00
|
|
|
var stylePaths = require('./src/piskel-style-list.js').styles;
|
|
|
|
var piskelStyles = prefixPaths(stylePaths, "src/");
|
2014-08-21 22:37:35 +00:00
|
|
|
|
2017-01-08 15:39:55 +00:00
|
|
|
// Casper JS tests
|
|
|
|
var casperjsOptions = [
|
|
|
|
'--baseUrl=http://' + hostname + ':' + PORT.TEST,
|
|
|
|
'--mode=?debug',
|
|
|
|
'--verbose=false',
|
2017-01-08 17:15:04 +00:00
|
|
|
'--includes=test/casperjs/integration/include.js',
|
2017-01-08 15:39:55 +00:00
|
|
|
'--log-level=info',
|
|
|
|
'--print-command=false',
|
|
|
|
'--print-file-paths=true',
|
|
|
|
];
|
|
|
|
|
2017-01-08 15:09:03 +00:00
|
|
|
var integrationTestPaths = require('./test/casperjs/integration/IntegrationSuite.js').tests;
|
|
|
|
var integrationTests = prefixPaths(integrationTestPaths, "test/casperjs/integration/");
|
2013-08-11 11:37:23 +00:00
|
|
|
|
2015-12-09 21:38:58 +00:00
|
|
|
var getConnectConfig = function (base, port, host) {
|
|
|
|
if (typeof base === 'string') {
|
|
|
|
base = [base];
|
2014-08-21 22:37:35 +00:00
|
|
|
}
|
|
|
|
|
2014-07-20 21:55:10 +00:00
|
|
|
return {
|
|
|
|
options: {
|
|
|
|
port: port,
|
2015-11-30 23:28:41 +00:00
|
|
|
hostname : host,
|
2015-12-09 21:38:58 +00:00
|
|
|
base: base
|
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-11-30 23:35:26 +00:00
|
|
|
all: ['dest', 'src/img/icons.png', 'src/css/icons.css'],
|
2015-11-30 23:28:41 +00:00
|
|
|
prod: ['dest/prod', 'dest/tmp'],
|
|
|
|
desktop: ['dest/desktop', 'dest/tmp'],
|
|
|
|
dev: ['dest/dev', 'dest/tmp']
|
2014-05-05 20:36:34 +00:00
|
|
|
},
|
2015-11-29 23:08:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* STYLE CHECKS
|
|
|
|
*/
|
|
|
|
|
2015-04-14 21:08:53 +00:00
|
|
|
leadingIndent : {
|
|
|
|
options: {
|
|
|
|
indentation : "spaces"
|
|
|
|
},
|
|
|
|
css : ['src/css/**/*.css']
|
|
|
|
},
|
2015-11-29 23:08:50 +00:00
|
|
|
|
2017-06-09 08:16:05 +00:00
|
|
|
eslint: {
|
2013-08-10 10:11:16 +00:00
|
|
|
files: [
|
2016-12-18 10:36:11 +00:00
|
|
|
// Includes
|
2014-03-16 20:15:34 +00:00
|
|
|
'src/js/**/*.js',
|
2017-06-09 08:16:05 +00:00
|
|
|
// Exludes
|
|
|
|
// TODO: remove this (for now we still get warnings from the lib folder)
|
2016-12-18 10:36:11 +00:00
|
|
|
'!src/js/**/lib/**/*.js'
|
2013-08-04 16:27:32 +00:00
|
|
|
]
|
|
|
|
},
|
2015-11-29 23:08:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SERVERS, BROWSER LAUNCHERS
|
|
|
|
*/
|
|
|
|
|
2015-12-09 21:38:58 +00: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-05 21:08:11 +00:00
|
|
|
},
|
2015-11-29 23:08:50 +00:00
|
|
|
|
2014-05-05 21:08:11 +00:00
|
|
|
open : {
|
2015-12-09 21:38:58 +00:00
|
|
|
prod : {
|
|
|
|
path : 'http://' + hostname + ':' + PORT.PROD + '/'
|
2014-05-05 21:20:00 +00:00
|
|
|
},
|
2015-12-09 21:38:58 +00:00
|
|
|
dev : {
|
2016-08-31 22:47:33 +00:00
|
|
|
path : 'http://' + hostname + ':' + PORT.DEV + '/?debug'
|
2014-05-05 21:08:11 +00:00
|
|
|
}
|
|
|
|
},
|
2015-11-29 23:08:50 +00:00
|
|
|
|
2014-05-05 21:08:11 +00:00
|
|
|
watch: {
|
2015-11-29 21:05:41 +00:00
|
|
|
prod: {
|
2014-05-05 21:08:11 +00:00
|
|
|
files: ['src/**/*.*'],
|
2015-11-29 21:05:41 +00:00
|
|
|
tasks: ['build'],
|
|
|
|
options: {
|
|
|
|
spawn: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
dev: {
|
2015-11-29 23:08:50 +00:00
|
|
|
files: ['src/**/*.*'],
|
|
|
|
tasks: ['build-dev'],
|
2014-05-05 21:08:11 +00:00
|
|
|
options: {
|
|
|
|
spawn: false
|
2013-08-04 16:27:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-11-29 23:08:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* BUILD STEPS
|
|
|
|
*/
|
|
|
|
|
|
|
|
sprite:{
|
|
|
|
all : {
|
|
|
|
src: 'src/img/icons/**/*.png',
|
2016-07-24 15:06:47 +00:00
|
|
|
retinaSrcFilter: 'src/img/icons/**/*@2x.png',
|
2015-11-29 23:08:50 +00:00
|
|
|
dest: 'src/img/icons.png',
|
2016-07-24 15:06:47 +00:00
|
|
|
retinaDest: 'src/img/icons@2x.png',
|
2015-11-29 23:08:50 +00:00
|
|
|
destCss: 'src/css/icons.css'
|
|
|
|
}
|
2013-08-04 16:27:32 +00:00
|
|
|
},
|
2015-11-29 23:08:50 +00:00
|
|
|
|
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,
|
2015-11-30 23:28:41 +00:00
|
|
|
dest : 'dest/prod/js/piskel-packaged' + version + '.js'
|
2013-12-18 22:22:25 +00:00
|
|
|
},
|
|
|
|
css : {
|
|
|
|
src : piskelStyles,
|
2017-01-11 00:13:56 +00:00
|
|
|
dest : 'dest/tmp/css/piskel-style-packaged' + version + '.css'
|
2013-09-28 21:52:51 +00:00
|
|
|
}
|
2013-08-04 16:27:32 +00:00
|
|
|
},
|
2015-11-29 23:08:50 +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 : {
|
2015-11-30 23:28:41 +00:00
|
|
|
'dest/tmp/js/piskel-packaged-min.js' : ['dest/prod/js/piskel-packaged' + version + '.js']
|
2013-08-04 16:27:32 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-28 16:51:10 +00:00
|
|
|
},
|
2015-11-29 23:08:50 +00:00
|
|
|
|
|
|
|
includereplace: {
|
|
|
|
all: {
|
|
|
|
src: 'src/index.html',
|
2015-11-30 23:28:41 +00:00
|
|
|
dest: 'dest/tmp/index.html',
|
2015-11-30 12:36:27 +00:00
|
|
|
options : {
|
|
|
|
globals : {
|
2017-05-14 15:16:24 +00:00
|
|
|
'version' : version,
|
|
|
|
'releaseVersion' : releaseVersion
|
2015-11-30 12:36:27 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-29 23:08:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-07-06 14:17:14 +00:00
|
|
|
replace: {
|
2015-11-29 23:08:50 +00:00
|
|
|
// main-partial.html is used when embedded in piskelapp.com
|
|
|
|
mainPartial: {
|
2014-07-06 14:17:14 +00:00
|
|
|
options: {
|
2015-11-29 23:08:50 +00:00
|
|
|
patterns: [{
|
2014-07-06 14:17:14 +00:00
|
|
|
match: /^(.|[\r\n])*<!--body-main-start-->/,
|
2015-11-30 13:22:11 +00:00
|
|
|
replacement: "{% raw %}",
|
2014-07-06 14:17:14 +00:00
|
|
|
description : "Remove everything before body-main-start comment"
|
|
|
|
},{
|
|
|
|
match: /<!--body-main-end-->(.|[\r\n])*$/,
|
2015-11-30 13:22:11 +00:00
|
|
|
replacement: "{% endraw %}",
|
2014-07-06 14:17:14 +00:00
|
|
|
description : "Remove everything after body-main-end comment"
|
|
|
|
},{
|
|
|
|
match: /([\r\n]) /g,
|
|
|
|
replacement: "$1",
|
|
|
|
description : "Decrease indentation by one"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
files: [
|
2015-11-29 23:08:50 +00:00
|
|
|
// src/index.html should already have been moved by the includereplace task
|
2015-11-30 23:28:41 +00:00
|
|
|
{src: ['dest/tmp/index.html'], dest: 'dest/prod/piskelapp-partials/main-partial.html'}
|
2014-07-06 14:17:14 +00:00
|
|
|
]
|
2016-07-10 11:59:11 +00:00
|
|
|
},
|
2017-01-11 00:13:56 +00:00
|
|
|
|
|
|
|
css: {
|
|
|
|
options: {
|
|
|
|
patterns: [{
|
|
|
|
match: /var\(--highlight-color\)/g,
|
|
|
|
replacement: "gold",
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
files: [{
|
|
|
|
src: ['dest/tmp/css/piskel-style-packaged' + version + '.css'],
|
|
|
|
dest: 'dest/prod/css/piskel-style-packaged' + version + '.css'
|
|
|
|
}]
|
2014-07-06 14:17:14 +00:00
|
|
|
}
|
|
|
|
},
|
2015-11-29 23:08:50 +00:00
|
|
|
|
2014-05-05 20:36:34 +00:00
|
|
|
copy: {
|
2015-11-29 23:08:50 +00:00
|
|
|
prod: {
|
2014-05-05 20:36:34 +00:00
|
|
|
files: [
|
2015-11-29 23:08:50 +00:00
|
|
|
// dest/js/piskel-packaged-min.js should have been created by the uglify task
|
2015-11-30 23:28:41 +00: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-29 23:08:50 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
dev: {
|
|
|
|
files: [
|
2015-11-30 23:28:41 +00: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-05 20:36:34 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2015-11-29 23:08:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* TESTING
|
|
|
|
*/
|
|
|
|
|
2014-08-13 23:50:33 +00:00
|
|
|
karma: {
|
|
|
|
unit: {
|
|
|
|
configFile: 'karma.conf.js'
|
|
|
|
}
|
|
|
|
},
|
2015-11-29 23:08:50 +00:00
|
|
|
|
2016-08-31 12:11:29 +00:00
|
|
|
casperjs : {
|
2017-01-08 15:09:03 +00:00
|
|
|
drawing : {
|
|
|
|
files : {
|
2017-01-08 17:15:04 +00:00
|
|
|
src: ['test/casperjs/DrawingTest.js']
|
2017-01-08 15:09:03 +00:00
|
|
|
},
|
|
|
|
options : {
|
2017-01-08 15:39:55 +00:00
|
|
|
casperjsOptions: casperjsOptions
|
2017-01-08 15:09:03 +00:00
|
|
|
}
|
2016-08-31 22:47:33 +00:00
|
|
|
},
|
2017-01-08 15:09:03 +00:00
|
|
|
integration : {
|
|
|
|
files : {
|
|
|
|
src: integrationTests
|
|
|
|
},
|
|
|
|
options : {
|
2017-01-08 15:39:55 +00:00
|
|
|
casperjsOptions: casperjsOptions
|
2017-01-08 15:09:03 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-29 23:08:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DESKTOP BUILDS
|
|
|
|
*/
|
|
|
|
|
2015-12-09 22:02:44 +00:00
|
|
|
nwjs: {
|
2015-08-08 23:22:25 +00:00
|
|
|
windows : {
|
|
|
|
options: {
|
2017-01-09 08:27:49 +00:00
|
|
|
downloadUrl: 'https://dl.nwjs.io/',
|
2017-01-09 08:19:12 +00:00
|
|
|
version : "0.19.4",
|
2015-08-08 23:22:25 +00:00
|
|
|
build_dir: './dest/desktop/', // destination folder of releases.
|
|
|
|
win: true,
|
|
|
|
linux32: true,
|
2017-05-12 23:03:14 +00:00
|
|
|
linux64: true,
|
|
|
|
flavor: "normal",
|
2015-08-08 23:22:25 +00:00
|
|
|
},
|
2015-11-30 23:28:41 +00:00
|
|
|
src: ['./dest/prod/**/*', "./package.json", "!./dest/desktop/"]
|
2014-05-06 01:53:18 +00:00
|
|
|
},
|
2015-08-08 23:22:25 +00:00
|
|
|
macos : {
|
|
|
|
options: {
|
2017-01-09 08:27:49 +00:00
|
|
|
downloadUrl: 'https://dl.nwjs.io/',
|
2015-12-29 22:44:02 +00:00
|
|
|
osx64: true,
|
2017-01-09 08:19:12 +00:00
|
|
|
version : "0.19.4",
|
2017-05-12 23:03:14 +00:00
|
|
|
build_dir: './dest/desktop/',
|
|
|
|
flavor: "normal",
|
2015-08-08 23:22:25 +00:00
|
|
|
},
|
2015-11-30 23:28:41 +00:00
|
|
|
src: ['./dest/prod/**/*', "./package.json", "!./dest/desktop/"]
|
2017-05-09 07:45:08 +00:00
|
|
|
},
|
|
|
|
macos_old : {
|
|
|
|
options: {
|
|
|
|
downloadUrl: 'https://dl.nwjs.io/',
|
|
|
|
osx64: true,
|
|
|
|
version : "0.12.3",
|
|
|
|
build_dir: './dest/desktop/old',
|
|
|
|
flavor: "normal",
|
|
|
|
},
|
|
|
|
src: ['./dest/prod/**/*', "./package.json", "!./dest/desktop/"]
|
2015-08-08 23:22:25 +00:00
|
|
|
}
|
2013-08-04 16:27:32 +00:00
|
|
|
}
|
|
|
|
});
|
2013-05-26 21:58:59 +00:00
|
|
|
|
2016-08-31 22:47:33 +00:00
|
|
|
// TEST TASKS
|
|
|
|
// Run linting
|
2017-06-09 08:16:05 +00:00
|
|
|
grunt.registerTask('lint', ['eslint', 'leadingIndent:css']);
|
2016-08-31 22:47:33 +00:00
|
|
|
// Run unit-tests
|
2014-08-13 23:50:33 +00:00
|
|
|
grunt.registerTask('unit-test', ['karma']);
|
2017-01-08 15:09:03 +00:00
|
|
|
// Run integration tests
|
2017-01-08 17:15:04 +00:00
|
|
|
grunt.registerTask('integration-test', ['build-dev', 'connect:test', 'casperjs:integration']);
|
2017-05-20 15:31:55 +00:00
|
|
|
// Run drawing tests
|
|
|
|
grunt.registerTask('drawing-test', ['build-dev', 'connect:test', 'casperjs:drawing']);
|
2017-01-08 15:09:03 +00:00
|
|
|
// Run linting, unit tests, drawing tests and integration tests
|
|
|
|
grunt.registerTask('test', ['lint', 'unit-test', 'build-dev', 'connect:test', 'casperjs:drawing', 'casperjs:integration']);
|
2016-09-01 13:37:28 +00:00
|
|
|
|
2016-08-31 22:47:33 +00:00
|
|
|
// Run the tests, even if the linting fails
|
2017-01-08 15:09:03 +00:00
|
|
|
grunt.registerTask('test-nolint', ['unit-test', 'build-dev', 'connect:test', 'casperjs:drawing', 'casperjs:integration']);
|
|
|
|
|
2016-08-31 22:47:33 +00:00
|
|
|
// Used by optional precommit hook
|
|
|
|
grunt.registerTask('precommit', ['test']);
|
|
|
|
|
|
|
|
// BUILD TASKS
|
2015-11-29 23:08:50 +00:00
|
|
|
grunt.registerTask('build-index.html', ['includereplace']);
|
|
|
|
grunt.registerTask('merge-statics', ['concat:js', 'concat:css', 'uglify']);
|
2017-01-11 00:13:56 +00:00
|
|
|
grunt.registerTask('build', ['clean:prod', 'sprite', 'merge-statics', 'build-index.html', 'replace:mainPartial', 'replace:css', 'copy:prod']);
|
2015-11-29 23:08:50 +00:00
|
|
|
grunt.registerTask('build-dev', ['clean:dev', 'sprite', 'build-index.html', 'copy:dev']);
|
2017-06-02 22:12:46 +00:00
|
|
|
grunt.registerTask('desktop', ['clean:desktop', 'default', 'nwjs:windows']);
|
|
|
|
grunt.registerTask('desktop-mac', ['clean:desktop', 'default', 'nwjs:macos']);
|
2017-05-09 07:45:08 +00:00
|
|
|
grunt.registerTask('desktop-mac-old', ['clean:desktop', 'default', 'replace:desktop', 'nwjs:macos_old']);
|
2014-05-06 01:53:18 +00:00
|
|
|
|
2016-08-31 22:47:33 +00:00
|
|
|
// SERVER TASKS
|
2014-05-05 21:20:00 +00:00
|
|
|
// Start webserver and watch for changes
|
2015-12-09 21:38:58 +00:00
|
|
|
grunt.registerTask('serve', ['build', 'connect:prod', 'open:prod', 'watch:prod']);
|
2014-05-05 21:43:23 +00:00
|
|
|
// Start webserver on src folder, in debug mode
|
2016-09-01 13:37:28 +00:00
|
|
|
grunt.registerTask('play', ['build-dev', 'connect:dev', 'open:dev', 'watch:dev']);
|
|
|
|
|
|
|
|
// ALIASES, kept for backward compatibility
|
|
|
|
grunt.registerTask('serve-debug', ['play']);
|
|
|
|
grunt.registerTask('serve-dev', ['play']);
|
|
|
|
grunt.registerTask('test-travis', ['test']);
|
|
|
|
grunt.registerTask('test-local', ['test']);
|
2016-08-31 22:47:33 +00:00
|
|
|
|
|
|
|
// Default task
|
|
|
|
grunt.registerTask('default', ['lint', 'build']);
|
2013-05-26 22:02:48 +00:00
|
|
|
};
|