Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert code to ES6 modules #628

Merged
merged 48 commits into from
Oct 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
88ee475
Initial work on ES6 modules
wycats Jul 1, 2013
12f8299
More modularization
wycats Jul 2, 2013
da130f7
Building an AMD file
wycats Jul 16, 2013
f5c8484
Further progress towards modularization.
wycats Jul 24, 2013
5f664dd
Make the Handlebars environment into an object
wycats Jul 26, 2013
d33408f
Move more testing mutations into the environment
wycats Jul 26, 2013
6f580c9
Global Handlebars.compile uses its env
wycats Jul 26, 2013
530f190
Merge branch 'else-if' into es6-modules
kpdecker Aug 30, 2013
192887c
Merge commit '87b5d4ee61605b026506e92c9e8873d867c5f150' into es6-modules
kpdecker Sep 2, 2013
cb0c45b
Merge branch 'master' into es6-modules
kpdecker Sep 2, 2013
a2687fd
Fix cjs output and testing
kpdecker Sep 2, 2013
1e8409e
Fix merge errors
kpdecker Sep 2, 2013
1173e5a
Update grunt build target
kpdecker Sep 28, 2013
27d9010
Update logger for es6 modules
kpdecker Oct 1, 2013
fbf8f13
Generate parser as es6 module
kpdecker Oct 1, 2013
80b748a
Fix global Handlebars references
kpdecker Oct 1, 2013
6a23391
Break exception class out into a standalone module
kpdecker Oct 2, 2013
e75839b
Break safe string out into standalone module
kpdecker Oct 2, 2013
e676e43
Use proper default vs. module import semantics
kpdecker Oct 2, 2013
fd09ff0
Expose current Handlebars namespace fields
kpdecker Oct 2, 2013
db0f03d
Remove empty file
kpdecker Oct 2, 2013
117357b
Output amd to dist
kpdecker Oct 2, 2013
a3b22ac
Update jshint for modules
kpdecker Oct 2, 2013
386c20c
Unify build target behavior with prior behavior
kpdecker Oct 2, 2013
19f1a1f
fixing jshint errors
twokul Oct 4, 2013
a8cd320
Merge pull request #622 from twokul/jshint-errors
kpdecker Oct 6, 2013
63bb459
Generate dist file using es6-module-packager
kpdecker Oct 9, 2013
820cbb0
Fix concurrent traceur exec error
kpdecker Oct 9, 2013
855eae3
Create runtime specific module
kpdecker Oct 9, 2013
0966f51
Defer load packager module
kpdecker Oct 9, 2013
b6c9f85
Use template env and compile methods
kpdecker Oct 9, 2013
4d7124f
Remove global Handlebars references
kpdecker Oct 9, 2013
3b0a3ca
Fix test runners under node
kpdecker Oct 9, 2013
2abe4d4
Generate single amd output file
kpdecker Oct 9, 2013
4e4c016
Merge branch 'master' into es6-modules
kpdecker Oct 9, 2013
096ac2d
Record stack on failed travis build
kpdecker Oct 9, 2013
b47f2cf
Additional logging on dist size task
kpdecker Oct 9, 2013
9769045
Cleanup unused var warnings
kpdecker Oct 9, 2013
e5a4889
Fix metrics exec
kpdecker Oct 9, 2013
e1f7f00
Fix dist-size metrics exec
kpdecker Oct 9, 2013
7ee0c10
Fix transpiler error in printer.js
kpdecker Oct 12, 2013
95d5768
Expose printer and visitor objects in node
kpdecker Oct 12, 2013
4d31df2
Update logger interface to expose prior API
kpdecker Oct 12, 2013
6136e7f
Do not emit configurations dir in npm
kpdecker Oct 12, 2013
abf37ad
Update package.json for backwards compatibility
kpdecker Oct 12, 2013
52dea1e
Force rebuild on publish
kpdecker Oct 12, 2013
83b5e10
Install grunt prior to other actions
kpdecker Oct 12, 2013
3f96319
Update compat notes for es6-modules
kpdecker Oct 12, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ vendor
.rvmrc
.DS_Store
lib/handlebars/compiler/parser.js
dist
/dist/
/tmp/
node_modules
*.sublime-project
*.sublime-workspace
Expand Down
2 changes: 2 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@

"node" : true,
"browser" : true,
"esnext": true,

"boss" : true,
"curly": false,
"debug": false,
"devel": false,
"eqeqeq": false,
"eqnull": true,
"evil": true,
"forin": false,
"immed": false,
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Rakefile
*.gemspec
*.nuspec
bench/*
configurations/*
spec/*
src/*
tasks/*
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ node_js:
- "0.8"
- "0.10"

before_script:
before_install:
- npm install -g grunt-cli

script:
- grunt build metrics publish:latest
- grunt --stack build metrics publish:latest

email:
on_failure: change
Expand Down
121 changes: 79 additions & 42 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
var childProcess = require('child_process');

function config(name) {
return require('./configurations/' + name);
}

module.exports = function(grunt) {

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

Expand All @@ -10,72 +15,105 @@ module.exports = function(grunt) {
force: true
},
files: [
'lib/**/!(parser|browser-prefix|browser-suffix).js'
'lib/**/!(parser).js'
]
},

