Skip to content

Commit

Permalink
feat(info): add info command to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed May 1, 2022
1 parent c0e8f96 commit 6fa1154
Show file tree
Hide file tree
Showing 15 changed files with 292 additions and 6 deletions.
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Expand Up @@ -22,6 +22,26 @@ body:
placeholder: Reproduction
validations:
required: true
- type: textarea
label: Lerna config, error files
description: provide your `lerna.json` config
value: |
<details><summary>lerna.json</summary><p>
<!-- browsers demand the next line be empty -->
```json
<!-- Please paste your `lerna.json` here -->
```
</p></details>
<details><summary>lerna-debug.log</summary><p>
<!-- browsers demand the next line be empty -->
```txt
<!-- If you have a `lerna-debug.log` available, please paste it here -->
<!-- Otherwise, feel free to delete this <details> block -->
```
</p></details>
- type: textarea
id: system-info
attributes:
Expand All @@ -34,6 +54,8 @@ body:
TypeScript (x.y)
Browser(s)
System OS
---
also run the `lerna info` command
validations:
required: true
- type: dropdown
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -88,8 +88,8 @@ Run the following commands to install Lerna-Lite in your project and/or install

| Command | Install | Description | Included |
|---------|-------------|-------------| ---------|
| 📰 [version](https://github.com/ghiscoding/lerna-lite/tree/main/packages/version) | `npm install @lerna-lite/cli` | create new version for each workspace package | Yes |
| 📰 [publish](https://github.com/ghiscoding/lerna-lite/tree/main/packages/publish) | `npm install @lerna-lite/cli` | publish each workspace package | Yes |
| 📑 [version](https://github.com/ghiscoding/lerna-lite/tree/main/packages/version) | `npm install @lerna-lite/cli` | create new version for each workspace package | Yes |
| ✉️ [publish](https://github.com/ghiscoding/lerna-lite/tree/main/packages/publish) | `npm install @lerna-lite/cli` | publish each workspace package | Yes |
| 🏃 [run](https://github.com/ghiscoding/lerna-lite/tree/main/packages/run) | `npm install @lerna-lite/run` | run npm script in each workspace package | Optional |

**Note:** the default `lerna` CLI is only including 2 built-in commands (`publish` and `version`), while the (`run`) command is optional and must be installed separately as shown below.
Expand Down
61 changes: 61 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -9,6 +9,7 @@
"build": "npm run build --ws",
"lint": "eslint packages/** --ext .ts",
"predist-roll-version": "npm run preroll-version",
"dist-info-cmd": "node ./packages/cli/dist/cli.js info",
"dist-roll-version": "node ./packages/cli/dist/cli.js version",
"dist-roll-version-dry-run": "node ./packages/cli/dist/cli.js version --git-dry-run",
"dist-roll-publish": "node ./packages/cli/dist/cli.js publish from-package",
Expand Down Expand Up @@ -88,6 +89,7 @@
},
"workspaces": [
"./packages/core",
"./packages/info",
"./packages/version",
"./packages/publish",
"./packages/run",
Expand Down
11 changes: 11 additions & 0 deletions packages/cli/src/cli-commands/cli-info-commands.ts
@@ -0,0 +1,11 @@
import { InfoCommand } from '@lerna-lite/info';

/**
* @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 new InfoCommand(argv);
};
2 changes: 2 additions & 0 deletions packages/cli/src/lerna-entry.ts
@@ -1,6 +1,7 @@
const cli = require('./lerna-cli');
const pkg = require('../package.json');

const infoCmd = require('./cli-commands/cli-info-commands');
const publishCmd = require('./cli-commands/cli-publish-commands');
const runCmd = require('./cli-commands/cli-run-commands');
const versionCmd = require('./cli-commands/cli-version-commands');
Expand All @@ -11,6 +12,7 @@ export function lerna(argv: any[]) {
};

return cli()
.command(infoCmd)
.command(publishCmd)
.command(runCmd)
.command(versionCmd)
Expand Down
47 changes: 47 additions & 0 deletions packages/info/README.md
@@ -0,0 +1,47 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
[![npm](https://img.shields.io/npm/v/@lerna-lite/info.svg?color=forest)](https://www.npmjs.com/package/@lerna-lite/info)
[![npm](https://img.shields.io/npm/dy/@lerna-lite/info?color=forest)](https://www.npmjs.com/package/@lerna-lite/info)
[![Actions Status](https://github.com/ghiscoding/lerna-lite/workflows/CI%20Build/badge.svg)](https://github.com/ghiscoding/lerna-lite/actions)

# @lerna-lite/info
## (`lerna info`) - Info command 💻

Print local environment information

---

## Installation
```sh
# install globally
npm install -g @lerna-lite/cli

# then use it (see usage below)
lerna info

# OR use npx
npx lerna info
```

## 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
```
42 changes: 42 additions & 0 deletions packages/info/package.json
@@ -0,0 +1,42 @@
{
"name": "@lerna-lite/info",
"description": "Lerna-Lite - Prints local environnment information",
"version": "1.0.5",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"typings": "dist/index.d.ts",
"files": [
"/dist"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsc --project tsconfig.bundle.json",
"pack-tarball": "npm pack"
},
"license": "MIT",
"author": "Ghislain B.",
"homepage": "https://github.com/ghiscoding/lerna-lite",
"repository": {
"type": "git",
"url": "https://github.com/ghiscoding/lerna-lite.git",
"directory": "packages/info"
},
"bugs": {
"url": "https://github.com/ghiscoding/lerna-lite/issues"
},
"engines": {
"node": ">=14.13.1",
"npm": ">=8.0.0"
},
"dependencies": {
"@lerna-lite/core": "^1.0.5",
"dedent": "^0.7.0",
"envinfo": "^7.8.1",
"yargs": "^17.4.1"
},
"devDependencies": {
"@types/envinfo": "^7.8.1"
}
}
57 changes: 57 additions & 0 deletions packages/info/src/__tests__/info-command.spec.ts
@@ -0,0 +1,57 @@
jest.mock('envinfo');

const path = require('path');
const envinfo = require('envinfo');

envinfo.run.mockResolvedValue('MOCK_ENVINFO');

// mocked modules of @lerna-lite/core
jest.mock('@lerna-lite/core', () => ({
...jest.requireActual('@lerna-lite/core') as any, // return the other real methods, below we'll mock only 2 of the methods
logOutput: jest.requireActual('../../../core/src/__mocks__/output').logOutput,
}));

const { logOutput } = require('@lerna-lite/core');

// file under test
const lernaInfo = require('@lerna-test/command-runner')(require('../../../cli/src/cli-commands/cli-info-commands'));
import { InfoCommand } from '../index';
import { factory } from '../info-command';

describe('Info Command', () => {
it('outputs result of envinfo() via CLI', async () => {
// project fixture is irrelevant, no actual changes are made
await lernaInfo(path.resolve(__dirname, '../../..'))();

expect(envinfo.run).toHaveBeenLastCalledWith(
expect.objectContaining({
npmPackages: ['lerna'],
})
);
expect(logOutput.logged()).toMatch('MOCK_ENVINFO');
});

it('outputs result of envinfo() via factory', async () => {
// project fixture is irrelevant, no actual changes are made
await new InfoCommand({});

expect(envinfo.run).toHaveBeenLastCalledWith(
expect.objectContaining({
npmPackages: ['lerna'],
})
);
expect(logOutput.logged()).toMatch('MOCK_ENVINFO');
});

it('outputs result of envinfo() via InfoCommand class', async () => {
// project fixture is irrelevant, no actual changes are made
await factory({});

expect(envinfo.run).toHaveBeenLastCalledWith(
expect.objectContaining({
npmPackages: ['lerna'],
})
);
expect(logOutput.logged()).toMatch('MOCK_ENVINFO');
});
});
1 change: 1 addition & 0 deletions packages/info/src/index.ts
@@ -0,0 +1 @@
export * from './info-command';
29 changes: 29 additions & 0 deletions packages/info/src/info-command.ts
@@ -0,0 +1,29 @@
import { Command, logOutput, } from '@lerna-lite/core';
import envinfo from 'envinfo';

export function factory(argv) {
return new InfoCommand(argv);
}

export class InfoCommand extends Command {
/** command name */
name = 'info';

constructor(argv: any) {
super(argv);
}

initialize() { }

execute() {
logOutput('\n Environment info:');
envinfo
.run({
System: ['OS', 'CPU'],
Binaries: ['Node', 'Yarn', 'npm'],
Utilities: ['Git'],
npmPackages: ['lerna'],
})
.then(logOutput);
}
}

0 comments on commit 6fa1154

Please sign in to comment.