Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
Latest commit
57 lines (50 loc) · 1.49 KB
/
Copy pathindex.js
File metadata and controls
57 lines (50 loc) · 1.49 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
'use strict';
constGitHubApi=require("github");
constfs=require("fs");
constnconf=require("nconf");
constHexoHelper=require("./lib/hexoHelper");
constUtil=require("./lib/utils");
nconf.env().argv({
u: {
alias: 'username',
describe: 'GitHub username',
demand: true,
type: 'string'
},
p: {
alias: 'password',
describe: 'GitHub password',
demand: true,
type: 'string'
},
o: {
alias: 'org',
describe: 'GitHub Organisation',
demand: true,
type: 'string'
}
});
constUSERNAME=nconf.get('username');
constPASSWORD=nconf.get('password');
constORG=nconf.get('org');
constgithub=newUtil(USERNAME,PASSWORD,ORG);
constgitHubConnection=github.getConnection();
constr=gitHubConnection.repos.getForOrg({org: ORG})
.then(repositories=>{
constreposNames=repositories.map(repository=>repository.name);
createPostForEachRepository(reposNames);
});
functioncreatePostForEachRepository(names){
constname=names.pop();
console.log("create post for: ",name);
returngithub.getServiceInfo(name)
.then(r=>fs.writeFileSync(`./source/_posts/${name}.md`,HexoHelper.createPost(r),'utf8'))
.then(()=>{
if(names.length===0){
console.log("finished");
}else{
createPostForEachRepository(names);
}
})
.catch(err=>console.error(err));
}