Skip to content

Commit

Permalink
More verbose logs
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-tpom6oh committed Feb 16, 2024
1 parent dbe50d3 commit e44c00b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Unreleased

More info in the verbose logs

## 3.2.9 (2024-02-13)

Improve error messages
Expand Down
54 changes: 38 additions & 16 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@ function findMatches(data: string, regex: RegExp): FileMatch[] {
return fileMatches;
}

function getEventMap(data: string): string[] | null {
function getEventMap(data: string, verbose: boolean): string[] | null {
const searchFor = 'AVOEVENTMAP:';
const lines = data.split('\n').filter((line) => line.indexOf(searchFor) > -1);
if (lines.length === 1) {
Expand All @@ -1407,11 +1407,13 @@ function getEventMap(data: string): string[] | null {
line = line.substring(line.indexOf('['), line.indexOf(']') + 1);
const eventMap = JSON.parse(line);
return eventMap;
} else if (verbose) {
report.error('No event map found');
}
return null;
}

function getModuleMap(data: string): string[] | null {
function getModuleMap(data: string, verbose: boolean): string[] | null {
const searchFor = 'AVOMODULEMAP:';
const lines = data.split('\n').filter((line) => line.indexOf(searchFor) > -1);
if (lines.length === 1) {
Expand All @@ -1421,6 +1423,8 @@ function getModuleMap(data: string): string[] | null {
line = line.substring(line.indexOf('"'), line.lastIndexOf('"') + 1);
const moduleMap = JSON.parse(line);
return moduleMap;
} else if (verbose) {
report.error('No module map found');
}
return null;
}
Expand Down Expand Up @@ -1467,15 +1471,24 @@ function status(source: string, json, argv: any): void {
results
.filter((result) => !result.startsWith('.git'))
.map((resultPath) =>
pify(fs.lstat)(resultPath).then((stats) => {
if (stats.isSymbolicLink()) {
return [];
}
return pify(fs.readFile)(resultPath, 'utf8').then((data) => [
resultPath,
data,
]);
}),
pify(fs.lstat)(resultPath)
.then((stats) => {
if (stats.isSymbolicLink()) {
return [];
}
return pify(fs.readFile)(resultPath, 'utf8')
.then((data) => [resultPath, data])
.catch((error) => {
if (argv.verbose) {
report.warn(`Failed to parse file: ${resultPath}`, error);
}
});
})
.catch((error) => {
if (argv.verbose) {
report.warn(`Failed to read file stats: ${resultPath}`, error);
}
}),
),
).then((cachePairs) => Object.fromEntries(cachePairs)),
);
Expand All @@ -1485,9 +1498,9 @@ function status(source: string, json, argv: any): void {
sources = Promise.all(
sources.map((source) =>
pify(fs.readFile)(source.path, 'utf8').then((data) => {
const eventMap = getEventMap(data);
const eventMap = getEventMap(data, argv.verbose);
if (eventMap !== null) {
const moduleMap = getModuleMap(data);
const moduleMap = getModuleMap(data, argv.verbose);
const sourcePath = path.parse(source.path);
const moduleName =
source.analysis?.module ??
Expand Down Expand Up @@ -1544,16 +1557,25 @@ function status(source: string, json, argv: any): void {
}
});

if (argv.verbose) {
const combinedPaths: string[] = [];

Object.entries(lookup).forEach(([path, _data]) => {
combinedPaths.push(path);
});

report.info(`Looking for events: ${eventMap.join('\n')}`);
report.info(`Looking in modules: ${moduleName}`);
report.info(`Looking in files: ${combinedPaths.join('\n')}`);
}

return Promise.all(
eventMap.map((eventName) => {
const re = new RegExp(
`(${moduleName}\\.${eventName}|\\[${moduleName} ${eventName})`,
);
const results = Object.entries(lookup)
.map(([path, data]) => {
if (argv.verbose) {
report.info(`Looking for events in ${path}`);
}
const results = findMatches(data, re);
return results.length ? [[path, results]] : [];
})
Expand Down

0 comments on commit e44c00b

Please sign in to comment.