-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathgithub-dev.js
89 lines (66 loc) · 2.05 KB
/
github-dev.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
81
82
83
84
85
86
87
88
89
/* Copyright (c) 2014-2017 Richard Rodger and other contributors, MIT License */
var MOCK_NPM = JSON.parse(process.env.MOCK_NPM || 'false')
var MOCK_INFO = JSON.parse(process.env.MOCK_INFO || 'false')
var MOCK = MOCK_NPM || MOCK_INFO
var TOKEN = process.env.TOKEN || 'NO_TOKEN'
var Seneca = require('seneca')
Seneca({tag: 'github'})
.test('print')
.use('entity')
.use('jsonfile-store', {folder: __dirname+'/../data'})
.use('..',{token:TOKEN})
.add('role:info,need:part',function(args,done){
done()
this.act(
'role:github,cmd:get',
{name:args.name},
function(err,mod){
if( err ) return;
if( mod ) {
return this.act(
'role:info,collect:part,part:github',
{name:args.name,data:this.util.clean(mod.data$())})
}
this.act(
'role:npm,cmd:get', {name:args.name},
function(err,mod){
if( err ) return;
if( mod ) {
this.act(
'role:github,cmd:get',
{name:args.name,giturl:mod.giturl},
function( err, mod ){
if( err ) return;
if( mod ) {
this.act('role:info,collect:part,part:github',
{name:args.name,data:this.util.clean(mod.data$())})
}
})
}
})
})
})
.use('seneca-repl', {port:10050})
.listen(9050)
.client({pin:'role:info', port:9030})
.client({pin:'role:npm', port:9040})
// Run mock services that this service depends on.
if (MOCK) {
var mock = Seneca({tag:'mock'})
.test('print')
.use('entity')
if (MOCK_NPM) {
mock
.listen(9040)
.add('role:npm', function (msg, reply) {
reply({"entity$":{"name":"npm"},"name":"jsonic","version":"0.2.2","giturl":"git://github.com/rjrodger/jsonic.git","desc":"JSON parser that isn't strict","readme":"","id":"jsonic"})
})
}
if (MOCK_INFO) {
mock
.listen(9030)
.add('role:info', function (msg, reply) {
reply()
})
}
}