Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Start adding command line opts, like -T, -P, -D.

  • Loading branch information...
commit 64daa51da2145755d422683426e6691c355478b8 1 parent 36083f2
Tom Robinson authored
View
5 bin/jake
@@ -1,5 +1,6 @@
#!/usr/bin/env narwhal
-var jake = require("jake");
+var JAKE = require("jake");
+var SYSTEM = require("system");
-jake.application().run();
+JAKE.application().run({ args : SYSTEM.args });
View
154 lib/jake/application.js
@@ -22,16 +22,44 @@
// IN THE SOFTWARE.
//
-var FILE = require("file"),
- SYSTEM = require("system"),
+var FILE = require("file");
+var SYSTEM = require("system");
+var printf = require("printf").printf;
- Task = require("jake/task").Task,
- FileTask = require("jake/filetask").FileTask,
- FileCreationTask = require("jake/filecreationtask").FileCreationTask,
- TaskManager = require("jake/taskmanager").TaskManager;
+var Task = require("jake/task").Task;
+var FileTask = require("jake/filetask").FileTask;
+var FileCreationTask = require("jake/filecreationtask").FileCreationTask;
+var TaskManager = require("jake/taskmanager").TaskManager;
var DEFAULT_JAKEFILES = ["jakefile", "Jakefile", "jakefile.js", "Jakefile.js", "jakefile.j", "Jakefile.j"];
+
+var parser = new (require("args").Parser)();
+parser.usage("targets...");
+
+parser.option("--jakefile", "-f", "file")
+ .set()
+ .help("Use FILE as the jakefile.");
+
+parser.option("--tasks", "-T", "showTasks")
+ .set("tasks")
+ .help("Display the tasks "/*(matching optional PATTERN) */+"with descriptions, then exit.");
+
+parser.option("--describe", "-D", "showTasks")
+ .set("describe")
+ .help("Describe the tasks "/*(matching optional PATTERN), */+"then exit.");
+
+parser.option("--prereqs", "-P", "showPrereqs")
+ .set(true)
+ .help("Display the tasks and dependencies, then exit.");
+
+parser.option("--verbose", "-v", "verbose")
+ .set(true)
+ .help("Log message to standard output.");
+
+parser.helpful();
+
+
var Application = function()
{
TaskManager.call(this);
@@ -53,27 +81,27 @@ var Application = function()
@tty_output = STDOUT.tty?*/
}
+Application.prototype.name = function() {
+ return this._name;
+}
+
Application.__proto__ = TaskManager;
Application.prototype.__proto__ = TaskManager.prototype;
-// Run the Rake application. The run method performs the following three steps:
+// Run the Jake application. The run method performs the following three steps:
//
// * Initialize the command line options (+init+).
// * Define the tasks (+loadRakefile+).
// * Run the top level tasks (+runTasks+).
//
-// If you wish to build a custom rake command, you should call +init+ on your
-// application. The define any tasks. Finally, call +topLevel+ to run your top
+// If you wish to build a custom jake command, you should call +init+ on your
+// application. Then define any tasks. Finally, call +topLevel+ to run your top
// level tasks.
-Application.prototype.run = function()
+Application.prototype.run = function(options)
{
- var start = new Date();
-
- this.init();
+ this.init(options);
this.loadJakefile();
this.topLevel();
-
- print("Build took " + timeDeltaString(new Date() - start));
}
function timeDeltaString(/*Date*/ aTimeDelta)
@@ -114,11 +142,10 @@ function timeDeltaString(/*Date*/ aTimeDelta)
}
// Initialize the command line parameters and app name.
-Application.prototype.init = function(/*String*/ anApplicationName)
+Application.prototype.init = function(options)
{
- this._name = anApplicationName || "jake";
-// this.handleOptions();
-//FIXME: options
+ this._name = options.appName || "jake";
+ this.handleOptions(options.args || SYSTEM.args);
this.collectTasks();
}
@@ -130,18 +157,18 @@ Application.prototype.loadJakefile = function()
// Run the top level tasks of a Rake application.
Application.prototype.topLevel = function()
-{/*
- if (options.showTasks())
+{
+ if (this._options.showTasks)
this.displayTasksAndComments();
-
- else if (options.showPrereqs)
- this.displayPreq;
- else
-*/
- this._topLevelTasks.forEach(function(/*String*/ aTaskName)
- {
- this.invokeTask(aTaskName);
- }, this);
+ else if (this._options.showPrereqs)
+ this.displayPrerequisites();
+ else {
+ var start = new Date();
+ this._topLevelTasks.forEach(function(/*String*/ aTaskName) {
+ this.invokeTask(aTaskName);
+ }, this);
+ print("Build took " + timeDeltaString(new Date() - start));
+ }
}
/*
@@ -205,17 +232,13 @@ Application.prototype.parseTaskString = function(/*String*/ aString)
end
*/
-// True if one of the files in RAKEFILES is in the current directory.
-// If a match is found, it is copied into @rakefile.
+// True if one of the files in JAKEFILES is in the current directory.
+// If a match is found, it is copied into @jakefile.
Application.prototype.hasJakefile = function(/*String*/ aDirectory)
{
- var jakefiles = this._jakefiles,
- index = 0,
- count = jakefiles.length;
-
- for (; index < count; ++index)
+ for (var i = 0; i < this._jakefiles.length; ++i)
{
- var jakefile = jakefiles[index];
+ var jakefile = this._jakefiles[i];
if (FILE.exists(FILE.join(aDirectory, jakefile)))
return jakefile;
@@ -242,8 +265,35 @@ Application.prototype.hasJakefile = function(/*String*/ aDirectory)
def truncate_output?
tty_output? || ENV['RAKE_COLUMNS']
end
+*/
+
+// Display the tasks and comments.
+Application.prototype.displayTasksAndComments = function()
+{
+ var displayableTasks = Object.keys(this._tasks).map(function(name) { return this._tasks[name]; }, this).filter(function(t) {
+ return !!t.fullComment();
+ }, this);
+
+ switch (this._options.showTasks) {
+ case "describe" :
+ displayableTasks.forEach(function(t) {
+ printf("%s %s", this.name(), t.name());
+ t.fullComment().split("\n").forEach(function(line) {
+ print(" " + line);
+ })
+ print("");
+ }, this);
+ break
+ case "tasks" :
+ var width = displayableTasks.reduce(function(width, t) { return Math.max(width, t.name().length); }, 0);
+ displayableTasks.forEach(function(t) {
+ printf("%s %-"+width+"s # %s", this.name(), t.name(), t.comment());
+ }, this);
+ break;
+ }
+}
- # Display the tasks and comments.
+/*
def display_tasks_and_comments
displayable_tasks = tasks.select { |t|
t.comment && t.name =~ options.show_task_pattern
@@ -305,8 +355,20 @@ Application.prototype.hasJakefile = function(/*String*/ aDirectory)
( string[0, width-3] || "" ) + "..."
end
end
+*/
+
+// Display the tasks and prerequisites
+Application.prototype.displayPrerequisites = function()
+{
+ this.tasks().forEach(function(t) {
+ printf("%s %s", this.name(), t.name());
+ t.prerequisites().forEach(function(pre) {
+ printf(" %s", pre);
+ });
+ }, this);
+}
- # Display the tasks and prerequisites
+/*
def display_prerequisites
tasks.each do |t|
puts "#{name} #{t.name}"
@@ -432,8 +494,18 @@ Application.prototype.hasJakefile = function(/*String*/ aDirectory)
]
]
end
+*/
- # Read and handle the command line options.
+// Read and handle the command line options.
+Application.prototype.handleOptions = function(args)
+{
+ this._options = parser.parse(args.slice());
+
+ if (this._options.file)
+ this._jakefiles = [this._options.file];
+}
+
+/*
def handle_options
options.rakelib = ['rakelib']
View
14 lib/jake/task.js
@@ -31,8 +31,8 @@ var Task = function(/*String*/ aName, /*Application*/ anApplication)
this._prerequisites = [];
this._actions = [];
this._alreadyInvoked = false;
- //this._fullComment = null;
- //this._comment = null;
+ this._fullComment = null;
+ this._comment = null;
//this.lock = Monitor.new
this._application = anApplication;
this._scope = anApplication.currentScope();
@@ -49,6 +49,16 @@ Task.prototype.name = function()
return this._name;
}
+Task.prototype.fullComment = function()
+{
+ return this._fullComment || "";
+}
+
+Task.prototype.comment = function()
+{
+ return this._comment || "";
+}
+
Task.prototype.prerequisites = function()
{
return this._prerequisites;
View
17 lib/jake/taskmanager.js
@@ -126,20 +126,9 @@ TaskManager.prototype.resolveArguments = function(args)
TaskManager.prototype.tasks = function()
{
- var tasks = Object.keys(this._tasks);
-
- tasks.sort(function(lhs, rhs)
- {
- if (lhs < rhs)
- return -1;
-
- else if (lhs > rhs)
- return 1;
-
- return 0;
- } );
-
- return tasks;
+ return Object.keys(this._tasks).sort().map(function(name) {
+ return this._tasks[name];
+ }, this);
}
// List of all the tasks defined in the given scope (and its
View
5 package.json
@@ -1,6 +1,9 @@
{
"name": "jake",
- "author": "Francisco Tolmasky (http://tolmasky.com/)",
+ "author": "Francisco Tolmasky (http://tolmasky.com/) <francisco@280north.com>",
+ "contributors": [
+ "Tom Robinson (http://tlrobinson.net/) <tom@280north.com>",
+ ],
"description": "A build system for CommonJS, lifted from Rake",
"keywords": ["build", "jake", "rake", "make"],
"version":"0.1.5"
Please sign in to comment.
Something went wrong with that request. Please try again.