-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
deoptigate.log.js
40 lines (33 loc) · 1.29 KB
/
deoptigate.log.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
'use strict'
const path = require('path')
const { processLogContent, deoptigate } = require('./')
const lineReader = require('./lib/line-reader')
const resolveFiles = require('./lib/grouping/resolve-files')
const groupByFile = require('./lib/grouping/group-by-file')
async function extractDataFromLog(p, { icStateChangesOnly, root }) {
const lines = await lineReader(p, 'utf-8')
root = root == null ? path.dirname(p) : root
const processed = await processLogContent(lines, root)
if (icStateChangesOnly) processed.filterIcStateChanges()
return processed
}
async function processLog(p, { icStateChangesOnly = true, root } = {}) {
const extracted = await extractDataFromLog(p, { icStateChangesOnly, root })
const data = extracted.toObject()
const files = await resolveFiles(data)
const groupedByFile = groupByFile(data, files)
return groupedByFile
}
async function logToJSON(p, { icStateChangesOnly = true, root } = {}) {
const groupedByFile = await processLog(p, { icStateChangesOnly, root })
return JSON.stringify(Array.from(groupedByFile), null, 2)
}
async function deoptigateLog(p, { icStateChangesOnly = true } = {}) {
const groupedByFile = await processLog(p, { icStateChangesOnly })
return deoptigate(groupedByFile)
}
module.exports = {
processLog
, logToJSON
, deoptigateLog
}