diff --git a/.gitattributes b/.gitattributes index 6b00c4c7f..d6b34c872 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ -build/* binary \ No newline at end of file +build/* binary +*.js eol=lf \ No newline at end of file diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 000000000..3b387bd38 --- /dev/null +++ b/.jscsrc @@ -0,0 +1,10 @@ +{ + "preset": "yandex", + "esnext":true, + "excludeFiles":[ + "src/addons/color-brewer.js" + ], + "requireLineFeedAtFileEnd":null, + "disallowMultipleVarDecl":null, + "disallowSpacesInsideParentheses":null +} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index e5e17fc04..175c9dd0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ notifications: slack: targetprocess:A8M6sVcJSfLnVOYtoMrPL7BA language: node_js -before_script: - - grunt travis node_js: - - "0.10" + - "0.12" diff --git a/Gruntfile.js b/Gruntfile.js index 5cd48af7c..471e34112 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,31 +1,42 @@ /*global module:false*/ var autoprefixer = require('autoprefixer-core'); +var webpack = require('webpack'); +var webpackConfig = require('./config/webpack.test.config'); module.exports = function (grunt) { - // Project configuration. var src = [ - "*.js", - "**/*.js", - "!charts/bar.js", - '!tau.plugins.js', - '!tau.svg.js', - '!charts/line.js', - '!charts/scatterplot.js', - '!addons/*.js', - '!tau.charts.js', - '!class.js', - '!tau.data.js', - '!tau.data.types.js' - ]; + '*.js', + '**/*.js', + '!addons/*.js' + ], webpackConf = { + entry: './src/tau.charts.js', + output: { + library: 'tauCharts', + libraryTarget: 'umd', + path: 'build/development', + filename: 'tauCharts.js' + }, + externals: { + d3: 'd3', + _: 'underscore' + }, + module: { + loaders: [{ + test: /\.js$/, + exclude: /node_modules/, + loader: 'babel-loader' + }] + } + }; grunt.initConfig({ - // Metadata. pkg: grunt.file.readJSON('package.json'), - banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' + - '<%= grunt.template.today("yyyy-mm-dd") %>\n' + - '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' + - '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' + - ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n', - // Task configuration. + banner: [ + '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ', + '<%= grunt.template.today("yyyy-mm-dd") %>\n', + '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>', + '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;', + ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n' + ].join(''), concat: { options: { banner: '<%= banner %>', @@ -36,7 +47,11 @@ module.exports = function (grunt) { dest: 'build/development/tauCharts.js' }, prodJS: { - src: ['build/development/tauCharts.js', 'build/development/tauCharts.color-brewer.js', 'build/development/plugins/*.js'], + src: [ + 'build/development/tauCharts.js', + 'build/development/tauCharts.color-brewer.js', + 'build/development/plugins/*.js' + ], dest: 'build/production/tauCharts.min.js' }, prodCSS: { @@ -53,36 +68,37 @@ module.exports = function (grunt) { }, compile: { build: { - cwd: "src/", + cwd: 'src/', src: src, - dest: "build/development/tauCharts.js" + dest: 'build/development/tauCharts.js' }, dev: { - cwd: "src/", + cwd: 'src/', src: src } }, karma: { - options: { - configFile: 'config/karma.conf.js' - }, + options: {configFile: 'config/karma.conf.js'}, dev: { - reporters: ["dots"], - browsers: ["Chrome"], - singleRun: false + reporters: ['dots'], + browsers: ['Chrome'], + singleRun: false, + webpack: webpackConfig.default }, unit: { - reporters: ["dots", "coverage"], - preprocessors: {"tau_modules/**/*.js": "coverage", "plugins/*.js": "coverage"}, + webpack: webpackConfig.coverage, + reporters: [ + 'coverage', + 'dots' + ], coverageReporter: { - + type: 'html', + dir: 'coverage/' } } }, uglify: { - options: { - banner: '<%= banner %>' - }, + options: {banner: '<%= banner %>'}, dist: { src: '<%= concat.prodJS.dest %>', dest: 'build/production/tauCharts.min.js' @@ -103,11 +119,7 @@ module.exports = function (grunt) { } }, postcss: { - options: { - processors: [ - autoprefixer({browsers: ['last 2 version']}).postcss - ] - }, + options: {processors: [autoprefixer({browsers: ['last 2 version']}).postcss]}, dist: {src: 'css/*.css'} }, copy: { @@ -205,72 +217,92 @@ module.exports = function (grunt) { 'git add build/tauCharts.js', 'git add build/tauCharts.min.js' ].join('&&'), - options: { - stdout: true - } + options: {stdout: true} } }, jshint: { all: { src: [ - "src/**/*.js", "Gruntfile.js" + 'src/**/*.js', + 'Gruntfile.js' ], options: { - "loopfunc": true, - "esnext": true + loopfunc: true, + esnext: true } } }, less: { development: { - options: { - paths: ["less"] - }, + options: {paths: ['less']}, files: { - "css/tooltip.css": "less/tooltip.less", - "css/export.css": "less/export.less", - "css/colorbrewer.css": "less/colorbrewer.less", - "css/base.css": "less/base.less", - "css/tauCharts.css": "less/tauCharts.less", - "css/layout.css": "less/layout.less", - "css/legend.css": "less/legend.less", - "css/trendline.css": "less/trendline.less" + 'css/tooltip.css': 'less/tooltip.less', + 'css/export.css': 'less/export.less', + 'css/colorbrewer.css': 'less/colorbrewer.less', + 'css/base.css': 'less/base.less', + 'css/tauCharts.css': 'less/tauCharts.less', + 'css/layout.css': 'less/layout.less', + 'css/legend.css': 'less/legend.less', + 'css/trendline.css': 'less/trendline.less' } } }, - clean: ['build/production/', 'build/development/'], + clean: [ + 'build/production/', + 'build/development/' + ], bowercopy: { - options: { - // clean: true - }, + options: {}, libs: { - options: { - destPrefix: "libs" - }, + options: {destPrefix: 'libs'}, files: { - "d3.js": "d3/d3.js", - "underscore.js": "underscore/underscore.js", - "jquery.js": "jquery/dist/jquery.js", - "modernizer.js": "modernizer/modernizr.js", - "js-schema.js": "js-schema/js-schema.debug.js", - "es5-shim.js": "es5-shim/es5-shim.js" + 'd3.js': 'd3/d3.js', + 'underscore.js': 'underscore/underscore.js', + 'jquery.js': 'jquery/dist/jquery.js', + 'js-schema.js': 'js-schema/js-schema.debug.js', + 'es5-shim.js': 'es5-shim/es5-shim.js' } } }, watch: { js: { files: ['<%= jshint.all.src %>'], - tasks: ['jshint', 'compile:dev', 'less'] + tasks: [ + 'jshint', + 'compile:dev', + 'less' + ] }, less: { files: ['less/*.less'], tasks: ['less'] } + }, + webpack: {build: webpackConf}, + 'webpack-dev-server': { + options: { + webpack: webpackConf, + publicPath: '/' + }, + start: { + port: 9000, + keepAlive: true, + webpack: { + devtool: 'eval', + debug: true + } + } + }, + jscs: { + src: [ + 'plugins/*.js', + 'src/**' + ], + options: {config: '.jscsrc'} } }); // load local tasks - grunt.loadTasks("tasks"); - + grunt.loadTasks('tasks'); // These plugins provide necessary tasks. grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-uglify'); @@ -286,12 +318,39 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-contrib-rename'); grunt.loadNpmTasks('grunt-postcss'); grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('grunt-webpack'); + grunt.loadNpmTasks('grunt-jscs'); // Default task. - //grunt.registerTask('default', ['jshint', 'qunit', 'concat', 'uglify']); - grunt.registerTask('default', ['bowercopy', 'less', 'compile:dev', 'jshint', 'watch:js']); - var buildWithoutPublish = ['bowercopy', 'less', 'postcss', 'copy:build', 'compile:build', 'concat:dist', 'concat:prodJS', 'concat:prodCSS', 'uglify', 'cssmin']; + // grunt.registerTask('default', ['jshint', 'qunit', 'concat', 'uglify']); + grunt.registerTask('default', [ + 'bowercopy', + 'less', + 'compile:dev', + 'jshint', + 'watch:js' + ]); + var buildWithoutPublish = [ + 'bowercopy', + 'less', + 'postcss', + 'copy:build', + 'compile:build', + 'concat:dist', + 'concat:prodJS', + 'concat:prodCSS', + 'uglify', + 'cssmin' + ]; grunt.registerTask('build', buildWithoutPublish); - grunt.registerTask('publish', buildWithoutPublish.concat(['copy:copybuild', 'clean'])); - grunt.registerTask('travis', ['bowercopy', 'jshint', 'build']); + grunt.registerTask('publish', buildWithoutPublish.concat([ + 'copy:copybuild', + 'clean' + ])); + grunt.registerTask('travis', [ + 'bowercopy', + 'jshint', + 'jscs', + 'build' + ]); grunt.registerTask('watching', ['default']); -}; +}; \ No newline at end of file diff --git a/bower.json b/bower.json index 8e4d768c8..6dfd74dc3 100644 --- a/bower.json +++ b/bower.json @@ -19,11 +19,10 @@ "!license.txt" ], "dependencies": { - "d3": "~3.4.3", - "underscore": "~1.6.0" + "d3": "~3.5.5", + "underscore": "~1.8.2" }, "devDependencies": { - "jquery": "2.1.1", "modernizer": "2.8.2", "js-schema": "0.7.0", "es5-shim": "latest", @@ -31,5 +30,9 @@ "FileSaver.js": "https://github.com/Mavrin/FileSaver.js.git", "fetch": "~0.6.1", "es6-promise": "~2.0.1" + }, + "resolutions": { + "d3": "~3.5.5", + "underscore": "~1.8.2" } } \ No newline at end of file diff --git a/config.rb b/config.rb deleted file mode 100644 index 95d45372a..000000000 --- a/config.rb +++ /dev/null @@ -1,19 +0,0 @@ -# Require any additional compass plugins here. - -# Set this to the root of your project when deployed: -http_path = "/" -css_dir = "css" -sass_dir = "sass" -images_dir = "images" -javascripts_dir = "src" - -# You can select your preferred output style here (can be overridden via the command line): -# output_style = :expanded or :nested or :compact or :compressed - -# To enable relative paths to assets via compass helper functions. Uncomment: -# relative_assets = true - -# To disable debugging comments that display the original location of your selectors. Uncomment: -line_comments = false - -preferred_syntax = :sass diff --git a/config/karma.conf.js b/config/karma.conf.js index a47e39b31..866af8dd5 100644 --- a/config/karma.conf.js +++ b/config/karma.conf.js @@ -1,43 +1,33 @@ module.exports = function (config) { + var webpackConfig = require('./webpack.test.config'); config.set({ // base path, that will be used to resolve files and exclude basePath: '..', // frameworks to use - frameworks: ['mocha', 'requirejs'], + frameworks: ['mocha'], // list of files / patterns to load in the browser files: [ - /*'test/utils/utils.js', - 'libs/underscore.js', - 'libs/js-schema.js', - 'libs/d3.js', - */ - {pattern: 'src/addons/color-brewer.js', included: false}, - {pattern: 'bower_components/**', included: false}, - {pattern: 'node_modules/requirejs-text/**', included: false}, - //'build/tauCharts.js', - {pattern: 'test/utils/*.js', included: false}, - {pattern: 'plugins/**', included: false}, {pattern: 'css/tooltip.css', included: true}, {pattern: 'css/tauCharts.css', included: true}, {pattern: 'test/utils/test.css', included: true}, {pattern: 'css/base.css', included: true}, - {pattern: 'libs/**', included: false}, - {pattern: 'node_modules/chai/*.js', included: false}, - {pattern: 'tau_modules/**', included: false}, - {pattern: 'test/*test.js', included: false}, 'test/tests-main.js' ], - browsers: ["PhantomJS"], - preprocessors: {"tau_modules/**/*.js": "coverage"}, - reporters: ["coverage", "dots", "coveralls"], + browsers: ['PhantomJS'], + preprocessors: {'test/tests-main.js': ['webpack', 'sourcemap']}, + reporters: ['coverage', 'dots', 'coveralls'], coverageReporter: { - type: "lcovonly", - dir: "coverage/" + type: 'lcovonly', + dir: 'coverage/' }, - // web server port + webpackMiddleware: { + noInfo: true + }, + webpack: webpackConfig.coverage, + browserNoActivityTimeout: 100000, port: 9876, // enable / disable colors in the output (reporters and logs) diff --git a/config/webpack.test.config.js b/config/webpack.test.config.js new file mode 100644 index 000000000..edb198448 --- /dev/null +++ b/config/webpack.test.config.js @@ -0,0 +1,73 @@ +var webpack = require('webpack'); +var path = require('path'); +var coverage = [{ + test: /\.js$/, + exclude: /test|addons|plugins|node_modules|bower_components|libs\//, + loader: 'istanbul-instrumenter' +}]; +var generateConf = function (postLoader) { + return { + resolve: { + root: [ + path.resolve('.') + ], + modulesDirectories: [ + 'bower_components', + 'node_modules' + ], + alias: { + 'schemes': 'test/utils/schemes.js', + 'testUtils': 'test/utils/utils.js', + 'es5-shim': 'libs/es5-shim.js', + 'brewer': 'src/addons/color-brewer.js', + 'tauCharts': 'src/tau.charts.js', + 'print.style.css': 'plugins/print.style.css', + 'rgbcolor': 'bower_components/canvg/rgbcolor.js', + 'stackblur': 'bower_components/canvg/StackBlur.js', + 'canvg': 'bower_components/canvg/canvg.js', + 'FileSaver': 'test/utils/saveAs.js', + 'fetch': 'bower_components/fetch/fetch.js', + 'promise': 'bower_components/es6-promise/promise.js' + }, + extensions: ['', '.js', '.json'] + }, + devtool: 'inline-source-map', + module: { + loaders: [ + {test: /\.css$/, loader: 'css-loader'}, + { + test: /modernizer[\\\/]modernizr\.js$/, + loader: 'imports?this=>window!exports?window.Modernizr' + }, + { + test: /\.js$/, + exclude: /node_modules|libs|bower_components/, + loader: 'babel-loader' + } + ], + postLoaders: postLoader + }, + externals: { + _: 'underscore' + }, + + plugins: [ + new webpack.ProvidePlugin({ + d3: 'd3', + _: 'underscore' + }) + ], + debug: false, + stats: { + colors: true, + reasons: true + }, + progress: true + } +}; +//console.log(generateConf(coverage)); +//console.log(generateConf([])); +module.exports = { + coverage: generateConf(coverage), + default: generateConf([]) +}; \ No newline at end of file diff --git a/examples/dsl.html b/examples/dsl.html index 86ab16bb6..8f891ebf2 100644 --- a/examples/dsl.html +++ b/examples/dsl.html @@ -2,7 +2,7 @@