-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from snyk/feat/enhanced-debug-android
feat: always print attributes on error with -d
- Loading branch information
Showing
3 changed files
with
73 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as chalk from 'chalk'; | ||
|
||
export function getGradleAttributesPretty(output: string): string | undefined { | ||
try { | ||
const lines = output.split('\n'); | ||
|
||
if (lines === null) { | ||
return undefined; | ||
} | ||
let jsonLine: string | null = null; | ||
lines.forEach((l) => { | ||
const line = l.trim(); | ||
// Extract attribute information via JSONATTRS marker: | ||
if (/^JSONATTRS /.test(line)) { | ||
if (jsonLine === null) { | ||
jsonLine = line.substr(10); | ||
} | ||
} | ||
}); | ||
|
||
const jsonAttrs = JSON.parse(jsonLine); | ||
const attrNameWidth = Math.max( | ||
...Object.keys(jsonAttrs).map((name) => name.length), | ||
); | ||
const jsonAttrsPretty = Object.keys(jsonAttrs) | ||
.map( | ||
(name) => | ||
chalk.whiteBright(leftPad(name, attrNameWidth)) + | ||
': ' + | ||
chalk.gray(jsonAttrs[name].join(', ')), | ||
) | ||
.join('\n'); | ||
return jsonAttrsPretty; | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} | ||
|
||
// <insert a npm left-pad joke here> | ||
function leftPad(s: string, n: number) { | ||
return ' '.repeat(Math.max(n - s.length, 0)) + s; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters