diff --git a/app.js b/app.js index e3cdfa2..b3bdd31 100644 --- a/app.js +++ b/app.js @@ -4,7 +4,10 @@ var http = require('http'), nodeStatic = require('node-static'), jade = require('jade'), path = require('path'), - fs = require('fs'); + fs = require('fs'), + Steppy = require('twostep').Steppy, + _ = require('underscore'), + reader = require('./lib/reader'); var staticServer = new nodeStatic.Server('./static'); var server = http.createServer(function(req, res, next) { @@ -29,17 +32,38 @@ var app = { dataio: dataio }; -app.config = {}; -app.config.paths = {}; -// path to root dir (with projects, builds etc) -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'); -fs.exists(app.config.paths.builds, function(exists) { - if (!exists) fs.mkdir(app.config.paths.builds); -}); +Steppy( + function() { + app.config = {}; + app.config.paths = {}; -require('./resources')(app); + // path to root dir (with projects, builds etc) + 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(); + fs.exists(app.config.paths.builds, function(isExists) { + stepCallback(null, isExists); + }); + + reader.load(app.config.paths.data, 'config', this.slot()); + }, + function(err, isBuildsDirExists, config) { + if (!isBuildsDirExists) { + fs.mkdir(app.config.paths.builds, this.slot()); + } + + _(app.config).defaults(config); + + console.log('Server config:', JSON.stringify(app.config.nodes, null, 4)); + + require('./resources')(app); + + }, + function(err) { + if (err) throw err; + } +); app.server.listen(3000); diff --git a/data/config.json b/data/config.json new file mode 100644 index 0000000..d387631 --- /dev/null +++ b/data/config.json @@ -0,0 +1,6 @@ +{ + "nodes": [{ + "type": "local", + "maxExecutorsCount": 1 + }] +} \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 6e3ff05..9c82a86 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -30,7 +30,7 @@ gulp.task('develop', function() { return nodemon({ ignore: ['static/**/*.js', 'app/**/*.js', 'node_modules/**'], script: 'app.js', - ext: 'js' + ext: 'js,json' }); }); diff --git a/resources/projects.js b/resources/projects.js index d093d8d..e4daabe 100644 --- a/resources/projects.js +++ b/resources/projects.js @@ -27,7 +27,7 @@ module.exports = function(app) { }); var distributor = new Distributor({ - nodes: [{type: 'local', maxExecutorsCount: 1}], + nodes: app.config.nodes, saveBuild: function(build, callback) { Steppy( function() {