diff --git a/.gitignore b/.gitignore index 751056522..9bc2dea3b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -build/min/ +build/ node_modules/ lib/*/* npm-debug.log \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index ebf8c0cd6..c6705a258 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,5 +12,4 @@ before_install: install: npm install before_script: - - rm -r dist - - grunt build:all + - grunt dist diff --git a/Gruntfile.js b/Gruntfile.js index d1c8cf558..397d443f6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,9 +1,14 @@ +'use strict'; + +var _ = require('lodash'); + module.exports = function(grunt) { require('time-grunt')(grunt); require('load-grunt-tasks')(grunt); - var banner = '/*! <%= pkg.title %> v<%= pkg.version %> - <%= pkg.description %> <%= grunt.template.today("yyyy-mm-dd") %> \n\n\nThis Source Code Form is subject to the terms of the Mozilla Public\nLicense, v. 2.0. If a copy of the MPL was not distributed with this\nfile, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n'; + var pkg = grunt.file.readJSON('package.json'); + var banner = _.template('/*! <%= pkg.title %> v<%= pkg.version %> - <%= pkg.description %> <%= grunt.template.today("yyyy-mm-dd") %> \n\n\nThis Source Code Form is subject to the terms of the Mozilla Public\nLicense, v. 2.0. If a copy of the MPL was not distributed with this\nfile, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n')({ pkg: pkg, grunt: grunt }); // Ignore webpack in node v5, until webpack is fixed for that version. var ignoreWebpack = process.version.substr(0, 'v5'.length) === 'v5'; @@ -103,16 +108,16 @@ module.exports = function(grunt) { var config = { - pkg: grunt.file.readJSON('package.json'), + pkg: pkg, webpack: { joint: { files: { - './dist/joint.webpack-bundle.js' : './dist/joint.min.js' + './build/joint.webpack-bundle.js' : './build/joint.min.js' }, - entry: './dist/joint.min.js', + entry: './build/joint.min.js', output: { - path: './dist/', + path: './build/', filename: 'joint.webpack-bundle.js', library: 'joint' }, @@ -127,7 +132,7 @@ module.exports = function(grunt) { browserify: { joint: { files: { - 'dist/joint.browserify-bundle.js': 'dist/joint.min.js' + 'build/joint.browserify-bundle.js': 'build/joint.min.js' }, options: { browserifyOptions: { @@ -136,94 +141,91 @@ module.exports = function(grunt) { } } }, + clean: { + dist: ['dist'] + }, concat: { - options: { - banner: banner, - process: { - delimiters: 'square' - } - }, geometry: { files: { - 'dist/geometry.js': [].concat( - ['build/wrappers/geometry.head.js'], + 'build/geometry.js': [].concat( + ['wrappers/geometry.head.js'], js.geometry, - ['build/wrappers/geometry.foot.js'] + ['wrappers/geometry.foot.js'] ), - 'dist/geometry.min.js': [].concat( - ['build/wrappers/geometry.head.js'], + 'build/geometry.min.js': [].concat( + ['wrappers/geometry.head.js'], ['build/min/geometry.min.js'], - ['build/wrappers/geometry.foot.js'] + ['wrappers/geometry.foot.js'] ) } }, vectorizer: { files: { - 'dist/vectorizer.js': [].concat( - ['build/wrappers/vectorizer.head.js'], + 'build/vectorizer.js': [].concat( + ['wrappers/vectorizer.head.js'], js.vectorizer, - ['build/wrappers/vectorizer.foot.js'] + ['wrappers/vectorizer.foot.js'] ), - 'dist/vectorizer.min.js': [].concat( - ['build/wrappers/vectorizer.head.js'], + 'build/vectorizer.min.js': [].concat( + ['wrappers/vectorizer.head.js'], ['build/min/vectorizer.min.js'], - ['build/wrappers/vectorizer.foot.js'] + ['wrappers/vectorizer.foot.js'] ) } }, joint: { files: { - 'dist/joint.core.js': [].concat( - ['build/wrappers/joint.head.js'], + 'build/joint.core.js': [].concat( + ['wrappers/joint.head.js'], js.geometry, js.vectorizer, js.core, - ['build/wrappers/joint.foot.js'] + ['wrappers/joint.foot.js'] ), - 'dist/joint.core.min.js': [].concat( - ['build/wrappers/joint.head.js'], + 'build/joint.core.min.js': [].concat( + ['wrappers/joint.head.js'], ['build/min/geometry.min.js'], ['build/min/vectorizer.min.js'], ['build/min/joint.min.js'], - ['build/wrappers/joint.foot.js'] + ['wrappers/joint.foot.js'] ), - 'dist/joint.core.css': [].concat( + 'build/joint.core.css': [].concat( css.core ), - 'dist/joint.core.min.css': [].concat( + 'build/joint.core.min.css': [].concat( ['build/min/joint.min.css'] ), - 'dist/joint.js': [].concat( - ['build/wrappers/joint.head.js'], + 'build/joint.js': [].concat( + ['wrappers/joint.head.js'], js.geometry, js.vectorizer, js.core, allJSPlugins(), - ['build/wrappers/joint.foot.js'] + ['wrappers/joint.foot.js'] ), - 'dist/joint.min.js': [].concat( - ['build/wrappers/joint.head.js'], + 'build/joint.min.js': [].concat( + ['wrappers/joint.head.js'], ['build/min/geometry.min.js'], ['build/min/vectorizer.min.js'], ['build/min/joint.min.js'], allMinifiedJSPlugins(), - ['build/wrappers/joint.foot.js'] + ['wrappers/joint.foot.js'] ), - 'dist/joint.css': [].concat( + 'build/joint.css': [].concat( css.core, allCSSPlugins() ), - 'dist/joint.min.css': [].concat( + 'build/joint.min.css': [].concat( ['build/min/joint.min.css'], allMinifiedCSSPlugins() ), - 'dist/joint.nowrap.js': [].concat( + 'build/joint.nowrap.js': [].concat( js.geometry, js.vectorizer, js.core, allJSPlugins() ), - 'dist/joint.nowrap.min.js': [].concat( + 'build/joint.nowrap.min.js': [].concat( ['build/min/geometry.min.js'], ['build/min/vectorizer.min.js'], ['build/min/joint.min.js'], @@ -232,6 +234,26 @@ module.exports = function(grunt) { } } }, + copy: { + dist: { + files: [{ + nonull: true, + expand: true, + cwd: 'build/', + src: [ + '*', + '!min' + ], + dest: 'dist/' + }], + options: { + process: function(content) { + // Add JointJS banner to all distribution files. + return banner + content; + } + } + } + }, cssmin: { joint: { files: { @@ -399,19 +421,19 @@ module.exports = function(grunt) { // Create targets for all the plugins. Object.keys(js.plugins).forEach(function(name) { - config.concat[name] = { files: {}, options: { banner: banner } }; + config.concat[name] = { files: {} }; config.uglify[name] = { files: {} }; config.uglify[name].files['build/min/joint.' + name + '.min.js'] = js.plugins[name]; - config.concat[name].files['dist/joint.' + name + '.js'] = js.plugins[name]; - config.concat[name].files['dist/joint.' + name + '.min.js'] = ['build/min/joint.' + name + '.min.js']; + config.concat[name].files['build/joint.' + name + '.js'] = js.plugins[name]; + config.concat[name].files['build/joint.' + name + '.min.js'] = ['build/min/joint.' + name + '.min.js']; if (css.plugins[name]) { config.cssmin[name] = { files: {} }; config.cssmin[name].files['build/min/joint.' + name + '.min.css'] = css.plugins[name]; - config.concat[name].files['dist/joint.' + name + '.css'] = css.plugins[name]; - config.concat[name].files['dist/joint.' + name + '.min.css'] = ['build/min/joint.' + name + '.min.css']; + config.concat[name].files['build/joint.' + name + '.css'] = css.plugins[name]; + config.concat[name].files['build/joint.' + name + '.min.css'] = ['build/min/joint.' + name + '.min.css']; } }); @@ -469,22 +491,34 @@ module.exports = function(grunt) { ]); grunt.registerTask('build', ['build:joint']); + grunt.registerTask('build:bundles', ignoreWebpack ? [ 'newer:browserify' ] : [ 'newer:browserify', 'newer:webpack' ]); - grunt.registerTask('build:all', ['build:joint', 'build:bundles']); + + grunt.registerTask('build:all', [ + 'build:joint', + 'build:bundles' + ]); + + grunt.registerTask('dist', [ + 'build:all', + 'clean:dist', + 'copy:dist' + ]); grunt.registerTask('test:server', ['mochaTest:server']); - grunt.registerTask('test:client', ['qunit:all', 'jscs']); - grunt.registerTask('test', ['test:server', 'test:client']); + grunt.registerTask('test:client', ['qunit:all']); + grunt.registerTask('test:code-style', ['jscs']); + grunt.registerTask('test', ['test:server', 'test:client', 'test:code-style']); grunt.registerTask('bowerInstall', [ 'shell:bowerInstall:.' ]); - grunt.registerTask('install', ['bowerInstall']); + grunt.registerTask('install', ['bowerInstall', 'build:all']); grunt.registerTask('default', ['install', 'build', 'watch']); }; diff --git a/README.md b/README.md index d2313dd9d..949253018 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,43 @@ Only the good ones (those that support SVG): * IE 9+ -## Tests +## Development Environment -Before running tests, be sure to run a full build: +If you want to work on JointJS locally, use the following guidelines to get started. + +### Dependencies + +Make sure you have the following dependencies installed on your system: +* [Node.js](https://nodejs.org/) +* [grunt-cli](http://gruntjs.com/using-the-cli) +* [bower](http://bower.io/) +* git + +### Setup + +Clone this git repository: +``` +git clone https://github.com/clientIO/joint.git +``` + +Change into the joint directory: +``` +cd joint +``` + +Run installation ``` -grunt build:all +npm install ``` +This will install all npm and bower dependencies as well as run a full build. + +### Tests + +Before running tests, be sure to run the following: +``` +npm install +``` +This will ensure that you have all NPM and bower dependencies, and will run a full build. To run all tests: ``` @@ -62,11 +93,10 @@ grunt test:client To run code style checks: ``` -grunt jscs +grunt test:code-style ``` - -## Code Coverage +### Code Coverage It is possible to generate code coverage reports using the existing qunit tests. For example, to output the coverage report in [lcov format](http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php) for all unit tests: ``` @@ -78,6 +108,13 @@ By default, the output will be saved to `coverage.info` at the root of the proje grunt qunit:all_coverage --reporter lcov --output customfilename.info --coverage ``` +### Building Distribution Files + +The `dist` directory contains pre-built distribution files. To re-build them, run the following: +``` +grunt dist +``` + ## License diff --git a/demo/3d.html b/demo/3d.html index 5d83712b3..4ba2ca6bb 100644 --- a/demo/3d.html +++ b/demo/3d.html @@ -5,7 +5,7 @@ 3d shapes experiment - + diff --git a/demo/requirejs/main.js b/demo/requirejs/main.js index 07c9cef53..147951e22 100644 --- a/demo/requirejs/main.js +++ b/demo/requirejs/main.js @@ -14,7 +14,7 @@ require.config({ } }); -require(['jquery', 'dist/joint'], function($, joint) { +require(['jquery', 'build/joint'], function($, joint) { var $paper = $('
').appendTo($('#app')); diff --git a/demo/responsive.html b/demo/responsive.html index 02f52aaf9..72d3ef35d 100644 --- a/demo/responsive.html +++ b/demo/responsive.html @@ -3,7 +3,7 @@ JointJS Hello World! - + @@ -15,7 +15,7 @@ - + diff --git a/demo/routing.html b/demo/routing.html index 29909ada8..0adec6b3a 100644 --- a/demo/routing.html +++ b/demo/routing.html @@ -6,7 +6,7 @@ Smart Routing demo - +