summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Gruntfile.js3
-rw-r--r--README.markdown2
-rw-r--r--Rakefile27
-rw-r--r--tasks/parser.js23
4 files changed, 27 insertions, 28 deletions
diff --git a/Gruntfile.js b/Gruntfile.js
index 0e56e00..8fed742 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -70,6 +70,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
+ grunt.loadTasks('tasks');
grunt.registerTask('dist-dir', function() {
grunt.file.delete('dist');
@@ -87,5 +88,5 @@ module.exports = function(grunt) {
});
});
- grunt.registerTask('default', ['jshint', 'dist-dir', 'concat', 'uglify', 'test']);
+ grunt.registerTask('default', ['jshint', 'parser', 'dist-dir', 'concat', 'uglify', 'test']);
};
diff --git a/README.markdown b/README.markdown
index 2ea39a8..b3904aa 100644
--- a/README.markdown
+++ b/README.markdown
@@ -400,7 +400,7 @@ To build Handlebars.js you'll need a few things installed.
There's a Gemfile in the repo, so you can run `bundle` to install rake
if you've got bundler installed.
-To build Handlebars.js from scratch, you'll want to run `rake build`
+To build Handlebars.js from scratch, you'll want to run `grunt`
in the root of the project. That will build Handlebars and output the
results to the dist/ folder. To run tests, run `grunt test` or `npm test`.
You can also run our set of benchmarks with `rake bench`.
diff --git a/Rakefile b/Rakefile
index 21a4cc8..429c545 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,34 +1,9 @@
require "rubygems"
require "bundler/setup"
-def compile_parser
- system "./node_modules/.bin/jison -m js src/handlebars.yy src/handlebars.l"
- if $?.success?
- File.open("lib/handlebars/compiler/parser.js", "w") do |file|
- file.puts File.read("src/parser-prefix.js") + File.read("handlebars.js") + File.read("src/parser-suffix.js")
- end
-
- sh "rm handlebars.js"
- else
- fail "Failed to run Jison."
- end
-end
-
-file "lib/handlebars/compiler/parser.js" => ["src/handlebars.yy","src/handlebars.l"] do
- if File.exists?('./node_modules/jison')
- compile_parser
- else
- puts "Jison is not installed. Trying `npm install jison`."
- sh "npm install"
- compile_parser
- end
-end
-
-task :compile => "lib/handlebars/compiler/parser.js"
-
task :default => [:build]
-task :build => [:compile] do |task|
+task :build do |task|
system "grunt"
end
diff --git a/tasks/parser.js b/tasks/parser.js
new file mode 100644
index 0000000..f6a72c6
--- /dev/null
+++ b/tasks/parser.js
@@ -0,0 +1,23 @@
+var childProcess = require('child_process');
+
+module.exports = function(grunt) {
+ grunt.registerTask('parser', 'Generate jison parser.', function() {
+ var done = this.async();
+
+ var child = childProcess.spawn('./node_modules/.bin/jison', ['-m', 'js', 'src/handlebars.yy', 'src/handlebars.l'], {stdio: 'inherit'});
+ child.on('exit', function(code) {
+ if (code != 0) {
+ grunt.fatal('Jison failure: ' + code);
+ done();
+ return;
+ }
+
+ var src = ['src/parser-prefix.js', 'handlebars.js', 'src/parser-suffix.js'].map(grunt.file.read).join('');
+ grunt.file.delete('handlebars.js');
+
+ grunt.file.write('lib/handlebars/compiler/parser.js', src);
+ grunt.log.writeln('Parser "lib/handlebars/compiler/parser.js" created.');
+ done();
+ });
+ });
+};