Skip to content

Commit

Permalink
actually remove old content from repos when they are updated
Browse files Browse the repository at this point in the history
  • Loading branch information
darobin committed Feb 20, 2015
1 parent e1f38f5 commit 76ba082
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 31 deletions.
46 changes: 32 additions & 14 deletions lib/git.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

var fs = require("fs-extra")
, exec = require("child_process").exec
, mkdirp = require("mkdirp")
, tmp = require("tmp")
, async = require("async")
, jn = require("path").join
, lock = require("./lock")
Expand All @@ -18,28 +18,46 @@ exports.cloneOrFetch = function (repo, dir, cb) {
}
else {
log.info("git clone --mirror " + repo + " " + dir);
mkdirp.sync(dir);
exec("git clone --mirror " + repo + " " + dir, release);
fs.mkdirp(dir, function (err) {
if (err) return release(err);
exec("git clone --mirror " + repo + " " + dir, release);
});
}
}
, cb
);
};

// if outDir is a function, it takes over the copying work
exports.publish = function (gitDir, branch, outDir, cb) {
var isOutFunc = typeof outDir === "function";
lock.lock(
"publish " + outDir
"publish " + gitDir
, function (release) {
var cmd = "git archive " + branch + " | tar -x -C " + outDir;
log.info("Publish: " + cmd + ", in " + gitDir);
async.series(
[
function (cb) { mkdirp(outDir, cb); }
, function (cb) { exec(cmd, { cwd: gitDir }, cb); }
, function (cb) { fs.copy(gitDir.replace(/\/$/, ""), jn(outDir, ".git"), cb); }
]
, release
);
tmp.dir(function (err, tmpDir) {
var cmd = "git archive " + branch + " | tar -x -C " + tmpDir;
log.info("Publish: " + cmd + ", in " + gitDir);
async.series(
[
function (cb) { exec(cmd, { cwd: gitDir }, cb); }
, function (cb) {
if (isOutFunc) outDir(tmpDir, cb);
else {
// fs.move does not overwrite directories with content, even with clobber
fs.remove(outDir, function (err) {
if (err) cb(err);
fs.move(tmpDir, outDir, { clobber: true }, cb);
});
}
}
, function (cb) {
if (isOutFunc) cb();
else fs.copy(gitDir.replace(/\/$/, ""), jn(outDir, ".git"), cb);
}
]
, release
);
});
}
, cb
);
Expand Down
25 changes: 17 additions & 8 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,23 @@ exports.publishRepositories = function (repos, conf, cb) {
exports.canonical2pairs(repos)
, function (target, cb) {
log.info("Publishing: " + target.gitDir + ", branch " + target.branch + " into " + target.publishDir);
git.publish(target.gitDir, target.branch, target.publishDir, function (err) {
if (err) return cb(err);
if (target.repository === "webspecs/the-index") {
log.info("Special processing for the-index");
ie.transform(jn(target.publishDir, "index.html"));
}
cb();
});
// we can't git.publish the-index at all, just get the index and publish it
if (target.repository === "webspecs/the-index") {
log.info("Special processing for the-index");
git.publish(
target.gitDir
, target.branch
, function (tmpDir, cb) {
log.info("Transforming the-index");
ie.transform(jn(tmpDir, "index.html"), jn(target.publishDir, "index.html"));
cb();
}
, cb
);
}
else {
git.publish(target.gitDir, target.branch, target.publishDir, cb);
}
}
, cb
);
Expand Down
6 changes: 3 additions & 3 deletions lib/the-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ exports.extract = function (path) {
return res;
};

exports.transform = function (path) {
var $ = whacko.load(fs.readFileSync(path, "utf8"));
exports.transform = function (src, dest) {
var $ = whacko.load(fs.readFileSync(src, "utf8"));
exports.specTables($);
exports.toc($);
fs.writeFileSync(path, $.html(), { encoding: "utf8" });
fs.writeFileSync(dest, $.html(), { encoding: "utf8" });
};

exports.specTables = function ($) {
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
"license": "MIT",
"dependencies": {
"async": "0.9.0",
"body-parser": "1.9.2",
"body-parser": "1.12.0",
"chalk": "0.5.1",
"express": "4.10.2",
"fs-extra": "0.12.0",
"fs-extra": "^0.16.3",
"lock": "0.1.0",
"mkdirp": "0.5.0",
"phantomjs": "^1.9.15",
"querystring": "^0.2.0",
"respec": "^3.2.40",
"respec": "3.2.40",
"superagent": "0.21.0",
"whacko": "0.17.1",
"winston": "0.8.3",
"winston-mail": "^0.3.0"
"tmp": "0.0.24",
"whacko": "0.17.3",
"winston": "0.9.0",
"winston-mail": "^0.3.1"
},
"bin": {
"serve-publican": "bin/server.js",
Expand Down

0 comments on commit 76ba082

Please sign in to comment.