Skip to content

Commit

Permalink
Merge pull request #1 from pazguille/master
Browse files Browse the repository at this point in the history
Update ES6 module workflow.
  • Loading branch information
pazguille committed Apr 9, 2015
2 parents d8c3792 + af9179a commit 13a81f8
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
node_modules
node_modules
npm-debug.log
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
babel.js
browserify.js
.gitignore
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> A JavaScript Emitter written in ES6.
## ES6 Usage
## Usage
```js
import Emitter from 'emitter';

Expand All @@ -11,15 +11,6 @@ const bus = new Emitter();
bus.emit('finish');
```

## ES5 Usage
```js
var Emitter = require('emitter/es5');

var bus = new Emitter();

bus.emit('finish');
```

## API

### Emitter#on(event, listener)
Expand Down Expand Up @@ -60,7 +51,11 @@ emitter.emit('live', 'data1', 'data2');

## npm-scripts
```
$ npm run es5
$ npm run compile
```

```
$ npm run browser
```

```
Expand Down
19 changes: 14 additions & 5 deletions babel.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
'use strict';

/**
* Dependencies
*/
var fs = require('fs');
var babel = require('babel');

if (!fs.existsSync('./es5')) {
fs.mkdirSync('./es5');
/**
* Create directories
*/
if (!fs.existsSync('./dist')) {
fs.mkdirSync('./dist');
}

babel.transformFile('index.js', {'loose': ['es6.classes']}, function (err, result) {
/**
* Babel
*/
babel.transformFile('./src/index.js', {'loose': ['es6.classes', 'es6.modules']}, function (err, result) {
if (err) { console.log('Error : ' + err.message); }
fs.writeFileSync('./es5/index.js', result.code);
});
fs.writeFileSync('./dist/index.js', result.code);
});
158 changes: 158 additions & 0 deletions browser/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions browserify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

/**
* Dependencies
*/
var fs = require('fs');
var browserify = require('browserify');

/**
* Create directories
*/
if (!fs.existsSync('./browser')) {
fs.mkdirSync('./browser');
}

/**
* Browserify
*/
browserify({ 'entries': './src/index.js', 'standalone': 'Emitter', 'debug': true })
.transform('babelify', {'loose': ['es6.classes', 'es6.modules']})
.bundle()
.on('error', function (err) { console.log('Error : ' + err.message); })
.pipe(fs.createWriteStream('browser/index.js'));
4 changes: 3 additions & 1 deletion es5/index.js → dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };

exports.__esModule = true;
/**
* Creates a new instance of Emitter.
* @class
Expand Down Expand Up @@ -148,4 +149,5 @@ var Emitter = (function () {
/**
* Exports Emitter
*/
module.exports = Emitter;
exports["default"] = Emitter;
module.exports = exports["default"];
25 changes: 17 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
{
"name": "emitter",
"repository": "git@github.com:mango/emitter.git",
"repository": {
"type": "git",
"url": "git@github.com:mango/emitter.git"
},
"description": "A JavaScript event emitter written in ES6.",
"author": "Guille Paz <guille87paz@gmail.com>",
"version": "0.0.2",
"author": {
"name": "Guille Paz",
"email": "guille87paz@gmail.com"
},
"version": "0.0.4",
"scripts": {
"test": "_mocha",
"es5": "node babel.js",
"hint": "jshint index.js",
"prepublish": "npm run es5"
"hint": "jshint ./src/index.js",
"compile": "node babel.js",
"browser": "node browserify.js",
"prepublish": "npm run compile"
},
"dependencies": {},
"devDependencies": {
"babel": "^5.0.2",
"babelify": "^6.0.0",
"better-assert": "1.0.2",
"browserify": "^9.0.7",
"jshint": "2.6.3",
"mocha": "2.1.0"
},
"main": "index.js",
"main": "./dist/index.js",
"keywords": [
"emitter"
],
"license": "MIT"
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'assert';
import Emitter from '../index.js';
import Emitter from '../src/index.js';

const bus = new Emitter();

Expand Down

0 comments on commit 13a81f8

Please sign in to comment.