-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
43 lines (35 loc) · 988 Bytes
/
utils.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
const { join } = require('path');
const { execSync } = require('child_process');
const { createWriteStream, statSync } = require('fs');
function getSuiteDir() {
return join(__dirname, 'suite');
}
function getNodeModulesDir() {
return join(getSuiteDir(), 'node_modules');
}
function getOutputStream(outputFileName) {
return createWriteStream(join(__dirname, outputFileName));
}
function getOutputSize(outputFileName) {
return `${(statSync(outputFileName).size / (1024 * 1024)).toFixed(2)} MB`;
}
function getFormattedEndTime(time) {
return `${(time / 1000).toFixed(2)}s`;
}
function runCommand(command) {
execSync(command, { cwd: getSuiteDir() });
}
function prepareEnvironment() {
console.log('Installing fresh dependencies.');
runCommand('npm ci --loglevel error');
console.log('Dependencies installed.');
}
module.exports = {
getSuiteDir,
getNodeModulesDir,
getOutputStream,
getOutputSize,
runCommand,
prepareEnvironment,
getFormattedEndTime,
};