Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup the Gruntfile #849

Merged
merged 4 commits into from
Apr 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 64 additions & 73 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,87 @@
module.exports = function (grunt) {
'use strict';

var jsFiles = module.exports.jsFiles;
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);

var output = {
js: '<%= pkg.name %>.js',
jsmin: '<%= pkg.name %>.min.js',
map: '<%= pkg.name %>.min.js.map'
var config = {
src: 'src',
spec: 'spec',
web: 'web',
pkg: require('./package.json'),
banner: grunt.file.read('./LICENSE_BANNER'),
jsFiles: module.exports.jsFiles
};

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
conf: config,

concat: {
options : {
process: true,
sourceMap: true,
banner : '<%= conf.banner %>'
},
js: {
src: jsFiles,
dest: output.js
src: '<%= conf.jsFiles %>',
dest: '<%= conf.pkg.name %>.js'
}
},
uglify: {
jsmin: {
options: {
mangle: true,
compress: true,
sourceMap: output.map
sourceMap: true,
banner : '<%= conf.banner %>'
},
src: output.js,
dest: output.jsmin
}
},
sed: {
version: {
pattern: '%VERSION%',
replacement: '<%= pkg.version %>',
path: [output.js, output.jsmin]
src: '<%= conf.pkg.name %>.js',
dest: '<%= conf.pkg.name %>.min.js'
}
},
jscs: {
old: {
src: ['spec/**/*.js'],
src: ['<%= conf.spec %>/**/*.js'],
options: {
validateIndentation: 4
}
},
source: {
src: ['src/**/*.js', '!src/{banner,footer}.js', 'Gruntfile.js', 'web/stock.js'],
src: ['<%= conf.src %>/**/*.js', '!<%= conf.src %>/{banner,footer}.js', 'Gruntfile.js',
'<%= conf.web %>/stock.js'],
options: {
config: '.jscsrc'
}
}
},
jshint: {
source: {
src: ['src/**/*.js', 'Gruntfile.js', 'web/stock.js'],
src: ['<%= conf.src %>/**/*.js', 'Gruntfile.js', '<%= conf.web %>/stock.js'],
options: {
jshintrc: '.jshintrc',
ignores: ['src/banner.js', 'src/footer.js']
ignores: ['<%= conf.src %>/banner.js', '<%= conf.src %>/footer.js']
}
}
},
watch: {
scripts: {
files: ['src/**/*.js'],
files: ['<%= conf.src %>/**/*.js'],
tasks: ['build', 'copy']
},
jasmineRunner: {
files: ['spec/**/*.js'],
files: ['<%= conf.spec %>/**/*.js'],
tasks: ['jasmine:specs:build']
},
tests: {
files: ['src/**/*.js', 'spec/**/*.js'],
files: ['<%= conf.src %>/**/*.js', '<%= conf.spec %>/**/*.js'],
tasks: ['test']
},
reload: {
files: ['dc.js', 'dc.css', 'web/js/dc.js', 'web/css/dc.css', 'dc.min.js'],
files: ['<%= conf.pkg.name %>.js',
'<%= conf.pkg.name %>css',
'<%= conf.web %>/js/<%= conf.pkg.name %>.js',
'<%= conf.web %>/css/<%= conf.pkg.name %>.css',
'<%= conf.pkg.name %>.min.js'],
options: {
livereload: true
}
Expand All @@ -92,17 +100,17 @@ module.exports = function (grunt) {
options: {
display: 'short',
summary: true,
specs: 'spec/*-spec.js',
helpers: 'spec/helpers/*.js',
specs: '<%= conf.spec %>/*-spec.js',
helpers: '<%= conf.spec %>/helpers/*.js',
version: '2.0.0',
outfile: 'spec/index.html',
outfile: '<%= conf.spec %>/index.html',
keepRunner: true
},
src: [
'web/js/d3.js',
'web/js/crossfilter.js',
'web/js/colorbrewer.js',
'dc.js'
'<%= conf.web %>/js/d3.js',
'<%= conf.web %>/js/crossfilter.js',
'<%= conf.web %>/js/colorbrewer.js',
'<%= conf.pkg.name %>.js'
]
},
coverage:{
Expand All @@ -129,10 +137,10 @@ module.exports = function (grunt) {
options: {
display: 'short',
summary: true,
specs: 'spec/*-spec.js',
helpers: 'spec/helpers/*.js',
specs: '<%= conf.spec %>/*-spec.js',
helpers: '<%= conf.spec %>/helpers/*.js',
version: '2.0.0',
outfile: 'spec/index-browserify.html',
outfile: '<%= conf.spec %>/index-browserify.html',
keepRunner: true
},
src: [
Expand Down Expand Up @@ -164,14 +172,14 @@ module.exports = function (grunt) {
platform: 'WIN8'
}
],
testname: 'dc.js'
testname: '<%= conf.pkg.name %>.js'
}
}
},
emu: {
api: {
src: output.js,
dest: 'web/docs/api-latest.md'
src: '<%= conf.pkg.name %>.js',
dest: '<%= conf.web %>/docs/api-latest.md'
}
},
toc: {
Expand All @@ -183,38 +191,40 @@ module.exports = function (grunt) {
markdown: {
html: {
src: '<%= emu.api.dest %>',
dest: 'web/docs/index.html'
dest: '<%= conf.web %>/docs/index.html'
},
options: {markdownOptions: {highlight: 'manual'}}
},
docco: {
options: {
dst: 'web/docs',
basepath:'web'
dst: '<%= conf.web %>/docs',
basepath:'<%= conf.web %>'
},
howto: {
files: [
{
src: ['web/stock.js']
src: ['<%= conf.web %>/stock.js']
}
]
}
},
copy: {
'dc-to-gh': {
files: [
{expand: true, flatten: true, src: 'dc.css', dest: 'web/css/'},
{expand: true, flatten: true, src: '<%= conf.pkg.name %>.css', dest: '<%= conf.web %>/css/'},
{
expand: true,
flatten: true,
src: [
output.js,
output.js + '.map',
'<%= conf.pkg.name %>.js',
'<%= conf.pkg.name %>.js.map',
'<%= conf.pkg.name %>.min.js',
'<%= conf.pkg.name %>.min.js.map',
'node_modules/d3/d3.js',
'node_modules/crossfilter/crossfilter.js',
'test/env-data.js'
],
dest: 'web/js/'
dest: '<%= conf.web %>/js/'
}
]
}
Expand Down Expand Up @@ -247,7 +257,7 @@ module.exports = function (grunt) {
'<p>An attempt to present a simple example of each chart type.',
'<a href="https://github.com/dc-js/dc.js/blob/master/CONTRIBUTING.md">',
'Contributions welcome</a>.</p>',
'<p>Source <a href="https://github.com/dc-js/dc.js/tree/master/web/examples">',
'<p>Source <a href="https://github.com/dc-js/dc.js/tree/master/<%= conf.web %>/examples">',
'here</a>.</p>',
body,
'</div></body></html>'
Expand All @@ -256,14 +266,14 @@ module.exports = function (grunt) {
absolute: true
},
files: [
{dest: 'web/examples/index.html', src: ['web/examples/*.html']}
{dest: '<%= conf.web %>/examples/index.html', src: ['<%= conf.web %>/examples/*.html']}
]
}
},

'gh-pages': {
options: {
base: 'web',
base: '<%= conf.web %>',
message: 'Synced from from master branch.'
},
src: ['**']
Expand Down Expand Up @@ -298,36 +308,17 @@ module.exports = function (grunt) {
},
browserify: {
dev: {
src: 'dc.js',
src: '<%= conf.pkg.name %>.js',
dest: 'bundle.js',
options: {
browserifyOptions: {
standalone: 'dc'
}
}
},
}
}
});

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-docco2');
grunt.loadNpmTasks('grunt-gh-pages');
grunt.loadNpmTasks('grunt-jscs');
grunt.loadNpmTasks('grunt-saucelabs');
grunt.loadNpmTasks('grunt-markdown');
grunt.loadNpmTasks('grunt-sed');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-debug-task');
grunt.loadNpmTasks('grunt-fileindex');
grunt.loadNpmTasks('grunt-browserify');

// custom tasks
grunt.registerMultiTask('emu', 'Documentation extraction by emu.', function () {
var emu = require('emu'),
Expand Down Expand Up @@ -376,7 +367,7 @@ module.exports = function (grunt) {
});

// task aliases
grunt.registerTask('build', ['concat', 'uglify', 'sed']);
grunt.registerTask('build', ['concat', 'uglify']);
grunt.registerTask('docs', ['build', 'copy', 'emu', 'toc', 'markdown', 'docco']);
grunt.registerTask('web', ['docs', 'gh-pages']);
grunt.registerTask('server', ['docs', 'fileindex', 'jasmine:specs:build', 'connect:server', 'watch:jasmine']);
Expand All @@ -390,7 +381,7 @@ module.exports = function (grunt) {
};

module.exports.jsFiles = [
'src/banner.js',
'src/banner.js', // NOTE: keep this first
'src/core.js',
'src/errors.js',
'src/utils.js',
Expand Down
17 changes: 17 additions & 0 deletions LICENSE_BANNER
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*!
* dc <%= conf.pkg.version %>
* http://dc-js.github.io/dc.js/
* Copyright 2012 Nick Zhu and other contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
26 changes: 14 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,31 @@
},
"devDependencies": {
"emu": "~0.0.2",
"grunt": "~0.4.1",
"grunt-browserify": "^3.2.1",
"grunt-cli": "~0.1.9",
"grunt": "~0.4.5",
"grunt-browserify": "~3.3.0",
"grunt-cli": "~0.1.13",
"grunt-contrib-concat": "~0.5.0",
"grunt-contrib-connect": "~0.9.0",
"grunt-contrib-copy": "~0.7.0",
"grunt-contrib-jasmine": "~0.8.1",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-jasmine": "~0.8.2",
"grunt-contrib-jshint": "~0.11.0",
"grunt-contrib-uglify": "~0.7.0",
"grunt-contrib-watch": "~0.6.1",
"grunt-debug-task": "~0.1.4",
"grunt-debug-task": "~0.1.5",
"grunt-docco2": "~0.2.0",
"grunt-fileindex": "^0.1.0",
"grunt-gh-pages": "~0.9.1",
"grunt-jscs": "~1.2.0",
"grunt-lib-phantomjs": "~0.6.0",
"grunt-markdown": "~0.6.1",
"grunt-saucelabs": "~8.4.1",
"grunt-sed": "~0.1.1",
"grunt-markdown": "~0.7.0",
"grunt-saucelabs": "~8.5.0",
"grunt-shell": "~1.1.1",
"grunt-template-jasmine-istanbul": "~0.3.1",
"marked": "~0.3.2",
"uglify-js": "2.4.x"
"grunt-template-jasmine-istanbul": "~0.3.2",
"load-grunt-tasks": "~3.0.0",
"jsdifflib": "~1.1.0",
"marked": "~0.3.3",
"uglify-js": "2.4.x",
"time-grunt": "~1.0.0"
},
"scripts": {
"test": "grunt test"
Expand Down
Loading