-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.ts
90 lines (63 loc) · 2.51 KB
/
index.ts
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env node
import open = require('open');
import { processFiles } from './extract';
import { convertForArc } from './arc';
import { convertForCascade } from './cascade';
import { convertForGraphViz } from './graphviz';
import { convertForMermaid } from './mermaid';
import { showHelpMessage, showServerRunning } from './helper';
const myArgs = process.argv.slice(2);
const onlyTypescript: string[] = myArgs.filter(file => file.endsWith('ts'));
const withoutNodeModules: string[] = onlyTypescript.filter(file => !file.includes('node_modules'));
if (withoutNodeModules.length) {
console.log(withoutNodeModules);
var inquirer = require('inquirer');
inquirer
.prompt([{
type: 'confirm',
name: 'want',
message: 'Are these the files you want to analyze?',
default: true
}])
.then(answer => {
if (answer.want) {
proceed();
}
})
} else {
showHelpMessage();
}
/**
* If user confirms the files they want to analyze, proceed
*/
function proceed(): void {
const functions = processFiles(withoutNodeModules);
startServer(functions.all, functions.called);
}
/**
* Start Express server with static files and API endpoints
* @param functionMap
*/
function startServer(allFunctions: string[], functionMap: Map<string, string[]>): void {
const express = require('express');
const app = express();
const path = require('path');
app.use(express.static(path.join(__dirname, '..', 'graphing')));
app.use('/arc', express.static(path.join(__dirname, '..', 'graphing/arc')));
app.use('/cascade', express.static(path.join(__dirname, '..', 'graphing/cascade')));
app.use('/graphviz', express.static(path.join(__dirname, '..', 'graphing/graphviz')));
app.use('/mermaid', express.static(path.join(__dirname, '..', 'graphing/mermaid')));
app.use('/vendor', express.static(path.join(__dirname, '..', 'graphing/vendor')));
// API endpoints
app.use('/all', function (req, res) { res.json(allFunctions) });
app.get('/arcAPI', function (req, res) { res.json(convertForArc(allFunctions, functionMap)) });
app.get('/cascadeAPI/:startFunc', function (req, res) {
res.json(convertForCascade(functionMap, req.params.startFunc))
});
app.get('/graphvizAPI', function (req, res) { res.json(convertForGraphViz(functionMap)) });
app.get('/mermaidAPI', function (req, res) { res.json(convertForMermaid(functionMap)) });
app.listen(3000)
const filePath: string = 'http://localhost:3000';
showServerRunning(filePath);
open(filePath);
}