Skip to content

Commit c653069

Browse files
committed
Should be almost useable now
1 parent f55eff6 commit c653069

File tree

6 files changed

+180
-7
lines changed

6 files changed

+180
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
dist/
44
public_html/
55
repo.git/
6+
build-command.sh

Gruntfile.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ grunt.initConfig({
1515

1616
grunt.registerTask( "default", [ "jshint", "cron" ] );
1717

18+
grunt.registerTask( "clean", function() {
19+
var data;
20+
try {
21+
data = require( config.output + "/data.json" );
22+
} catch( e ) {
23+
console.log( "No data.json found" );
24+
return;
25+
}
26+
Object.keys( data.branches || {} )
27+
.concat( Object.keys( data.tags || {} ) )
28+
.forEach(function( directory ) {
29+
grunt.log.writeln( "Removing " + directory );
30+
grunt.file.remove( config.output + "/" + directory );
31+
});
32+
grunt.log.writeln( "Removing data.json" );
33+
grunt.file.remove( config.output + "/data.json" );
34+
});
35+
1836
grunt.registerTask( "update-repo", function() {
1937
function thenFetch( err ) {
2038
if ( err ) {

lib/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ function resolvePath( key, _default ) {
77

88
resolvePath( "output", "public_html" );
99
resolvePath( "working", "repo.git" );
10+
resolvePath( "buildCommand", "build-command.sh" );
1011

1112
module.exports = config;

lib/update.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,52 @@ var _ = require( "underscore" ),
33
config = require( "./config" ),
44
grunt = require( "grunt" ),
55
fs = require( "fs" ),
6-
Repo = require( "git-tools" );
6+
Repo = require( "git-tools" ),
7+
buildCommand = fs.existsSync( config.buildCommand );
78

89
function removeDirectory( directory ) {
910
console.log( "Removing", directory );
1011
grunt.file["delete"]( directory, { force: true });
1112
}
1213

1314
function generateUpdateFunction( repo, directory, sha ) {
14-
var realDirectory = config.working + "/" + directory;
15+
var realDirectory = config.output + "/" + directory;
1516
if ( !fs.existsSync( realDirectory ) ) {
1617
grunt.file.mkdir( realDirectory );
1718
}
1819
return function( callback ) {
19-
console.log( "Archiving " + sha + " to " + directory );
20+
console.log( "Archiving " + sha + " to " + realDirectory );
2021
grunt.util.spawn({
2122
cmd: __dirname + "/export-sha.sh",
2223
args: [ sha, realDirectory ],
23-
cwd: config.working
24-
}, callback );
24+
opts: { cwd: config.working }
25+
}, function( err ) {
26+
if ( err ) {
27+
callback( err );
28+
}
29+
if ( buildCommand ) {
30+
console.log( "Running build command" );
31+
grunt.util.spawn({
32+
cmd: config.buildCommand,
33+
args: [ directory, sha ],
34+
opts: { stdio: "inherit", cwd: realDirectory }
35+
}, function() {
36+
// swallow error from build
37+
callback();
38+
});
39+
} else {
40+
callback();
41+
}
42+
});
2543
};
2644
}
2745

2846
module.exports = function( callback ) {
2947
var lastrun,
30-
thisrun = {},
48+
thisrun = {
49+
repo: config.repo,
50+
title: config.title
51+
},
3152
repo = new Repo( config.working );
3253

3354
try {
@@ -80,7 +101,8 @@ module.exports = function( callback ) {
80101
removeDirectory( config.output + "/" + branch );
81102
});
82103
async.series( _.map( branches, function( branch ) {
83-
if ( lastrun.branches[ branch.name ] && lastrun.branches[ branch.name ].sha === branch.sha ) {
104+
if ( lastrun.branches[ branch.name ] &&
105+
lastrun.branches[ branch.name ].sha === branch.sha ) {
84106
return function( callback ) {
85107
console.log( "Skipping " + branch.name + " @ " + branch.sha );
86108
callback();

public_html/index.html

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<!DoctypE html>
2+
<html>
3+
<head>
4+
<title>Web Git Proxy</title>
5+
<style>
6+
html, body { height:100%; }
7+
body {
8+
font-family: Arial;
9+
background:#888;
10+
text-align:center;
11+
}
12+
h1 {
13+
font-size:2.4em;
14+
text-shadow: rgba(0,0,0,0.5) -1px 0, rgba(0,0,0,0.3) 0 -1px, rgba(255,255,255,0.5) 0 1px, rgba(0,0,0,0.3) -1px -1px;
15+
}
16+
input[type="text"] {
17+
width:500px;
18+
border:1px solid #555;
19+
padding:5px;
20+
font-size:1.2em;
21+
border-radius:5px;
22+
background:#444;
23+
background: rgba(0,0,0,.5 );
24+
color:#CCC;
25+
outline:none;
26+
}
27+
input[type="submit"] {
28+
border:1px solid #555;
29+
cursor: pointer;
30+
background: #333;
31+
font-size:1.2em;
32+
padding:5px;
33+
border-radius:5px;
34+
background-image: -webkit-gradient(
35+
linear,
36+
left bottom,
37+
left top,
38+
color-stop(0.41, rgb(8,8,8)),
39+
color-stop(0.52, rgb(77,77,77))
40+
);
41+
background-image: -moz-linear-gradient(
42+
center bottom,
43+
rgb(8,8,8) 41%,
44+
rgb(77,77,77) 52%
45+
);
46+
color:#DDD;
47+
}
48+
.error {
49+
margin:10px;
50+
padding:10px;
51+
font-size:1.2em;
52+
color:#5f1313;
53+
}
54+
.loading * {
55+
display: none;
56+
}
57+
.loading .error {
58+
display: block;
59+
}
60+
.listing a {
61+
color:#000;
62+
padding:2px 10px;
63+
}
64+
65+
</style>
66+
</head>
67+
<body>
68+
<section>
69+
<h1>Paste in github file-uri to view</h1>
70+
<form method="POST">
71+
<input id="url-input" type="text" name="url" size="30" autofocus />
72+
<input type="submit" name="submit" value="Go" />
73+
<span class="error"></span>
74+
</form>
75+
</section>
76+
<section class="listingSection">
77+
<h1>Or Start Browsing <span class="title"></span></h1>
78+
<div class="loading">
79+
<span class="error">loading...</span>
80+
<h2>Branches:</h2>
81+
<div id="branch-list" class="listing"></div>
82+
<h2>Tags:</h2>
83+
<div id="tag-list" class="listing"></div>
84+
</div>
85+
</section>
86+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
87+
<script src="view.js"></script>
88+
</body>
89+
</html>

public_html/view.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
(function($){
2+
3+
var data = $.ajax({
4+
url: "data.json",
5+
dataType: "json"
6+
});
7+
8+
$(function() {
9+
var loadingError = $(".loading .error");
10+
data.done( function( data ) {
11+
$("title").text( function( index, text ) {
12+
return data.title + ": " + text;
13+
});
14+
$(".title").text( data.title );
15+
16+
function renderRepoList( dest, refList ) {
17+
dest.html( $.map( refList, function( ref, directory ) {
18+
return "<a href='" + directory +"/'>" + directory + "</a>";
19+
}).join("") );
20+
}
21+
renderRepoList( $("#branch-list"), data.branches );
22+
renderRepoList( $("#tag-list"), data.tags );
23+
$(".loading").removeClass("loading");
24+
loadingError.remove();
25+
}).fail( function() {
26+
loadingError.text("Problem loading url");
27+
});
28+
29+
var urlRegexp = /github.com\/[^\/]+\/[^\/]+\/(?:blob|tree)\/?(.*)$/;
30+
31+
$("form").submit(function( event ) {
32+
event.preventDefault();
33+
var match = urlRegexp.exec( $("#url-input").val() );
34+
if ( match ) {
35+
window.location = "/" + match[1];
36+
} else {
37+
$("#parse-error").text("Error parsing URL");
38+
}
39+
});
40+
});
41+
42+
})(jQuery);

0 commit comments

Comments
 (0)