This repository was archived by the owner on Apr 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathgetContent.ts
More file actions
86 lines (75 loc) · 1.92 KB
/
getContent.ts
File metadata and controls
86 lines (75 loc) · 1.92 KB
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
81
82
83
84
85
86
/// <reference path="_ref.d.ts" />
'use strict';
import Promise = require('bluebird');
import path = require('path');
import fileIO = require('./xm/fileIO');
import tsd = require('./api');
import API = require('./tsd/API');
function getAPI(options): API {
var api = tsd.getAPI(options.config, options.verbose);
if (options.cacheDir) {
api.context.paths.cacheDir = path.resolve(options.cacheDir);
}
return api;
}
function getContent(options): Promise<any> {
var api = getAPI(options);
return api.readConfig(false).then(() => {
var opts = new tsd.Options();
opts.resolveDependencies = false;
var query = new tsd.Query();
query.addNamePattern('*');
query.setVersionRange('all');
query.parseInfo = true;
return api.select(query, opts);
}).then((selection) => {
return selection.definitions.filter((def) => {
return !def.isLegacy && def.isMain;
}).sort(tsd.defUtil.defCompare).map((def) => {
var ret: any = {
project: def.project,
name: def.name,
path: def.path,
semver: (def.semver || 'latest')
};
if (def.head.info) {
ret.info = def.head.info;
}
if (def.head.dependencies) {
ret.dependencies = def.head.dependencies.map((dep) => {
var ret: any = {
project: dep.project,
name: dep.name,
path: dep.path,
semver: (dep.semver || 'latest')
};
return ret;
});
}
if (def.releases) {
ret.releases = def.releases.map((rel) => {
var ret: any = {
path: rel.path,
semver: (rel.semver || null)
};
return ret;
});
}
return ret;
});
}).then((content) => {
var ret: any = {
repo: api.context.config.repo,
ref: api.context.config.ref,
githubHost: api.context.config.githubHost,
count: content.length,
time: new Date().toISOString()
};
ret.urls = {
def: ret.githubHost + '/' + ret.repo + '/blob/' + ret.ref + '/{path}'
};
ret.content = content;
return ret;
});
}
export = getContent;