Created
January 18, 2023 15:53
-
-
Save dmoptimal/4fe97513456c6114ba8c2bfc41f6a092 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//npm i chalk | |
const util = require('util') | |
const exec = util.promisify(require('child_process').exec) | |
const chalk = require('chalk') | |
async function main() { | |
try { | |
const { stdout } = await exec('npm ls --depth=0 --long --json') | |
const outputJSON = JSON.parse(stdout) | |
const outputArray = Object.values(outputJSON.dependencies) | |
const prodPackages = outputArray.filter(item => !item.dev).map(item => ({[item.name]: item.version})) | |
const devPackages = outputArray.filter(item => item.dev).map(item => ({ [item.name]: item.version })) | |
const prod = Object.assign({}, ...prodPackages) | |
const dev = Object.assign({}, ...devPackages) | |
console.log(chalk.green('PROD DEPENDENCIES')) | |
console.log(JSON.stringify(prod)) | |
console.log(chalk.green('DEV DEPENDENCIES')) | |
console.log(JSON.stringify(dev)) | |
} catch (error) { | |
console.log(error) | |
} | |
} | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment