all files / dist/ index.js

100% Statements 36/36
100% Branches 6/6
100% Functions 5/5
100% Lines 36/36
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                     
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const opn = require("opn");
const express = require("express");
let serverInstances = 0;
const app = express();
const port = 8080;
let server;
let container = [];
let resetFlag = false;
function clear() {
    container = [];
}
exports.clear = clear;
function stack(data) {
    checkReset();
    container.push(data);
}
exports.stack = stack;
function plot(data) {
    checkReset();
    data && container.push(data);
    spawn();
    resetFlag = true;
}
exports.plot = plot;
function checkReset() {
    if (resetFlag) {
        container = [];
        resetFlag = false;
    }
}
function spawn() {
    if (serverInstances === 0) {
        app.use(express.static(path_1.join(__dirname, 'www')));
        app.get('/data', (_, res) => {
            res.send(container);
            server.close();
        });
        server = app.listen(port, () => {
            opn(`http://localhost:${port}`);
        });
        serverInstances++;
    }
}
//# sourceMappingURL=index.js.map