forked from edewit/keycloak-admin-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.js
executable file
·53 lines (45 loc) · 1.42 KB
/
start.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
#!/usr/bin/env node
const http = require('https');
const fs = require('fs');
const path = require('path');
const { spawn } = require('child_process');
const decompress = require('decompress');
const decompressTargz = require('decompress-targz');
const args = process.argv.slice(2);
const version = args[0] || '11.0.0';
const folder = 'server';
const fileName = path.join(folder, 'keycloak.tar.gz');
const serverPath = path.join(folder, `keycloak-${version}`);
const extension = process.platform === "win32" ? '.bat' : '.sh'
if (!fs.existsSync(folder)) {
fs.mkdirSync(folder);
}
const decompressKeycloak = () =>
decompress(fileName, folder, {
plugins: [
decompressTargz()
]
}).then(() => {
console.log('Files decompressed');
}).catch(e => console.error(e));
;
const run = () => {
const proc = spawn(path.join(serverPath, 'bin', `standalone${extension}`), ['-Djboss.socket.binding.port-offset=100']);
proc.stdout.on('data', (data) => {
console.log(data.toString());
});
}
if (!fs.existsSync(fileName)) {
const file = fs.createWriteStream(fileName);
http.get(`https://downloads.jboss.org/keycloak/${version}/keycloak-${version}.tar.gz`, (response) => {
response.pipe(file)
response.on('end', () => {
console.log('Downloaded keycloak');
decompressKeycloak().then(() => run());
});
});
} else if (!fs.existsSync(serverPath)) {
decompressKeycloak().then(() => run());
} else {
run();
}