Skip to content

Commit 2e05aa6

Browse files
authored
Merge pull request #1 from clemy/packaging
Feature: Delivery Package Creation
2 parents 87c0760 + f62e0ad commit 2e05aa6

File tree

6 files changed

+1044
-31
lines changed

6 files changed

+1044
-31
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
node_modules/
2+
3+
# files from build
4+
/prexvis
5+
/prexvis-*.tgz

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,32 @@ chrome http://localhost:3000/
4343
| `./bin/aalwines` | binary of AalWiNes tool |
4444
| `./bin/moped` | binary of moped tool |
4545

46+
## Building a binary delivery package
47+
48+
Building a package containing a binary delivery can easily be done with the command
49+
50+
```bash
51+
npm run pack
52+
```
53+
54+
The delivery package including aalwines, moped, sample data and the prexvis binary is in:
55+
56+
`./prexvis-0.1.0.tgz`
57+
58+
Beside the prexvis tool it includes everything necessary to run it: nodejs, aalwines, moped and sample data.
59+
60+
Unpack it, run the binary and use your browser to go to http://localhost:3000/
61+
62+
```bash
63+
tar -xzvf prexvis-0.1.0.tgz
64+
cd prexvis-0.1.0
65+
./prexvis
66+
67+
# browse to http://localhost:3000/
68+
```
69+
70+
Own sample data can be added in the directory `data/models`.
71+
4672
## Optional Requirements
4773

4874
### PM2 (optional)

app.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ const path = require('path');
44
const http = require('http').createServer(app);
55
const io = require('socket.io')(http);
66

7-
const modelsPath = path.join(__dirname, 'data', 'models');
8-
const binPath = path.join(__dirname, 'bin');
7+
console.log('prexvis - Visualization for AaalWiNes');
8+
console.log(' Version 0.1.0');
9+
10+
const modelsPath = path.join(process.cwd(), 'data', 'models');
11+
const binPath = path.join(process.cwd(), 'bin');
912
const models = require('./backend/models')(modelsPath, binPath, models => {
1013
io.emit('models', models);
1114
});
@@ -38,5 +41,6 @@ app.use(function(req, res) {
3841
});
3942

4043
http.listen(3000, function() {
41-
console.log('Listening on port 3000!');
44+
console.log();
45+
console.log('Start your browser and go to http://localhost:3000/');
4246
});

backend/models.js

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,40 @@ const path = require('path');
66
const tmp = require('tmp-promise');
77

88
class Models {
9-
#modelsPath;
10-
#binPath;
11-
#models = [];
12-
#cb;
13-
149
constructor(modelsPath, binPath, cb) {
15-
this.#modelsPath = modelsPath;
16-
this.#binPath = binPath;
17-
this.#cb = cb;
10+
this._modelsPath = modelsPath;
11+
this._binPath = binPath;
12+
this._cb = cb;
13+
this._models = [];
1814
const onChange = async () => {
1915
try {
20-
var items = await fsp.readdir(this.#modelsPath, { withFileTypes: true });
16+
var items = await fsp.readdir(this._modelsPath, { withFileTypes: true });
2117
} catch (err) {
2218
console.error('Error during readdir', err);
2319
var items = [];
2420
}
2521
const models = items.filter(entry => entry.isDirectory()).map(entry => entry.name).sort();
26-
if (models.length !== this.#models.length || models.some((value, index) => value !== this.#models[index])) {
22+
if (models.length !== this._models.length || models.some((value, index) => value !== this._models[index])) {
2723
// if array changed
28-
this.#models = models;
29-
this.#cb(this.#models);
24+
this._models = models;
25+
this._cb(this._models);
3026
}
3127
};
32-
fs.watch(this.#modelsPath, { persistent: false }, onChange);
28+
fs.watch(this._modelsPath, { persistent: false }, onChange);
3329
onChange();
3430
}
3531

3632
get models() {
37-
return this.#models;
33+
return this._models;
3834
}
3935

4036
async loadModel(name) {
41-
const mopedPath = path.join(this.#binPath, 'moped');
42-
const topologyFile = path.join(this.#modelsPath, name, 'topo.xml');
43-
const routingFile = path.join(this.#modelsPath, name, 'routing.xml');
37+
const mopedPath = path.join(this._binPath, 'moped');
38+
const topologyFile = path.join(this._modelsPath, name, 'topo.xml');
39+
const routingFile = path.join(this._modelsPath, name, 'routing.xml');
4440
var stdout, stderr;
4541
try {
46-
({ stdout, stderr } = await execFile(path.join(this.#binPath, 'aalwines'),
42+
({ stdout, stderr } = await execFile(path.join(this._binPath, 'aalwines'),
4743
['--topology', topologyFile, '--routing', routingFile, '--net'],
4844
{ env: { MOPED_PATH: mopedPath }}
4945
));
@@ -55,22 +51,22 @@ class Models {
5551
}
5652

5753
async doQuery(model, query, options) {
58-
const mopedPath = path.join(this.#binPath, 'moped');
59-
const topologyFile = path.join(this.#modelsPath, model, 'topo.xml');
60-
const routingFile = path.join(this.#modelsPath, model, 'routing.xml');
54+
const mopedPath = path.join(this._binPath, 'moped');
55+
const topologyFile = path.join(this._modelsPath, model, 'topo.xml');
56+
const routingFile = path.join(this._modelsPath, model, 'routing.xml');
6157
var stdout, stderr;
6258
await tmp.withFile(async ({ path: tmpQueryFile }) => {
6359
await fsp.writeFile(tmpQueryFile, query);
6460
try {
65-
({ stdout, stderr } = await execFile(path.join(this.#binPath, 'aalwines'),
61+
({ stdout, stderr } = await execFile(path.join(this._binPath, 'aalwines'),
6662
['--topology', topologyFile, '--routing', routingFile, '-e', options.engine, '-t', '-q', tmpQueryFile],
6763
{ env: { MOPED_PATH: mopedPath }}
6864
));
6965
} catch (err) {
7066
console.error('loadModel error', model, err);
7167
throw err.toString();
7268
}
73-
}, { discardDescriptor: true/*, dir: path.join(this.#modelsPath, model)*/ });
69+
}, { discardDescriptor: true/*, dir: path.join(this._modelsPath, model)*/ });
7470
return JSON.parse(stdout);
7571
}
7672
}

0 commit comments

Comments
 (0)