-
Notifications
You must be signed in to change notification settings - Fork 8
/
conductor.js
114 lines (97 loc) · 3.68 KB
/
conductor.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const { app } = require('electron')
const path = require('path');
const fs = require('fs')
const Mustache = require('mustache')
const spawn = require('child_process').spawn
const persona = process.env.HOLOSCAPE_PERSONA ? process.env.HOLOSCAPE_PERSONA : "default"
const rootConfigPath = path.join(app.getPath('appData'), 'Holoscape-'+persona)
const configPath = path.join(rootConfigPath, 'conductor-config.toml')
const passphraseSocketPath = path.join(rootConfigPath, 'conductor_login.socket')
const DNA_PORT = process.env.HOLOSCAPE_DNA_PORT ? process.env.HOLOSCAPE_DNA_PORT : 10000
const ADMIN_PORT = process.env.HOLOSCAPE_ADMIN_PORT ? process.env.HOLOSCAPE_ADMIN_PORT : 4435
module.exports = {
configPath,
passphraseSocketPath,
persona: () => {
return persona
},
rootConfigPath: () => {
return rootConfigPath
},
hasConfig: () => {
return fs.existsSync(configPath)
},
adminPort: () => {
return ADMIN_PORT
},
dnaPort: () => {
return DNA_PORT
},
initConfig: (networkConfigToml) => {
const initialConfigTemplate = fs.readFileSync(path.join(__dirname, 'initial_conductor_config.toml'), 'utf8')
const persistenceDir = rootConfigPath
const adminPort = ADMIN_PORT
const passphraseSocket = passphraseSocketPath
const config = Mustache.render(initialConfigTemplate, {adminPort,persistenceDir,networkConfigToml,rootConfigPath,passphraseSocket})
if(!fs.existsSync(rootConfigPath)) {
fs.mkdirSync(rootConfigPath)
}
if(!fs.existsSync(persistenceDir)) {
fs.mkdirSync(persistenceDir)
}
fs.writeFileSync(configPath, config)
},
start: (log, onExit) => {
if(fs.existsSync(passphraseSocketPath)){
fs.unlinkSync(passphraseSocketPath)
}
if (process.platform === "win32") {
run = spawn(path.join(__dirname, "./holochain.exe"), ["-c", "./conductor-config.toml"], {env:{...process.env, RUST_BACKTRACE: 1}})
} else if (process.platform === "darwin") {
run = spawn(path.join(__dirname, "./holochain-darwin"), ["-c", configPath], {env:{...process.env, RUST_BACKTRACE: 'full'}})
} else if (process.platform === "linux") {
if (process.env.HOLOSCAPE_FLAME_GRAPH==="yes")
{
run = spawn("perf", ["record","--call-graph","dwarf",path.join(__dirname, "./holochain-linux"),"-c", configPath], {env:{...process.env, RUST_BACKTRACE: 'full'}})
}
else
{
run = spawn(path.join(__dirname, "./holochain-linux"), ["-c", configPath], {env:{...process.env, RUST_BACKTRACE: 'full'}})
}
}
else {
log('error', "unsupported platform: "+process.platform)
return
}
run.stdout.on('data', data => {
log('info', data.toString())
if (data.toString().indexOf("Listening on http://127.0.0.1:3000") > -1) {
mainWindow.loadFile('ui/index.html')
}
})
run.stderr.on('data', data => log('error', data.toString()))
run.on('exit', (code, signal) => {
if (signal) {
log('info', `holochain process terminated due to receipt of signal ${signal}`)
} else {
log('info', `holochain process terminated with exit code ${code}`)
}
onExit()
})
return run
},
hasBinaries: () => {
let holochain, hc
if (process.platform === "win32") {
holochain = "./holochain.exe"
hc = "./hc.exe"
} else if (process.platform === "darwin") {
holochain = "./holochain-darwin"
hc = "./hc-darwin"
} else if (process.platform === "linux") {
holochain = "./holochain-linux"
hc = "./hc-linux"
}
return fs.existsSync(path.join(__dirname, holochain)) && fs.existsSync(path.join(__dirname, hc))
}
}