Skip to content

Commit c42c0ce

Browse files
phatedactions-user
authored andcommitted
chore: Run prettier
1 parent 7d54ad8 commit c42c0ce

File tree

3 files changed

+62
-58
lines changed

3 files changed

+62
-58
lines changed

README.md

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,30 @@ gulp.registry(registry);
2525

2626
### new UndertakerRegistry([options])
2727

28-
Constructor for the default registry. Inherit from this constructor to build custom registries.
28+
Constructor for the default registry. Inherit from this constructor to build custom registries.
2929

3030
### init(taker)
3131

32-
No-op method that receives the undertaker instance. Useful to set pre-defined tasks using the
33-
`undertaker.task(taskName, fn)` method. Custom registries can override this method when inheriting
32+
No-op method that receives the undertaker instance. Useful to set pre-defined tasks using the
33+
`undertaker.task(taskName, fn)` method. Custom registries can override this method when inheriting
3434
from this default registry.
3535

3636
### get(taskName) => Function
3737

38-
Returns the task with that name or undefined if no task is registered with that name. Useful for custom
39-
task storage. Custom registries can override this method when inheriting from this default registry.
38+
Returns the task with that name or undefined if no task is registered with that name. Useful for custom
39+
task storage. Custom registries can override this method when inheriting from this default registry.
4040

4141
### set(taskName, fn) => [Function]
4242

43-
Adds a task to the registry. If `set` modifies a task, it should return the new task so Undertaker can
44-
properly maintain metadata for the task. Useful for adding custom behavior to every task as it is
45-
registered in the system. Custom registries can override this method when inheriting from this default
43+
Adds a task to the registry. If `set` modifies a task, it should return the new task so Undertaker can
44+
properly maintain metadata for the task. Useful for adding custom behavior to every task as it is
45+
registered in the system. Custom registries can override this method when inheriting from this default
4646
registry.
4747

4848
### tasks() => Object
4949

50-
Returns an object listing all tasks in the registry. Necessary to override if the `get` method is overridden
51-
for custom task storage. Custom registries can override this when when inheriting from this default
50+
Returns an object listing all tasks in the registry. Necessary to override if the `get` method is overridden
51+
for custom task storage. Custom registries can override this when when inheriting from this default
5252
registry.
5353

5454
## Custom Registries
@@ -60,7 +60,7 @@ A registry's prototype should define:
6060

6161
- `init(taker)`: receives the undertaker instance to set pre-defined tasks using the `task(taskName, fn)` method.
6262
- `get(taskName)`: returns the task with that name
63-
or `undefined` if no task is registered with that name.
63+
or `undefined` if no task is registered with that name.
6464
- `set(taskName, fn)`: add task to the registry. If `set` modifies a task, it should return the new task.
6565
- `tasks()`: returns an object listing all tasks in the registry.
6666

@@ -75,7 +75,7 @@ var util = require('util');
7575

7676
var DefaultRegistry = require('undertaker-registry');
7777

