Move dist dir generation into Grunt

This commit is contained in:
kpdecker
2013-08-17 11:57:50 -05:00
parent 87b5d4ee61
commit 3d77d172ec
6 changed files with 78 additions and 50 deletions
+67
View File
@@ -0,0 +1,67 @@
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
banner: '/*!\n\n <%= pkg.name %> v<%= pkg.version %>\n\n<%= grunt.file.read("LICENSE") %>\n@license\n*/\n',
process: function(src, name) {
var match = /\/\/ BEGIN\(BROWSER\)\n((?:.|\n)*)\n\/\/ END\(BROWSER\)/.exec(src);
return '\n// ' + name + '\n' + (match ? match[1] : src);
},
separator: ';'
},
dist: {
src: [
'lib/handlebars/browser-prefix.js',
'lib/handlebars/base.js',
'lib/handlebars/compiler/parser.js',
'lib/handlebars/compiler/base.js',
'lib/handlebars/compiler/ast.js',
'lib/handlebars/utils.js',
'lib/handlebars/compiler/compiler.js',
'lib/handlebars/compiler/javascript-compiler.js',
'lib/handlebars/runtime.js',
'lib/handlebars/browser-suffix.js'
],
dest: 'dist/handlebars.js'
},
runtime: {
src: [
'lib/handlebars/browser-prefix.js',
'lib/handlebars/base.js',
'lib/handlebars/utils.js',
'lib/handlebars/runtime.js',
'lib/handlebars/browser-suffix.js'
],
dest: 'dist/handlebars.runtime.js'
}
},
uglify: {
options: {
mangle: true,
compress: true,
preserveComments: 'some'
},
dist: {
src: 'dist/<%= pkg.name %>.js',
dest: 'dist/<%= pkg.name %>.min.js'
},
runtime: {
src: 'dist/<%= pkg.name %>.runtime.js',
dest: 'dist/<%= pkg.name %>.runtime.min.js'
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.registerTask('dist-dir', function() {
grunt.file.delete('dist');
grunt.file.mkdir('dist');
});
grunt.registerTask('default', ['dist-dir', 'concat', 'uglify']);
};
+1
View File
@@ -393,6 +393,7 @@ Helping Out
To build Handlebars.js you'll need a few things installed.
* Node.js
* [Grunt](http://gruntjs.com/getting-started)
* Ruby
* Rake
+1 -46
View File
@@ -34,53 +34,8 @@ end
task :default => [:compile, :spec]
def remove_exports(string)
match = string.match(%r{^// BEGIN\(BROWSER\)\n(.*)\n^// END\(BROWSER\)}m)
match ? match[1] : string
end
minimal_deps = %w(browser-prefix base compiler/parser compiler/base compiler/ast utils compiler/compiler compiler/javascript-compiler runtime browser-suffix).map do |file|
"lib/handlebars/#{file}.js"
end
runtime_deps = %w(browser-prefix base utils runtime browser-suffix).map do |file|
"lib/handlebars/#{file}.js"
end
directory "dist"
minimal_deps.unshift "dist"
def build_for_task(task)
FileUtils.rm_rf("dist/*") if File.directory?("dist")
FileUtils.mkdir_p("dist")
contents = ["/*\n\n" + File.read('LICENSE') + "\n@license\n*/\n"]
task.prerequisites.each do |filename|
next if filename == "dist"
contents << "// #{filename}\n" + remove_exports(File.read(filename)) + ";"
end
File.open(task.name, "w") do |file|
file.puts contents.join("\n")
end
end
file "dist/handlebars.js" => minimal_deps do |task|
build_for_task(task)
end
file "dist/handlebars.runtime.js" => runtime_deps do |task|
build_for_task(task)
end
task :build => [:compile] do |task|
Rake::Task["dist/handlebars.js"].execute
Rake::Task["dist/handlebars.runtime.js"].execute
system "./node_modules/.bin/uglifyjs -m -c --comments -o dist/handlebars.min.js dist/handlebars.js"
system "./node_modules/.bin/uglifyjs -m -c --comments -o dist/handlebars.runtime.min.js dist/handlebars.runtime.js"
system "grunt"
end
# Updates the various version numbers.
+3 -2
View File
@@ -1,4 +1,6 @@
/*
/*!
handlebars v1.0.12
Copyright (C) 2011 by Yehuda Katz
@@ -2279,4 +2281,3 @@ Handlebars.template = Handlebars.VM.template;
this.Handlebars = Handlebars;
}
}).call(this);
;
+3 -2
View File
@@ -1,4 +1,6 @@
/*
/*!
handlebars v1.0.12
Copyright (C) 2011 by Yehuda Katz
@@ -371,4 +373,3 @@ Handlebars.template = Handlebars.VM.template;
this.Handlebars = Handlebars;
}
}).call(this);
;
+3
View File
@@ -23,6 +23,9 @@
"devDependencies": {
"benchmark": "~1.0",
"dust": "~0.3",
"grunt": "~0.4.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.2.2",
"jison": "~0.3",
"mocha": "*",
"mustache": "~0.7.2",