From 8db6393ec8cac592f323724e43a2a7122a84614f Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Sat, 21 Mar 2015 14:17:52 -0400 Subject: [PATCH] Copy from pr/528 --- .travis.yml | 7 +- CONTRIBUTING.md | 2 +- Makefile | 4 +- auto_tests/karma.conf.js | 31 +++++++++ gulpfile.js | 165 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 18 ++++++ 6 files changed, 222 insertions(+), 5 deletions(-) create mode 100644 auto_tests/karma.conf.js create mode 100644 gulpfile.js diff --git a/.travis.yml b/.travis.yml index c20a913..5a4bb52 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ language: node_js node_js: - "0.10" -sudo: false # use container-based architecture -script: "make travis" +before_script: + - npm install -g bower + - bower install + +script: "gulp travis" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3b5598b..9e2f923 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,7 +13,7 @@ page. For instance, instead of doing this: do this: ```html - + ``` This makes error messages and debugging simpler. The jsfiddle does this automatically. diff --git a/Makefile b/Makefile index 2ab31de..6cddafa 100644 --- a/Makefile +++ b/Makefile @@ -29,11 +29,11 @@ test: test-combined: move-combined test clean-combined-test move-combined: generate-combined - mv dygraph-combined.js dygraph-dev.js + mv dygraph-combined.js dygraph-autoloader.js clean-combined-test: clean @echo restoring combined - git checkout dygraph-dev.js + git checkout dygraph-autoloader.js rm dygraph-combined.js.map lint: diff --git a/auto_tests/karma.conf.js b/auto_tests/karma.conf.js new file mode 100644 index 0000000..939ddf6 --- /dev/null +++ b/auto_tests/karma.conf.js @@ -0,0 +1,31 @@ +module.exports = function (config) { + config.set({ + basePath: '../', + frameworks: ['mocha', 'chai', 'chai-as-promised', 'sinon-chai', 'chai-things', 'dirty-chai'], + files: [ + 'bower_components/jquery/dist/jquery.min.js', + 'specs/utils/*.js', + 'dist/scratch/dygraph-combined.dev.js', + 'src/dygraph/extras/smooth-plotter.js', + 'specs/unit/**/*.spec.js' + ], + autoWatch: false, + singleRun: true, + reporters: ['spec', 'coverage'], + preprocessors: { + 'dist/scratch/dygraph-combined.dev.js': ['coverage'] + }, + coverageReporter: { + type: 'html', + dir: 'dist/coverage' + }, + browsers: ['PhantomJS'], + plugins: [ + 'karma-mocha', + 'karma-chai-plugins', + 'karma-phantomjs-launcher', + 'karma-coverage', + 'karma-spec-reporter' + ] + }); +}; diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..09b636f --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,165 @@ +var gulp = require('gulp'); +var plugins = require('gulp-load-plugins')(); +var karma = require('karma').server; +var lazypipe = require('lazypipe'); +var path = require('path'); + +var dev = false; +var src = { + base: "src", + lib: { + base: "src/lib", + files: [ + "console.js", + "dashed-canvas.js" + ] + }, + main: { + base: "src/dygraph", + files: [ + "dygraph-options.js", + "dygraph-layout.js", + "dygraph-canvas.js", + "dygraph.js", + "dygraph-utils.js", + "dygraph-gviz.js", + "dygraph-interaction-model.js", + "dygraph-tickers.js", + "dygraph-plugin-base.js" + ] + } , + plugins: { + base: "src/dygraph/plugins", + files: [ + "annotations.js", + "axes.js", + "chart-labels.js", + "grid.js", + "legend.js", + "range-selector.js", + "../dygraph-plugin-install.js" + ] + }, + // Only used by dynamic loader + devOptions: { + base: "src/dygraph", + files: ["dygraph-options-reference.js"] + }, + datahandlers: { + base: "src/dygraph/datahandler", + files: [ + "datahandler.js", + "default.js", + "default-fractions.js", + "bars.js", + "bars-error.js", + "bars-custom.js", + "bars-fractions.js" + ] + } +}; + +// Convenience function to merge multiple arrays into one +var mergePaths = function() { + var paths = []; + var pathobj = null; + if (arguments.length > 0) { + for (var i = 0; i < arguments.length; i++) { + pathObj = arguments[i]; + pathObj.files.map(function(filename) { + paths.push(path.join(pathObj.base, filename)); + }); + } + + return paths; + } else { + return []; + } +}; + +var copyright = '/*! @license Copyright 2014 Dan Vanderkam (danvdk@gmail.com) MIT-licensed (http://opensource.org/licenses/MIT) */'; + +// Creates the dygraph-autoloader +gulp.task('create-loader', function() { + // Create string ready for javascript array + var files = mergePaths(src.lib, src.main, src.plugins, src.devOptions, src.datahandlers) + .map(function(filename) { + // Make the path relative to dist file and add quotes + return "'" + filename.replace(src.base, '../../' + src.base) + "'"; + }) + .join(","); + + return gulp.src(src.base + '/dygraph/dygraph-autoloader.js') + .pipe(plugins.replace(/\/\* REPLACEME \*\//, files)) + .pipe(gulp.dest('dist/scratch')); +}); + +gulp.task('create-dev', function() { + var dest = 'dist/scratch'; + return gulp.src(mergePaths(src.lib, src.main, src.plugins, src.devOptions, src.datahandlers)) + .pipe(plugins.sourcemaps.init()) + .pipe(plugins.concat('dygraph-combined.dev.js')) + .pipe(plugins.header(copyright)) + .pipe(gulp.dest(dest)); +}); + +gulp.task('concat', function() { + var dest = 'dist/scratch'; + return gulp.src(mergePaths(src.lib, src.main, src.plugins, src.datahandlers)) + .pipe(plugins.sourcemaps.init()) + .pipe(plugins.concat('dygraph-combined.js')) + .pipe(plugins.header(copyright)) + .pipe(gulp.dest(dest)) + .pipe(plugins.uglify({ + define: "DEBUG=false", + warnings: false, + preserveComments: "none" + })) + .pipe(plugins.header(copyright)) + .pipe(plugins.rename('dygraph-combined.min.js')) + .pipe(plugins.sourcemaps.write('.')) + .pipe(gulp.dest(dest)); + +}); + +gulp.task("bower-dist", ['concat'], function() { + gulp.src('src/dygraph/extras/**', {base: 'src/dygraph'}) + .pipe(gulp.dest('dist/bower')); + + return gulp.src('dist/scratch/dygraph-combined*') + .pipe(gulp.dest('dist/bower')); +}); + +gulp.task('gwt-dist', ['concat'], function() { + // Copy package structure to dist folder + gulp.src('gwt/**', {'base': '.'}) + .pipe(gulp.dest('dist')); + + gulp.src('scratch/dygraph-combined.min.js') + .pipe(gulp.dest('dist/gwt/org/danvk')); + + // Generate jar + gulp.src('') + .pipe(plugins.shell([ + 'bash -c "jar -cf dygraph-gwt.jar -C dist/gwt org"' + ])) +}); + +gulp.task('test', ['concat', 'create-dev'], function(done) { + karma.start({ + configFile: process.cwd() + '/specs/karma.conf.js', + singleRun: true + }, done); +}); + +gulp.task('watch', function() { + gulp.watch('src/dygraph/**', ['concat']); +}); + +gulp.task('watch-test', function() { + gulp.watch(['src/dygraph/**', 'specs/unit/**'], ['test']); +}); + +gulp.task('dist', ['gwt-dist', 'bower-dist']); +gulp.task('travis', ['test']); +gulp.task('default', ['test', 'dist']); diff --git a/package.json b/package.json index 25aff77..bed1437 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,25 @@ "devDependencies": { "closure-compiler": "^0.2.6", "coveralls": "^2.11.2", + "gulp": "^3.8.10", + "gulp-concat": "^2.4.3", + "gulp-eslint": "^0.2.0", + "gulp-header": "^1.2.2", + "gulp-load-plugins": "^0.8.0", + "gulp-rename": "^1.2.0", + "gulp-replace": "^0.5.0", + "gulp-shell": "^0.2.11", + "gulp-sourcemaps": "^1.3.0", + "gulp-uglify": "^1.0.2", "jshint": "^2.5.10", + "karma": "^0.12.28", + "karma-coverage": "^0.2.7", + "karma-chai-plugins": "git+https://github.com/cthrax/karma-chai-plugins.git#c44bd9c2026bcbaf5bb56a9ee35a13d216e44d20", + "karma-mocha": "^0.1.10", + "karma-phantomjs-launcher": "^0.1.4", + "karma-spec-reporter": "0.0.16", + "lazypipe": "^0.2.2", + "mocha": "^2.1.0", "obvious-closure-library": "^20140401.0.2", "phantomjs": "^1.9.7-8", "uglify-js": "^2" -- 2.7.4