Skip to content

Commit

Permalink
webspecs#22 Proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
renoirb committed May 21, 2015
1 parent 735f9cb commit 8e68119
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 10 deletions.
3 changes: 3 additions & 0 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var fs = require("fs")
, processStatic = require("./tasks/process-static")
, processBikeshed = require("./tasks/init-bikeshed")
, processSpec = require("./tasks/process-spec")
, purge = require("./tasks/purge")
;

// loads the configuration itself
Expand Down Expand Up @@ -119,7 +120,9 @@ Manager.prototype = {
else {
ctx.subDirOnly = ctx.specSubDir;
this.runTask(processSpec, ctx, cb);
this.runTask(purge, ctx, cb);
}
}

};
module.exports = Manager;
1 change: 1 addition & 0 deletions lib/tasks/process-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ module.exports = [
return this.runTask(require("./generate-bikeshed"), ctx, cb);
cb(new Error("Failed to find a specification file in " + ctx.specDir));
}
, require("./purge")
]
;
1 change: 1 addition & 0 deletions lib/tasks/process-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
module.exports = [
require("./git-clone-or-fetch")
, require("./git-publish")
, require("./purge-all")
]
;
31 changes: 22 additions & 9 deletions lib/tasks/purge-all.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@

var sua = require("superagent");
var request = require("request");

// expects:
// purgeAllURL: the URL to purge Fastly
// purgeAllKey: the key for the Fastly service
module.exports = function (ctx, cb) {
sua.post(ctx.purgeAllURL)
.set("Fastly-Key", ctx.purgeAllKey)
.set('Accept', 'application/json')
.end(function (err, res) {
if (!err && res.body && res.body.status === "ok") return cb();
cb(new Error(res.body ? res.body.status : "No response body for purge"));
})
;

var options = {
url: ctx.purgeAllURL
, method: 'POST'
, headers: {
'User-Agent': 'WebPlatformPublican/1'
, 'Fastly-Key': ctx.purgeAllKey
}
};

return request(options, function requestCallback(error, response, body) {
var info = JSON.parse(body);
if (!error && response.statusCode == 200) {
console.log('Purge worked', info);
return cb();
} else {
cb( new Error('Error purging, message ', info ) );
}
});

};

27 changes: 27 additions & 0 deletions lib/tasks/purge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

var request = require("request");

module.exports = function (ctx, cb) {

var parts = ctx.repository.split("/", 2);
var options = {
url: 'https://specs.webplatform.org/'
, method: 'PURGE'
, headers: {
'User-Agent': 'WebPlatformPublican/1'
}
};

options.url += parts[1] + '/' + parts[0] + '/' + ctx.branch;

return request(options, function purgeRequestHandler (error, response, body) {
var info = JSON.parse(body);
if (!error && response.statusCode == 200) {
console.log('Purge worked on ' + options.url, info);
return cb();
} else {
return cb(new Error('Error purging ' + options.url, info));
}
});

};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"phantomjs": "1.9.15",
"querystring": "^0.2.0",
"respec": "3.2.40",
"superagent": "1.1.0",
"request": "2.42.0",
"tmp": "0.0.25",
"whacko": "0.17.4",
"winston": "0.9.0",
Expand Down

0 comments on commit 8e68119

Please sign in to comment.