Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
36 additions
and
36 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 |
---|---|---|
@@ -1,81 +1,81 @@ | ||
#!/usr/bin/env node | ||
|
||
var PACKAGER = require("../packager") | ||
, fs = require("fs") | ||
, fs = require("fs") | ||
, UGLIFY = require("uglify-js") | ||
, jsp = UGLIFY.parser | ||
, pro = UGLIFY.uglify | ||
|
||
, args = process.argv | ||
, args = process.argv | ||
, node = args.shift() | ||
, thisPath = args.shift().split("/") | ||
, thisFile = thisPath[thisPath.length-1] | ||
, thisFile = thisPath[thisPath.length-1] | ||
|
||
, files = [] | ||
, arg | ||
, options = { | ||
compress: false | ||
}; | ||
, files = [] | ||
, arg | ||
, options = { | ||
compress: false | ||
}; | ||
|
||
while (args.length > 0) { | ||
arg = args.shift(); | ||
switch (arg) { | ||
case "--help": | ||
printUsage(process.stdout); | ||
return; | ||
case "--output": | ||
case "-o": | ||
options.output = args.shift(); | ||
break; | ||
case "--compress": | ||
case "-c": | ||
options.compress = true; | ||
break; | ||
default: | ||
files.push(arg); | ||
} | ||
arg = args.shift(); | ||
switch (arg) { | ||
case "--help": | ||
printUsage(process.stdout); | ||
return; | ||
case "--output": | ||
case "-o": | ||
options.output = args.shift(); | ||
break; | ||
case "--compress": | ||
case "-c": | ||
options.compress = true; | ||
break; | ||
default: | ||
files.push(arg); | ||
} | ||
} | ||
|
||
if (files.length == 0) { | ||
process.stderr.write("ERR: No input files provided.\n\n"); | ||
printUsage(process.stderr); | ||
return; | ||
process.stderr.write("ERR: No input files provided.\n\n"); | ||
printUsage(process.stderr); | ||
return; | ||
|
||
} else { | ||
|
||
var data = PACKAGER.package(files); | ||
if (options.compress) { | ||
var data = PACKAGER.package(files); | ||
if (options.compress) { | ||
var ast = jsp.parse(data); | ||
ast = pro.ast_mangle(ast); | ||
ast = pro.ast_squeeze(ast); | ||
data = pro.gen_code(ast); | ||
} | ||
write(data); | ||
} | ||
write(data); | ||
} | ||
|
||
function printUsage(stream) { | ||
stream.write("Usage:\n\t"); | ||
stream.write(thisFile + " [--help] [--compress] [--output file] input.js\n"); | ||
stream.write("Usage:\n\t"); | ||
stream.write(thisFile + " [--help] [--compress] [--output file] input.js\n"); | ||
} | ||
|
||
function write(data) { | ||
var stream; | ||
if (options.output !== undefined) { | ||
// write to output file | ||
// write to output file | ||
stream = fs.createWriteStream(options.output, { | ||
flags: "w", | ||
encoding: "utf8", | ||
mode: 0644 | ||
}); | ||
|
||
} else { | ||
// default to stdout | ||
// default to stdout | ||
stream = process.stdout; | ||
} | ||
stream.write(data); | ||
|
||
if (options.output !== undefined) { | ||
// Close file (if open) | ||
// Close file (if open) | ||
stream.end(); | ||
} | ||
}; |