This repository has been archived by the owner on Jun 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfiles.js
80 lines (73 loc) · 2.31 KB
/
files.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var fs = require('fs'),
zip = require('adm-zip'),
markdown = require('markdown').markdown;
var Utils = require('./utils');
module.exports.fetchChangelog = function(details, callback){
/*
Utils.Clone(details.github_repo, details.curse, function(err, path){
if(err)
callback(err);
else {
var filePath = path + '/' + details.changelogPath;
fs.stat(filePath, function(err, stats){
if(stats && stats.isFile()){
fs.readFile(filePath, {encoding: details.encoding || 'utf8'}, function(rerr, data){
if(rerr)
callback(rerr);
else
callback(null, data);
});
} else
callback(new Error(Utils.Strings.CHANGELOG_MISSING.replace('%s', details.changelogPath)));
});
}
});
*/
var archive = new zip(details.path + '-' + details.tag + '.zip');
var file = archive.getEntry(details.path + '/' + (details.changelogPath || 'CHANGELOG.md'));
if(file)
callback(null, archive.readAsText(file));
else
callback(new Error(Utils.Strings.CHANGELOG_MISSING.replace('%s', details.changelogPath)));
}
module.exports.formatChangelog = function(data){
return Utils.HTMLToBBCode(markdown.toHTML(data));
}
module.exports.getInterfaceVersion = function(details, callback){
/*
Utils.Clone(details.github_repo, details.curse, function(err, path){
if(err)
callback(err);
else {
var filePath = path + '/' + details.path + '.toc';
fs.stat(filePath, function(err, stats){
if(stats && stats.isFile()){
fs.readFile(filePath, {encoding: details.encoding || 'utf8'}, function(rerr, data){
if(rerr)
callback(rerr);
else {
var interfaceVersion = data.match(/Interface: ?(.+)/);
if(!interfaceVersion)
callback(new Error(Utils.Strings.INTERFACE_VERSION_MISSING));
else
callback(null, interfaceVersion[1]);
}
});
} else
callback(new Error(Utils.Strings.TOC_MISSING));
});
}
});
*/
var archive = new zip(details.path + '-' + details.tag + '.zip');
var file = archive.getEntry(details.path + '/' + details.path + '.toc');
if(file){
var contents = archive.readAsText(file);
var interfaceVersion = contents.match(/Interface: ?(.+)/);
if(!interfaceVersion)
callback(new Error(Utils.Strings.INTERFACE_VERSION_MISSING));
else
callback(null, interfaceVersion[1]);
} else
callback(new Error(Utils.Strings.TOC_MISSING));
}