mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-11 05:29:16 +00:00
add basic project config validation
This commit is contained in:
parent
6e6f19b07d
commit
969e3633f2
@ -7,14 +7,55 @@ var Steppy = require('twostep').Steppy,
|
|||||||
reader = require('./reader'),
|
reader = require('./reader'),
|
||||||
db = require('../db'),
|
db = require('../db'),
|
||||||
utils = require('./utils'),
|
utils = require('./utils'),
|
||||||
SpawnCommand = require('./command/spawn').Command;
|
SpawnCommand = require('./command/spawn').Command,
|
||||||
|
validateParams = require('./validateParams');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates and returns given `config` to the `callback`(err, config)
|
* Validates and returns given `config` to the `callback`(err, config)
|
||||||
*/
|
*/
|
||||||
exports.validateConfig = function(config, callback) {
|
exports.validateConfig = function(config, callback) {
|
||||||
callback(null, config);
|
Steppy(
|
||||||
|
function() {
|
||||||
|
validateParams(config, {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
scm: {
|
||||||
|
type: 'object',
|
||||||
|
required: true,
|
||||||
|
properties: {
|
||||||
|
type: {enum: ['git', 'mercurial'], required: true},
|
||||||
|
repository: {type: 'string', required: true},
|
||||||
|
rev: {type: 'string', required: true}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
steps: {
|
||||||
|
type: 'array',
|
||||||
|
required: true,
|
||||||
|
items: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
cmd: {type: 'string', required: true},
|
||||||
|
shell: {type: 'string'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
additionalProperties: true
|
||||||
|
});
|
||||||
|
|
||||||
|
this.pass(null);
|
||||||
|
},
|
||||||
|
function(err) {
|
||||||
|
if (err) {
|
||||||
|
err.message = (
|
||||||
|
'Error during validation of project "' + config.name +
|
||||||
|
'": ' + err.message
|
||||||
|
);
|
||||||
|
}
|
||||||
|
callback(err, config);
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,13 +70,11 @@ exports.load = function(baseDir, name, callback) {
|
|||||||
function(err, dirContent) {
|
function(err, dirContent) {
|
||||||
exports.loadConfig(dir, this.slot());
|
exports.loadConfig(dir, this.slot());
|
||||||
},
|
},
|
||||||
function(err, config) {
|
|
||||||
exports.validateConfig(config, this.slot());
|
|
||||||
},
|
|
||||||
function(err, config) {
|
function(err, config) {
|
||||||
config.name = name;
|
config.name = name;
|
||||||
config.dir = dir;
|
config.dir = dir;
|
||||||
this.pass(config);
|
|
||||||
|
exports.validateConfig(config, this.slot());
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
);
|
);
|
||||||
@ -79,10 +118,10 @@ exports.loadConfig = function(dir, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply defaults
|
// apply defaults to not yet validated config
|
||||||
_(config.steps).each(function(step) {
|
_(config.steps).each(function(step) {
|
||||||
if (!step.type) step.type = 'shell';
|
if (!step.type) step.type = 'shell';
|
||||||
if (!step.name) step.name = utils.prune(step.cmd, 40);
|
if (!step.name && step.cmd) step.name = utils.prune(step.cmd, 40);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.pass(config);
|
this.pass(config);
|
||||||
|
@ -51,7 +51,8 @@
|
|||||||
"socket.io": "1.3.5",
|
"socket.io": "1.3.5",
|
||||||
"twostep": "0.4.1",
|
"twostep": "0.4.1",
|
||||||
"underscore": "1.8.3",
|
"underscore": "1.8.3",
|
||||||
"through": "2.3.6"
|
"through": "2.3.6",
|
||||||
|
"conform": "0.2.12"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"bower": "1.4.1",
|
"bower": "1.4.1",
|
||||||
|
Loading…
Reference in New Issue
Block a user