This repository was archived by the owner on Apr 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (39 loc) · 1.48 KB
/
index.js
File metadata and controls
46 lines (39 loc) · 1.48 KB
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
const parser = require('./lib/parser.js').parser;
const fs = require('fs');
const ruler = require('./lib/createLineRules.js').ruler;
const inject = require('./lib/injector.js');
const run = require('./lib/run.js');
const anonFunc = require('./lib/tools.js').anonFuncCheck;
const minty = {};
/**
* reads the file the user provides, creates an abstract syntax tree, creates rules, injects monitoring code based on rules, generates HTML file for user
* @param {string} absolute path to file that will be analyze
**/
function file(path) {
const JSTEXT = fs.readFileSync(path).toString();
const parsed = parser(JSTEXT);
const rules = ruler(parsed);
const injected = inject(rules, JSTEXT);
run.runFile(injected, path, JSTEXT);
return;
}
/**
* turns function to a string, turns function into abstract syntax tree, creates rules to inject monitoring code, and returns function that will output HTML file each time it is called
* @param {function}
* @returns {function} each time returned function is executed, an HTML visualization will be created
**/
function wrap(func) {
const JSTEXT = func.toString();
const namedJsFunc = anonFunc(JSTEXT);
const parsed = parser(namedJsFunc);
const rules = ruler(parsed);
const injected = inject(rules, namedJsFunc);
const mintified = run.wrap(injected, namedJsFunc);
return function() {
const args = Array.prototype.slice.call(arguments);
return mintified.apply(null, args);
};
}
minty.file = file;
minty.wrap = wrap;
module.exports = minty;