]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Make `src/xterm.js` ES2015 and export EventEmitter into its own file
authorParis Kasidiaris <paris@sourcelair.com>
Fri, 26 Aug 2016 12:28:52 +0000 (15:28 +0300)
committerParis Kasidiaris <paris@sourcelair.com>
Mon, 29 Aug 2016 19:51:40 +0000 (19:51 +0000)
Fix #158

15 files changed:
.babelrc [new file with mode: 0644]
addons/attach/attach.js
addons/fit/fit.js
addons/fullscreen/fullscreen.js
addons/linkify/linkify.js
bin/build [new file with mode: 0755]
bin/prepare-release
demo/app.js
demo/index.html
package.json
src/EventEmitter.js [new file with mode: 0644]
src/xterm.js
test/composition-helper-test.js
test/escape_sequences.js
test/viewport-test.js

diff --git a/.babelrc b/.babelrc
new file mode 100644 (file)
index 0000000..c13c5f6
--- /dev/null
+++ b/.babelrc
@@ -0,0 +1,3 @@
+{
+  "presets": ["es2015"]
+}
index 24a45eaea02dd926a7afb797b7348fb4e52b9984..2ef1f7378c97bc69aa05d36537934c82e46343d5 100644 (file)
@@ -21,7 +21,7 @@
     /*
      * Plain browser environment
      */
-    attach(this.Xterm);
+    attach(window.Terminal);
   }
 })(function (Xterm) {
   'use strict';
index deefd1fd7f1443994872ca7358ea21a8cbbd1d01..209e0596439168cae8a2a4b1ac2fa169af0bf331 100644 (file)
@@ -26,7 +26,7 @@
     /*
      * Plain browser environment
      */
-    fit(this.Xterm);
+    fit(window.Terminal);
   }
 })(function (Xterm) {
   /**
index 2689e6163e28a88e5f08fb3e7949d720e5e2fe2e..9a655b32bbc9bbfcf3e93cd2e6fe4abaa81e63d8 100644 (file)
@@ -25,7 +25,7 @@
     /*
      * Plain browser environment
      */
-    fullscreen(this.Xterm);
+    fullscreen(window.Terminal);
   }
 })(function (Xterm) {
   var exports = {};
index 4fc0b95fbb65ac1d632d15079f3706a928f6e5f3..746b4305b843d226e97027fb61bf60dc76273d2c 100644 (file)
@@ -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 (executable)
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.');
index 5084583236dd179b5028861fd9ab6aea3d0f22f3..0aa022b112d7ff70410695015f1c43c4dd7996cf 100755 (executable)
@@ -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
index 83195e62dbe741eb9c4a94e68403dfb8494c916f..353482eda3209acf4056545341ab2ac9f9f8d8a7 100644 (file)
@@ -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){
index 2150c3796ee5c01cce2e6fde1a3972aa4cec1a20..5325949a914f5bf6056a377714b8160531bca643 100644 (file)
@@ -2,11 +2,11 @@
 <html>
     <head>
         <title>xterm.js demo</title>
-        <link rel="stylesheet" href="../src/xterm.css" />
+        <link rel="stylesheet" href="../build/xterm.css" />
         <link rel="stylesheet" href="../addons/fullscreen/fullscreen.css" />
         <link rel="stylesheet" href="style.css" />
        <script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"></script>
-        <script src="../src/xterm.js" ></script>
+        <script src="../build/xterm.js" ></script>
         <script src="../addons/attach/attach.js" ></script>
         <script src="../addons/fit/fit.js" ></script>
         <script src="../addons/fullscreen/fullscreen.js" ></script>
index 70331d89f5c90d1f46c19c6e01daf0fb966daeaf..6b667dcc8469fbb967e4cba2275cf7db4cb11464 100644 (file)
   "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 (file)
index 0000000..b17fbc7
--- /dev/null
@@ -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 };
index bb74a3e26442bd07d230955d41c51166b27ffaea..f4d26465868b74532a175efbbe5d19dd27067c8d 100644 (file)
  *   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/
      *   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
       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--) {
     Terminal.off = off;
     Terminal.cancel = cancel;
 
-
-    return Terminal;
-});
+module.exports = Terminal;
index 2f2ba5f16616515a40a05abe8271bc0b859cd8be..d3071c2dabcc0b0dfced2d8be076ae5e61d54fb5 100644 (file)
@@ -15,7 +15,7 @@ describe('CompositionHelper', function () {
         remove: function () {},
       },
       getBoundingClientRect: function () {
-        return { width: 0 }
+        return { width: 0 };
       },
       style: {
         left: 0,
index 85785d68a7a1b29074ad745bb18db2180278222c..43523e60b1ab0ae94a7bc4b6e8ac823a4764e5f5 100644 (file)
@@ -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');
 }
index 7e99c4301fb67eb7d9d2955e92ad5d4c6547bb52..4916574433b6aeb0b943d5adacae54849051b849 100644 (file)
@@ -6,6 +6,7 @@ describe('Viewport', function () {
   var viewportElement;
   var charMeasureElement;
   var viewport;
+  var scrollAreaElement;
 
   var CHARACTER_HEIGHT = 10;