Navigation Menu

Skip to content

Commit

Permalink
feat(cli): Add new info command to output information about local e…
Browse files Browse the repository at this point in the history
…nvironment (#2106)
  • Loading branch information
jamesgeorge007 authored and evocateur committed Dec 15, 2019
1 parent bd19a34 commit 7abfe43
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions 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
```
26 changes: 26 additions & 0 deletions 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");
});
12 changes: 12 additions & 0 deletions 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);
};
30 changes: 30 additions & 0 deletions 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;
41 changes: 41 additions & 0 deletions 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"
}
}

2 changes: 2 additions & 0 deletions core/lerna/index.js
Expand Up @@ -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");
Expand All @@ -35,6 +36,7 @@ function main(argv) {
.command(diffCmd)
.command(execCmd)
.command(importCmd)
.command(infoCmd)
.command(initCmd)
.command(linkCmd)
.command(listCmd)
Expand Down
1 change: 1 addition & 0 deletions core/lerna/package.json
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7abfe43

Please sign in to comment.