Skip to content
This repository was archived by the owner on Jul 17, 2020. It is now read-only.

Commit 0dcc8aa

Browse files
committed
Merge branch 'master' of https://github.com/Zirak/SO-ChatBot
Conflicts: source/adapter.js source/commands.js source/plugins/summon.js source/plugins/welcome.js
2 parents 9b601e6 + 6a98a11 commit 0dcc8aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2581
-3610
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
*.*~
22
\#*\#
33
node_modules/
4+
data/
5+
*.jar

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
For usage info, on how to use the bot, see [here](https://github.com/Zirak/SO-ChatBot/wiki/Interacting-with-the-bot).
22

33
###Running the bot###
4-
The bot is currently a big dangle-on script running in your browser. **Run `bookmarklet.js`** in your browser to get it up an' running.
4+
The bot is currently a big dangle-on script running in your browser. **Run `bookmarklet.js`** in your browser to get it up an' running. For some tips on handling the bot, see [Bot Handling](https://github.com/Zirak/SO-ChatBot/wiki/Bot-Handling).
55

66
###Building###
7-
(For build minification, install [uglify-js2](https://github.com/mishoo/UglifyJS2))
87

98
```sh
109
#one must first get the repo
11-
$ git clone git://github.com/Zirak/SO-ChatBot.git
10+
$ git clone https://github.com/Zirak/SO-ChatBot.git
1211
$ cd SO-ChatBot
1312
```
1413

@@ -27,6 +26,8 @@ $ node build.js no-min
2726
```
2827
The result will be in `master.js` and `master.min.js`
2928

29+
Minifying will run [closure-compiler.jar](https://developers.google.com/closure/compiler/docs/gettingstarted_app) if java is installed, and then try to run [uglify-js2](https://github.com/mishoo/UglifyJS2).
30+
3031
###The Bot API###
3132
(, a very short explanation of a limited subset of)
3233

build.js

Lines changed: 90 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ var build = {
128128
this.write( code );
129129

130130
if ( this.doMinify ) {
131-
minify( code, this.minEndCallback );
131+
minify( this.outputName, this.outputMin, this.minEndCallback );
132132
}
133133
code = null;
134134
}
@@ -153,30 +153,107 @@ var build = {
153153
}
154154
};
155155

156-
var minify = function ( code, callback, outName ) {
157-
outName = outName || 'master.min.js';
158-
build.print( '\nminifying...' );
156+
var minify = (function () {
157+
158+
var exec = require('child_process').exec;
159+
160+
var minifiers = [
161+
{
162+
name : 'closure-compiler',
163+
test : function ( success, fail ) {
164+
exec( 'java -version &> /dev/null; echo $?', finish );
165+
166+
function finish ( err, stdout, stderr ) {
167+
if (err || Number(stdout)) {
168+
fail();
169+
}
170+
else {
171+
success();
172+
}
173+
}
174+
},
175+
minify : function ( sourceFile, outFile, cb ) {
176+
var cmd = [
177+
'java -jar closure-compiler.jar',
178+
'--language_in ECMASCRIPT5_STRICT',
179+
'--compilation_level SIMPLE_OPTIMIZATIONS',
180+
'--js', sourceFile,
181+
'--js_output_file', outFile,
182+
].join( ' ' );
183+
184+
exec( cmd, cb );
185+
}
186+
},
187+
{
188+
name : 'uglify2',
189+
test : function ( success, fail ) {
190+
try {
191+
require.resolve( 'uglify-js2' );
192+
success();
193+
}
194+
catch ( e ) {
195+
fail();
196+
}
197+
},
198+
minify : function ( sourceFile, outFile, cb ) {
199+
var code;
200+
try {
201+
code = require( 'uglify-js2' ).minify( sourceFile ).code;
202+
}
203+
catch ( e ) {
204+
cb( e );
205+
//I find it extremely pleasing how the above lines line up.
206+
return;
207+
}
159208

160-
var min;
161-
try {
162-
min = require( 'uglify-js2' )
163-
.minify( code, { fromString : true } ).code;
209+
fs.writeFile( outFile, code, cb );
210+
}
211+
},
212+
{
213+
name : 'default',
214+
test : function ( success ) {
215+
success();
216+
},
217+
minify : function ( cb ) {
218+
console.warn( 'no minifier found; skipping' );
219+
cb();
220+
}
164221
}
165-
catch ( e ) {
166-
console.error( e.toString() );
167-
return;
222+
];
223+
224+
return function minify ( inFile, outFile, callback ) {
225+
build.print( '\nminifying...' );
226+
continuation( minifiers.slice() );
227+
228+
function continuation (fiers /* 'Merica */) {
229+
var minifier = fiers.shift();
230+
231+
minifier.test(
232+
function success () {
233+
build.print( 'running minifier: ' + minifier.name );
234+
runMinifier( minifier );
235+
},
236+
function fail () {
237+
build.print( 'skipping minifier: ' + minifier.name );
238+
continuation(fiers);
239+
}
240+
);
168241
}
169242

170-
fs.writeFile( outName, min, finish );
243+
function runMinifier ( minifier ) {
244+
minifier.minify( inFile, outFile, finish );
245+
}
171246

172247
function finish ( err ) {
173248
if ( err ) {
174249
throw err;
175250
}
176-
callback( outName, min.length );
251+
callback( outFile, fs.statSync(outFile).size );
177252
}
178253
};
179254

255+
})();
256+
180257
var preprocessor = (function () {
181258

182259
var preprocessor = {

0 commit comments

Comments
 (0)