Skip to content

Commit

Permalink
Merge pull request #272 from null-a/grunt
Browse files Browse the repository at this point in the history
Use grunt rather than make to compile for browser.
  • Loading branch information
stuhlmueller committed Dec 2, 2015
2 parents f279b93 + ec6e803 commit 98d00e8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*.swp
node_modules
npm-debug.log
compiled/webppl.js
compiled/webppl.min.js
compiled/
docs/_build
docs/_static
docs/_templates
28 changes: 27 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
'use strict';

var _ = require('underscore');
var open = require('open');
var execSync = require('child_process').execSync;

var jslintSettings = {
options: {
flags: ['--flagfile .gjslintrc'],
Expand Down Expand Up @@ -58,15 +62,37 @@ module.exports = function(grunt) {
}
},
gjslint: jslintSettings,
fixjsstyle: jslintSettings
fixjsstyle: jslintSettings,
clean: ['compiled/*.js']
});

grunt.loadNpmTasks('grunt-gjslint');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-clean');

grunt.registerTask('default', ['nodeunit', 'gjslint']);
grunt.registerTask('test', ['nodeunit']);
grunt.registerTask('lint', ['gjslint']);
grunt.registerTask('hint', ['jshint']);
grunt.registerTask('fixstyle', ['fixjsstyle']);

grunt.registerTask('compile', 'Compile for the browser', function() {
var pkgArg = '';
if (arguments.length > 0) {
var requires = _.chain(_.toArray(arguments))
.map(function(name) { return ['--require', '\"' + name + '\"']; })
.flatten().value();
pkgArg = ' -t [' + ['./src/bundle.js'].concat(requires).join(' ') + ']';
}
execSync('mkdir -p compiled');
grunt.log.writeln('Running browserify');
execSync('browserify' + pkgArg + ' -g brfs src/browser.js > compiled/webppl.js');
grunt.log.writeln('Running uglifyjs');
execSync('uglifyjs compiled/webppl.js -b ascii_only=true,beautify=false > compiled/webppl.min.js');
});

grunt.registerTask('test-browser', function() {
open('tests/browser/index.html', process.env.BROWSER);
});
};
23 changes: 0 additions & 23 deletions compiled/Makefile

This file was deleted.

13 changes: 5 additions & 8 deletions docs/development/workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,23 @@ many of them automatically using::
To compile webppl for use in browser, run::

npm install -g browserify uglifyjs
cd compiled
make clean
make
grunt compile

Then, to run the browser tests use::

make test
grunt test-browser

The tests will run in the default browser. Specify a different browser
using the ``BROWSER`` environment variable. For example::

BROWSER="Google Chrome" make test
BROWSER="Google Chrome" grunt test-browser

Packages can also be used in the browser. For example, to include the
``webppl-viz`` package use::

browserify -t [./src/bundle.js --require webppl-viz] -g brfs src/browser.js > compiled/webppl.js
grunt compile:path/to/webppl-viz

Multiple ``--require`` arguments can be used to include multiple
packages.
Multiple packages can specified, separated by colons.

.. _continuous integration tests: https://travis-ci.org/probmods/webppl
.. _nodeunit documentation: https://github.com/caolan/nodeunit#command-line-options
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"brfs": "0.0.8",
"closure-linter-wrapper": "^1.0.1",
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-jshint": "^0.11.3",
"grunt-contrib-nodeunit": "^0.4.1",
"grunt-gjslint": "^0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion tests/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>WebPPL</title>
<script src="../../compiled/webppl.js"></script>
<script src="../../compiled/webppl.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.19.0.css">
</head>
<body>
Expand Down

0 comments on commit 98d00e8

Please sign in to comment.