Skip to content

Instantly share code, notes, and snippets.

@shisama
Last active October 1, 2019 17:42
Show Gist options
  • Save shisama/1c857b7ae25904a5b67ae5cef27b3613 to your computer and use it in GitHub Desktop.
Save shisama/1c857b7ae25904a5b67ae5cef27b3613 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const path = require('path')
const execa = require('execa');
const problemPackage = 'cowsay';
const {devDependencies, dependencies} = require(path.resolve(__dirname, 'package.json'));
const problemPackageVersion = {...devDependencies, ...dependencies}[problemPackage]
const execSync = require('child_process').execSync;
const execCommand = (command, fallback) => {
try {
return execSync(command);
} catch (err) {
return fallback;
}
}
const nodeVersion = execCommand('node -v', 'Can\'t find node\n');
const yarnVersion = execCommand('yarn -v', 'Can\'t find yarn\n')
const npmVersion = execCommand('npm -v', 'Can\'t find npm\n');
const report = `package version : ${problemPackageVersion}\nnode version : ${nodeVersion}yarn version : ${yarnVersion}npm version : ${npmVersion}`
@shisama
Copy link
Author

shisama commented Oct 1, 2019

console.log(report) prints the below.

package version : ^1.4.0
node version : v10.11.0
yarn version : Can't find yarn
npm version : 6.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment