|
| 1 | +/** |
| 2 | + * Copyright (c) 2002-2016 "Neo Technology," |
| 3 | + * Network Engine for Objects in Lund AB [http://neotechnology.com] |
| 4 | + * |
| 5 | + * This file is part of Neo4j. |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +var childProcess = require("child_process"); |
| 21 | + |
| 22 | +var BoltKit = function () {}; |
| 23 | + |
| 24 | +BoltKit.prototype.start = function(script, port) { |
| 25 | + var spawn = childProcess.spawn, server, code = -1; |
| 26 | + |
| 27 | + server = spawn('/usr/local/bin/boltstub', ['-v', port, script]); |
| 28 | + server.stdout.on('data', (data) => { |
| 29 | + console.log(`${data}`); |
| 30 | + }); |
| 31 | + server.stderr.on('data', (data) => { |
| 32 | + console.log(`${data}`); |
| 33 | + }); |
| 34 | + |
| 35 | + server.on('close', function (c) { |
| 36 | + code = c; |
| 37 | + }); |
| 38 | + |
| 39 | + server.on('end', function (data) { |
| 40 | + console.log(data); |
| 41 | + }); |
| 42 | + |
| 43 | + server.on('error', function (err) { |
| 44 | + console.log('Failed to start child process:' + err); |
| 45 | + }); |
| 46 | + |
| 47 | + var Server = function(){}; |
| 48 | + //give process some time to exit |
| 49 | + Server.prototype.exit = function(callback) {setTimeout(function(){callback(code);}, 500)}; |
| 50 | + |
| 51 | + return new Server(); |
| 52 | +}; |
| 53 | + |
| 54 | +//Make sure boltstub is started before running |
| 55 | +//user code |
| 56 | +BoltKit.prototype.run = function(callback) { |
| 57 | + setTimeout(callback, 500); |
| 58 | +}; |
| 59 | + |
| 60 | +module.exports = { |
| 61 | + BoltKit: BoltKit |
| 62 | +}; |
| 63 | + |
0 commit comments