提交 1aff2cac 编写于 作者: M Mr.doob

Merge branch 'nodejsbuildsystem' of git://github.com/gero3/three.js into dev

var fs = require("fs");
var path = require("path");
var argsparser = require( "argsparser" );
var uglify = require("uglify-js");
function merge(files){
"use strict";
var buffer = [];
for (var i = 0,il = files.length;i<il;i++){
var fileName = path.join("src", files[i]);
buffer.push(fs.readFileSync(fileName,'utf8'));
}
return buffer.join("");
}
function output(text, filename){
"use strict";
var file = path.join('build', filename);
fs.writeFileSync(file,text,'utf8');
}
function compress(text, fname_externs){
/*
externs = ""
if fname_externs:
externs = "--externs %s.js" % fname_externs
in_tuple = tempfile.mkstemp()
with os.fdopen(in_tuple[0], 'w') as handle:
handle.write(text)
out_tuple = tempfile.mkstemp()
os.system("java -jar compiler/compiler.jar --warning_level=VERBOSE --jscomp_off=globalThis --jscomp_off=checkTypes --externs externs_common.js %s --language_in=ECMASCRIPT5_STRICT --js %s --js_output_file %s" % (externs, in_tuple[1], out_tuple[1]))
with os.fdopen(out_tuple[0], 'r') as handle:
compressed = handle.read()
os.unlink(in_tuple[1])
os.unlink(out_tuple[1])
return compressed*/
"use strict";
return uglify(text);
}
function addHeader(text, endFilename){
"use strict";
return "// " + endFilename + " - http://github.com/mrdoob/three.js\n" + text;
}
function makeDebug(text){
"use strict";
var position = 0;
while (true){
position = text.indexOf("/* DEBUG", position);
if (position == -1){
break;
}
text = text.substring(0,position) + text.substring(position+8);
position = text.find("*/", position);
text = text.substring(0,position) + text.substring(position+2);
}
return text;
}
function buildLib(files, debug, minified, filename, fname_externs){
"use strict";
var text = merge(files);
if (debug){
text = makeDebug(text);
filename = filename + 'Debug';
}
var folder;
if (filename == "Three"){
folder = '';
} else {
folder = 'custom/';
}
filename = filename + '.js';
//print("=" * 40)
console.log("========================================");
console.log("Compiling " + filename);
//print("=" * 40)
console.log("========================================");
if (minified){
text = compress(text, fname_externs);
}
output(addHeader(text, filename), folder + filename);
}
function buildIncludes(files, filename){
"use strict";
//var template = "\t\t<script src='../src/%s'></script>";
//var text = "\n".join(template % f for f in files)
var text = [];
for (var i = 0,il = files.length;i<il;i++){
text.push("\t\t<script src='../src/" + files[i] + "'></script>");
}
output(text.join("\n"), filename + '.js');
}
function getFileNames(){
"use strict";
var fileName = "utils/files.json";
var data = JSON.parse(fs.readFileSync(fileName,'utf8'));
return data;
}
function parse_args(){
"use strict";
//parse
var returnValue = argsparser.parse();
/*
# If no arguments have been passed, show the help message and exit
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
*/
for (var i in returnValue){
if (i.substring(0,2) == "--"){
returnValue[i.substring(2)] = returnValue[i];
delete returnValue[i];
} else {
delete returnValue[i];
}
}
return returnValue;
}
function main(){
"use strict";
var args = parse_args();
var debug = args.debug;
var minified = args.minified;
var files = getFileNames();
var config = [
['Three', 'includes', '', files["COMMON"].concat(files["EXTRAS"]), args.common],
['ThreeCanvas', 'includes_canvas', '', files["CANVAS"], args.canvas],
['ThreeWebGL', 'includes_webgl', '', files["WEBGL"], args.webgl],
['ThreeExtras', 'includes_extras', 'externs_extras', files["EXTRAS"], args.extras]
];
for (var i = 0,il = config.length;i<il;i++){
var chosenConfig = config[i],
fname_lib = chosenConfig[0],
fname_inc = chosenConfig[1],
fname_externs = chosenConfig[2],
files = chosenConfig[3],
enabled = chosenConfig[4];
if (enabled || args.all){
buildLib(files, debug, minified, fname_lib, fname_externs);
if (args.includes){
buildIncludes(files, fname_inc);
}
}
}
}
main();
.DS_Store
\ No newline at end of file
test:
node test/test.js
.PHONY: test
\ No newline at end of file
module.exports = require('./lib/argsparser');
/**
* Parser arguments array
* @param {Array} args optional arguments arrray.
* @return {Object} opts key value hash.
* @export
*/
exports.parse = function(args) {
// args is optional, default is process.argv
args = args || process.argv;
var opts = {}, curSwitch;
args.forEach(function(arg) {
// its a switch
if (/^(-|--)/.test(arg) || !curSwitch) {
opts[arg] = true;
curSwitch = arg;
// this arg is a data
} else {
if (arg === 'false') {
arg = false;
} else if (arg === 'true') {
arg = true;
} else if (!isNaN(arg)) {
arg = Number(arg);
}
// it was a boolean switch per default,
// now it has got a val
if (typeof opts[curSwitch] === 'boolean') {
opts[curSwitch] = arg;
} else if (Array.isArray(opts[curSwitch])) {
opts[curSwitch].push(arg);
} else {
opts[curSwitch] = [opts[curSwitch], arg];
}
}
});
return opts;
};
{
"name": "argsparser",
"description": "A tiny command line arguments parser",
"version": "0.0.6",
"author": "Oleg Slobodskoi <oleg008@gmail.com>",
"repository": {
"type": "git",
"url": "http://github.com/kof/node-argsparser.git"
},
"keywords": [ "arguments", "options", "command line", "parser" ],
"engines": { "node": ">= 0.2.0" },
"scripts": { "test": "node ./test/test.js" },
"licenses": [
{
"type": "MIT",
"url" : "http://www.opensource.org/licenses/mit-license.php"
}
]
}
## Yet another tiny arguments parser for node
## Features
* extremely tiny
* instead to parse all possible spellings, it uses just some simple rules
## How this parser works
The target is to get a key-value object from an array. A key can be the first element or element prefixed by "-" and "--" (switch).
So the parser loops through the array and looks for keys. After he could detect an a key all next elements will be added as a value of this key until he find another key.
If there is no value, then the key is true (boolean). If there are a lot of values, then the key is an array.
## Examples
node script.js -> {"node": "script.js"}
node script.js -o -> {"node": "script.js", "-o": true}
node script.js -o test -> {"node": "script.js", "-o": "test"}
node script.js -a testa --b testb -> {node: "script.js", "-a": "testa", "--b": "testb"}
node script.js -paths /test.js /test1.js -> {node: "script.js", "-paths": ["/test.js", "/test1.js"]}
## Usage
// per default it parses process.argv
var args = require( "argsparser" ).parse(); // {"node": "/path/to/your/script.js"}
// optional you can pass your own arguments array
var args = require( "argsparser" ).parse(["-a", "test"]); // {"-a": "test"}
## Installation
npm install argsparser
\ No newline at end of file
var a = require('assert'),
util = require('util'),
parse = require('../lib/argsparser').parse;
util.print('Run tests...\n');
a.deepEqual(parse(), {node: __filename}, 'node script.js');
a.deepEqual(parse(['-o']), {'-o': true}, 'node script.js -o');
a.deepEqual(parse(['-o', 'true']), {'-o': true}, 'node script.js -o true');
a.deepEqual(parse(['-o', 'false']), {'-o': false}, 'node script.js -o false');
a.deepEqual(parse(['-o', '123']), {'-o': 123}, 'node script.js -o 123');
a.deepEqual(parse(['--token', 'bla--bla']), {'--token': 'bla--bla'}, 'node script.js --token bla--bla');
a.deepEqual(parse(['-o', '123.456']), {'-o': 123.456}, 'node script.js -o 123.456');
a.deepEqual(parse(['-o', 'test']), {'-o': 'test'}, 'node script.js -o test');
a.deepEqual(parse(['-a', 'testa', '-b', 'testb']), {'-a': 'testa', '-b': 'testb'}, 'node script.js -a testa -b testb');
a.deepEqual(parse(['--a', 'testa', '--b', 'testb']), {'--a': 'testa', '--b': 'testb'}, 'node script.js --a testa --b testb ');
a.deepEqual(parse(['-a', 'testa', '--b', 'testb']), {'-a': 'testa', '--b': 'testb'}, 'node script.js -a testa --b testb');
a.deepEqual(parse(['--a', 'testa', '-b', 'testb']), {'--a': 'testa', '-b': 'testb'}, 'node script.js --a testa -b testb');
a.deepEqual(parse(['-paths', '/test.js', '/test1.js']), {'-paths': ['/test.js', '/test1.js']}, 'node script.js -paths /test.js /test1.js');
a.deepEqual(parse(['--paths', '/test.js', '/test1.js']), {'--paths': ['/test.js', '/test1.js']}, 'node script.js --paths /test.js /test1.js');
a.deepEqual(parse(['--paths', '/test.js', '/test1.js', '-a', 'testa']), {'--paths': ['/test.js', '/test1.js'], '-a': 'testa'}, 'node script.js --paths /test.js /test1.js -a testa');
a.deepEqual(parse(['--port', '80', '8080']), {'--port': [80, 8080]}, 'node server.js --port 80 8080');
util.print('All tests ok\n');
.DS_Store
.tmp*~
*.local.*
.pinf-*
\ No newline at end of file
此差异已折叠。
此差异已折叠。
#!/usr/bin/env node
// -*- js -*-
global.sys = require(/^v0\.[012]/.test(process.version) ? "sys" : "util");
var fs = require("fs");
var uglify = require("uglify-js"), // symlink ~/.node_libraries/uglify-js.js to ../uglify-js.js
consolidator = uglify.consolidator,
jsp = uglify.parser,
pro = uglify.uglify;
var options = {
ast: false,
consolidate: false,
mangle: true,
mangle_toplevel: false,
no_mangle_functions: false,
squeeze: true,
make_seqs: true,
dead_code: true,
verbose: false,
show_copyright: true,
out_same_file: false,
max_line_length: 32 * 1024,
unsafe: false,
reserved_names: null,
defines: { },
lift_vars: false,
codegen_options: {
ascii_only: false,
beautify: false,
indent_level: 4,
indent_start: 0,
quote_keys: false,
space_colon: false,
inline_script: false
},
make: false,
output: true // stdout
};
var args = jsp.slice(process.argv, 2);
var filename;
out: while (args.length > 0) {
var v = args.shift();
switch (v) {
case "-b":
case "--beautify":
options.codegen_options.beautify = true;
break;
case "-c":
case "--consolidate-primitive-values":
options.consolidate = true;
break;
case "-i":
case "--indent":
options.codegen_options.indent_level = args.shift();
break;
case "-q":
case "--quote-keys":
options.codegen_options.quote_keys = true;
break;
case "-mt":
case "--mangle-toplevel":
options.mangle_toplevel = true;
break;
case "-nmf":
case "--no-mangle-functions":
options.no_mangle_functions = true;
break;
case "--no-mangle":
case "-nm":
options.mangle = false;
break;
case "--no-squeeze":
case "-ns":
options.squeeze = false;
break;
case "--no-seqs":
options.make_seqs = false;
break;
case "--no-dead-code":
options.dead_code = false;
break;
case "--no-copyright":
case "-nc":
options.show_copyright = false;
break;
case "-o":
case "--output":
options.output = args.shift();
break;
case "--overwrite":
options.out_same_file = true;
break;
case "-v":
case "--verbose":
options.verbose = true;
break;
case "--ast":
options.ast = true;
break;
case "--unsafe":
options.unsafe = true;
break;
case "--max-line-len":
options.max_line_length = parseInt(args.shift(), 10);
break;
case "--reserved-names":
options.reserved_names = args.shift().split(",");
break;
case "--lift-vars":
options.lift_vars = true;
break;
case "-d":
case "--define":
var defarg = args.shift();
try {
var defsym = function(sym) {
// KEYWORDS_ATOM doesn't include NaN or Infinity - should we check
// for them too ?? We don't check reserved words and the like as the
// define values are only substituted AFTER parsing
if (jsp.KEYWORDS_ATOM.hasOwnProperty(sym)) {
throw "Don't define values for inbuilt constant '"+sym+"'";
}
return sym;
},
defval = function(v) {
if (v.match(/^"(.*)"$/) || v.match(/^'(.*)'$/)) {
return [ "string", RegExp.$1 ];
}
else if (!isNaN(parseFloat(v))) {
return [ "num", parseFloat(v) ];
}
else if (v.match(/^[a-z\$_][a-z\$_0-9]*$/i)) {
return [ "name", v ];
}
else if (!v.match(/"/)) {
return [ "string", v ];
}
else if (!v.match(/'/)) {
return [ "string", v ];
}
throw "Can't understand the specified value: "+v;
};
if (defarg.match(/^([a-z_\$][a-z_\$0-9]*)(=(.*))?$/i)) {
var sym = defsym(RegExp.$1),
val = RegExp.$2 ? defval(RegExp.$2.substr(1)) : [ 'name', 'true' ];
options.defines[sym] = val;
}
else {
throw "The --define option expects SYMBOL[=value]";
}
} catch(ex) {
sys.print("ERROR: In option --define "+defarg+"\n"+ex+"\n");
process.exit(1);
}
break;
case "--define-from-module":
var defmodarg = args.shift(),
defmodule = require(defmodarg),
sym,
val;
for (sym in defmodule) {
if (defmodule.hasOwnProperty(sym)) {
options.defines[sym] = function(val) {
if (typeof val == "string")
return [ "string", val ];
if (typeof val == "number")
return [ "num", val ];
if (val === true)
return [ 'name', 'true' ];
if (val === false)
return [ 'name', 'false' ];
if (val === null)
return [ 'name', 'null' ];
if (val === undefined)
return [ 'name', 'undefined' ];
sys.print("ERROR: In option --define-from-module "+defmodarg+"\n");
sys.print("ERROR: Unknown object type for: "+sym+"="+val+"\n");
process.exit(1);
return null;
}(defmodule[sym]);
}
}
break;
case "--ascii":
options.codegen_options.ascii_only = true;
break;
case "--make":
options.make = true;
break;
case "--inline-script":
options.codegen_options.inline_script = true;
break;
default:
filename = v;
break out;
}
}
if (options.verbose) {
pro.set_logger(function(msg){
sys.debug(msg);
});
}
jsp.set_logger(function(msg){
sys.debug(msg);
});
if (options.make) {
options.out_same_file = false; // doesn't make sense in this case
var makefile = JSON.parse(fs.readFileSync(filename || "Makefile.uglify.js").toString());
output(makefile.files.map(function(file){
var code = fs.readFileSync(file.name);
if (file.module) {
code = "!function(exports, global){global = this;\n" + code + "\n;this." + file.module + " = exports;}({})";
}
else if (file.hide) {
code = "(function(){" + code + "}());";
}
return squeeze_it(code);
}).join("\n"));
}
else if (filename) {
fs.readFile(filename, "utf8", function(err, text){
if (err) throw err;
output(squeeze_it(text));
});
}
else {
var stdin = process.openStdin();
stdin.setEncoding("utf8");
var text = "";
stdin.on("data", function(chunk){
text += chunk;
});
stdin.on("end", function() {
output(squeeze_it(text));
});
}
function output(text) {
var out;
if (options.out_same_file && filename)
options.output = filename;
if (options.output === true) {
out = process.stdout;
} else {
out = fs.createWriteStream(options.output, {
flags: "w",
encoding: "utf8",
mode: 0644
});
}
out.write(text.replace(/;*$/, ";"));
if (options.output !== true) {
out.end();
}
};
// --------- main ends here.
function show_copyright(comments) {
var ret = "";
for (var i = 0; i < comments.length; ++i) {
var c = comments[i];
if (c.type == "comment1") {
ret += "//" + c.value + "\n";
} else {
ret += "/*" + c.value + "*/";
}
}
return ret;
};
function squeeze_it(code) {
var result = "";
if (options.show_copyright) {
var tok = jsp.tokenizer(code), c;
c = tok();
result += show_copyright(c.comments_before);
}
try {
var ast = time_it("parse", function(){ return jsp.parse(code); });
if (options.consolidate) ast = time_it("consolidate", function(){
return consolidator.ast_consolidate(ast);
});
if (options.lift_vars) {
ast = time_it("lift", function(){ return pro.ast_lift_variables(ast); });
}
if (options.mangle) ast = time_it("mangle", function(){
return pro.ast_mangle(ast, {
toplevel : options.mangle_toplevel,
defines : options.defines,
except : options.reserved_names,
no_functions : options.no_mangle_functions
});
});
if (options.squeeze) ast = time_it("squeeze", function(){
ast = pro.ast_squeeze(ast, {
make_seqs : options.make_seqs,
dead_code : options.dead_code,
keep_comps : !options.unsafe
});
if (options.unsafe)
ast = pro.ast_squeeze_more(ast);
return ast;
});
if (options.ast)
return sys.inspect(ast, null, null);
result += time_it("generate", function(){ return pro.gen_code(ast, options.codegen_options) });
if (!options.codegen_options.beautify && options.max_line_length) {
result = time_it("split", function(){ return pro.split_lines(result, options.max_line_length) });
}
return result;
} catch(ex) {
sys.debug(ex.stack);
sys.debug(sys.inspect(ex));
sys.debug(JSON.stringify(ex));
process.exit(1);
}
};
function time_it(name, cont) {
if (!options.verbose)
return cont();
var t1 = new Date().getTime();
try { return cont(); }
finally { sys.debug("// " + name + ": " + ((new Date().getTime() - t1) / 1000).toFixed(3) + " sec."); }
};
html { font-family: "Lucida Grande","Trebuchet MS",sans-serif; font-size: 12pt; }
body { max-width: 60em; }
.title { text-align: center; }
.todo { color: red; }
.done { color: green; }
.tag { background-color:lightblue; font-weight:normal }
.target { }
.timestamp { color: grey }
.timestamp-kwd { color: CadetBlue }
p.verse { margin-left: 3% }
pre {
border: 1pt solid #AEBDCC;
background-color: #F3F5F7;
padding: 5pt;
font-family: monospace;
font-size: 90%;
overflow:auto;
}
pre.src {
background-color: #eee; color: #112; border: 1px solid #000;
}
table { border-collapse: collapse; }
td, th { vertical-align: top; }
dt { font-weight: bold; }
div.figure { padding: 0.5em; }
div.figure p { text-align: center; }
.linenr { font-size:smaller }
.code-highlighted {background-color:#ffff00;}
.org-info-js_info-navigation { border-style:none; }
#org-info-js_console-label { font-size:10px; font-weight:bold;
white-space:nowrap; }
.org-info-js_search-highlight {background-color:#ffff00; color:#000000;
font-weight:bold; }
sup {
vertical-align: baseline;
position: relative;
top: -0.5em;
font-size: 80%;
}
sup a:link, sup a:visited {
text-decoration: none;
color: #c00;
}
sup a:before { content: "["; color: #999; }
sup a:after { content: "]"; color: #999; }
h1.title { border-bottom: 4px solid #000; padding-bottom: 5px; margin-bottom: 2em; }
#postamble {
color: #777;
font-size: 90%;
padding-top: 1em; padding-bottom: 1em; border-top: 1px solid #999;
margin-top: 2em;
padding-left: 2em;
padding-right: 2em;
text-align: right;
}
#postamble p { margin: 0; }
#footnotes { border-top: 1px solid #000; }
h1 { font-size: 200% }
h2 { font-size: 175% }
h3 { font-size: 150% }
h4 { font-size: 125% }
h1, h2, h3, h4 { font-family: "Bookman",Georgia,"Times New Roman",serif; font-weight: normal; }
@media print {
html { font-size: 11pt; }
}
此差异已折叠。
var jsp = require("./parse-js"),
pro = require("./process");
var BY_TYPE = {};
function HOP(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
};
function AST_Node(parent) {
this.parent = parent;
};
AST_Node.prototype.init = function(){};
function DEFINE_NODE_CLASS(type, props, methods) {
var base = methods && methods.BASE || AST_Node;
if (!base) base = AST_Node;
function D(parent, data) {
base.apply(this, arguments);
if (props) props.forEach(function(name, i){
this["_" + name] = data[i];
});
this.init();
};
var P = D.prototype = new AST_Node;
P.node_type = function(){ return type };
if (props) props.forEach(function(name){
var propname = "_" + name;
P["set_" + name] = function(val) {
this[propname] = val;
return this;
};
P["get_" + name] = function() {
return this[propname];
};
});
if (type != null) BY_TYPE[type] = D;
if (methods) for (var i in methods) if (HOP(methods, i)) {
P[i] = methods[i];
}
return D;
};
var AST_String_Node = DEFINE_NODE_CLASS("string", ["value"]);
var AST_Number_Node = DEFINE_NODE_CLASS("num", ["value"]);
var AST_Name_Node = DEFINE_NODE_CLASS("name", ["value"]);
var AST_Statlist_Node = DEFINE_NODE_CLASS(null, ["body"]);
var AST_Root_Node = DEFINE_NODE_CLASS("toplevel", null, { BASE: AST_Statlist_Node });
var AST_Block_Node = DEFINE_NODE_CLASS("block", null, { BASE: AST_Statlist_Node });
var AST_Splice_Node = DEFINE_NODE_CLASS("splice", null, { BASE: AST_Statlist_Node });
var AST_Var_Node = DEFINE_NODE_CLASS("var", ["definitions"]);
var AST_Const_Node = DEFINE_NODE_CLASS("const", ["definitions"]);
var AST_Try_Node = DEFINE_NODE_CLASS("try", ["body", "catch", "finally"]);
var AST_Throw_Node = DEFINE_NODE_CLASS("throw", ["exception"]);
var AST_New_Node = DEFINE_NODE_CLASS("new", ["constructor", "arguments"]);
var AST_Switch_Node = DEFINE_NODE_CLASS("switch", ["expression", "branches"]);
var AST_Switch_Branch_Node = DEFINE_NODE_CLASS(null, ["expression", "body"]);
var AST_Break_Node = DEFINE_NODE_CLASS("break", ["label"]);
var AST_Continue_Node = DEFINE_NODE_CLASS("continue", ["label"]);
var AST_Assign_Node = DEFINE_NODE_CLASS("assign", ["operator", "lvalue", "rvalue"]);
var AST_Dot_Node = DEFINE_NODE_CLASS("dot", ["expression", "name"]);
var AST_Call_Node = DEFINE_NODE_CLASS("call", ["function", "arguments"]);
var AST_Lambda_Node = DEFINE_NODE_CLASS(null, ["name", "arguments", "body"])
var AST_Function_Node = DEFINE_NODE_CLASS("function", null, AST_Lambda_Node);
var AST_Defun_Node = DEFINE_NODE_CLASS("defun", null, AST_Lambda_Node);
var AST_If_Node = DEFINE_NODE_CLASS("if", ["condition", "then", "else"]);
此差异已折叠。
此差异已折叠。
此差异已折叠。
{
"name" : "uglify-js",
"description" : "JavaScript parser and compressor/beautifier toolkit",
"author" : {
"name" : "Mihai Bazon",
"email" : "mihai.bazon@gmail.com",
"url" : "http://mihai.bazon.net/blog"
},
"version" : "1.2.6",
"main" : "./uglify-js.js",
"bin" : {
"uglifyjs" : "./bin/uglifyjs"
},
"repository": {
"type": "git",
"url": "git@github.com:mishoo/UglifyJS.git"
}
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
(function(){var a=function(){};return new a(1,2,3,4)})()
(function(){function a(){}return new a(1,2,3,4)})()
(function(){function a(){}(function(){return new a(1,2,3)})()})()
a=1,b=a,c=1,d=b,e=d,longname=2;if(longname+1){x=3;if(x)var z=7}z=1,y=1,x=1,g+=1,h=g,++i,j=i,i++,j=i+17
\ No newline at end of file
var a=a+"a"+"b"+1+c,b=a+"c"+"ds"+123+c,c=a+"c"+123+d+"ds"+c
\ No newline at end of file
function bar(){return--x}function foo(){while(bar());}function mak(){for(;;);}var x=5
function x(a){return typeof a=="object"?a:a===42?0:a*2}function y(a){return typeof a=="object"?a:null}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册