diff --git a/package-lock.json b/package-lock.json index dbb8121..14685ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -438,6 +438,11 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-4.3.6.tgz", "integrity": "sha1-MAvG4OhjdPe6YQaLWx7NV/xlMto=" }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + }, "split": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/split/-/split-0.3.3.tgz", @@ -489,9 +494,20 @@ "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" }, "uglify-js": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-1.3.3.tgz", - "integrity": "sha1-3dPpiqJ/X0flic+z+VzduiYJYZA=" + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.1.6.tgz", + "integrity": "sha512-/rseyxEKEVMBo8279lqpoJgD6C/i/CIi+9TJDvWmb+Xo6mqMKwjA8Io3IMHlcXQzj99feR6zrN8m3wqqvm/nYA==", + "requires": { + "commander": "2.11.0", + "source-map": "0.6.1" + }, + "dependencies": { + "commander": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", + "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==" + } + } }, "unpipe": { "version": "1.0.0", diff --git a/package.json b/package.json index 1e87fa3..9453b1e 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "winston": "0.6.2", "redis-url": "0.1.0", "redis": "0.8.1", - "uglify-js": "1.3.3", + "uglify-js": "3.1.6", "busboy": "0.2.4", "pg": "4.1.1" }, diff --git a/server.js b/server.js index 7cd5ec6..57bd3da 100644 --- a/server.js +++ b/server.js @@ -1,6 +1,7 @@ var http = require('http'); var fs = require('fs'); +var uglify = require('uglify-js'); var winston = require('winston'); var connect = require('connect'); var route = require('connect-route'); @@ -54,19 +55,14 @@ else { // Compress the static javascript assets if (config.recompressStaticAssets) { - var jsp = require('uglify-js').parser; - var pro = require('uglify-js').uglify; var list = fs.readdirSync('./static'); for (var j = 0; j < list.length; j++) { var item = list[j]; - var orig_code, ast; if ((item.indexOf('.js') === item.length - 3) && (item.indexOf('.min.js') === -1)) { var dest = item.substring(0, item.length - 3) + '.min' + item.substring(item.length - 3); - orig_code = fs.readFileSync('./static/' + item, 'utf8'); - ast = jsp.parse(orig_code); - ast = pro.ast_mangle(ast); - ast = pro.ast_squeeze(ast); - fs.writeFileSync('./static/' + dest, pro.gen_code(ast), 'utf8'); + var orig_code = fs.readFileSync('./static/' + item, 'utf8'); + + fs.writeFileSync('./static/' + dest, uglify.minify(orig_code).code, 'utf8'); winston.info('compressed ' + item + ' into ' + dest); } } diff --git a/static/application.min.js b/static/application.min.js index 0a2a91d..e30f711 100644 --- a/static/application.min.js +++ b/static/application.min.js @@ -1 +1 @@ -var haste_document=function(){this.locked=!1};haste_document.prototype.htmlEscape=function(e){return e.replace(/&/g,"&").replace(/>/g,">").replace(/'+e+"");$("#messages").prepend(n),setTimeout(function(){n.slideUp("fast",function(){$(this).remove()})},3e3)},haste.prototype.lightKey=function(){this.configureKey(["new","save"])},haste.prototype.fullKey=function(){this.configureKey(["new","duplicate","twitter","raw"])},haste.prototype.configureKey=function(e){var t,n=0;$("#box2 .function").each(function(){t=$(this);for(n=0;n";$("#linenos").html(t)},haste.prototype.removeLineNumbers=function(){$("#linenos").html(">")},haste.prototype.loadDocument=function(e){var t=e.split(".",2),n=this;n.doc=new haste_document,n.doc.load(t[0],function(e){e?(n.$code.html(e.value),n.setTitle(e.key),n.fullKey(),n.$textarea.val("").hide(),n.$box.show().focus(),n.addLineNumbers(e.lineCount)):n.newDocument()},this.lookupTypeByExtension(t[1]))},haste.prototype.duplicateDocument=function(){if(this.doc.locked){var e=this.doc.data;this.newDocument(),this.$textarea.val(e)}},haste.prototype.lockDocument=function(){var e=this;this.doc.save(this.$textarea.val(),function(t,n){if(t)e.showMessage(t.message,"error");else if(n){e.$code.html(n.value),e.setTitle(n.key);var r="/"+n.key;n.language&&(r+="."+e.lookupExtensionByType(n.language)),window.history.pushState(null,e.appName+"-"+n.key,r),e.fullKey(),e.$textarea.val("").hide(),e.$box.show().focus(),e.addLineNumbers(n.lineCount)}})},haste.prototype.configureButtons=function(){var e=this;this.buttons=[{$where:$("#box2 .save"),label:"Save",shortcutDescription:"control + s",shortcut:function(e){return e.ctrlKey&&e.keyCode===83},action:function(){e.$textarea.val().replace(/^\s+|\s+$/g,"")!==""&&e.lockDocument()}},{$where:$("#box2 .new"),label:"New",shortcut:function(e){return e.ctrlKey&&e.keyCode===78},shortcutDescription:"control + n",action:function(){e.newDocument(!e.doc.key)}},{$where:$("#box2 .duplicate"),label:"Duplicate & Edit",shortcut:function(t){return e.doc.locked&&t.ctrlKey&&t.keyCode===68},shortcutDescription:"control + d",action:function(){e.duplicateDocument()}},{$where:$("#box2 .raw"),label:"Just Text",shortcut:function(e){return e.ctrlKey&&e.shiftKey&&e.keyCode===82},shortcutDescription:"control + shift + r",action:function(){window.location.href="/raw/"+e.doc.key}},{$where:$("#box2 .twitter"),label:"Twitter",shortcut:function(t){return e.options.twitter&&e.doc.locked&&t.shiftKey&&t.ctrlKey&&t.keyCode==84},shortcutDescription:"control + shift + t",action:function(){window.open("https://twitter.com/share?url="+encodeURI(window.location.href))}}];for(var t=0;t/g,">").replace(/'+t+"");$("#messages").prepend(o),setTimeout(function(){o.slideUp("fast",function(){$(this).remove()})},3e3)},haste.prototype.lightKey=function(){this.configureKey(["new","save"])},haste.prototype.fullKey=function(){this.configureKey(["new","duplicate","twitter","raw"])},haste.prototype.configureKey=function(t){var e,o=0;$("#box2 .function").each(function(){for(e=$(this),o=0;o";$("#linenos").html(e)},haste.prototype.removeLineNumbers=function(){$("#linenos").html(">")},haste.prototype.loadDocument=function(t){var e=t.split(".",2),o=this;o.doc=new haste_document,o.doc.load(e[0],function(t){t?(o.$code.html(t.value),o.setTitle(t.key),o.fullKey(),o.$textarea.val("").hide(),o.$box.show().focus(),o.addLineNumbers(t.lineCount)):o.newDocument()},this.lookupTypeByExtension(e[1]))},haste.prototype.duplicateDocument=function(){if(this.doc.locked){var t=this.doc.data;this.newDocument(),this.$textarea.val(t)}},haste.prototype.lockDocument=function(){var t=this;this.doc.save(this.$textarea.val(),function(e,o){if(e)t.showMessage(e.message,"error");else if(o){t.$code.html(o.value),t.setTitle(o.key);var n="/"+o.key;o.language&&(n+="."+t.lookupExtensionByType(o.language)),window.history.pushState(null,t.appName+"-"+o.key,n),t.fullKey(),t.$textarea.val("").hide(),t.$box.show().focus(),t.addLineNumbers(o.lineCount)}})},haste.prototype.configureButtons=function(){var t=this;this.buttons=[{$where:$("#box2 .save"),label:"Save",shortcutDescription:"control + s",shortcut:function(t){return t.ctrlKey&&83===t.keyCode},action:function(){""!==t.$textarea.val().replace(/^\s+|\s+$/g,"")&&t.lockDocument()}},{$where:$("#box2 .new"),label:"New",shortcut:function(t){return t.ctrlKey&&78===t.keyCode},shortcutDescription:"control + n",action:function(){t.newDocument(!t.doc.key)}},{$where:$("#box2 .duplicate"),label:"Duplicate & Edit",shortcut:function(e){return t.doc.locked&&e.ctrlKey&&68===e.keyCode},shortcutDescription:"control + d",action:function(){t.duplicateDocument()}},{$where:$("#box2 .raw"),label:"Just Text",shortcut:function(t){return t.ctrlKey&&t.shiftKey&&82===t.keyCode},shortcutDescription:"control + shift + r",action:function(){window.location.href="/raw/"+t.doc.key}},{$where:$("#box2 .twitter"),label:"Twitter",shortcut:function(e){return t.options.twitter&&t.doc.locked&&e.shiftKey&&e.ctrlKey&&84==e.keyCode},shortcutDescription:"control + shift + t",action:function(){window.open("https://twitter.com/share?url="+encodeURI(window.location.href))}}];for(var e=0;e