Skip to content

Commit a8f6bdd

Browse files
committed
refactor start.js for clarity
1 parent 1125b46 commit a8f6bdd

2 files changed

Lines changed: 36 additions & 26 deletions

File tree

lib/github.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ module.exports = function (options) {
2222
seneca.add('role:github,cmd:parse', cmdParse)
2323
seneca.add('role:github,cmd:extract', cmdExtract)
2424

25+
seneca.add('role:info,req:part', function (args, done) {
26+
console.log('foo')
27+
done()
28+
29+
this.act('role:github,cmd:get', {name: args.name}, function (err, mod) {
30+
if (err) {
31+
return done(err)
32+
}
33+
this.act('role:info,res:part,part:github', {name: args.name, data: mod.data$()})
34+
})
35+
})
36+
2537
return {
2638
name: 'nodezoo-github'
2739
}

srv/start.js

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
'use strict'
22

3-
// your github token can be stored in an env variable named token,
4-
// and will be picked up here
3+
var Seneca = require('seneca')
4+
var Entities = require('seneca-entity')
5+
var Mesh = require('seneca-mesh')
6+
var Github = require('../lib/github')
57

6-
var GITHUB_TOKEN = process.env.GITHUB_TOKEN || ''
8+
var envs = process.env
9+
var opts = {
10+
seneca: {
11+
tag: envs.GITHUB_TAG || 'nodezoo-github'
12+
},
13+
github: {
14+
token: envs.GITHUB_TOKEN || ''
15+
},
16+
mesh: {
17+
auto: true,
18+
listen: [
19+
{pin: 'role:github,cmd:get', model: 'consume'},
20+
{pin: 'role:info,req:part', model: 'observe'}
21+
]
22+
}
23+
}
724

8-
require('seneca')()
9-
.use('entity')
10-
.use('../github.js', {token: GITHUB_TOKEN})
11-
.add('role:info,req:part', function (args, done) {
12-
done()
13-
14-
this.act('role:github,cmd:get', {name: args.name}, function (err, mod) {
15-
if (err) {
16-
return done(err)
17-
}
18-
this.act('role:info,res:part,part:github', {name: args.name, data: mod.data$()})
19-
})
20-
})
21-
22-
.add('role:github,info:change', function (args, done) {
23-
done()
24-
this.act('role:info,cmd:get', {name: args.name, update: true})
25-
})
26-
.use('mesh', {
27-
auto: true,
28-
pin: ['role:github', 'role:info,req:part'],
29-
model: 'publish'
30-
})
25+
Seneca(opts.seneca)
26+
.use(Entities)
27+
.use(Github, opts.github)
28+
.use(Mesh, opts.mesh)

0 commit comments

Comments
 (0)