/
m4j
executable file
·78 lines (64 loc) · 2.02 KB
/
m4j
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
#!/usr/bin/env node
var child_process = require('child_process')
var fs = require('fs')
var instructions = "Install Neo4j with Homebrew\n\n" +
"brew install neo4j\n\n" +
"Export a NEO4J_PATH environment variable. You might want to put in your .bashrc. " +
"It might look like this:\n\n" +
"export NEO4J_PATH=/usr/local/Cellar/neo4j/2.1.7";
function help() {
console.log(instructions);
}
function neo4jPath() {
// export NEO4J_PATH=/usr/local/Cellar/neo4j/2.1.7
var n4j = process.env.NEO4J_PATH
if (!n4j)
throw new Error("Please create an environment variable, NEO4J_PATH.")
if (n4j[n4j.length-1] != '/')
n4j += '/'
return n4j
}
function getAppDir() {
var dir = process.cwd()
var path = dir.split('/')
while (path.length > 0) {
dir = path.join('/')
if (fs.existsSync(dir + '/.meteor/'))
return dir + '/'
else
path.splice(path.length-1,1)
}
throw new Error("Couldn't find a Meteor app on your path.")
}
function setNeo4jPath() {
// org.neo4j.server.database.location=data/graph.db
var dbPath = getAppDir() + '.meteor/local/neo4j/graph.db'
var file = neo4jPath() + 'libexec/conf/neo4j-server.properties'
var data = fs.readFileSync(file, {encoding:'utf8'})
var result = data.replace(/org\.neo4j\.server\.database\.location=.*/,
'org.neo4j.server.database.location='+dbPath);
fs.writeFileSync(file, result, {encoding:'utf8'})
}
function exec(name, args) {
var child = child_process.spawn(name, args)
child.stdout.on('data', function (data) { process.stdout.write(data.toString()); });
child.stderr.on('data', function (data) { process.stdout.write(data.toString()); });
}
function startNeo4j() {
exec('neo4j', ['start-no-wait'])
}
function stopNeo4j() {
exec('neo4j', ['stop'])
}
var args = process.argv
args.splice(0,2)
if (args[0] == '--help') {
help()
}
if (args[0] == 'start') {
setNeo4jPath()
startNeo4j()
}
if (args[0] == 'stop') {
stopNeo4j()
}