add yaml configs support

This commit is contained in:
oleg 2015-05-18 23:27:02 +03:00
parent bf97e2c7c5
commit bfc877bba5
8 changed files with 84 additions and 30 deletions

22
app.js
View File

@ -32,6 +32,8 @@ var app = {
dataio: dataio
};
app.lib = {};
app.lib.reader = reader;
Steppy(
function() {
@ -46,20 +48,26 @@ Steppy(
fs.exists(app.config.paths.builds, function(isExists) {
stepCallback(null, isExists);
});
},
function(err, isBuildsDirExists) {
if (!isBuildsDirExists) {
fs.mkdir(app.config.paths.builds, this.slot());
} else {
this.pass(null);
}
// register plugins
require('./lib/reader/yaml').register(app);
reader.load(app.config.paths.data, 'config', this.slot());
},
function(err, isBuildsDirExists, config) {
if (!isBuildsDirExists) {
fs.mkdir(app.config.paths.builds, this.slot());
}
function(err, mkdirResult, config) {
_(app.config).defaults(config);
console.log('Server config:', JSON.stringify(app.config.nodes, null, 4));
console.log('Server config:', JSON.stringify(app.config, null, 4));
// init resources
require('./resources')(app);
},
function(err) {
if (err) throw err;

View File

@ -1,6 +0,0 @@
{
"nodes": [{
"type": "local",
"maxExecutorsCount": 1
}]
}

4
data/config.yaml Normal file
View File

@ -0,0 +1,4 @@
nodes:
- type: local
maxExecutorsCount: 1

View File

@ -1,16 +0,0 @@
{
"name": "project1",
"scm": {
"type": "mercurial",
"repository": "./test/repos/mercurial",
"rev": "default"
},
"steps": [
{"type": "shell", "cmd": "sleep 2 && echo \"hello, cur dir is `pwd`\""},
{"type": "shell", "name": "sleep", "cmd": "sleep 4"},
{"type": "shell", "cmd": "echo 1 > 1.txt"},
{"type": "shell", "cmd": "sleep 4"},
{"type": "shell", "cmd": "echo 2 > 2.txt"},
{"type": "shell", "cmd": "cat 1.txt 2.txt"}
]
}

View File

@ -0,0 +1,26 @@
name: project1
scm:
type: mercurial
repository: ./test/repos/mercurial
rev: default
steps:
- type: shell
cmd: >
echo "long multiline string" &&
sleep 2 &&
echo "is not a problem when you're using yaml" &&
echo "cur dir is `pwd`"
- type: shell
name: sleep
cmd: sleep 4
- type: shell
cmd: echo 1 > 1.txt
- type: shell
cmd: sleep 4
- type: shell
cmd: echo 2 > 2.txt
- type: shell
cmd: cat 1.txt 2.txt

View File

@ -30,7 +30,7 @@ gulp.task('develop', function() {
return nodemon({
ignore: ['static/**/*.js', 'app/**/*.js', 'node_modules/**'],
script: 'app.js',
ext: 'js,json'
ext: 'js,json,yaml'
});
});

37
lib/reader/yaml.js Normal file
View File

@ -0,0 +1,37 @@
'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

@ -29,6 +29,7 @@
"dependencies": {
"data.io": "0.3.0",
"jade": "1.9.2",
"js-yaml": "3.3.1",
"nlevel": "1.0.2",
"node-static": "0.7.6",
"socket.io": "1.3.5",