Skip to content

Commit

Permalink
feat(env-info): print installed packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Jan 21, 2019
1 parent f75db0d commit 98bd4eb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/@nodepack/cli/src/bin/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ program
.command('env-info')
.description('print your environment infos for debugging')
.option('-e, --env', 'Output env variables')
.action((cmd) => {
.action(async (cmd) => {
const options = cleanArgs(cmd)
const { printEnvInfo } = require('@nodepack/env-check')
printEnvInfo(options.env)
const { printEnvInfo, printInstalledPackages } = require('@nodepack/env-check')
await printEnvInfo(options.env)
await printInstalledPackages(process.cwd())
})

// output help information on unknown commands
Expand Down
1 change: 1 addition & 0 deletions packages/@nodepack/env-check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"chalk": "^2.4.1",
"execa": "^1.0.0",
"fs-extra": "^7.0.1",
"semver": "^5.6.0",
"systeminformation": "^3.51.4"
}
Expand Down
1 change: 1 addition & 0 deletions packages/@nodepack/env-check/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
...require('./env-info'),
...require('./node'),
...require('./pkg'),
}
23 changes: 23 additions & 0 deletions packages/@nodepack/env-check/src/pkg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @param {string} cwd
*/
exports.printInstalledPackages = async (cwd) => {
const fs = require('fs-extra')
const path = require('path')
const { default: chalk } = require('chalk')
const pkgFile = path.resolve(cwd, 'package.json')
if (fs.existsSync(pkgFile)) {
try {
const pkg = await fs.readJson(pkgFile)
if (pkg.dependencies) {
console.log(`dependencies:\n`, JSON.stringify(pkg.dependencies, null, 2))
}
if (pkg.devDependencies) {
console.log(`devDependencies:\n`, JSON.stringify(pkg.devDependencies, null, 2))
}
} catch (e) {
console.log(chalk.red(`Couldn't parse JSON: ${pkgFile}`))
console.error(e)
}
}
}

0 comments on commit 98bd4eb

Please sign in to comment.