From 7719cdc760e21cf1a61dac1fb6485e11f9fc89f7 Mon Sep 17 00:00:00 2001 From: TAT Date: Sat, 15 Mar 2014 12:42:19 +0100 Subject: [PATCH] Using Grunt to run Closure Compiler on the api --- .gitignore | 1 + Gruntfile.js | 22 ++++++++++++++++++++++ README.md | 12 ++++++++++-- package.json | 7 +++++-- src/client.js | 2 +- 5 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 Gruntfile.js diff --git a/.gitignore b/.gitignore index 3b4c7b6..95a1901 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,7 @@ Thumbs.db # node.js # node_modules +bin lib assets diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..da47f5d --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,22 @@ +var fs = require('fs'); + +module.exports = function(grunt) { + grunt.initConfig({ + closurecompiler: { + minify: { + files: { + './bin/client.js': ['./src/client.js'], + './bin/room.js': ['./src/room.js'] + }, + options: { + 'compilation_level': 'SIMPLE_OPTIMIZATIONS', + banner: '/*' + fs.readFileSync('LICENSE.md') + '*/' + } + } + } + }); + + grunt.loadNpmTasks('grunt-closurecompiler'); + + grunt.registerTask('default', 'closurecompiler:minify'); +} \ No newline at end of file diff --git a/README.md b/README.md index 315458d..0106a8a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Originally by [Chris Vickery](https://github.com/chrisinajar), now maintained by ## How to use Run the following: -```npm install plugapi``` +```npm install plugapi --production``` To connect, do this! @@ -60,7 +60,7 @@ Read about some of the events on the [wiki](https://github.com/TATDK/plugapi/wik Read about the actions on the [wiki](https://github.com/TATDK/plugapi/wiki/actions). -##Misc +## Misc #### setLogObject(logger) You can set your own custom logger for the API to use when it logs important events, such as errors or stack traces from the server. @@ -72,6 +72,14 @@ var prompt = new Prompt(); bot.setLogObject(prompt); ``` +## Contribute +1. Clone repository to empty folder. +2. Cd to the repository. +3. Run `npm install` to set up the environment. +4. Edit your code. +5. Run `grunt` to compile the code and test. +6. After it's bug free, you may submit it as a Pull Request to the main repo. + #### Multi line chat Since Plug.dj cuts off chat messages at 250 characters, you can choose to have your bot split up chat messages into multiple lines: diff --git a/package.json b/package.json index 56b081e..7f2e25b 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,7 @@ "name": "Chris Bellew", "email": "atomjack@gmail.com" }], - "main": "./src/client.js", - "lib": "./src/client.js", + "main": "./bin/client.js", "keywords": [ "plug.dj", "plug", @@ -28,6 +27,10 @@ "request": "*", "sockjs-client-node": "https://github.com/TATDK/sockjs-client-node/tarball/master" }, + "devDependencies": { + "grunt": "*", + "grunt-closurecompiler": "*" + }, "repository": { "type": "git", "url": "https://github.com/TATDK/plugapi" diff --git a/src/client.js b/src/client.js index 2ae2fe2..668e844 100644 --- a/src/client.js +++ b/src/client.js @@ -774,7 +774,7 @@ PlugAPI.prototype.intChat = function(msg, timeout) { chatID: cID }] })); - if (timeout !== undefined && ~~timeout !== NaN && ~~timeout > 0) { + if (timeout !== undefined && !isNaN(~~timeout) && ~~timeout > 0) { setTimeout(function() { _this.moderateDeleteChat(cID); }, ~~timeout * 1E3);