Skip to content

Commit bcf7372

Browse files
authored
Merge pull request #9 from EliasJorgensen/npmToJs
Rewrite npm Docker scripts in JavaScript to make them run on Windows
2 parents 66818b1 + 68d26c1 commit bcf7372

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
22
server/db/
3+
npm-debug.log

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"start": "node index.js",
8-
"db:start": "docker run -d -p 28015:28015 -p 8090:8080 -v $PWD/db:/data --name expertsdb rethinkdb",
8+
"db:start": "node util/db/start",
99
"db:stop": "docker stop expertsdb",
1010
"db:rm": "docker rm expertsdb",
1111
"test": "eslint src/ && node test/index.js | tap-spec"

server/util/db/start.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* eslint no-console: 0 */
2+
3+
// node module
4+
const exec = require('child_process').exec;
5+
const path = require('path');
6+
7+
// dir to store the data in
8+
const dbPath = path.join(__dirname, '..', '..', 'db');
9+
10+
// docker run command
11+
const cmd = `docker run -d -p 28015:28015 -p 8090:8080 -v ${dbPath}:/data --name expertsdb rethinkdb`;
12+
13+
// execute command
14+
const start = exec(cmd);
15+
16+
// remember if docker is installing image
17+
let dbImage = false;
18+
19+
// runs when command writes to stdout
20+
start.stdout.on('data', (data) => {
21+
if (data) {
22+
console.log('Sucessfully created expertsdb\n');
23+
}
24+
});
25+
26+
// runs when command writes to stderr
27+
start.stderr.on('data', (data) => {
28+
if (data === "Unable to find image 'rethinkdb:latest' locally\n" || dbImage) {
29+
console.log(data);
30+
dbImage = true;
31+
} else {
32+
console.log('Error while creating expertsdb:', data);
33+
}
34+
});

0 commit comments

Comments
 (0)