├── Commands └── Compress To File.tmCommand ├── README.markdown ├── Support └── images │ ├── multi_select.png │ └── running.png └── info.plist /Commands/Compress To File.tmCommand: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | beforeRunningCommand 6 | saveModifiedFiles 7 | command 8 | #! /usr/bin/env ruby -w 9 | require 'pp' 10 | require 'open3' 11 | 12 | def verify_node_path 13 | if !ENV['NODE_PATH'] or ENV['NODE_PATH'].empty? 14 | if File.directory?('/usr/local/lib/node/') 15 | ENV['NODE_PATH'] = '/usr/local/lib/node' 16 | else 17 | puts "Cannot detect node path. Please set NODE_PATH environment variable manually in Textmate Preferences (Advanced)." 18 | exit 19 | end 20 | elsif !File.directory?(ENV['NODE_PATH']) 21 | puts "Specified node path does not exist. You may need to set manually with a NODE_PATH environment variable in Textmate Preferences (Advanced)." 22 | exit 23 | end 24 | end 25 | 26 | def verify_exec_path(executable) 27 | location = `which #{executable}` 28 | if location.empty? 29 | puts "Cannot find executable '#{executable}'. Make sure that it is accessible in your Textmate PATH (in TextMate Preferences -> Advanced)" 30 | exit 31 | end 32 | location 33 | end 34 | 35 | files = ENV['TM_SELECTED_FILES'][1..-2].split("' '") 36 | 37 | verify_exec_path 'node' 38 | verify_node_path 39 | verify_exec_path 'uglifyjs' 40 | 41 | compressed = '' 42 | files.each do |file| 43 | to_execute = %Q[uglifyjs "#{file}"] 44 | Open3.popen3(to_execute) do |stdin, stdout, stderr, wait_thr| 45 | compressed = compressed + stdout.read 46 | end 47 | end 48 | 49 | new_file = files[0].gsub('.js','.min.js') 50 | File.open(new_file, 'w') { |f| f.write compressed } 51 | if File.size?(new_file) 52 | puts "Created uglified file at #{File.basename(new_file)}" 53 | else 54 | puts "An error occurred writing compressed file at #{new_file}" 55 | end 56 | 57 | fallbackInput 58 | document 59 | input 60 | none 61 | keyEquivalent 62 | @U 63 | name 64 | Compress To File 65 | output 66 | showAsHTML 67 | scope 68 | source.js 69 | uuid 70 | 02B2EEA6-A6EF-47DB-9C48-A8C32D73D7F8 71 | 72 | 73 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # UglifyJS TextMate Bundle 2 | 3 | ## Overview 4 | 5 | A TextMate bundle which allows you to easily minify your JavaScript files using [UglifyJS](https://github.com/mishoo/UglifyJS) by Mihai Bazon. 6 | 7 | ## Usage 8 | 9 | Select one or more files in the file drawer. 10 | 11 | ![Selecting files to compress](https://github.com/nextmat/UglifyJS.tmbundle/blob/master/Support/images/multi_select.png?raw=true) 12 | 13 | Use the shortcut (command-shift-u) or select from the bundle action menu at the bottom of your Textmate window. 14 | 15 | ![Running the compress command](https://github.com/nextmat/UglifyJS.tmbundle/blob/master/Support/images/running.png?raw=true) 16 | 17 | A new file will be created with your files combined and minified. 18 | 19 | ## Installing the bundle 20 | 21 | The bundle currently relies on [node.js](http://nodejs.org/) and the [UglifyJS npm package](https://github.com/mishoo/UglifyJS). If you need to install these, follow the instructions in the next section, then return here to install the bundle. 22 | 23 | mkdir -p ~/Library/Application\ Support/TextMate/Bundles/ 24 | cd ~/Library/Application\ Support/TextMate/Bundles/ 25 | git clone https://github.com/nextmat/UglifyJS.tmbundle.git UglifyJS.tmbundle 26 | 27 | If Textmate is already running you will either need to restart it or run 28 | Bundles (menu) → Bundle Editor → Reload Bundles`. 29 | 30 | There are a couple of environment variables to set up in TextMate (menu) → Preferences → Advanced → Shell Variables 31 | 32 | 1: The directories of `node` and `uglifyjs` need to be in your `PATH`. If you used Homebrew to install these will likely both be in `/usr/local/bin`. You can verify the locations with: 33 | 34 | which node 35 | which uglifyjs 36 | 37 | 2: The bundle should auto-detect your `NODE_PATH`. If it can't and complains, you should add your `NODE_PATH` to TextMate’s environment variables. 38 | 39 | ## Installing the UglifyJS package 40 | 41 | The bundle currently relies on the UglifyJS package, which runs on top of NodeJS. There are multiple ways to get this installed, but [Homebrew](http://mxcl.github.com/homebrew/) is an excellent choice. 42 | 43 | brew install node # install node.js 44 | curl http://npmjs.org/install.sh | sh # install node package manager 45 | npm install -g uglify-js 46 | 47 | Be sure to follow any instructions given by Homebrew regarding environment variables for your shell. After installation you should be able to `which node` and `which uglifyjs`. If either don't show you a path, read the post-install instructions from Homebrew again before continuing. 48 | 49 | ## ToDo / Contributing 50 | 51 | Planned improvements: 52 | 53 | * Make bundle dependency-free by including UglifyJS and using Apple's built-in Webkit js intepreter 54 | * More attractive result pages 55 | * Interface improvements 56 | * Add a command for updating to the latest version of the bundle from inside TextMate 57 | 58 | I'll get to these as I can, if you feel so motivated I will happily accept patches! 59 | 60 | ## License 61 | 62 | The UglifyJS.tmbundle is released under the MIT license. 63 | 64 | Copyright (c) 2011 Matt Sanders 65 | 66 | Permission is hereby granted, free of charge, to any person obtaining a copy 67 | of this software and associated documentation files (the "Software"), to deal 68 | in the Software without restriction, including without limitation the rights 69 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 70 | copies of the Software, and to permit persons to whom the Software is 71 | furnished to do so, subject to the following conditions: 72 | 73 | The above copyright notice and this permission notice shall be included in 74 | all copies or substantial portions of the Software. 75 | 76 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 77 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 78 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 79 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 80 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 81 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 82 | THE SOFTWARE. -------------------------------------------------------------------------------- /Support/images/multi_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nextmat/UglifyJS.tmbundle/4dc2f87661d6c45f80294a1cca49e67ab3601466/Support/images/multi_select.png -------------------------------------------------------------------------------- /Support/images/running.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nextmat/UglifyJS.tmbundle/4dc2f87661d6c45f80294a1cca49e67ab3601466/Support/images/running.png -------------------------------------------------------------------------------- /info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | name 6 | UglifyJS 7 | uuid 8 | 0F2AE461-A91D-45EE-8CCA-BF03255EA9C5 9 | 10 | 11 | --------------------------------------------------------------------------------