-
Notifications
You must be signed in to change notification settings - Fork 15
/
setup.js
36 lines (32 loc) · 1.22 KB
/
setup.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
var exec = require('child_process').exec;
var sysPath = require('path');
var mkdirp = require('mkdirp');
var fs = require('fs');
var util = require("util");
var mode = process.argv[2];
var execute = function(pathParts, params, callback) {
if (callback === null) callback = function() {};
var path = sysPath.join.apply(null, pathParts);
var command = 'node ' + path + ' ' + params;
console.log('Executing', command);
exec(command, function(error, stdout, stderr) {
if (error !== null) return process.stderr.write(stderr.toString());
console.log(stdout.toString());
});
};
var copy = function(path, targetPath) {
var target = fs.createWriteStream(targetPath);
var original = fs.createReadStream(path);
target.once('open', function(fd){
util.pump(original, target);
});
}
if (mode === 'postinstall') {
console.log("Creating .middlefiddle home directory");
mkdirp.sync(process.env["HOME"] + "/.middlefiddle");
mkdirp.sync(process.env["HOME"] + "/.middlefiddle/sites");
copy(__dirname + "/.middlefiddle/config.json", process.env["HOME"] + "/.middlefiddle/config.json");
} else if (mode === 'test') {
execute(['node_modules', 'mocha', 'bin', 'mocha'],
'--compilers coffee:coffee-script test/*.coffee');
}