concat: {
clean: ["dist"],
watch: config('watch') ,
concat: config('concat'),
connect: config('connect'),
transpile: config('transpile'),

packager: {
options: {
export: 'Handlebars'
},

global: {
files: [{
cwd: 'lib/',
expand: true,
src: ['handlebars*.js'],
dest: 'dist/'
}]
}
},
requirejs: {
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: ';'
optimize: "none",
baseUrl: "dist/amd/"
},
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'
options: {
name: "handlebars",
out: "dist/handlebars.amd.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'
options: {
name: "handlebars.runtime",
out: "dist/handlebars.runtime.amd.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'
files: [{
cwd: 'dist/',
expand: true,
src: ['handlebars*.js'],
dest: 'dist/',
rename: function(dest, src) {
return dest + src.replace(/\.js$/, '.min.js');
}
}]
}
}
});

// Build a new version of the library
this.registerTask('build', "Builds a distributable version of the current project", [
'jshint',
'clean',
'parser',
'transpile:amd',
'transpile:cjs',
'packager-fork',
'requirejs',
'uglify']);

grunt.registerTask('packager-fork', function() {
// Allows us to run the packager task out of process to work around the multiple
// traceur exec issues
grunt.util.spawn({grunt: true, args: ['packager']}, this.async());
});

// Run a server. This is ideal for running the QUnit tests in the browser.
this.registerTask('server', [
'build',
'tests',
'connect',
'watch']);

// Load tasks from npm
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-es6-module-transpiler');

grunt.loadTasks('tasks');
grunt.task.loadTasks('tasks');

grunt.registerTask('dist-dir', function() {
grunt.file.delete('dist');
grunt.file.mkdir('dist');
});
grunt.registerTask('test', function() {
var done = this.async();

Expand All @@ -89,6 +127,5 @@ module.exports = function(grunt) {
});
grunt.registerTask('bench', ['metrics']);

grunt.registerTask('build', ['jshint', 'parser', 'dist-dir', 'concat', 'uglify', 'test']);
grunt.registerTask('default', 'build');
grunt.registerTask('default', ['build', 'test']);
};
12 changes: 11 additions & 1 deletion bench/dist-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ module.exports = function(grunt, callback) {
distSizes = {};

async.each(distFiles, function(file, callback) {
var content = fs.readFileSync('dist/' + file);
var content;
try {
content = fs.readFileSync('dist/' + file);
} catch (err) {
if (err.code === 'EISDIR') {
callback();
return;
} else {
throw err;
}
}

file = file.replace(/\.js/, '').replace(/\./g, '_');
distSizes[file] = content.length;
Expand Down
2 changes: 1 addition & 1 deletion bench/precompile-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var _ = require('underscore'),

module.exports = function(grunt, callback) {
// Deferring to here in case we have a build for parser, etc as part of this grunt exec
var Handlebars = require('../lib/handlebars');
var Handlebars = require('../lib');

var templateSizes = {};
_.each(templates, function(info, template) {
Expand Down
2 changes: 1 addition & 1 deletion bench/throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function makeSuite(bench, name, template, handlebarsOnly) {

module.exports = function(grunt, callback) {
// Deferring load incase we are being run inline with the grunt build
Handlebars = require('../lib/handlebars');
Handlebars = require('../lib');

console.log('Execution Throughput');
runner(grunt, makeSuite, function(times, scaled) {
Expand Down
6 changes: 6 additions & 0 deletions configurations/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
dist: {
src: 'tmp/<%= pkg.barename %>.browser1.js',
dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.js'
}
};
34 changes: 34 additions & 0 deletions configurations/concat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {
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);
}
},
dist: {
src: [
'dist/amd/handlebars/browser-prefix.js',
'dist/amd/handlebars/base.js',
'dist/amd/handlebars/compiler/parser.js',
'dist/amd/handlebars/compiler/base.js',
'dist/amd/handlebars/compiler/ast.js',
'dist/amd/handlebars/utils.js',
'dist/amd/handlebars/compiler/compiler.js',
'dist/amd/handlebars/compiler/javascript-compiler.js',
'dist/amd/handlebars/runtime.js',
'dist/amd/handlebars/browser-suffix.js'
],
dest: 'dist/handlebars.js'
},
runtime: {
src: [
'dist/amd/handlebars/browser-prefix.js',
'dist/amd/handlebars/base.js',
'dist/amd/handlebars/utils.js',
'dist/amd/handlebars/runtime.js',
'dist/amd/handlebars/browser-suffix.js'
],
dest: 'dist/handlebars.runtime.js'
}
};
8 changes: 8 additions & 0 deletions configurations/connect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
server: {},
options: {
hostname: '0.0.0.0',
port: 8000,
base: '.'
}
};
34 changes: 34 additions & 0 deletions configurations/transpile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {
amd: {
type: "amd",
anonymous: true,
files: [{
expand: true,
cwd: 'lib/',
src: '**/!(index).js',
dest: 'dist/amd/'
}]
},

cjs: {
type: 'cjs',
files: [{
expand: true,
cwd: 'lib/',
src: '**/!(index).js',
dest: 'dist/cjs/'
}]
},

globals: {
type: 'globals',
src: ["lib/<%= pkg.barename %>.js", "lib/*/**/*.js"],
dest: "tmp/<%= pkg.barename %>.globals.js"
},

tests: {
type: 'amd',
src: ['test/test_helpers.js', 'test/tests.js', 'test/tests/**/*_test.js'],
dest: 'tmp/tests.amd.js'
}
};
4 changes: 4 additions & 0 deletions configurations/watch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
files: ['lib/**', 'vendor/*', 'test/**/*'],
tasks: ['build', 'tests']
};
Loading