mirror of
https://github.com/Febbweiss/ProjectDeployer.git
synced 2026-03-04 22:25:38 +00:00
Refactoring: reorganize files between client and server + initiate deployment
This commit is contained in:
36
server/lib/command_runner.js
Normal file
36
server/lib/command_runner.js
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
var exec = Npm.require('child_process').exec,
|
||||
execSync = function(cmd, options, stdoutHandler, stderrHandler) {
|
||||
exec(cmd,
|
||||
options,
|
||||
Meteor.bindEnvironment(
|
||||
function(error, stdout, stderr) {
|
||||
if( stdout != '' ) {
|
||||
stdoutHandler(stdout);
|
||||
}
|
||||
if( stderr != '' ) {
|
||||
stderrHandler(stderr);
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
var CommandRunner = {
|
||||
run: function( script, deployment, stdout, stderr, counter, callback ) {
|
||||
var command = script[command].cmd.replace('%ROOT_CWD%', DEPLOYMENT_FOLDER).replace('%CWD%', deployment._id),
|
||||
options = script[command].options;
|
||||
options.cwd.replace('%ROOT_CWD%', DEPLOYMENT_FOLDER).replace('%CWD%', deployment._id);
|
||||
|
||||
execSync(command, options, stdout, stderr, function() {
|
||||
counter++;
|
||||
if( counter > script.length ) {
|
||||
if( callback ) {
|
||||
callback();
|
||||
}
|
||||
} else {
|
||||
CommandRunner.run(script, deployment, stdout, stderr, counter, callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
33
server/lib/deployment.service.js
Normal file
33
server/lib/deployment.service.js
Normal file
@@ -0,0 +1,33 @@
|
||||
Deployments = new Mongo.Collection('deployments');
|
||||
|
||||
DeploymentService = {
|
||||
get: function(id) {
|
||||
return Deployments.find({_id: id}, {date: 1});
|
||||
},
|
||||
|
||||
appendLog: function(id, data, error) {
|
||||
Deployments.update({ _id: id },{ $push: {
|
||||
output: {
|
||||
timestamp : new Date().getTime(),
|
||||
data : data
|
||||
}
|
||||
}});
|
||||
},
|
||||
create: function(project, callback) {
|
||||
return Deployment.insert({
|
||||
project_id: projet._id,
|
||||
timestamp: new Date().getTime(),
|
||||
output: []
|
||||
}, function(errors, deploymentId) {
|
||||
_execSync(cmd, function(data) {
|
||||
DeploymentService.appendLog(deploymentId, data, false);
|
||||
}, function(data) {
|
||||
DeploymentService.appendLog(deploymentId, data, true);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
deploy: function(project) {
|
||||
|
||||
}
|
||||
}
|
||||
27
server/lib/projects.methods.js
Normal file
27
server/lib/projects.methods.js
Normal file
@@ -0,0 +1,27 @@
|
||||
Meteor.methods({
|
||||
listProjects: function() {
|
||||
return ProjectService.list();
|
||||
},
|
||||
|
||||
getProject: function(id) {
|
||||
return ProjectService.get(id);
|
||||
},
|
||||
|
||||
addProject: function(label, git_url, public_url ,commands) {
|
||||
return ProjectService.insert(label, git_url, public_url ,commands, function(errors, id) {
|
||||
if( id ) {
|
||||
/*DeploymentService.deploy(ProjectService.get(id), function(errors, deploymentId) {
|
||||
|
||||
});*/
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
editProject: function(id, label, git_url, public_url ,commands) {
|
||||
ProjectService.update(id, label, git_url, public_url ,commands);
|
||||
},
|
||||
|
||||
deleteProject: function(id) {
|
||||
ProjectService.delete(id);
|
||||
}
|
||||
});
|
||||
37
server/lib/projects.service.js
Normal file
37
server/lib/projects.service.js
Normal file
@@ -0,0 +1,37 @@
|
||||
Projects = new Mongo.Collection('projects');
|
||||
|
||||
ProjectService = {
|
||||
insert: function(label, git_url, public_url, commands, callback) {
|
||||
Projects.insert({
|
||||
label: label,
|
||||
git_url: git_url,
|
||||
public_url: public_url,
|
||||
commands: commands
|
||||
}, callback);
|
||||
},
|
||||
|
||||
update: function(id, label, git_url, public_url ,commands) {
|
||||
Projects.update(
|
||||
id,
|
||||
{ $set: {
|
||||
label: label,
|
||||
git_url: git_url,
|
||||
public_url: public_url,
|
||||
commands: commands
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
delete: function(id) {
|
||||
Projects.remove(id);
|
||||
},
|
||||
|
||||
get: function(id) {
|
||||
return Projects.findOne({_id: id});
|
||||
},
|
||||
|
||||
list: function() {
|
||||
return Projects.find({}, {sort: {label: 1}});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user