From 7abfe43426197fbc7f18c44b0c994324609fc769 Mon Sep 17 00:00:00 2001 From: James George Date: Mon, 16 Dec 2019 03:16:46 +0530 Subject: [PATCH] feat(cli): Add new `info` command to output information about local environment (#2106) --- README.md | 1 + commands/info/README.md | 28 +++++++++++++ commands/info/__tests__/info-command.test.js | 26 +++++++++++++ commands/info/command.js | 12 ++++++ commands/info/index.js | 30 ++++++++++++++ commands/info/package.json | 41 ++++++++++++++++++++ core/lerna/index.js | 2 + core/lerna/package.json | 1 + package-lock.json | 14 +++++++ 9 files changed, 155 insertions(+) create mode 100644 commands/info/README.md create mode 100644 commands/info/__tests__/info-command.test.js create mode 100644 commands/info/command.js create mode 100644 commands/info/index.js create mode 100644 commands/info/package.json diff --git a/README.md b/README.md index de2b42ce60..ff4d200e98 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ - [`lerna import`](./commands/import#readme) - [`lerna link`](./commands/link#readme) - [`lerna create`](./commands/create#readme) + - [`lerna info`](./commands/info#readme) - [Concepts](#concepts) - [Lerna.json](#lernajson) - [Global Flags](./core/global-options) diff --git a/commands/info/README.md b/commands/info/README.md new file mode 100644 index 0000000000..9b343e179e --- /dev/null +++ b/commands/info/README.md @@ -0,0 +1,28 @@ +# `@lerna/info` + +> Print local environment information + +Install [lerna](https://www.npmjs.com/package/lerna) for access to the `lerna` CLI. + +## Usage + +The `info` prints local environment information that proves to be useful especially while submitting bug reports. + +`lerna info` + +```bash +Environment Info: + + System: + OS: Linux 4.18 Ubuntu 18.10 (Cosmic Cuttlefish) + CPU: (4) x64 Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz + Binaries: + Node: 8.11.4 - /usr/bin/node + Yarn: 1.17.0-0 - /usr/local/bin/yarn + npm: 6.9.0 - /usr/local/bin/npm + Browsers: + Chrome: 74.0.3729.157 + Firefox: 66.0.5 + npmPackages: + lerna: 3.14.1 +``` diff --git a/commands/info/__tests__/info-command.test.js b/commands/info/__tests__/info-command.test.js new file mode 100644 index 0000000000..7cdc1b04d2 --- /dev/null +++ b/commands/info/__tests__/info-command.test.js @@ -0,0 +1,26 @@ +"use strict"; + +jest.mock("envinfo"); + +const path = require("path"); +const envinfo = require("envinfo"); + +envinfo.run.mockResolvedValue("MOCK_ENVINFO"); + +// helper +const output = require("@lerna/output"); + +// file under test +const lernaInfo = require("@lerna-test/command-runner")(require("../command")); + +it("outputs result of envinfo()", async () => { + // project fixture is irrelevant, no actual changes are made + await lernaInfo(path.resolve(__dirname, "../../.."))(); + + expect(envinfo.run).toHaveBeenLastCalledWith( + expect.objectContaining({ + npmPackages: ["lerna"], + }) + ); + expect(output.logged()).toMatch("MOCK_ENVINFO"); +}); diff --git a/commands/info/command.js b/commands/info/command.js new file mode 100644 index 0000000000..9c2e16bd5e --- /dev/null +++ b/commands/info/command.js @@ -0,0 +1,12 @@ +"use strict"; + +/** + * @see https://github.com/yargs/yargs/blob/master/docs/advanced.md#providing-a-command-module + */ +exports.command = "info"; + +exports.describe = "Prints debugging information about the local environment"; + +exports.handler = function handler(argv) { + return require(".")(argv); +}; diff --git a/commands/info/index.js b/commands/info/index.js new file mode 100644 index 0000000000..caa44121e4 --- /dev/null +++ b/commands/info/index.js @@ -0,0 +1,30 @@ +"use strict"; + +const Command = require("@lerna/command"); +const output = require("@lerna/output"); +const envinfo = require("envinfo"); + +module.exports = factory; + +function factory(argv) { + return new InfoCommand(argv); +} + +class InfoCommand extends Command { + // eslint-disable-next-line + initialize() {} + // eslint-disable-next-line + execute() { + output("\n Environment info:"); + envinfo + .run({ + System: ["OS", "CPU"], + Binaries: ["Node", "Yarn", "npm"], + Utilities: ["Git"], + npmPackages: ["lerna"], + }) + .then(output); + } +} + +module.exports.InfoCommand = InfoCommand; diff --git a/commands/info/package.json b/commands/info/package.json new file mode 100644 index 0000000000..45154913fe --- /dev/null +++ b/commands/info/package.json @@ -0,0 +1,41 @@ + +{ + "name": "@lerna/info", + "version": "1.0.0", + "description": "Prints local environnment information", + "keywords": [ + "lerna", + "command" + ], + "homepage": "https://github.com/lerna/lerna/tree/master/commands/info#readme", + "license": "MIT", + "author": { + "name": "James George", + "url": "https://github.com/jamesgeorge007" + }, + "files": [ + "command.js", + "index.js" + ], + "main": "index.js", + "engines": { + "node": ">= 6.9.0" + }, + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/lerna/lerna.git", + "directory": "commands/info" + }, + "scripts": { + "test": "echo \"Run tests from root\" && exit 1" + }, + "dependencies": { + "@lerna/command": "file:../../core/command", + "@lerna/output": "file:../../utils/output", + "envinfo": "^7.3.1" + } + } + diff --git a/core/lerna/index.js b/core/lerna/index.js index a46caba313..dadfe8a407 100644 --- a/core/lerna/index.js +++ b/core/lerna/index.js @@ -10,6 +10,7 @@ const createCmd = require("@lerna/create/command"); const diffCmd = require("@lerna/diff/command"); const execCmd = require("@lerna/exec/command"); const importCmd = require("@lerna/import/command"); +const infoCmd = require("@lerna/info/command"); const initCmd = require("@lerna/init/command"); const linkCmd = require("@lerna/link/command"); const listCmd = require("@lerna/list/command"); @@ -35,6 +36,7 @@ function main(argv) { .command(diffCmd) .command(execCmd) .command(importCmd) + .command(infoCmd) .command(initCmd) .command(linkCmd) .command(listCmd) diff --git a/core/lerna/package.json b/core/lerna/package.json index 760c1b2d17..ef4c302724 100644 --- a/core/lerna/package.json +++ b/core/lerna/package.json @@ -41,6 +41,7 @@ "@lerna/diff": "file:../../commands/diff", "@lerna/exec": "file:../../commands/exec", "@lerna/import": "file:../../commands/import", + "@lerna/info": "file:../../commands/info", "@lerna/init": "file:../../commands/init", "@lerna/link": "file:../../commands/link", "@lerna/list": "file:../../commands/list", diff --git a/package-lock.json b/package-lock.json index f95c72aceb..3971ee8f9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1036,6 +1036,14 @@ "p-map-series": "^1.0.0" } }, + "@lerna/info": { + "version": "file:commands/info", + "requires": { + "@lerna/command": "file:core/command", + "@lerna/output": "file:utils/output", + "envinfo": "^7.3.1" + } + }, "@lerna/init": { "version": "file:commands/init", "requires": { @@ -2991,6 +2999,11 @@ "once": "^1.4.0" } }, + "envinfo": { + "version": "7.3.1", + "resolved": "https://registry.npmjs.org/envinfo/-/envinfo-7.3.1.tgz", + "integrity": "sha512-GvXiDTqLYrORVSCuJCsWHPXF5BFvoWMQA9xX4YVjPT1jyS3aZEHUBwjzxU/6LTPF9ReHgVEbX7IEN5UvSXHw/A==" + }, "env-paths": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-1.0.0.tgz", @@ -6520,6 +6533,7 @@ "@lerna/diff": "file:commands/diff", "@lerna/exec": "file:commands/exec", "@lerna/import": "file:commands/import", + "@lerna/info": "file:commands/info", "@lerna/init": "file:commands/init", "@lerna/link": "file:commands/link", "@lerna/list": "file:commands/list",