move yaml reader to separate repository

This commit is contained in:
oleg 2015-07-06 01:02:37 +03:00
parent 748008fbed
commit e92c5de80b
5 changed files with 25 additions and 44 deletions

22
app.js
View File

@ -53,20 +53,32 @@ Steppy(
app.config.paths.data = path.join(process.cwd(), 'data');
app.config.paths.projects = path.join(app.config.paths.data, 'projects');
app.config.paths.builds = path.join(app.config.paths.data, 'builds');
var stepCallback = this.slot();
app.config.paths.preload = path.join(app.config.paths.data, 'preload.json');
var buildDirExistsCallback = this.slot();
fs.exists(app.config.paths.builds, function(isExists) {
stepCallback(null, isExists);
buildDirExistsCallback(null, isExists);
});
var preloadExistsCallback = this.slot();
fs.exists(app.config.paths.preload, function(isExists) {
preloadExistsCallback(null, isExists);
});
},
function(err, isBuildsDirExists) {
function(err, isBuildsDirExists, isPreloadExists) {
if (!isBuildsDirExists) {
fs.mkdir(app.config.paths.builds, this.slot());
} else {
this.pass(null);
}
// register reader plugins
require('./lib/reader/yaml').register(app);
if (isPreloadExists) {
var preload = require(app.config.paths.preload);
// register rc plugins
_(preload.plugins).each(function(plugin) {
require(plugin).register(app);
});
}
reader.load(app.config.paths.data, 'config', this.slot());
},

3
data/preload.json Normal file
View File

@ -0,0 +1,3 @@
{
"plugins": ["nci-yaml-reader"]
}

View File

@ -3,12 +3,15 @@
var Steppy = require('twostep').Steppy,
_ = require('underscore'),
fs = require('fs'),
path = require('path');
path = require('path'),
BaseReader = require('./base').Reader;
var constructors = {
json: require('./json').Reader
};
exports.BaseReader = BaseReader;
exports.register = function(ext, constructor) {
constructors[ext] = constructor;
};

View File

@ -1,37 +0,0 @@
'use strict';
var Steppy = require('twostep').Steppy,
inherits = require('util').inherits,
ParentReader = require('./base').Reader,
fs = require('fs'),
path = require('path'),
yaml = require('js-yaml');
function Reader() {
ParentReader.call(this);
}
inherits(Reader, ParentReader);
Reader.prototype.ext = 'yaml';
exports.register = function(app) {
app.lib.reader.register(Reader.prototype.ext, Reader);
};
Reader.prototype._load = function(dir, name, callback) {
var self = this;
Steppy(
function() {
var filePath = path.join(dir, name + '.' + self.ext);
fs.readFile(filePath, 'utf8', this.slot());
},
function(err, text) {
var content = yaml.load(text);
this.pass(content);
},
callback
);
};

View File

@ -32,7 +32,6 @@
"colors": "1.1.2",
"data.io": "0.3.0",
"jade": "1.9.2",
"js-yaml": "3.3.1",
"nlevel": "1.0.2",
"node-static": "0.7.6",
"nodemailer": "1.4.0",
@ -50,6 +49,7 @@
"main-bower-files": "2.7.0",
"memdown": "1.0.0",
"mocha": "1.18.2",
"nci-yaml-reader": "0.1.0",
"nodemon": "1.3.7",
"sinon": "1.14.1"
}