Move parser generation into grunt file

This commit is contained in:
kpdecker
2013-08-17 12:41:04 -05:00
parent b7c62d8cc5
commit 2f1a454467
4 changed files with 27 additions and 28 deletions
+2 -1
View File
@@ -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']);
};
+1 -1
View File
@@ -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`.
+1 -26
View File
@@ -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
+23
View File
@@ -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();
});
});
};