This repository has been archived by the owner on Aug 5, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a script to generate the minified version of jsmad.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env node | ||
|
||
var sys = require( 'sys' ), | ||
path = require( 'path' ), | ||
fs = require( 'fs' ), | ||
uglify = require( 'uglify-js' ); | ||
|
||
var root = path.dirname( __dirname ) + '/', | ||
files = [ | ||
'src/mad.js', | ||
'src/rq_table.js', | ||
'src/imdct_s.js', | ||
'src/huffman.js', | ||
'src/bit.js', | ||
'src/stream.js', | ||
'src/layer3.js', | ||
'src/frame.js', | ||
'src/synth.js', | ||
'src/bytestream.js', | ||
'src/filestream.js', | ||
'src/substream.js', | ||
'src/id3v22stream.js', | ||
'src/id3v23stream.js', | ||
'src/mp3file.js', | ||
'src/ajaxstream.js', | ||
'src/stringstream.js', | ||
'src/player.js' | ||
], | ||
i, | ||
file, | ||
code = ''; | ||
|
||
for( i = 0; i < files.length; i++ ) { | ||
|
||
console.log( 'Reading ' + files[ i ] + '...' ); | ||
|
||
file = root + files[ i ]; | ||
code += '\n/* File: ' + files[ i ] + ' */\n'; | ||
code += fs.readFileSync( file, 'utf-8' ); | ||
} | ||
|
||
try { | ||
|
||
console.log( 'UglifyJS: Parsing the source code...' ); | ||
var ast = uglify.parser.parse( code ); | ||
|
||
console.log( 'UglifyJS: Mangling the code...' ); | ||
ast = uglify.uglify.ast_mangle( ast ); // get a new AST with mangled names | ||
|
||
console.log( 'UglifyJS: Squeezing the code...' ); | ||
ast = uglify.uglify.ast_squeeze( ast ); // get an AST with compression optimizations | ||
|
||
console.log( 'UglifyJS: Generating the code...' ); | ||
var finalCode = uglify.uglify.gen_code( ast ); // compressed code here | ||
|
||
console.log( 'Writing the code into src/jsmad.min.js...' ); | ||
fs.writeFileSync( root + 'src/jsmad.min.js', finalCode, 'utf-8' ); | ||
|
||
console.log( 'Success! The uglified source code has been stored into src/jsmad.min.js.' ); | ||
|
||
} catch( e ) | ||
{ | ||
console.error( 'Error: something went wrong.' ); | ||
console.error( e.toString() ); | ||
} |