-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.js
56 lines (47 loc) · 1.47 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
const fs = require('fs');
const util = require('util');
const config = require('config');
const commandLineArgs = require('command-line-args');
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: 'host', type: String, alias: 'h' },
{ name: 'protocol', type: String, default: 'https' },
{ name: 'dataPath', type: String },
{ name: 'pathname', type: String },
];
const args = commandLineArgs(optionDefinitions);
if (!args.host) {
console.log('--host is required');
return;
}
const DATA_PATH = args.dataPath || config.dataPath;
bitbacket
.useAuth(args.user, args.password)
.useHost(args.host)
.useProtocol(args.protocol)
.usePathname(args.pathname);
async function run(page = 0) {
const list = await loadReposPage(page);
console.log(`Is last page: ${list.isLastPage}`);
if (!list.isLastPage) {
await run(list.nextPageStart);
}
}
rimraf(DATA_PATH)
.then(() => {
console.log('Old data have been removed');
fs.mkdirSync(DATA_PATH);
console.log('Folder for data have been created');
return run();
})
.then(() => {
console.log(`---=== SUCCESS ===---`);
})
.catch(e => {
console.log(`ERROR`);
console.log(e);
});