2015-06-07 12:30:32 +02:00
|
|
|
module.exports = function (grunt) {
|
2015-06-08 12:21:50 +02:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
var testDir = 'test';
|
2015-07-06 10:16:07 +02:00
|
|
|
var testHost = 'http://localhost:8000/';
|
2015-06-08 12:21:50 +02:00
|
|
|
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
|
|
|
qunit: {
|
2016-12-04 12:48:57 +01:00
|
|
|
options: {
|
|
|
|
'--web-security': 'no',
|
|
|
|
coverage: {
|
|
|
|
disposeCollector: true,
|
|
|
|
src: ['dist/tablefilter/*.js'],
|
2019-06-07 10:26:33 +02:00
|
|
|
instrumentedFiles: 'report/temp/',
|
2016-12-04 12:48:57 +01:00
|
|
|
htmlReport: 'report/coverage',
|
|
|
|
coberturaReport: 'report/',
|
2016-12-07 13:48:28 +01:00
|
|
|
lcovReport: 'report/',
|
|
|
|
jsonReport: 'report',
|
|
|
|
linesThresholdPct: 80
|
2016-12-04 12:48:57 +01:00
|
|
|
}
|
|
|
|
},
|
2015-05-15 12:37:27 +02:00
|
|
|
all: {
|
|
|
|
options: {
|
|
|
|
urls: getTestFiles(testDir, testHost)
|
|
|
|
}
|
|
|
|
},
|
2016-12-07 13:48:28 +01:00
|
|
|
only: {
|
|
|
|
options: {
|
|
|
|
urls: []
|
|
|
|
}
|
|
|
|
}
|
2015-05-10 13:12:31 +02:00
|
|
|
},
|
|
|
|
|
2015-06-30 10:46:37 +02:00
|
|
|
connect: {
|
|
|
|
server: {
|
|
|
|
options: {
|
2015-07-01 09:27:23 +02:00
|
|
|
port: 8000,
|
2015-06-30 10:46:37 +02:00
|
|
|
base: '.'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-05-14 12:08:19 +02:00
|
|
|
copy: {
|
|
|
|
dist: {
|
2015-08-04 10:38:40 +02:00
|
|
|
src: [
|
|
|
|
'**',
|
2015-08-07 12:11:27 +02:00
|
|
|
'!**/*.styl',
|
2015-08-05 09:10:53 +02:00
|
|
|
'!**/extensions/**',
|
2015-08-07 12:11:27 +02:00
|
|
|
'!**/mixins/**'
|
2015-08-04 10:38:40 +02:00
|
|
|
],
|
2015-05-14 12:08:19 +02:00
|
|
|
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',
|
2015-06-28 03:56:40 +02:00
|
|
|
dest: 'demos',
|
2015-06-08 12:21:50 +02:00
|
|
|
expand: true
|
2015-06-13 14:57:48 +02:00
|
|
|
},
|
|
|
|
assets: {
|
|
|
|
src: ['**'],
|
2015-06-28 03:56:40 +02:00
|
|
|
cwd: 'static/demos-assets',
|
|
|
|
dest: 'demos/assets',
|
2015-06-13 14:57:48 +02:00
|
|
|
expand: true
|
2015-07-10 09:39:23 +02:00
|
|
|
},
|
|
|
|
starter: {
|
|
|
|
src: ['demos/starter.html'],
|
|
|
|
dest: 'dist/starter.html'
|
2015-06-08 12:21:50 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'string-replace': {
|
2015-06-28 03:56:40 +02:00
|
|
|
demos: {
|
|
|
|
files: { 'demos/': 'demos/*.html' },
|
2015-06-08 12:21:50 +02:00
|
|
|
options: {
|
|
|
|
replacements: [
|
|
|
|
{
|
|
|
|
pattern: /{NAME}/ig,
|
|
|
|
replacement: pkg.name
|
2016-05-31 11:22:21 +02:00
|
|
|
}, {
|
2015-06-08 12:21:50 +02:00
|
|
|
pattern: /{VERSION}/ig,
|
|
|
|
replacement: pkg.version
|
2016-05-31 11:22:21 +02:00
|
|
|
}, {
|
2015-07-11 12:38:36 +02:00
|
|
|
pattern: /{EZEDITTABLE_LINK}/ig,
|
|
|
|
replacement: '<a href="http://edittable.free.fr/' +
|
2016-05-31 11:22:21 +02:00
|
|
|
'zip.php?f=ezEditTable.zip&p=1"' +
|
|
|
|
'target="_blank" title="ezEditTable is a ' +
|
|
|
|
'javascript code aimed at enhancing regular ' +
|
|
|
|
'HTML tables by adding features such as ' +
|
|
|
|
'inline editing components, advanced ' +
|
|
|
|
'selection and keyboard navigation ' +
|
|
|
|
'- Developed by ' + pkg.author.name + '">' +
|
|
|
|
'ezEditTable</a>'
|
|
|
|
}, {
|
2015-06-08 12:21:50 +02:00
|
|
|
pattern: /<!-- @import (.*?) -->/ig,
|
|
|
|
replacement: function (match, p1) {
|
|
|
|
return grunt.file.read('static/' + p1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2015-05-14 12:08:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-07-14 14:36:24 +02:00
|
|
|
clean: ['demos/starter.html'],
|
|
|
|
|
2015-06-05 15:10:25 +02:00
|
|
|
watch: {
|
|
|
|
app: {
|
2015-07-04 10:49:30 +02:00
|
|
|
files: ['src/**/*', 'static/style/**/*'],
|
2015-06-06 14:22:13 +02:00
|
|
|
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/**/*'],
|
2015-06-28 03:56:40 +02:00
|
|
|
tasks: ['build-demos'],
|
2015-06-08 12:21:50 +02:00
|
|
|
options: {
|
|
|
|
spawn: false
|
|
|
|
}
|
2015-06-05 15:10:25 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-03-02 13:24:16 +01:00
|
|
|
// temporary shell commands while decommissioning grunt
|
2018-01-16 12:13:31 +01:00
|
|
|
shell: {
|
|
|
|
eslint: {
|
|
|
|
command: 'npm run lint'
|
|
|
|
},
|
|
|
|
esdoc: {
|
|
|
|
command: 'npm run esdoc'
|
2018-03-02 07:12:15 +01:00
|
|
|
},
|
|
|
|
build: {
|
|
|
|
command: 'npm run build'
|
2018-03-02 13:24:16 +01:00
|
|
|
},
|
|
|
|
dev: {
|
|
|
|
command: 'npm run dev'
|
|
|
|
},
|
|
|
|
test: {
|
|
|
|
command: 'npm run build:test'
|
2018-03-18 02:59:33 +01:00
|
|
|
},
|
|
|
|
'build-css': {
|
|
|
|
command: 'npm run build:css'
|
2015-08-02 10:27:59 +02:00
|
|
|
}
|
2015-05-02 11:54:24 +02:00
|
|
|
}
|
2014-09-07 09:56:17 +02:00
|
|
|
});
|
|
|
|
|
2015-05-14 12:08:19 +02:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
2015-07-14 14:36:24 +02:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-clean');
|
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-06-30 10:46:37 +02:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-connect');
|
2018-01-16 12:13:31 +01:00
|
|
|
grunt.loadNpmTasks('grunt-shell');
|
2016-12-07 13:48:28 +01:00
|
|
|
grunt.loadNpmTasks('grunt-qunit-istanbul');
|
2015-05-02 11:54:24 +02:00
|
|
|
|
2018-01-16 12:13:31 +01:00
|
|
|
grunt.registerTask('eslint', ['shell:eslint']);
|
|
|
|
grunt.registerTask('esdoc', ['shell:esdoc']);
|
|
|
|
|
2016-12-07 13:48:28 +01:00
|
|
|
grunt.registerTask('default', ['test', 'build', 'build-demos']);
|
2015-06-02 09:33:16 +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',
|
2018-03-18 02:59:33 +01:00
|
|
|
['eslint', 'shell:dev', 'copy:dist', 'shell:build-css', 'watch:app']);
|
2015-05-02 11:54:24 +02:00
|
|
|
|
|
|
|
// Production build
|
2015-08-04 10:38:40 +02:00
|
|
|
grunt.registerTask('build',
|
2018-03-18 02:59:33 +01:00
|
|
|
['eslint', 'shell:build', 'copy:dist', 'shell:build-css']);
|
2015-05-10 13:12:31 +02:00
|
|
|
|
2015-06-28 03:56:40 +02:00
|
|
|
// Build demos
|
|
|
|
grunt.registerTask('dev-demos', ['build-demos', 'watch:templates']);
|
2015-07-14 14:36:24 +02:00
|
|
|
grunt.registerTask('build-demos', ['copy:templates', 'copy:assets',
|
|
|
|
'string-replace:demos', 'copy:starter', 'clean']);
|
2015-06-08 12:21:50 +02:00
|
|
|
|
2016-12-07 13:48:28 +01:00
|
|
|
// Build tests
|
|
|
|
grunt.registerTask('build-test',
|
2018-03-18 02:59:33 +01:00
|
|
|
['eslint', 'shell:test', 'copy:dist', 'shell:build-css']);
|
2015-05-13 12:54:29 +02:00
|
|
|
|
2016-12-07 13:48:28 +01:00
|
|
|
// Tests with coverage
|
|
|
|
grunt.registerTask('test', ['build-test', 'connect', 'qunit:all']);
|
2015-05-15 12:37:27 +02:00
|
|
|
|
2018-05-06 03:24:38 +02:00
|
|
|
// Build all for deployment from travis
|
|
|
|
grunt.registerTask('build-all', 'Prepare for deployment', [
|
|
|
|
'build', 'build-demos', 'esdoc'
|
2015-08-18 14:24:32 +02:00
|
|
|
]);
|
|
|
|
|
2015-05-15 12:37:27 +02:00
|
|
|
// Custom task running QUnit tests for specified files.
|
2015-06-27 12:52:40 +02:00
|
|
|
// Usage example: grunt test-only:test.html,test-help.html
|
2015-05-15 12:37:27 +02:00
|
|
|
grunt.registerTask('test-only',
|
|
|
|
'A task that runs only specified tests.',
|
2016-05-31 11:22:21 +02:00
|
|
|
function (tests) {
|
|
|
|
if (!tests) {
|
2015-05-15 12:37:27 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
tests = tests.split(',');
|
|
|
|
var res = [];
|
|
|
|
|
2016-05-31 11:22:21 +02:00
|
|
|
tests.forEach(function (itm) {
|
2015-05-15 12:37:27 +02:00
|
|
|
var filePath = path.resolve(testDir, itm);
|
|
|
|
var parts = filePath.split(path.sep);
|
|
|
|
res.push(buildTestUrl(testHost, testDir, parts));
|
|
|
|
});
|
|
|
|
|
2015-06-30 10:46:37 +02:00
|
|
|
grunt.task.run('connect');
|
2015-05-15 12:37:27 +02:00
|
|
|
grunt.config('qunit.only.options.urls', res);
|
|
|
|
grunt.task.run('qunit:only');
|
2016-02-22 08:14:58 +01:00
|
|
|
}
|
|
|
|
);
|
2015-05-15 12:37:27 +02:00
|
|
|
|
|
|
|
function isTestFile(pth) {
|
|
|
|
var allowedExts = ['.html', '.htm'];
|
2016-05-31 11:22:21 +02:00
|
|
|
for (var i = 0, len = allowedExts.length; i < len; i++) {
|
2015-05-15 12:37:27 +02:00
|
|
|
var ext = allowedExts[i];
|
2016-05-31 11:22:21 +02:00
|
|
|
if (pth.indexOf(ext) !== -1) {
|
2015-05-15 12:37:27 +02:00
|
|
|
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) {
|
2016-05-31 11:22:21 +02:00
|
|
|
var getFiles = function (dir, host) {
|
2015-05-15 12:37:27 +02:00
|
|
|
var res = [];
|
|
|
|
var items = fs.readdirSync(dir);
|
|
|
|
|
2016-05-31 11:22:21 +02:00
|
|
|
items.forEach(function (itm) {
|
2015-05-15 12:37:27 +02:00
|
|
|
var fileOrDir = path.resolve(dir, itm);
|
2016-05-31 11:22:21 +02:00
|
|
|
if (isTestFile(fileOrDir)) {
|
2015-05-15 12:37:27 +02:00
|
|
|
var parts = fileOrDir.split(path.sep);
|
|
|
|
res.push(buildTestUrl(host, testDir, parts));
|
|
|
|
} else {
|
2016-05-31 11:22:21 +02:00
|
|
|
if (fs.lstatSync(fileOrDir).isDirectory()) {
|
2015-05-15 12:37:27 +02:00
|
|
|
res = res.concat(getFiles(fileOrDir, host));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
return getFiles(testDir, host);
|
|
|
|
}
|
2015-02-15 09:55:23 +01:00
|
|
|
};
|