Skip to content

Commit d688e5d

Browse files
committed
add validator to check for issues in the component.json file
1 parent 4f427c4 commit d688e5d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/builder.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,13 @@ Builder.prototype.append = function(str){
342342
Builder.prototype.json = function(fn){
343343
var self = this;
344344
var cache = this._cache;
345-
345+
346+
// conf has already been validated
346347
if (this.conf) return fn(null, this.conf);
347348

348349
var path = this.path('component.json');
349350
var conf = cache[path];
350-
if (conf) return fn(null, this.conf = conf);
351+
if (conf) return validate(this.conf);
351352

352353
debug('reading %s', path);
353354
fs.readFile(path, 'utf8', function(err, str){
@@ -359,11 +360,17 @@ Builder.prototype.json = function(fn){
359360
self._emittedConfig = true;
360361
self.emit('config');
361362
}
362-
fn(null, self.conf);
363+
validate(self.conf);
363364
} catch (err) {
364365
fn(err);
365366
}
366367
});
368+
369+
function validate(conf){
370+
if(!conf.name) return fn(new Error( path + " attribute \"name\" missing"));
371+
self.conf = conf;
372+
fn(null, conf);
373+
}
367374
};
368375

369376
/**

0 commit comments

Comments
 (0)