-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlServer.js
93 lines (78 loc) · 2.27 KB
/
sqlServer.js
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
85
86
87
88
89
90
91
92
93
var fs = require('fs'),
zip = require('machinepack-zip');
var mysqlServer = {
humans: 'Only Broda Noel :(',
unzip: function(ok, err){
// Unzip xampp
console.log('First run... Installing...');
zip.unzip({
source: __dirname + '/lib/xampp.zip',
destination: __dirname + '/lib'
}).exec({
error: function(data) {
console.log('Unzip done with errors');
console.log(data);
if(typeof err === 'function')
err();
},
success: function() {
console.log('Unzip done successfuly');
console.log('Removing zip file');
fs.unlinkSync(__dirname + '/lib/xampp.zip');
if(typeof ok === 'function')
ok();
}
});
},
initConfig: function(params) {
// New my.ini
console.log('Copy base configuration');
fs.createReadStream(__dirname + '/lib/xampp/mysql/bin/my.ini.backup').pipe(fs.createWriteStream(__dirname + '/lib/xampp/mysql/bin/my.ini'));
fs.readFile(__dirname + '/lib/xampp/mysql/bin/my.ini', 'utf8', function (err, data) {
if (err) return console.log(err);
// Replace all #FULLDIR# for ".";
var result = data.replace(/#FULLDIR#/g, __dirname.replace(/\\/g, '/'));
fs.writeFile(__dirname + '/lib/xampp/mysql/bin/my.ini', result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
},
start: function() {
try {
fs.accessSync(__dirname + '/lib/xampp.zip', fs.F_OK);
mysqlServer.unzip(function(){
mysqlServer.initConfig();
mysqlServer.run();
});
} catch (e) {
mysqlServer.run();
}
},
stop: function() {
console.log('Stopping MySQL instance');
const exec = require('child_process').exec;
const child = exec('call ' + __dirname + '/lib/xampp/mysql_stop.bat', function (error, stdout, stderr) {
if (error) {
console.log('ERROR stopping!');
throw error;
}
console.log('stdout', stdout);
console.log('stderr', stderr);
});
},
run: function(){
console.log('Running MySQL instance');
console.log('Ctrl + C to stop');
const exec = require('child_process').exec;
const child = exec('call ' + __dirname + '/lib/xampp/mysql_start.bat', function (error, stdout, stderr) {
if (error) {
console.log('ERROR!');
throw error;
}
console.log('stdout', stdout);
console.log('stderr', stderr);
});
}
};
module.exports = mysqlServer;
mysqlServer.start();