diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..c13c5f6 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015"] +} diff --git a/addons/attach/attach.js b/addons/attach/attach.js index 24a45ea..2ef1f73 100644 --- a/addons/attach/attach.js +++ b/addons/attach/attach.js @@ -21,7 +21,7 @@ /* * Plain browser environment */ - attach(this.Xterm); + attach(window.Terminal); } })(function (Xterm) { 'use strict'; diff --git a/addons/fit/fit.js b/addons/fit/fit.js index deefd1f..209e059 100644 --- a/addons/fit/fit.js +++ b/addons/fit/fit.js @@ -26,7 +26,7 @@ /* * Plain browser environment */ - fit(this.Xterm); + fit(window.Terminal); } })(function (Xterm) { /** diff --git a/addons/fullscreen/fullscreen.js b/addons/fullscreen/fullscreen.js index 2689e61..9a655b3 100644 --- a/addons/fullscreen/fullscreen.js +++ b/addons/fullscreen/fullscreen.js @@ -25,7 +25,7 @@ /* * Plain browser environment */ - fullscreen(this.Xterm); + fullscreen(window.Terminal); } })(function (Xterm) { var exports = {}; diff --git a/addons/linkify/linkify.js b/addons/linkify/linkify.js index 4fc0b95..746b430 100644 --- a/addons/linkify/linkify.js +++ b/addons/linkify/linkify.js @@ -13,7 +13,7 @@ /* * Plain browser environment */ - linkify(this.Xterm); + linkify(window.Terminal); } })(function (Xterm) { 'use strict'; diff --git a/bin/build b/bin/build new file mode 100755 index 0000000..42a4788 --- /dev/null +++ b/bin/build @@ -0,0 +1,38 @@ +#! /usr/bin/env node + +var child_process = require('child_process'); +var fs = require('fs'); + +var buildDir = process.env.BUILD_DIR || 'build'; + +if (!fs.existsSync(buildDir)){ + fs.mkdirSync(buildDir); +} + +// Add `node_modules/.bin` to PATH +process.env.PATH = process.cwd() + '/node_modules/.bin:' + process.env.PATH; + +console.log('Building xterm.js into ' + buildDir); + +// Build ES2015 modules into ES5 form, then concatenate them, +// then remove unused require calls and save in output file with source map. +console.log(' - Building ' + buildDir + '/xterm.js...'); + +var jsBuildCmd = 'browserify src/xterm.js -s Terminal -t [ babelify --presets [ es2015 ] ] --debug | '; +jsBuildCmd += 'derequire | exorcist ' + buildDir + '/xterm.js.map > ' + buildDir + '/xterm.js'; + +var jsBuildProcess = child_process.execSync(jsBuildCmd); + +if (jsBuildProcess.status) { + console.log(jsBuildProcess.error); +} + +console.log(' OK.'); + +// Copy CSS into $BUILD_DIR +console.log(' - Building ' + buildDir + '/xterm.css...'); + +fs.createReadStream('src/xterm.css').pipe( + fs.createWriteStream(buildDir + '/xterm.css') +); +console.log(' OK.'); diff --git a/bin/prepare-release b/bin/prepare-release index 5084583..0aa022b 100755 --- a/bin/prepare-release +++ b/bin/prepare-release @@ -17,12 +17,16 @@ CURRENT_BOWER_JSON_VERSION=$(cat bower.json \ | sed 's/[",]//g' \ | tr -d '[[:space:]]') -# Update version in package.json and bower.json -sed -i "s/\"version\": \"$CURRENT_PACKAGE_JSON_VERSION\"/\"version\": \"$NEW_VERSION\"/g" package.json -sed -i "s/\"version\": \"$CURRENT_BOWER_JSON_VERSION\"/\"version\": \"$NEW_VERSION\"/g" bower.json +# Build xterm.js into `dist` +export BUILD_DIR=dist +sh bin/build # Update AUTHORS file sh bin/generate-authors +# Update version in package.json and bower.json +sed -i "s/\"version\": \"$CURRENT_PACKAGE_JSON_VERSION\"/\"version\": \"$NEW_VERSION\"/g" package.json +sed -i "s/\"version\": \"$CURRENT_BOWER_JSON_VERSION\"/\"version\": \"$NEW_VERSION\"/g" bower.json + git commit -S -s -a -m "Bump version to $NEW_VERSION" git tag $NEW_VERSION diff --git a/demo/app.js b/demo/app.js index 83195e6..353482e 100644 --- a/demo/app.js +++ b/demo/app.js @@ -7,7 +7,7 @@ var pty = require('pty.js'); var terminals = {}, logs = {}; -app.use('/src', express.static(__dirname + '/../src')); +app.use('/build', express.static(__dirname + '/../build')); app.use('/addons', express.static(__dirname + '/../addons')); app.get('/', function(req, res){ diff --git a/demo/index.html b/demo/index.html index 2150c37..5325949 100644 --- a/demo/index.html +++ b/demo/index.html @@ -2,11 +2,11 @@ xterm.js demo - + - + diff --git a/package.json b/package.json index 70331d8..6b667dc 100644 --- a/package.json +++ b/package.json @@ -10,19 +10,27 @@ "repository": "https://github.com/sourcelair/xterm.js", "license": "MIT", "devDependencies": { + "babel-core": "6.14.0", + "babel-preset-es2015": "6.14.0", + "babelify": "^7.3.0", + "browserify": "^13.1.0", "chai": "3.5.0", + "derequire": "^2.0.3", "docdash": "0.4.0", + "exorcist": "^0.4.0", "express": "4.13.4", "express-ws": "2.0.0-rc.1", "glob": "^7.0.5", "jsdoc": "3.4.0", "mocha": "2.5.3", + "nodemon": "1.10.2", "pty.js": "0.3.1", "sleep": "^3.0.1" }, "scripts": { - "start": "node demo/app", - "test": "mocha --recursive", - "build:docs": "node_modules/.bin/jsdoc -c jsdoc.json" + "start": "nodemon --watch src --watch addons --exec bash -c './bin/build && node demo/app'", + "test": "mocha --recursive --compilers js:babel-core/register", + "build:docs": "jsdoc -c jsdoc.json", + "build": "./bin/build" } } diff --git a/src/EventEmitter.js b/src/EventEmitter.js new file mode 100644 index 0000000..b17fbc7 --- /dev/null +++ b/src/EventEmitter.js @@ -0,0 +1,64 @@ +/** + * EventEmitter + */ + +function EventEmitter() { + this._events = this._events || {}; +} + +EventEmitter.prototype.addListener = function(type, listener) { + this._events[type] = this._events[type] || []; + this._events[type].push(listener); +}; + +EventEmitter.prototype.on = EventEmitter.prototype.addListener; + +EventEmitter.prototype.removeListener = function(type, listener) { + if (!this._events[type]) return; + + var obj = this._events[type] + , i = obj.length; + + while (i--) { + if (obj[i] === listener || obj[i].listener === listener) { + obj.splice(i, 1); + return; + } + } +}; + +EventEmitter.prototype.off = EventEmitter.prototype.removeListener; + +EventEmitter.prototype.removeAllListeners = function(type) { + if (this._events[type]) delete this._events[type]; +}; + +EventEmitter.prototype.once = function(type, listener) { + var self = this; + function on() { + var args = Array.prototype.slice.call(arguments); + this.removeListener(type, on); + return listener.apply(this, args); + } + on.listener = listener; + return this.on(type, on); +}; + +EventEmitter.prototype.emit = function(type) { + if (!this._events[type]) return; + + var args = Array.prototype.slice.call(arguments, 1) + , obj = this._events[type] + , l = obj.length + , i = 0; + + for (; i < l; i++) { + obj[i].apply(this, args); + } +}; + +EventEmitter.prototype.listeners = function(type) { + return this._events[type] = this._events[type] || []; +}; + +export { EventEmitter }; diff --git a/src/xterm.js b/src/xterm.js index bb74a3e..f4d2646 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -31,25 +31,8 @@ * other features. */ -(function (xterm) { - if (typeof exports === 'object' && typeof module === 'object') { - /* - * CommonJS environment - */ - module.exports = xterm.call(this); - } else if (typeof define == 'function') { - /* - * Require.js is available - */ - define([], xterm.bind(window)); - } else { - /* - * Plain browser environment - */ - this.Xterm = xterm.call(this); - this.Terminal = this.Xterm; /* Backwards compatibility with term.js */ - } -})(function() { +import { EventEmitter } from './EventEmitter.js'; + /** * Terminal Emulation References: * http://vt100.net/ @@ -61,77 +44,8 @@ * http://linux.die.net/man/7/urxvt */ - 'use strict'; - - /** - * Shared - */ - - var window = this, document = this.document; - - /** - * EventEmitter - */ - - function EventEmitter() { - this._events = this._events || {}; - } - - EventEmitter.prototype.addListener = function(type, listener) { - this._events[type] = this._events[type] || []; - this._events[type].push(listener); - }; - - EventEmitter.prototype.on = EventEmitter.prototype.addListener; - - EventEmitter.prototype.removeListener = function(type, listener) { - if (!this._events[type]) return; - - var obj = this._events[type] - , i = obj.length; - - while (i--) { - if (obj[i] === listener || obj[i].listener === listener) { - obj.splice(i, 1); - return; - } - } - }; - - EventEmitter.prototype.off = EventEmitter.prototype.removeListener; - - EventEmitter.prototype.removeAllListeners = function(type) { - if (this._events[type]) delete this._events[type]; - }; - - EventEmitter.prototype.once = function(type, listener) { - var self = this; - function on() { - var args = Array.prototype.slice.call(arguments); - this.removeListener(type, on); - return listener.apply(this, args); - } - on.listener = listener; - return this.on(type, on); - }; - - EventEmitter.prototype.emit = function(type) { - if (!this._events[type]) return; - - var args = Array.prototype.slice.call(arguments, 1) - , obj = this._events[type] - , l = obj.length - , i = 0; - - for (; i < l; i++) { - obj[i].apply(this, args); - } - }; - - EventEmitter.prototype.listeners = function(type) { - return this._events[type] = this._events[type] || []; - }; - + // Let it work inside Node.js for automated testing purposes. + var document = (typeof window != 'undefined') ? window.document : null; /** * Encapsulates the logic for handling compositionstart, compositionupdate and compositionend @@ -5232,10 +5146,6 @@ return w1 !== w2; } - var String = this.String; - var setTimeout = this.setTimeout; - var setInterval = this.setInterval; - function indexOf(obj, el) { var i = obj.length; while (i--) { @@ -5444,6 +5354,4 @@ Terminal.off = off; Terminal.cancel = cancel; - - return Terminal; -}); +module.exports = Terminal; diff --git a/test/composition-helper-test.js b/test/composition-helper-test.js index 2f2ba5f..d3071c2 100644 --- a/test/composition-helper-test.js +++ b/test/composition-helper-test.js @@ -15,7 +15,7 @@ describe('CompositionHelper', function () { remove: function () {}, }, getBoundingClientRect: function () { - return { width: 0 } + return { width: 0 }; }, style: { left: 0, diff --git a/test/escape_sequences.js b/test/escape_sequences.js index 85785d6..43523e6 100644 --- a/test/escape_sequences.js +++ b/test/escape_sequences.js @@ -27,7 +27,7 @@ function pty_write_read(s) { return b.toString('utf8', 0, bytes); } -// make sure raw pty is at x=0 and has no pending data +// make sure raw pty is at x=0 and has no pending data function pty_reset() { pty_write_read('\r\n'); } diff --git a/test/viewport-test.js b/test/viewport-test.js index 7e99c43..4916574 100644 --- a/test/viewport-test.js +++ b/test/viewport-test.js @@ -6,6 +6,7 @@ describe('Viewport', function () { var viewportElement; var charMeasureElement; var viewport; + var scrollAreaElement; var CHARACTER_HEIGHT = 10;