78-
function MyRegistry(){
78+
function MyRegistry() {
7979
DefaultRegistry.call(this);
8080
}
8181

@@ -99,7 +99,7 @@ var util = require('util');
9999
var DefaultRegistry = require('undertaker-registry');
100100
var del = require('del');
101101

102-
function CommonRegistry(opts){
102+
function CommonRegistry(opts) {
103103
DefaultRegistry.call(this);
104104

105105
opts = opts || {};
@@ -109,40 +109,46 @@ function CommonRegistry(opts){
109109

110110
util.inherits(CommonRegistry, DefaultRegistry);
111111

112-
CommonRegistry.prototype.init = function(takerInst){
112+
CommonRegistry.prototype.init = function (takerInst) {
113113
var buildDir = this.buildDir;
114114
var exists = fs.existsSync(buildDir);
115115

116-
if(exists){
117-
throw new Error('Cannot initialize common tasks. ' + buildDir + ' directory exists.');
116+
if (exists) {
117+
throw new Error(
118+
'Cannot initialize common tasks. ' + buildDir + ' directory exists.'
119+
);
118120
}
119121

120-
takerInst.task('clean', function(){
122+
takerInst.task('clean', function () {
121123
return del([buildDir]);
122124
});
123-
}
125+
};
124126

125127
module.exports = CommonRegistry;
126128
```
127129

128130
Then to use it in a project:
131+
129132
```javascript
130133
var Undertaker = require('undertaker');
131134
var CommonRegistry = require('myorg-common-tasks');
132135

133136
var taker = new Undertaker(CommonRegistry({ buildDir: '/dist' }));
134137

135-
taker.task('build', taker.series('clean', function build(cb) {
136-
// do things
137-
cb();
138-
}));
138+
taker.task(
139+
'build',
140+
taker.series('clean', function build(cb) {
141+
// do things
142+
cb();
143+
})
144+
);
139145
```
140146

141147
### Sharing Functionalities
142148

143149
By controlling how tasks are added to the registry, you can decorate them.
144150

145-
For example if you wanted all tasks to share some data, you can use a custom registry
151+
For example if you wanted all tasks to share some data, you can use a custom registry
146152
to bind them to that data. Be sure to return the altered task, as per the description
147153
of registry methods above:
148154

@@ -156,7 +162,7 @@ var DefaultRegistry = require('undertaker-registry');
156162
var BuildRegistry = require('./build.js');
157163
var ServeRegistry = require('./serve.js');
158164

159-
function ConfigRegistry(config){
165+
function ConfigRegistry(config) {
160166
DefaultRegistry.call(this);
161167
this.config = config;
162168
}
@@ -165,7 +171,7 @@ util.inherits(ConfigRegistry, DefaultRegistry);
165171

166172
ConfigRegistry.prototype.set = function set(name, fn) {
167173
// The `DefaultRegistry` uses `this._tasks` for storage.
168-
var task = this._tasks[name] = fn.bind(this.config);
174+
var task = (this._tasks[name] = fn.bind(this.config));
169175
return task;
170176
};
171177

@@ -176,24 +182,28 @@ taker.registry(new ServeRegistry());
176182

177183
// `taker.registry` will reset each task in the registry with
178184
// `ConfigRegistry.prototype.set` which will bind them to the config object.
179-
taker.registry(new ConfigRegistry({
180-
src: './src',
181-
build: './build',
182-
bindTo: '0.0.0.0:8888'
183-
}));
184-
185-
taker.task('default', taker.series('clean', 'build', 'serve', function(cb) {
186-
console.log('Server bind to ' + this.bindTo);
187-
console.log('Serving' + this.build);
188-
cb();
189-
}));
185+
taker.registry(
186+
new ConfigRegistry({
187+
src: './src',
188+
build: './build',
189+
bindTo: '0.0.0.0:8888',
190+
})
191+
);
192+
193+
taker.task(
194+
'default',
195+
taker.series('clean', 'build', 'serve', function (cb) {
196+
console.log('Server bind to ' + this.bindTo);
197+
console.log('Serving' + this.build);
198+
cb();
199+
})
200+
);
190201
```
191202

192203
## License
193204

194205
MIT
195206

196-
197207
<!-- prettier-ignore-start -->
198208
[downloads-image]: https://img.shields.io/npm/dm/undertaker-registry.svg?style=flat-square
199209
[npm-url]: https://npmjs.org/package/undertaker-registry

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ DefaultRegistry.prototype.get = function get(name) {
1616
};
1717

1818
DefaultRegistry.prototype.set = function set(name, fn) {
19-
return this._tasks[name] = fn;
19+
return (this._tasks[name] = fn);
2020
};
2121

2222
DefaultRegistry.prototype.tasks = function tasks() {
2323
var self = this;
2424

25-
return Object.keys(this._tasks).reduce(function(tasks, name) {
25+
return Object.keys(this._tasks).reduce(function (tasks, name) {
2626
tasks[name] = self.get(name);
2727
return tasks;
2828
}, {});

test/index.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@ var Registry = require('../');
66

77
function noop() {}
88

9-
describe('undertaker-registry', function() {
10-
11-
describe('constructor', function() {
12-
13-
it('can be constructed with new', function(done) {
9+
describe('undertaker-registry', function () {
10+
describe('constructor', function () {
11+
it('can be constructed with new', function (done) {
1412
var reg = new Registry();
1513
expect(typeof reg.get).toEqual('function');
1614
expect(typeof reg.set).toEqual('function');
1715
expect(typeof reg.tasks).toEqual('function');
1816
done();
1917
});
2018

21-
it('can be constructed without new', function(done) {
19+
it('can be constructed without new', function (done) {
2220
/* eslint new-cap: 0 */
2321
var reg = Registry();
2422
expect(typeof reg.get).toEqual('function');
@@ -28,45 +26,41 @@ describe('undertaker-registry', function() {
2826
});
2927
});
3028

31-
describe('init', function() {
32-
33-
it('is a noop', function(done) {
29+
describe('init', function () {
30+
it('is a noop', function (done) {
3431
var reg = new Registry();
3532
expect(typeof reg.init).toEqual('function');
3633
done();
3734
});
3835
});
3936

40-
describe('get', function() {
41-
42-
it('returns a task from the registry', function(done) {
37+
describe('get', function () {
38+
it('returns a task from the registry', function (done) {
4339
var reg = new Registry();
4440
reg._tasks.test = noop;
4541
expect(reg.get('test')).toEqual(noop);
4642
done();
4743
});
4844
});
4945

50-
describe('set', function() {
51-
52-
it('registers a task', function(done) {
46+
describe('set', function () {
47+
it('registers a task', function (done) {
5348
var reg = new Registry();
5449
reg.set('test', noop);
5550
expect(reg._tasks.test).toEqual(noop);
5651
done();
5752
});
5853

59-
it('returns the task (useful for inheriting)', function(done) {
54+
it('returns the task (useful for inheriting)', function (done) {
6055
var reg = new Registry();
6156
var task = reg.set('test', noop);
6257
expect(task).toEqual(noop);
6358
done();
6459
});
6560
});
6661

67-
describe('tasks', function() {
68-
69-
it('returns an object of task name->functions', function(done) {
62+
describe('tasks', function () {
63+
it('returns an object of task name->functions', function (done) {
7064
var reg = new Registry();
7165
reg.set('test1', noop);
7266
reg.set('test2', noop);

0 commit comments

Comments
 (0)