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

improve packageTask api #324

Open
wants to merge 7 commits into
base: main
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
26 changes: 15 additions & 11 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,20 @@ var api = new (function () {
}
};

this.packageTask = function (name, version, definition) {
return new jake.PackageTask(name, version, definition);
};
function createApi(jakeTaskConstructorGetter) {
return function() {
var jakeTaskConstructor = jakeTaskConstructorGetter();

var ctor = function () {}
, t;
ctor.prototype = jakeTaskConstructor.prototype;
t = new ctor();
jakeTaskConstructor.apply(t, arguments);
return t;
};
}

this.packageTask = createApi(function() { return jake.PackageTask;});

this.publishTask = function (name, prereqs, opts, definition) {
return new jake.PublishTask(name, prereqs, opts, definition);
Expand All @@ -368,14 +379,7 @@ var api = new (function () {
return new jake.WatchTask(name, taskNames, definition);
};

this.testTask = function () {
var ctor = function () {}
, t;
ctor.prototype = jake.TestTask.prototype;
t = new ctor();
jake.TestTask.apply(t, arguments);
return t;
};
this.testTask = createApi(function() { return jake.TestTask;});

})();

Expand Down
8 changes: 4 additions & 4 deletions lib/jake.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ var Invocation = function (taskName, args) {
// Globalize jake and top-level API methods (e.g., `task`, `desc`)
utils.mixin(global, api);

// Also add top-level API methods to exported object for those who don't want to
// use the globals
utils.mixin(jake, api);

// Copy utils onto base jake
utils.mixin(jake, utils);
// File utils should be aliased directly on base jake as well
utils.mixin(jake, utils.file);

// Also add top-level API methods to exported object for those who don't want to
// use the globals (`file` here will overwrite the 'file' utils namespace)
utils.mixin(jake, api);

utils.mixin(jake, new (function () {

this._invocationChain = [];
Expand Down
28 changes: 20 additions & 8 deletions lib/publish_task.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var PublishTask = function () {
this.prereqs = prereqs;
this.packageFiles = new FileList();
this.publishCmd = opts.publishCmd || 'npm publish %filename';
this.publishMessage = opts.publishMessage || 'BOOM! Published.';
this.gitCmd = opts.gitCmd || 'git';
this.versionFiles = opts.versionFiles || ['package.json'];
this.scheduleDelay = 5000;
Expand Down Expand Up @@ -253,15 +254,26 @@ PublishTask.prototype = new (function () {
cmd = self.publishCmd.replace(/%filename/gi, filename);
}

// Hackity hack -- NPM publish sometimes returns errror like:
// Error sending version data\nnpm ERR!
// Error: forbidden 0.2.4 is modified, should match modified time
setTimeout(function () {
jake.exec(cmd, function () {
console.log('BOOM! Published.');
if (typeof cmd == 'function') {
cmd(function (err) {
if (err) {
throw err;
}
console.log(self.publishMessage);
complete();
}, {printStdout: true, printStderr: true});
}, self.scheduleDelay);
});
}
else {
// Hackity hack -- NPM publish sometimes returns errror like:
// Error sending version data\nnpm ERR!
// Error: forbidden 0.2.4 is modified, should match modified time
setTimeout(function () {
jake.exec(cmd, function () {
console.log(self.publishMessage);
complete();
}, {printStdout: true, printStderr: true});
}, self.scheduleDelay);
}
});

task('cleanup', {async: true}, function () {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"make",
"rake"
],
"version": "8.0.13",
"version": "8.0.15",
"author": "Matthew Eernisse <[email protected]> (http://fleegix.org)",
"license": "Apache-2.0",
"bin": {
Expand All @@ -24,7 +24,7 @@
"preferGlobal": true,
"dependencies": {
"filelist": "0.0.x",
"minimatch": "0.2.x",
"minimatch": "3.x",
"chalk": "0.4.x",
"utilities": "1.0.x",
"async": "0.9.x"
Expand Down