-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: output all dependency data as csv
- Loading branch information
Showing
12 changed files
with
807 additions
and
541 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
function jsonToCsv(items) { | ||
const headerNames = Object.keys(items[0]); | ||
const rowItems = items.map((row) => | ||
headerNames | ||
.map((fieldName) => JSON.stringify(row[fieldName], (_, value) => value ?? '-')) | ||
.join(','), | ||
); | ||
return [headerNames.join(','), ...rowItems].join('\r\n'); | ||
} | ||
|
||
module.exports = (dependencies) => { | ||
const processedDependencies = (dependencies || []).map( | ||
({name, version, flags, parents, size, license}) => ({ | ||
name, | ||
version, | ||
size, | ||
license, | ||
isProd: !!flags.prod, | ||
isDev: !!flags.dev, | ||
isOptional: !!flags.optional, | ||
isPeer: !!flags.peer, | ||
isBundled: !!flags.bundled, | ||
parents: Object.values(parents || {}) | ||
.reduce( | ||
(agg, deps) => | ||
agg.concat( | ||
Object.values(deps).map(({name: dname, version: dversion}) => `${dname}@${dversion}`), | ||
), | ||
[], | ||
) | ||
.join(','), | ||
}), | ||
); | ||
|
||
return jsonToCsv(processedDependencies); | ||
}; |
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
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