This repository was archived by the owner on Mar 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
110 lines (96 loc) · 3.53 KB
/
index.js
File metadata and controls
110 lines (96 loc) · 3.53 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
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
'use strict';
const debug = require('debug');
const flags = require('flags');
const fs = require('fs');
const {transformFile, transformResult} = require('./src/transformFile.js');
const {verifyTransformation} = require('./src/verify.js');
const FILE_FLAG = 'file';
const DIR_FLAG = 'dir';
const OUTPUT_DIR_FLAG = 'output_dir';
const QUIET_FLAG = 'quiet';
const TARGET_BUILD_FLAG = 'target_build';
const VERIFY_FLAG = 'verify';
// If flags are added, deleted, or modified, UPDATE README.
// Specify exactly one of --file or --dir.
flags.defineString(FILE_FLAG, null, 'Path to test file to transform');
flags.defineString(DIR_FLAG, null, 'Path to dir of test files to transform');
// eslint-disable-next-line max-len
flags.defineString(OUTPUT_DIR_FLAG, null, 'Path to dir where output files should be written. If null, will overwrite input files.');
// eslint-disable-next-line max-len
flags.defineString(TARGET_BUILD_FLAG, 'Default', 'Target build used in -t parameter for run_web_tests.py');
flags.defineBoolean(QUIET_FLAG, false, 'Disable logging');
flags.defineBoolean(VERIFY_FLAG, true, 'Runs web test after transforming.');
flags.parse();
const log = debug('index.js');
const error = debug('index.js:ERROR');
// For some reason 1 is RED
error.color = 1;
// babel npm package has very verbose debug usage, so enable all but babel.
debug.enable('* -babel');
if (flags.get(QUIET_FLAG)) {
// disables all namespaces
debug.disable();
}
async function main() {
const file = flags.get(FILE_FLAG);
const dir = flags.get(DIR_FLAG);
const outputDir = flags.get(OUTPUT_DIR_FLAG);
const targetBuild = flags.get(TARGET_BUILD_FLAG);
const verify = flags.get(VERIFY_FLAG);
if ((file && dir) || (!file && !dir)) {
throw new Error('Specify exactly one of --file or --dir');
}
if (file) {
if (transformFile(file, outputDir) === transformResult.SUCCESS && verify) {
verifyTransformation(file, targetBuild);
}
return;
}
// The code below is for processing a directory (if --dir) specified.
// The tool outputs a summary output on transformation and verification
// results.
const fileNames = fs.readdirSync(dir);
const completedTransformations = [];
const skippedTransformations = [];
const failedTransformations = [];
const successfulVerifications = [];
const failedVerifications = [];
fileNames.forEach((fileName) => {
if (fileName.split('.').pop() !== 'html') {
return;
}
const filePath = dir + '/' + fileName;
const result = transformFile(filePath, outputDir);
if (result === transformResult.SUCCESS) {
completedTransformations.push(filePath);
if (!verify) {
return;
}
if (verifyTransformation(filePath, targetBuild)) {
successfulVerifications.push(filePath);
} else {
failedVerifications.push(filePath);
}
} else if (result === transformResult.FAIL) {
failedTransformations.push(filePath);
} else if (result === transformResult.SKIP) {
skippedTransformations.push(filePath);
}
});
log('Transformation Results:');
log('Completed Transformations:');
console.log(completedTransformations.join('\n'));
log('Skipped Transformations:');
console.log(skippedTransformations.join('\n'));
log('Failed Transformations:');
console.log(failedTransformations.join('\n'));
log('\nVerification Results:');
log('Succesful Verifications:');
console.log(successfulVerifications.join('\n'));
log('Failed Verifications:');
console.log(failedVerifications.join('\n'));
}
main().catch((reason) => {
error(reason);
process.exit(1);
});