Add documentation rebuild script

This commit is contained in:
Joshua Granick
2014-02-21 17:25:30 -08:00
parent 7a76cc4150
commit cf233f8af1
2 changed files with 154 additions and 0 deletions

BIN
run.n vendored

Binary file not shown.

View File

@@ -115,6 +115,31 @@ class RunScript {
}
} else if (target == "documentation") {
var wiki = null;
var output = null;
for (define in defines) {
if (StringTools.startsWith (define, "-Dwiki=")) {
wiki = define.substr (define.indexOf ("=") + 1);
} else if (StringTools.startsWith (define, "-Doutput=")) {
output = define.substr (define.indexOf ("=") + 1);
}
}
if (wiki != null && output != null) {
copyDocumentation (wiki, output);
}
} else if (target == "clean") {
var directories = [ PathHelper.combine (path, "obj") ];
@@ -546,6 +571,135 @@ class RunScript {
}
private static function copyDocumentation (source:String, output:String):Void {
var sourcePaths = PathHelper.readDirectory (source, [ ".git" ]);
var targetPaths = [];
var names = [];
var titles = [];
for (sourcePath in sourcePaths) {
var path = sourcePath.substr (source.length);
var components = path.split ("/");
var targetPath = "";
var name = "";
var title = "";
for (i in 0...components.length - 1) {
var component = components[i];
var index = component.lastIndexOf (".-");
if (index > -1) {
targetPath += component.substr (index + 2).toLowerCase () + "/";
} else if (component != "") {
targetPath += component + "/";
}
}
var lastComponent = components[components.length - 1];
var index = lastComponent.lastIndexOf (".-");
name = lastComponent.substr (0, lastComponent.length - 3);
if (index > -1) {
var trim = name.substr (index + 2);
title = StringTools.replace (trim, "-", " ");
targetPath += trim.toLowerCase () + "/index.md";
} else {
title = StringTools.replace (lastComponent, "-", " ");
targetPath += lastComponent;
}
targetPaths.push (targetPath);
names.push (name);
titles.push (title);
}
var links = ~/\[\[(.+)\]\]/g;
for (i in 0...sourcePaths.length) {
var sourcePath = sourcePaths[i];
var targetPath = targetPaths[i];
var outputPath = PathHelper.combine (output, targetPath);
var title = titles[i];
Sys.println (outputPath);
PathHelper.mkdir (Path.directory (outputPath));
var content = File.getContent (sourcePath);
while (links.match (content)) {
var link = links.matched (0);
link = link.substr (2, link.length - 4);
var components = link.split ("|");
var title = "";
var target = "";
if (components.length > 1) {
title = components[0];
target = components[1];
} else {
title = target = components[0];
}
if (StringTools.endsWith (target, ".md")) {
target = target.substr (0, target.length - 3);
}
var replacement = "[" + title + "](/documentation/)";
for (i in 0...names.length) {
if (target == names[i]) {
var path = targetPaths[i];
path = path.substr (0, path.lastIndexOf ("/"));
replacement = "[" + title + "](/documentation/" + path + ")";
break;
}
}
content = links.matchedLeft () + replacement + links.matchedRight ();
}
var output = File.write (outputPath, false);
output.writeString ("---\n");
output.writeString ("layout: default\n");
output.writeString ("title: " + title + "\n");
output.writeString ("---\n\n");
output.writeString ("# " + title + "\n\n");
output.writeString (content);
output.close ();
}
}
private static function downloadFile (remotePath:String, localPath:String) {
var out = File.write (localPath, true);