-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfooter.js
253 lines (224 loc) · 10.7 KB
/
footer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// Find all narwhal packages with Objective-J frameworks.
exports.objj_frameworks = [];
exports.objj_debug_frameworks = [];
/*var catalog = require("narwhal/packages").catalog;
for (var name in catalog)
{
if (!catalog.hasOwnProperty(name))
continue;
var info = catalog[name];
if (!info)
continue;
var frameworks = info["objj-frameworks"];
if (frameworks) {
if (!Array.isArray(frameworks))
frameworks = [String(frameworks)];
exports.objj_frameworks.push.apply(exports.objj_frameworks, frameworks.map(function(aFrameworkPath) {
return FILE.join(info.directory, aFrameworkPath);
}));
}
var debugFrameworks = info["objj-debug-frameworks"];
if (debugFrameworks) {
if (!Array.isArray(debugFrameworks))
debugFrameworks = [String(debugFrameworks)];
exports.objj_debug_frameworks.push.apply(exports.objj_debug_frameworks, debugFrameworks.map(function(aFrameworkPath) {
return FILE.join(info.directory, aFrameworkPath);
}));
}
}*/
// push to the front of the array lowest priority first.
OBJJ_INCLUDE_PATHS.unshift.apply(OBJJ_INCLUDE_PATHS, exports.objj_frameworks);
OBJJ_INCLUDE_PATHS.unshift.apply(OBJJ_INCLUDE_PATHS, exports.objj_debug_frameworks);
if (((typeof system !== "undefined" && system) || process).env["OBJJ_INCLUDE_PATHS"])
OBJJ_INCLUDE_PATHS.unshift.apply(OBJJ_INCLUDE_PATHS, ((typeof system !== "undefined" && system) || process).env["OBJJ_INCLUDE_PATHS"].split(":"));
// bring the "window" object into scope.
// TODO: somehow make window object the top scope?
with (window)
{
// runs the objj repl or file provided in args
exports.run = function(args, someCompilerOptions)
{
if (args)
{
function help(status) {
console.log("usage: " + require('path').basename(process.argv[1]) + " infile [--ecma3|--ecma5] [--strict-semicolons] [--track-comments]");
console.log(" [--include-comments] [--include-comment-line-break]");
console.log(" [--formatter <path>] [--indent-tab] [--indent-width <n>] [--indent-string <string>]");
console.log(" [--track-spaces] [--track-locations] [--no-objj] [--no-preprocess]");
console.log(" [--no-debug-symbols] [--no-type-signatures] [--generate-objj]");
console.log(" [--no-source-map] [-x | --xml] [-m | --multifiles] [-I<objj/include/paths>]");
console.log(" [-Dmacro[([p1, p2, ...])][=definition]] [--help]");
process.exit(status);
}
// we expect args to be in the format:
// 1) "objj" [options] path [pgm-options]
// 2) optional "-I" args
// 3) real or "virtual" main.j
// 4) optional program arguments
var options = someCompilerOptions || {},
acornOptions = {},
objjOptions = process.env.OBJJ_OPT,
argv = (objjOptions ? ObjectiveJ.utils.file.parse(objjOptions) : []).concat(args.slice(1)), // copy the args since we're going to modify them
argv0 = argv.shift(),
multipleFiles = false;
// We loop as long as there is an option that starts with '-'
while (argv0 && argv0.lastIndexOf('-', 0) === 0) {
if (argv0 === "--version")
{
console.log(exports.fullVersionString());
}
else if (argv0 == "--ecma3") acornOptions.ecmaVersion = 3;
else if (argv0 == "--ecma5") acornOptions.ecmaVersion = 5;
else if (argv0 == "--strict-semicolons") acornOptions.strictSemicolons = true;
else if (argv0 == "--track-comments") acornOptions.trackComments = true;
else if (argv0 == "--include-comment-line-break") acornOptions.trackCommentsIncludeLineBreak = true;
else if (argv0 == "--include-comments") options.includeComments = true, acornOptions.trackComments = true;
else if (argv0 == "--track-spaces") acornOptions.trackSpaces = true;
else if (argv0 == "--track-locations") acornOptions.locations = true;
else if (argv0 == "--no-objj") acornOptions.objj = false;
else if (argv0 == "--no-preprocess") acornOptions.preprocess = false;
else if (argv0 == "--generate-objj") options.generateObjJ = true;
//else if (argv0 == "--silent") silent = true;
//else if (argv0 == "--old-safari-bug") options.transformNamedFunctionDeclarationToAssignment = true;
else if (argv0 == "--no-source-map") options.sourceMap = false;
else if (argv0 == "--no-debug-symbols") options.includeDebugSymbols = false;
else if (argv0 == "--no-type-signatures") options.includeTypeSignatures = false;
else if (argv0 == "--indent-width") options.indentationSpaces = parseInt(argv.shift());
else if (argv0 == "--indent-string") {
if (options.indentationType) {
console.log("Can't have both '--indent-string' and '--indent-tab'");
help(1);
} else
options.indentationType = argv.shift();
}
else if (argv0 == "--indent-tab") {
if (options.indentationType) {
console.log("Can't have both '--indent-string' and '--indent-tab'");
help(1);
} else {
options.indentationType = "\t";
if (!options.indentationSpaces) options.indentationSpaces = 1;
}
}
else if (argv0 == "--formatter") {
var filePath = argv.shift(),
relative = filePath.substring(0, 1) !== '/',
jsonFile = JSON.parse(fs.readFileSync(relative ? path.resolve(process.cwd(), filePath) : filePath,'utf8'));
options.formatDescription = jsonFile;
}
//else if (argv0 == "--output" || argv0 == "-o") output = process.argv[++i];
else if (argv0.slice(0, 2) == "-D") (acornOptions.macros || (acornOptions.macros = [])).push(argv0.slice(2));
else if (argv0 === "-x" || argv0 === "--xml") exports.messageOutputFormatInXML = true;
else if (argv0 === "-m" || argv0 === "--multifiles") multipleFiles = true;
else if (argv0 == "--help") help(0);
else if (argv0 == "-") help(1);
else if (argv0.lastIndexOf('-I', 0) === 0) {
// If nothing after the '-I' take the next argument as path.
// If not take the argument directly after the '-I' and allow multiple paths separated by ':'
var filePaths = argv0.length === 2 ? [argv.shift()] : argv0.substr(2).split(':');
OBJJ_INCLUDE_PATHS.unshift.apply(OBJJ_INCLUDE_PATHS, filePaths);
}
argv0 = argv.shift();
}
}
if (argv0)
{
var mainFilePath = PATH.resolve(argv0);
var callback = function() {
if (typeof main === "function")
{
var arguments = [argv0];
if (argv && argv.length > 0)
arguments = arguments.concat(argv);
main(arguments);
}
else if (multipleFiles && (argv0 = argv.shift())) {
mainFilePath = PATH.resolve(argv0);
exports.make_narwhal_factory(mainFilePath, null, null, callback)(require, { }, module, typeof system !== "undefined" && system, console.log);
}
else
{
console.error("No main function is found for " + mainFilePath);
}
}
// resolve and read all links
while ((NODEFILE.existsSync(mainFilePath) && NODEFILE.lstatSync(mainFilePath).isSymbolicLink())) {
var linkPath = NODEFILE.readlinkSync(mainFilePath);
if (!PATH.isAbsolute(linkPath)) {
linkPath = PATH.join(PATH.dirname(mainFilePath), linkPath);
}
mainFilePath = PATH.resolve(linkPath);
}
options.acornOptions = acornOptions;
StaticResource.setCurrentCompilerFlags(options);
exports.make_narwhal_factory(mainFilePath, null, null, callback)(require, { }, module, typeof system !== "undefined" && system, console.log);
require("./timeout").serviceTimeouts();
}
else
{
exports.repl();
}
}
exports.repl = function()
{
var READLINE = require('readline-history');
READLINE.createInterface({
path: "/tmp/history",
maxLength: 1234,
input: process.stdin,
output: process.stdout,
next: function(rli) {
rli.setPrompt("objj> ");
rli.prompt();
rli.on('line',function(line) {
try {
var result = exports.objj_eval(line);
if (result !== undefined)
console.log(result);
} catch (e) {
console.log(e);
}
require("./timeout").serviceTimeouts();
});
}
});
};
// creates a narwhal factory function in the objj module scope
exports.make_narwhal_factory = function(path, basePath, filenameTranslateDictionary, aCallback)
{
return function(require, exports, module, system, print)
{
Executable.setCommonJSParameters("require", "exports", "module", "system", "print", "window");
Executable.setCommonJSArguments(require, exports, module, typeof system !== "undefined" && system, print, window);
filenameTranslateDictionary && Executable.setFilenameTranslateDictionary(filenameTranslateDictionary);
Executable.fileImporterForURL(basePath ? basePath : PATH.dirname(path))(path, YES, aCallback);
}
};
} // end "with"
var pkg = null;
function getPackage() {
if (!pkg)
//pkg = JSON.parse(FILE.path(module.filename).directory().directory().join("package.json").read({ charset : "UTF-8" }));
pkg = JSON.parse(NODEFILE.readFileSync(PATH.join("..", "..","package.json"), 'utf8'));
return pkg;
}
exports.version = function() { return getPackage()["version"]; }
exports.revision = function() { return getPackage()["cappuccino-revision"]; }
exports.timestamp = function() { return new Date(getPackage()["cappuccino-timestamp"]); }
exports.fullVersionString = function() {
var rev = exports.revision();
return sprintf("objective-j %s (%04d-%02d-%02d %s)",
exports.version(),
exports.timestamp().getUTCFullYear(),
exports.timestamp().getUTCMonth()+1,
exports.timestamp().getUTCDate(),
rev ? rev.slice(0,6) : null
);
}
global.ObjectiveJ = {};
for (var key in exports)
if (Object.prototype.hasOwnProperty.call(exports, key))
global.ObjectiveJ[key] = exports[key];
if (require.main == module.id)
exports.run((typeof system !== "undefined" && system.args) || process.argv);
});