-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
84 lines (82 loc) · 2.6 KB
/
index.js
File metadata and controls
84 lines (82 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var fs = require('fs'),
path = require('path'),
program = require('commander');
var currentPath = path.resolve(__filename,'../');
var errorPrefix = "Vagrantfile Error: ";
/**
* Vagrantfiles Module
*
* @module index.js
*/
module.exports = {
/**
* Checks the status of the Vagrantfile configuration creation
* @param {Function} Callback
* @returns {Number}
*/
checkSuccess: function(cb){
if((bootstrapSuccess === true) && (vagrantfileSuccess === true)){
//console.log("okaynow!");
return cb(null, 1);
}
},
/**
* Request the creation of a Vagrantfile configuration
* @param {Object} Configuration
* @returns {Function}
*/
create: function(configuration, cb){
that = this;
vagrantfileSuccess = false;
bootstrapSuccess = false;
if(typeof(configuration) != "string"){
//throw errorPrefix + "Configuration should be a string"
cb("Configuration should be a string", null);
}
this.copy(configuration, function(err,success){
if (err) cb(err,null)//;throw err;
if (success){
//console.log(success);
cb(null,success);
//console.log(1);
//this.checkSuccess();
}
});
},
copy: function(configuration, cb){
var vagrantfileRS = fs.createReadStream(currentPath+'/vagrantfiles/'+configuration+'/Vagrantfile')
.on('error',function(err){
//throw "Vagrantfile Error: Vagrantfile Configuration Does Not Exist (Yet)"
cb("Vagrantfile Error: Vagrantfile Configuration Does Not Exist (Yet)", null);
})
.on('data',function(data){
fs.writeFile('Vagrantfile', data, function(err){
if(err) cb("Could not write file", null);
else {
vagrantfileSuccess = true;
that.checkSuccess(function(){
cb(null, "Created Vagrantfile and Bootstrap Successfully");
});
}
});
});
var bootstrapRS = fs.createReadStream(currentPath+'/vagrantfiles/'+configuration+'/bootstrap.sh')
.on('error',function(err){
//throw "Vagrantfile Error: Vagrantfile Configuration Does Not Exist (Yet)"
cb("Vagrantfile Error: Vagrantfile Configuration Does Not Exist (Yet)", null);
})
.on('data',function(data){
//console.log(data.toString());
fs.writeFile('bootstrap.sh', data, function(err){
//if(err) throw err;
if (err) cb(err, null);
else{
bootstrapSuccess = true;
that.checkSuccess(function(){
cb(null, "Created Vagrantfile and Bootstrap Successfully");
});
}
});
});
}
};