add sample projects and their loading

This commit is contained in:
oleg 2015-04-13 01:19:42 +03:00
parent cea9e7b1fb
commit bea76d8873
4 changed files with 58 additions and 3 deletions

View File

@ -1,8 +1,9 @@
'use strict';
var Steppy = require('Steppy'),
var Steppy = require('twostep').Steppy,
fs = require('fs'),
path = require('path');
path = require('path'),
_ = require('underscore');
function Project(config) {
this.config = config;
@ -34,7 +35,25 @@ exports.load = function(baseDir, name, callback) {
exports.validateConfig(config, this.slot());
},
function(err, config) {
this.pass(new Project(confg));
this.pass(new Project(config));
},
callback
);
};
/**
* Loads all projects from `baseDir` and returns array of project instances
*/
exports.loadAll = function(baseDir, callback) {
Steppy(
function() {
fs.readdir(baseDir, this.slot());
},
function(err, dirs) {
var loadGroup = this.makeGroup();
_(dirs).each(function(dir) {
exports.load(baseDir, dir, loadGroup.slot());
});
},
callback
);

View File

@ -0,0 +1,12 @@
{
"name": "project1",
"scm": {
"type": "mercurial",
"repository": "./test/repos/mercurial",
"rev": "default"
},
"steps": [
{"type": "shell", "cmd": "echo 1 > 1.txt"},
{"type": "shell", "cmd": "echo 2 > 2.txt"}
]
}

View File

@ -0,0 +1,12 @@
{
"name": "project2",
"scm": {
"type": "mercurial",
"repository": "./test/repos/mercurial",
"rev": "1"
},
"steps": [
{"type": "shell", "cmd": "echo 11 > 11.txt"},
{"type": "shell", "cmd": "echo 22 > 22.txt"}
]
}

View File

@ -1,5 +1,17 @@
'use strict';
var _ = require('underscore'),
project = require('../lib/project');
var projects;
project.loadAll('projects', function(err, loadedProjects) {
if (err) throw err;
projects = loadedProjects;
console.log('Loaded projects: ', _(projects).map(function(project) {
return project.config.name;
}));
});
module.exports = function(data) {
var projects = [{
name: 'foo'