Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved logger, support for more js shells, and quit() env module #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ build/tests/override/node_modules
build/tests/override/one-built.js
tests/node/node_modules
tests/node/embedded/node_modules
*.sw*
1 change: 1 addition & 0 deletions build/jslib/browser/args.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
define(function(){return function(){};});
1 change: 1 addition & 0 deletions build/jslib/browser/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
define(function(){return function(){};});
2 changes: 2 additions & 0 deletions build/jslib/browser/load.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//nothing to do here
define(function(){return function(){};});
1 change: 1 addition & 0 deletions build/jslib/browser/optimize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
define(function(){return function(){};});
6 changes: 6 additions & 0 deletions build/jslib/browser/print.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
define(function(){
return function(){
console.log.apply(console,Array.prototype.slice.apply(arguments));
};
});

1 change: 1 addition & 0 deletions build/jslib/browser/quit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
define(function(){return function(){};});
4 changes: 3 additions & 1 deletion build/jslib/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
env = 'node';
} else if (typeof window !== "undefined" && navigator && document) {
env = 'browser';
} else if (typeof load === 'function' && typeof print === 'function'){
env = 'spartan';
}

define({
Expand All @@ -44,4 +46,4 @@
});
}
});
}());
}());
24 changes: 12 additions & 12 deletions build/jslib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,36 @@ define(['env!env/print'], function (print) {
this.level = level;
},

trace: function (message) {
trace: function () {
if (this.level <= this.TRACE) {
this._print(message);
this._print(arguments);
}
},

info: function (message) {
info: function () {
if (this.level <= this.INFO) {
this._print(message);
this._print(arguments);
}
},

warn: function (message) {
warn: function () {
if (this.level <= this.WARN) {
this._print(message);
this._print(arguments);
}
},

error: function (message) {
error: function () {
if (this.level <= this.ERROR) {
this._print(message);
this._print(arguments);
}
},

_print: function (message) {
this._sysPrint((this.logPrefix ? (this.logPrefix + " ") : "") + message);
_print: function (args) {
this._sysPrint(this.logPrefix ? (this.logPrefix + " ") : "", Array.prototype.slice.apply(args));
},

_sysPrint: function (message) {
print(message);
_sysPrint: function (logPrefix,args) {
print.apply(this,[logPrefix].concat(args));
}
};

Expand Down
6 changes: 1 addition & 5 deletions build/jslib/node/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@
/*global define: false, console: false */

define(function () {
function print(msg) {
console.log(msg);
}

return print;
return console.log;
});
4 changes: 4 additions & 0 deletions build/jslib/node/quit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
define(function(){
return process.exit;
});

3 changes: 3 additions & 0 deletions build/jslib/rhino/quit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
define(function(){
return quit;
});
1 change: 1 addition & 0 deletions build/jslib/spartan.js
1 change: 1 addition & 0 deletions build/jslib/spartan/args.js
48 changes: 48 additions & 0 deletions build/jslib/spartan/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//file API's may not be supported in spartan shell environments
define({
getLineSeparator: function () {
},

exists: function (fileName) {
},

parent: function (fileName) {
},

normalize: function (fileName) {
},

isFile: function (path) {
},

isDirectory: function (path) {
},

absPath: function (fileObj) {
},

getFilteredFileList: function (/*String*/startDir, /*RegExp*/regExpFilters, /*boolean?*/makeUnixPaths, /*boolean?*/startDirIsJavaObject) {
},

copyDir: function (/*String*/srcDir, /*String*/destDir, /*RegExp?*/regExpFilter, /*boolean?*/onlyCopyNew) {
},

copyFile: function (/*String*/srcFileName, /*String*/destFileName, /*boolean?*/onlyCopyNew) {
},

renameFile: function (from, to) {
},

readFile: function (/*String*/path, /*String?*/encoding) {
},

saveUtf8File: function (/*String*/fileName, /*String*/fileContents) {
},

saveFile: function (/*String*/fileName, /*String*/fileContents, /*String?*/encoding) {
},

deleteFile: function (/*String*/fileName) {
}
});

1 change: 1 addition & 0 deletions build/jslib/spartan/load.js
1 change: 1 addition & 0 deletions build/jslib/spartan/optimize.js
1 change: 1 addition & 0 deletions build/jslib/spartan/print.js
1 change: 1 addition & 0 deletions build/jslib/spartan/quit.js
49 changes: 40 additions & 9 deletions build/jslib/x.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,30 @@ var requirejs, require, define;
commandOption = fileName.substring(1);
fileName = process.argv[3];
}
}
} else if (typeof window !== "undefined" && navigator && document) {
env = 'browser';
} else if (typeof load === 'function' && typeof print === 'function'){
env = 'spartan';

fileName = args[0];

if (fileName && fileName.indexOf('-') === 0) {
commandOption = fileName.substring(1);
fileName = args[1];
}

exec = eval;

//Define a console.log for easier logging. Don't
//get fancy though.
if (typeof console === 'undefined') {
console = {
log: function () {
print.apply(undefined, arguments);
}
};
}
}

//INSERT require.js

Expand All @@ -115,6 +138,9 @@ var requirejs, require, define;

//INSERT build/jslib/node.js

} else if (env === 'spartan'){

//INSERT build/jslib/spartan.js
}

//Support a default file name to execute. Useful for hosted envs
Expand Down Expand Up @@ -225,19 +251,24 @@ var requirejs, require, define;
//Just run an app

//Load the bundled libraries for use in the app.
if (commandOption === 'lib') {
//browser loads libs by default
if (commandOption === 'lib' || env === 'browser') {
loadLib();
}

setBaseUrl(fileName);

if (exists(fileName)) {
exec(readFile(fileName), fileName);
} else {
showHelp();
if(env === 'spartan'){
load(fileName);
} else if (env !== 'browser'){
if (exists(fileName)) {
exec(readFile(fileName), fileName);
} else {
showHelp();
}
}
}

}((typeof console !== 'undefined' ? console : undefined),
(typeof Packages !== 'undefined' ? Array.prototype.slice.call(arguments, 0) : []),
(typeof readFile !== 'undefined' ? readFile : undefined)));
})((typeof console !== 'undefined' ? console : undefined),
((typeof Packages !== 'undefined' || (typeof load === 'function' && typeof print === 'function'))? Array.prototype.slice.call(arguments, 0) : []),
(typeof readFile !== 'undefined' ? readFile : undefined));
3 changes: 2 additions & 1 deletion dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var fs = require('fs'),
loadRegExp = /\/\/INSERT ([\w\/\.]+)/g,
moduleNameRegExp = /build\/jslib\/([\w\/\-]+)\.js$/,
defRegExp = /define\s*\(/,
envs = ['node', 'rhino'],
envs = ['node', 'rhino', 'spartan', 'browser'],
//Update this list of files by running the optimizer against
//build/jslib/opto.build.js,
//but then remove any jslib/node entries and make sure there is
Expand All @@ -36,6 +36,7 @@ var fs = require('fs'),
'env!env/file',
'build/jslib/lang.js',
'env!env/print',
'env!env/quit',
'build/jslib/logger.js',
'build/jslib/blank.js',
'build/jslib/blank.js',
Expand Down