2015-06-07 12:30:32 +02:00
|
|
|
module.exports = function (grunt) {
|
2015-05-02 11:54:24 +02:00
|
|
|
|
2015-06-08 12:21:50 +02:00
|
|
|
var webpack = require('webpack');
|
|
|
|
var webpackConfig = require('./webpack.config.js');
|
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
var testDir = 'test';
|
|
|
|
var testHost = 'http://localhost:8080/';
|
|
|
|
var pkg = grunt.file.readJSON('package.json');
|
|
|
|
|
2015-04-28 09:50:53 +02:00
|
|
|
grunt.initConfig({
|
2015-05-02 11:54:24 +02:00
|
|
|
|
2015-05-10 13:12:31 +02:00
|
|
|
jshint: {
|
|
|
|
src: [
|
|
|
|
'Gruntfile.js',
|
2015-05-15 16:26:21 +02:00
|
|
|
'webpack.config.js',
|
2015-06-06 12:06:15 +02:00
|
|
|
'src/**/*.js'
|
2015-05-10 13:12:31 +02:00
|
|
|
],
|
|
|
|
options: {
|
|
|
|
jshintrc: '.jshintrc'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
qunit: {
|
2015-05-15 12:37:27 +02:00
|
|
|
// files: ['test/**/*.html'],
|
|
|
|
// urls: ['http://localhost:9000/test/test.html']
|
|
|
|
all: {
|
|
|
|
options: {
|
|
|
|
urls: getTestFiles(testDir, testHost)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
only: {
|
|
|
|
options: {
|
|
|
|
urls: []
|
|
|
|
}
|
|
|
|
}
|
2015-05-10 13:12:31 +02:00
|
|
|
},
|
|
|
|
|
2015-05-14 12:08:19 +02:00
|
|
|
copy: {
|
|
|
|
dist: {
|
|
|
|
src: ['**'],
|
|
|
|
cwd: 'static/style',
|
2015-06-06 14:22:13 +02:00
|
|
|
dest: 'dist/tablefilter/style',
|
2015-05-14 12:08:19 +02:00
|
|
|
expand: true
|
2015-06-08 12:21:50 +02:00
|
|
|
},
|
|
|
|
templates: {
|
|
|
|
src: ['**'],
|
|
|
|
cwd: 'static/templates',
|
|
|
|
dest: 'examples',
|
|
|
|
expand: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'string-replace': {
|
|
|
|
examples: {
|
|
|
|
files: { 'examples/': 'examples/*.html' },
|
|
|
|
options: {
|
|
|
|
replacements: [
|
|
|
|
{
|
|
|
|
pattern: /{NAME}/ig,
|
|
|
|
replacement: pkg.name
|
|
|
|
},{
|
|
|
|
pattern: /{VERSION}/ig,
|
|
|
|
replacement: pkg.version
|
|
|
|
},{
|
|
|
|
pattern: /<!-- @import (.*?) -->/ig,
|
|
|
|
replacement: function (match, p1) {
|
|
|
|
return grunt.file.read('static/' + p1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2015-05-14 12:08:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'webpack-dev-server': {
|
2015-05-02 11:54:24 +02:00
|
|
|
options: {
|
|
|
|
webpack: webpack.dev,
|
2015-06-06 14:22:13 +02:00
|
|
|
publicPath: '/dist/'
|
2015-05-02 11:54:24 +02:00
|
|
|
},
|
|
|
|
start: {
|
|
|
|
keepAlive: true,
|
|
|
|
webpack: {
|
2015-05-14 12:08:19 +02:00
|
|
|
devtool: 'eval',
|
2015-05-02 11:54:24 +02:00
|
|
|
debug: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
webpack: {
|
2015-06-06 14:22:13 +02:00
|
|
|
options: webpackConfig,
|
2015-06-07 12:30:32 +02:00
|
|
|
build: webpackConfig.build,
|
|
|
|
dev: webpackConfig.dev
|
2015-05-13 12:54:29 +02:00
|
|
|
},
|
|
|
|
|
2015-06-05 15:10:25 +02:00
|
|
|
watch: {
|
|
|
|
app: {
|
2015-06-06 14:22:13 +02:00
|
|
|
files: ['src/**/*'],
|
|
|
|
tasks: ['dev'],
|
2015-06-05 15:10:25 +02:00
|
|
|
options: {
|
|
|
|
spawn: false
|
|
|
|
}
|
2015-06-08 12:21:50 +02:00
|
|
|
},
|
|
|
|
templates: {
|
|
|
|
files: ['static/templates/**/*', 'static/partials/**/*'],
|
|
|
|
tasks: ['build-examples'],
|
|
|
|
options: {
|
|
|
|
spawn: false
|
|
|
|
}
|
2015-06-05 15:10:25 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-05-13 12:54:29 +02:00
|
|
|
babel: {
|
|
|
|
options: {
|
|
|
|
sourceMap: true,
|
|
|
|
modules: 'amd',
|
|
|
|
compact: false
|
|
|
|
},
|
|
|
|
dist: {
|
|
|
|
files: [{
|
|
|
|
expand: true,
|
2015-06-06 12:06:15 +02:00
|
|
|
cwd: 'src',
|
2015-05-13 12:54:29 +02:00
|
|
|
src: ['**/*.js'],
|
2015-06-06 14:22:13 +02:00
|
|
|
dest: 'dist/tablefilter'
|
2015-05-13 12:54:29 +02:00
|
|
|
}]
|
|
|
|
}
|
2015-05-02 11:54:24 +02:00
|
|
|
}
|
|
|
|
|
2014-09-07 09:56:17 +02:00
|
|
|
});
|
|
|
|
|
2015-05-10 13:12:31 +02:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-qunit');
|
2015-05-14 12:08:19 +02:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
2015-06-05 15:10:25 +02:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
2015-06-08 12:21:50 +02:00
|
|
|
grunt.loadNpmTasks('grunt-string-replace');
|
2015-05-02 11:54:24 +02:00
|
|
|
grunt.loadNpmTasks('grunt-webpack');
|
2015-05-13 12:54:29 +02:00
|
|
|
grunt.loadNpmTasks('grunt-babel');
|
2015-05-02 11:54:24 +02:00
|
|
|
|
2015-06-02 09:33:16 +02:00
|
|
|
grunt.registerTask('default',
|
2015-06-06 14:22:13 +02:00
|
|
|
['jshint', 'webpack:build', 'copy:dist', 'test']);
|
2015-06-02 09:33:16 +02:00
|
|
|
|
2015-06-08 12:21:50 +02:00
|
|
|
// Development server
|
2015-05-15 12:37:27 +02:00
|
|
|
grunt.registerTask('server', ['webpack-dev-server:start']);
|
2015-05-02 11:54:24 +02:00
|
|
|
|
2015-06-08 12:21:50 +02:00
|
|
|
// Dev dev/build/watch cycle
|
2015-06-05 15:10:25 +02:00
|
|
|
grunt.registerTask('dev',
|
2015-06-07 12:30:32 +02:00
|
|
|
['jshint', 'webpack:dev', 'copy:dist', 'watch:app']);
|
2015-05-02 11:54:24 +02:00
|
|
|
|
|
|
|
// Production build
|
2015-06-06 14:22:13 +02:00
|
|
|
grunt.registerTask('build',
|
|
|
|
['jshint', 'webpack:build', 'copy:dist']);
|
2015-05-10 13:12:31 +02:00
|
|
|
|
2015-06-08 12:21:50 +02:00
|
|
|
// Build examples
|
|
|
|
grunt.registerTask('dev-examples', ['build-examples', 'watch:templates']);
|
|
|
|
grunt.registerTask('build-examples',
|
|
|
|
['copy:templates', 'string-replace:examples']);
|
|
|
|
|
2015-05-13 12:54:29 +02:00
|
|
|
// Transpile with Babel
|
2015-06-06 14:22:13 +02:00
|
|
|
grunt.registerTask('dev-modules', ['babel', 'copy:dist']);
|
2015-05-13 12:54:29 +02:00
|
|
|
|
2015-05-15 12:37:27 +02:00
|
|
|
// Tests
|
|
|
|
grunt.registerTask('test', ['qunit:all']);
|
|
|
|
|
|
|
|
// Custom task running QUnit tests for specified files.
|
|
|
|
// Usage: grunt test-only:test.html,test-help.html
|
|
|
|
grunt.registerTask('test-only',
|
|
|
|
'A task that runs only specified tests.',
|
|
|
|
function(tests) {
|
|
|
|
if(!tests) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tests = tests.split(',');
|
|
|
|
var res = [];
|
|
|
|
|
|
|
|
tests.forEach(function(itm) {
|
|
|
|
var filePath = path.resolve(testDir, itm);
|
|
|
|
var parts = filePath.split(path.sep);
|
|
|
|
res.push(buildTestUrl(testHost, testDir, parts));
|
|
|
|
});
|
|
|
|
|
|
|
|
grunt.config('qunit.only.options.urls', res);
|
|
|
|
grunt.task.run('qunit:only');
|
|
|
|
});
|
|
|
|
|
|
|
|
function isTestFile(pth) {
|
|
|
|
var allowedExts = ['.html', '.htm'];
|
|
|
|
for(var i=0, len=allowedExts.length; i<len; i++){
|
|
|
|
var ext = allowedExts[i];
|
|
|
|
if(pth.indexOf(ext) !== -1){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildTestUrl(host, testDir, parts) {
|
|
|
|
var idx = parts.indexOf(testDir);
|
|
|
|
var fileIdx = parts.length;
|
|
|
|
var relParts = parts.slice(idx, fileIdx);
|
|
|
|
return host.concat(relParts.join('/'));
|
|
|
|
}
|
|
|
|
|
2015-06-07 12:30:32 +02:00
|
|
|
// Returns the list of test files from the test folder for qunit task
|
2015-05-15 12:37:27 +02:00
|
|
|
function getTestFiles(testDir, host) {
|
|
|
|
|
|
|
|
var getFiles = function(dir, host) {
|
|
|
|
var res = [];
|
|
|
|
var items = fs.readdirSync(dir);
|
|
|
|
|
|
|
|
items.forEach(function(itm){
|
|
|
|
var fileOrDir = path.resolve(dir, itm);
|
|
|
|
if(isTestFile(fileOrDir)) {
|
|
|
|
var parts = fileOrDir.split(path.sep);
|
|
|
|
res.push(buildTestUrl(host, testDir, parts));
|
|
|
|
} else {
|
|
|
|
if(fs.lstatSync(fileOrDir).isDirectory()) {
|
|
|
|
res = res.concat(getFiles(fileOrDir, host));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
return getFiles(testDir, host);
|
|
|
|
}
|
|
|
|
|
2015-02-15 09:55:23 +01:00
|
|
|
};
|
2015-05-15 12:37:27 +02:00
|
|
|
|