nci/lib/reader/loader/json.js

32 lines
587 B
JavaScript
Raw Normal View History

2015-05-18 17:52:01 +00:00
'use strict';
var Steppy = require('twostep').Steppy,
inherits = require('util').inherits,
2016-01-10 13:55:57 +00:00
ParentLoader = require('./base').Loader,
path = require('path'),
fs = require('fs');
2015-05-18 17:52:01 +00:00
2016-01-10 13:55:57 +00:00
function Loader() {
ParentLoader.call(this);
2015-05-18 17:52:01 +00:00
}
2016-01-10 13:55:57 +00:00
inherits(Loader, ParentLoader);
2015-05-18 17:52:01 +00:00
2016-01-10 13:55:57 +00:00
exports.Loader = Loader;
2015-05-18 17:52:01 +00:00
2016-01-10 13:55:57 +00:00
Loader.prototype.ext = 'json';
2015-05-18 17:52:01 +00:00
2016-01-10 13:55:57 +00:00
Loader.prototype._load = function(dir, name, callback) {
var self = this;
Steppy(
function() {
fs.readFile(path.join(dir, name + '.' + self.ext), 'utf8', this.slot())
},
function(err, content) {
this.pass(JSON.parse(content));
},
callback
);
2015-05-18 17:52:01 +00:00
};