Skip to content

Commit 2683302

Browse files
committed
static-zip: allow to download pages archive from repo and make static file the default
1 parent 5807688 commit 2683302

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"repository" : "tldr-pages/tldr",
32
"colors": {
43
"text": "green",
54
"command-background": "black",

lib/remote.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,21 @@ exports.download = function(done) {
1919
var src = source();
2020
var url = 'http://tldr-pages.github.io/assets/tldr.zip';
2121
var target = path.join(os.tmpdir(), 'tldr');
22+
var inside = target;
23+
if (src) {
24+
url = 'https://github.com/' + src.user + '/' + src.repo + '/archive/' + src.branch + '.zip';
25+
inside = path.join(target, src.repo + '-' + src.branch);
26+
}
2227

2328
rimraf.sync(target);
2429
mkdirp.sync(target);
2530

2631
var extractor = unzip.Extract({path: target});
27-
extractor.on('error', done);
32+
extractor.on('error', function (e) {
33+
done(new Error('Cannot update from ' + url), inside);
34+
});
2835
extractor.on('close', function() {
29-
done(null, target);
36+
done(null, inside);
3037
});
3138

3239
var req = request.get({
@@ -39,11 +46,14 @@ exports.download = function(done) {
3946
}
4047

4148
function source() {
42-
var parts = config.get().repository.split('#');
43-
var github = parts[0].match(/^(.*)\/(.*)$/);
44-
return {
45-
user: github[1],
46-
repo: github[2],
47-
branch: parts[1] || 'master'
48-
};
49+
var repository = config.get().repository;
50+
if (repository) {
51+
var parts = repository.split('#');
52+
var github = parts[0].match(/^(.*)\/(.*)$/);
53+
return {
54+
user: github[1],
55+
repo: github[2],
56+
branch: parts[1] || 'master'
57+
};
58+
}
4959
}

0 commit comments

Comments
 (0)