-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.js
66 lines (58 loc) · 1.79 KB
/
load.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
const fs = require('fs');
const util = require('util');
const commandLineArgs = require('command-line-args');
const config = require('config');
const rimraf = util.promisify(require('rimraf'));
const loadReposPage = require('./src/util/load-repo-part');
const bitbacket = require('./src/resource/bitbucket');
const optionDefinitions = [
{ name: 'user', type: String, alias: 'u' },
{ name: 'password', type: String, alias: 'p' },
{ name: 'basic', type: String, alias: 'b' },
{ name: 'host', type: String, alias: 'h' },
{ name: 'protocol', type: String },
{ name: 'pathname', type: String },
{ name: 'dataPath', type: String, default: config.dataPath }
];
const args = commandLineArgs(optionDefinitions);
if (!args.host) {
console.log('--host is required');
return;
}
if (args.basic) {
bitbacket.userBasic(args.basic);
} else {
bitbacket.useAuth(args.user, args.password);
}
bitbacket
.setApi({
protocol: 'https',
pathname: '/rest/api/1.0'
})
.useHost(args.host)
.useProtocol(args.protocol)
.usePathname(args.pathname);
async function run(page = 0) {
const list = await loadReposPage(page, args.dataPath);
console.log(`Next page: ${list.nextPageStart}. Is last page: ${!!list.isLastPage}`);
if (!list.isLastPage) {
await run(list.nextPageStart);
}
}
const TIME_LABEL = 'Loading time';
rimraf(args.dataPath)
.then(() => {
console.log('Old data have been removed');
fs.mkdirSync(args.dataPath);
console.log('Folder for data have been created');
console.time(TIME_LABEL);
return run();
})
.then(() => {
console.log(`---=== SUCCESS ===---`);
console.timeEnd(TIME_LABEL);
})
.catch(e => {
console.log(`ERROR`);
console.log(e);
});