-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuilder.js
More file actions
74 lines (65 loc) · 1.65 KB
/
builder.js
File metadata and controls
74 lines (65 loc) · 1.65 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
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
import fs from 'fs'
import path from 'path'
import webpack from 'webpack'
const usage = () => {
console.log(
`builder.js - compile relevant browser javascript files
- 'node builder.js build': build once
- 'node builder.js watch': start on watch mode to recompile on each change`
);
process.exit(1);
}
if (process.argv.length < 3) {
usage();
}
const action = process.argv[2];
fs.rmSync('www/build', { recursive: true, force: true });
const compiler = webpack({
mode: 'none',
entry: {
'build/eye-tracker': path.resolve(
path.dirname(''), '/eye-tracker/index.js'),
'build/jspsych-interface': path.resolve(
path.dirname(''), '/jspsych-interface/index.js'),
},
output: {
path: path.resolve(path.dirname(''), 'www'),
filename: '[name].js',
}
});
const getCompilationHandler = (compiler) => {
const closeCompiler = !!compiler;
return (err, stats) => {
if (err) {
console.error(err.stack || err);
if (err.details) {
console.error(err.details);
}
return;
}
const info = stats.toJson();
if (stats.hasErrors()) {
info.errors.forEach(err => console.error(err));
return;
}
if (stats.hasWarnings()) {
info.warnings.forEach(message => console.log(message));
return;
}
console.log(`[${(new Date).toISOString()}] compiled`);
if (closeCompiler) {
compiler.close((closeErr) => {
if (closeErr) {
console.error(closeErr);
}
})
}
}
};
if (action === 'watch') {
compiler.watch({}, getCompilationHandler());
} else if (action === 'build') {
compiler.run(getCompilationHandler(compiler));
} else {
usage();
}