The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.
Please select the desired protocol below to get the URL.
This URL has Read-Only access.
main_repo / src / main.js @ 63a9cd38
History | View | Annotate | Download (2.29 KB)
1 |
// module search paths
|
---|---|
2 |
node.includes = ["."];
|
3 |
|
4 |
node.path = new function () { |
5 |
this.join = function () { |
6 |
var joined = ""; |
7 |
for (var i = 0; i < arguments.length; i++) { |
8 |
var part = arguments[i].toString(); |
9 |
if (i === 0) { |
10 |
part = part.replace(/\/*$/, "/"); |
11 |
} else if (i === arguments.length - 1) { |
12 |
part = part.replace(/^\/*/, ""); |
13 |
} else {
|
14 |
part = part.replace(/^\/*/, "") |
15 |
.replace(/\/*$/, "/"); |
16 |
} |
17 |
joined += part; |
18 |
} |
19 |
return joined;
|
20 |
}; |
21 |
|
22 |
this.dirname = function (path) { |
23 |
var parts = path.split("/"); |
24 |
return parts.slice(0, parts.length-1); |
25 |
}; |
26 |
}; |
27 |
|
28 |
function __include (module, path) { |
29 |
var export = module.require(path); |
30 |
for (var i in export) { |
31 |
if (export.hasOwnProperty(i)) |
32 |
module[i] = export[i];
|
33 |
} |
34 |
} |
35 |
|
36 |
|
37 |
|
38 |
function __require (path, loading_file) { |
39 |
|
40 |
var filename = path;
|
41 |
// relative path
|
42 |
// absolute path
|
43 |
if (path.slice(0,1) === "/") { |
44 |
} else {
|
45 |
filename = node.path.join(node.path.dirname(loading_file), path); |
46 |
} |
47 |
node.blocking.print("require: " + filename);
|
48 |
|
49 |
/*
|
50 |
for (var i = 0; i < suffixes.length; i++) {
|
51 |
var f = filename + "." + suffixes[i];
|
52 |
|
53 |
var stats = node.blocking.stat(f);
|
54 |
for (var j in stats) {
|
55 |
node.blocking.print("stats." + j + " = " + stats[j].toString());
|
56 |
}
|
57 |
}
|
58 |
*/
|
59 |
|
60 |
var source = node.blocking.cat(filename);
|
61 |
|
62 |
// wrap the source in a function
|
63 |
source = "function (__file__, __dir__) { "
|
64 |
+ " var exports = {};"
|
65 |
+ " function require (m) { return __require(m, __file__); }"
|
66 |
+ " function include (m) { return __include(this, m); }"
|
67 |
+ source |
68 |
+ " return exports;"
|
69 |
+ "};"
|
70 |
; |
71 |
var create_module = node.blocking.exec(source, filename);
|
72 |
|
73 |
// execute the function wrap
|
74 |
return create_module(filename, node.path.dirname(filename));
|
75 |
} |
76 |
|
77 |
// main script execution.
|
78 |
//__require(ARGV[1], ARGV[1]);
|
79 |
//
|
80 |
fs.stat("/tmp/world", function (stat, status, msg) { |
81 |
for ( var i in stat ) { |
82 |
node.blocking.print(i + ": " + stat[i]);
|
83 |
} |
84 |
node.blocking.print("done: " + status.toString() + " " + msg.toString()); |
85 |
}); |