Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial work on ES6 modules
  • Loading branch information
wycats committed Jul 1, 2013
1 parent 8e2416d commit 88ee475
Show file tree
Hide file tree
Showing 15 changed files with 452 additions and 399 deletions.
51 changes: 51 additions & 0 deletions Gruntfile.js
@@ -0,0 +1,51 @@
function config(name) {
return require('./configurations/' + name);
}

module.exports = function(grunt) {

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

clean: ["dist"],
watch: config('watch') ,
concat: config('concat'),
browser: config('browser'),
connect: config('connect'),
transpile: config('transpile')
});

// By default, (i.e., if you invoke `grunt` without arguments), do
// a new build.
this.registerTask('default', ['build']);

// Build a new version of the library
this.registerTask('build', "Builds a distributable version of the current project", [
'clean',
'transpile:amd',
'concat:library',
'concat:browser',
'browser:dist',
'bytes']);

this.registerTask('tests', "Builds the test package", [
'build',
'concat:deps',
'transpile:tests']);

// 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-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-es6-module-transpiler');

grunt.task.loadTasks('tasks');
};
6 changes: 6 additions & 0 deletions configurations/browser.js
@@ -0,0 +1,6 @@
module.exports = {
dist: {
src: 'tmp/<%= pkg.barename %>.browser1.js',
dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.js'
}
};
16 changes: 16 additions & 0 deletions configurations/concat.js
@@ -0,0 +1,16 @@
module.exports = {
library: {
src: ['tmp/<%= pkg.barename %>.amd.js'],
dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.amd.js'
},

deps: {
src: ['vendor/deps/*.js'],
dest: 'tmp/deps.amd.js'
},

browser: {
src: ['vendor/loader.js', 'tmp/<%= pkg.barename %>.amd.js'],
dest: 'tmp/<%= pkg.barename %>.browser1.js'
}
};
8 changes: 8 additions & 0 deletions configurations/connect.js
@@ -0,0 +1,8 @@
module.exports = {
server: {},
options: {
hostname: '0.0.0.0',
port: 8000,
base: '.'
}
};
25 changes: 25 additions & 0 deletions configurations/transpile.js
@@ -0,0 +1,25 @@
module.exports = {
amd: {
type: 'amd',
src: ["lib/<%= pkg.barename %>.js", "lib/*/**/*.js"],
dest: "tmp/<%= pkg.barename %>.amd.js"
},

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

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
@@ -0,0 +1,4 @@
module.exports = {
files: ['lib/**', 'vendor/*', 'test/**/*'],
tasks: ['build', 'tests']
};
22 changes: 11 additions & 11 deletions lib/handlebars.js
@@ -1,15 +1,19 @@
var handlebars = require("./handlebars/base"),
import handlebars from "handlebars/base";

This comment has been minimized.

Copy link
@kpdecker

kpdecker Jul 1, 2013

Collaborator

What is the build/install flow for this for node modules? AFAIK harmony is still buried behind a config flag so node modules will have to use build output as well.

This comment has been minimized.

Copy link
@wycats

wycats Jul 2, 2013

Author Collaborator

In the short-term there would be a build step, but it would eliminate the complicated special browser source hacks. This is still preliminary. I'll ping you soon to discuss 😄

This comment has been minimized.

Copy link
@kpdecker

kpdecker Jul 3, 2013

Collaborator

One thought before the discussion:

Should we hold off on the current module implementation that has yet to be released while this is worked out then? There have been some questions on #537, etc when this will be be out in a formalized alpha but this path takes a different approach of creating a separate build for each packaging system.

https://github.com/wycats/handlebars.js/blob/master/lib/handlebars/browser-suffix.js

This comment has been minimized.

Copy link
@stefanpenner

stefanpenner Jul 3, 2013

Collaborator

@kpdecker once esnext/es6-module-transpiler#18 lands the basic parts of the spec and the transpilar will be in sync. Any future changes will likely be rather quick changes.

This comment has been minimized.

Copy link
@kpdecker

kpdecker Jul 3, 2013

Collaborator

My question was more of do we ever release the conditional module impl that is on master right now. My concern is if we jump between use one of these two files and use one of these 6 files that it could be confusing for users. Then again everything would be in alpha...


// Each of these augment the Handlebars object. No need to setup here.
// (This is done to easily share code between commonjs and browse envs)
utils = require("./handlebars/utils"),
compiler = require("./handlebars/compiler"),
runtime = require("./handlebars/runtime");
import { SafeString, Exception, extend, escapeExpression, isEmpty } from "handlebars/utils";
import compiler from "handlebars/compiler";
import runtime from "handlebars/runtime";

// For compatibility and usage outside of module systems, make the Handlebars object a namespace
var create = function() {
var hb = handlebars.create();

utils.attach(hb);
hb.SafeString = SafeString;
hb.Exception = Exception;
hb.utils = { extend: extend, escapeExpression: escapeExpression, isEmpty: isEmpty };

compiler.attach(hb);
runtime.attach(hb);

Expand All @@ -19,10 +23,10 @@ var create = function() {
var Handlebars = create();
Handlebars.create = create;

module.exports = Handlebars; // instantiate an instance
export default Handlebars;

// Publish a Node.js require() handler for .handlebars and .hbs files
if (require.extensions) {
if (typeof require !== 'undefined' && require.extensions) {
var extension = function(module, filename) {
var fs = require("fs");
var templateString = fs.readFileSync(filename, "utf8");
Expand All @@ -32,10 +36,6 @@ if (require.extensions) {
require.extensions[".hbs"] = extension;
}

// BEGIN(BROWSER)

// END(BROWSER)

// USAGE:
// var handlebars = require('handlebars');

Expand Down

1 comment on commit 88ee475

@stefanpenner
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Please sign in to comment.