mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-10 23:45:07 +00:00
add yaml configs support
This commit is contained in:
parent
bf97e2c7c5
commit
bfc877bba5
22
app.js
22
app.js
@ -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;
|
||||
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"nodes": [{
|
||||
"type": "local",
|
||||
"maxExecutorsCount": 1
|
||||
}]
|
||||
}
|
4
data/config.yaml
Normal file
4
data/config.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
nodes:
|
||||
- type: local
|
||||
maxExecutorsCount: 1
|
@ -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"}
|
||||
]
|
||||
}
|
26
data/projects/project1/config.yaml
Normal file
26
data/projects/project1/config.yaml
Normal 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
|
@ -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
37
lib/reader/yaml.js
Normal 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
|
||||
);
|
||||
};
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user