piskel/Gruntfile.js

336 lines
9.7 KiB
JavaScript
Raw Normal View History

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