forked from Kishanjay/LacunaV2-evaluator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodomvc_lacuna_normalizer.js
126 lines (108 loc) · 3.77 KB
/
todomvc_lacuna_normalizer.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* @description
* Runs lacuna on all todomvc applications for each analyzer combination
*/
require("./prototype_extension");
const path = require("path");
const fs = require("fs-extra");
const lacuna = require("../LacunaV2/lacuna_runner");
const TODOMVC_DIR = "todomvc";
const EXAMPLES_DIR = "examples";
const EXAMPLES_OUTPUT_DIR = "examples.normalized.new";
start().then((result) => {
console.log("Finished");
}).catch((e) => {
console.log(e);
console.log("catch error");
}).finally(() => {
console.log("finally");
})
function start() {
let frameworks = getFrameworks();
assert(frameworks, "Invalid frameworks");
createDestinationFolder(); // should work with EXAMPLES_OUTPUT_DIR after this
lacunaNormalizeFrameworks(frameworks).then(() => {
console.log("Normalization finished");
});
}
/**
* Fetches the todomvc- frameworks that will be used
*/
function getFrameworks() {
const tests_dir = path.join(TODOMVC_DIR, "tests")
const cwd = process.cwd(); // fixes relative path issue
process.chdir(tests_dir);
const frameworkPathLookup = require("./" + path.join(tests_dir, 'framework-path-lookup'));
const frameworks = frameworkPathLookup();
process.chdir(cwd);
return frameworks;
}
/**
* Creates and clears the new examples folder (that will be normalized)
*/
function createDestinationFolder() {
examplesSource = path.join(TODOMVC_DIR, EXAMPLES_DIR);
examplesDestination = path.join(TODOMVC_DIR, EXAMPLES_OUTPUT_DIR);
if (fs.existsSync(examplesDestination) && fs.lstatSync(examplesDestination).isDirectory()) {
fs.removeSync(examplesDestination);
}
fs.copySync(examplesSource, examplesDestination);
}
/**
* Lacuna normalizes the frameworks
* - exports inline JS
* - imports externally hosted JS
* - exports eventAttributes to a file
*/
async function lacunaNormalizeFrameworks(frameworks) {
for (framework of frameworks){
let directory = generateFrameworkDirectory(framework);
/* Create new object for every setup */
let normalizeRunOption = {
directory: directory,
entry: "index.html",
normalizeOnly: true,
force: true
};
/* Handle exceptions on the folder structure */
if (framework.name == 'angular-dart') {
normalizeRunOption.directory = normalizeRunOption.directory.slice(0, -4);
normalizeRunOption.entry = 'web/index.html';
}
if (framework.name == 'chaplin-brunch') {
normalizeRunOption.directory = normalizeRunOption.directory.slice(0, -7);
normalizeRunOption.entry = 'public/index.html';
}
if (framework.name == 'duel') {
normalizeRunOption.directory = normalizeRunOption.directory.slice(0, -4);
normalizeRunOption.entry = 'www/index.html';
}
if (framework.name == 'vanilladart') {
normalizeRunOption.directory = normalizeRunOption.directory.slice(0, -10);
normalizeRunOption.entry = 'build/web/index.html';
}
try {
await lacunaRunPromise(normalizeRunOption); // async doesn't seem to work
} catch (e) { console.log(e); }
}
}
/**
* Fetches the directory for a framework
*/
function generateFrameworkDirectory({path: frameworkPath}) {
frameworkPath = frameworkPath.splice(0, 8, EXAMPLES_OUTPUT_DIR); // append to examples
let pwdFrameworkPath = path.join(TODOMVC_DIR, frameworkPath);
return pwdFrameworkPath;
}
function lacunaRunPromise (lacunaRunOption) {
return new Promise((resolve, reject) => {
try { lacuna.run(lacunaRunOption, resolve); }
catch (e) { reject(); }
})
}
function assert(assertion, msg) {
if (!assertion) {
console.log(msg);
process.exit(1);
}
}