Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(info): adding more functionality to info package #833

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
242c613
feat(info): adding more functionality and improves performance
pranshuchittora Apr 16, 2019
d52396b
feat(info): adds the list of supported flags
pranshuchittora Apr 18, 2019
754ad92
chore(depen): updates the package-lock of info package
pranshuchittora Apr 18, 2019
2f31b5b
feat(info): adds different command types and options
pranshuchittora Apr 20, 2019
2badfd1
chore(info): fixes the linting
pranshuchittora Apr 20, 2019
227f584
feat(info): error for invalid flags
pranshuchittora Apr 21, 2019
dd8b9f1
feat(info): adds aliases and default
pranshuchittora Apr 21, 2019
89b6aa3
feat(info): adds tests for the revamped info pkg
pranshuchittora Apr 27, 2019
b4bd57e
feat(info): removes junit.xml
pranshuchittora Apr 28, 2019
37e4bc0
Merge branch 'master' into info
pranshuchittora Apr 28, 2019
385a66f
Merge branch 'master' of github.com:webpack/webpack-cli into info
pranshuchittora May 2, 2019
f4ce1e9
Merge branch 'master' of github.com:webpack/webpack-cli into info
pranshuchittora May 30, 2019
2695ac8
feat(info): seperates func calls from the stdout
pranshuchittora May 30, 2019
721bd36
chore(plock): updates the package-lock.json
pranshuchittora May 30, 2019
696fda8
Merge branch 'master' of github.com:webpack/webpack-cli into info
pranshuchittora Jun 2, 2019
155a5ed
feat(info): adds support custom args when imported as module
pranshuchittora Jun 2, 2019
4d0b9de
docs(info): updates readme for the new info package
pranshuchittora Jun 2, 2019
c525a79
chore(info): fixes codacy pr issues
pranshuchittora Jun 2, 2019
3e142a4
feat(info): merges master and implements the interface
pranshuchittora Jun 6, 2019
064750a
chore(info): auto prettify
pranshuchittora Jun 6, 2019
cb5e84d
feat(info): adds support for config parsing
pranshuchittora Jun 10, 2019
55ca613
feat(info): parses config fron given argv path
pranshuchittora Jun 10, 2019
f1f0fb1
Merge branch 'master' of github.com:webpack/webpack-cli into info
pranshuchittora Jun 10, 2019
a1301be
chore(deps): removes unwanted deps and updates lock file
pranshuchittora Jun 10, 2019
0d70982
Merge branch 'master' of github.com:webpack/webpack-cli into info
pranshuchittora Jun 11, 2019
71ebc63
fix(lint): fixes linting issues
pranshuchittora Jun 11, 2019
b54efd0
chore(info): changes output flags as per review
pranshuchittora Jun 11, 2019
c5d50b1
docs(info): updates the docs for the updated output flags
pranshuchittora Jun 11, 2019
0b88f32
chore(options): improves aliases of flags
pranshuchittora Jun 11, 2019
2a893c7
docs(info): improves the docs for the flags
pranshuchittora Jun 11, 2019
aa03e7d
chore(options): fixes broken option rejectiong and updates desc
pranshuchittora Jun 11, 2019
4ec2b89
docs(readme): updates the docs for using package as local module
pranshuchittora Jun 11, 2019
339dc2c
docs(readme): updates the docs hence removes unused vars
pranshuchittora Jun 11, 2019
e623e0e
fix(config): improves exception handling for config parsing
pranshuchittora Jun 11, 2019
4396e73
feat(info): adds return types
pranshuchittora Jun 11, 2019
54d7954
chore(info): improves string concatination
pranshuchittora Jun 11, 2019
facbbbc
tests(info): updates the test for the info package
pranshuchittora Jun 11, 2019
1fe3eb9
fix(info): fixes some issues when the info is called remotely
pranshuchittora Jun 12, 2019
4166096
fix(flags): makes output flags to follow general standards
pranshuchittora Jun 13, 2019
211b2be
feat(info): now config can be passed as a custom argument
pranshuchittora Jun 13, 2019
9395964
chore(info): updates the types
pranshuchittora Jun 13, 2019
b521aaa
chore(deps): added types/yargs as a dependency
pranshuchittora Jun 13, 2019
88dc7cd
docs(info): adds config props
pranshuchittora Jun 13, 2019
80abe70
chore(deps): updates the lock file
pranshuchittora Jun 13, 2019
83f038c
chore(docs): updates description and docs
pranshuchittora Jun 13, 2019
b3c98ad
chore(comments): removes unwanted comments
pranshuchittora Jun 13, 2019
4b3105f
feat(info): adds support for plugin name from the parsed config
pranshuchittora Jun 17, 2019
8843786
Merge branch 'master' of github.com:webpack/webpack-cli into info
pranshuchittora Jun 17, 2019
2e9c758
Merge branch 'master' of github.com:webpack/webpack-cli into info
pranshuchittora Jun 25, 2019
479df8d
chore(files): undo the changes in migrate
pranshuchittora Jun 25, 2019
5e043b9
chore(init): undo file changes in init
pranshuchittora Jun 25, 2019
110fa5e
chore: fix sec vuln
evenstensberg Jul 14, 2019
a56e916
chore: v3.3.6
evenstensberg Jul 14, 2019
d14d878
Merge branch 'master' of github.com:webpack/webpack-cli into info
pranshuchittora Jul 24, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 36 additions & 3 deletions packages/info/README.md
Expand Up @@ -9,22 +9,55 @@ This package returns a set of information related to the local environment.
## Installation

```bash
#npm
npm i -D @webpack-cli/info

#yarn
yarn add @webpack-cli/info -D
```

## Usage

pranshuchittora marked this conversation as resolved.
Show resolved Hide resolved
### Args / Flags

#### Output format

| Flag | Description | Type | | |
pranshuchittora marked this conversation as resolved.
Show resolved Hide resolved
| ------------ | ----------------------------- | ----------- | --- | --- |
| `--json` | To get the output as JSON | [ boolean ] | | |
| `--markdown` | To get the output as markdown | [ boolean ] | | |

#### Options

| Flag | Description | Type |
| ---------------------- | -------------------------------------------------------------- | ----------- |
| `--help` | Show help | [ boolean ] |
| `--version` | Show version number | [ boolean ] |
pranshuchittora marked this conversation as resolved.
Show resolved Hide resolved
| `--system` , `--sys` | System information ( OS, CPU ) | [ boolean ] |
pranshuchittora marked this conversation as resolved.
Show resolved Hide resolved
| `--binaries` , `--bin` | Installed binaries | [ boolean ] |
| `--browsers` | Installed web browsers | [ boolean ] |
| `--npmg` | Globally installed NPM packages ( webpack & webpack-cli only ) | [ boolean ] |
| `--npmPackages` | Info about webpack installed in the project | [ boolean ] |
pranshuchittora marked this conversation as resolved.
Show resolved Hide resolved

### Node

```js
const envinfo = require("@webpack-cli/info").default;
envinfo();
const info = require("webpack-cli/packages/info").default;
pranshuchittora marked this conversation as resolved.
Show resolved Hide resolved

async function wrapperFunc() {
let envinfo = await info({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the config needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supplying a config from --config is great I think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the variable envinfo. Is it needed in this example?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evenstensberg shall I change the config input to --config=[PATH] a flag?

pranshuchittora marked this conversation as resolved.
Show resolved Hide resolved
/* Custom Config */
});
}
wrapperFunc();
```

**Custom Config** => Custom arguments are key pair boolean values.

### CLI (via `webpack-cli`)

```bash
npx webpack-cli info
webpack-cli info --FLAGS #Flags are optional for custom output
```

[downloads]: https://img.shields.io/npm/dm/@webpack-cli/info.svg
Expand Down
54 changes: 42 additions & 12 deletions packages/info/__tests__/index.test.ts
@@ -1,15 +1,45 @@
import { information } from "../index";

describe("info", () => {
it("should return the information of the enviroment", async () => {
const returnedInformation = information();
const expectedInformation = {
Binaries: ["Node", "Yarn", "npm"],
Browsers: ["Chrome", "Firefox", "Safari"],
System: ["OS", "CPU"],
npmGlobalPackages: ["webpack", "webpack-cli"],
npmPackages: "*webpack*"
};
import { informationType } from "../index";

describe("infoSystem", () => {
it("should return the information of the system", async () => {
const returnedInformation = informationType("system");
const expectedInformation = { System: ["OS", "CPU", "Memory"] };

expect(returnedInformation).toEqual(expectedInformation);
});
});

describe("infoBinaries", () => {
it("should return the information of the binaries", async () => {
const returnedInformation = informationType("binaries");
const expectedInformation = { Binaries: ["Node", "Yarn", "npm"] };

expect(returnedInformation).toEqual(expectedInformation);
});
});

describe("infoBrowsers", () => {
it("should return the information of the browsers installed", async () => {
const returnedInformation = informationType("browsers");
const expectedInformation = { Browsers: ["Chrome", "Firefox", "Safari"] };

expect(returnedInformation).toEqual(expectedInformation);
});
});

describe("infoNpmGlobal", () => {
it("should return the information of the NPM global packages", async () => {
const returnedInformation = informationType("npmg");
const expectedInformation = { npmGlobalPackages: ["webpack", "webpack-cli"] };

expect(returnedInformation).toEqual(expectedInformation);
});
});

describe("infoNpm", () => {
it("should return the information of the NPM packages (webpack)", async () => {
const returnedInformation = informationType("npm");
const expectedInformation = { npmPackages: "*webpack*" };

expect(returnedInformation).toEqual(expectedInformation);
});
Expand Down
13 changes: 13 additions & 0 deletions packages/info/commands.ts
@@ -0,0 +1,13 @@
export const AVAILABLE_COMMANDS: string[] = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use these constants inside your commands.ts, so you can keep your code DRY.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not getting it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. You should create an enum for your available commands.
  2. Later you will use AVAILABLE_COMMANDS.BINARIES inside commands.ts

Basically it's not convenient to have the same string repeated in different places. Create ONE constant and it in those places

"binaries",
"system",
"browsers",
"npmGlobalPackages",
"npmPackages",
"bin",
"sys",
"npmg",
"npm"
];
export const AVAILABLE_FORMATS: string[] = ["json", "markdown"];
export const IGNORE_FLAGS: string[] = ["_", "$0"];
75 changes: 56 additions & 19 deletions packages/info/index.ts
@@ -1,29 +1,66 @@
import chalk from "chalk";
import * as envinfo from "envinfo";
import * as process from "process";
import { argv } from "./options";

/**
* Prints debugging information for webpack issue reporting
*/
import { AVAILABLE_COMMANDS, AVAILABLE_FORMATS, IGNORE_FLAGS } from "./commands";

interface Information {
Binaries: string[];
Browsers: string[];
System: string[];
npmGlobalPackages: string[];
npmPackages: string | string[];
Binaries?: string[];
Browsers?: string[];
System?: string[];
npmGlobalPackages?: string[];
npmPackages?: string | string[];
}

// eslint-disable-next-line
export function information(): Information {
return {
Binaries: ["Node", "Yarn", "npm"],
Browsers: ["Chrome", "Firefox", "Safari"],
System: ["OS", "CPU"],
npmGlobalPackages: ["webpack", "webpack-cli"],
npmPackages: "*webpack*"
};
const CONFIG = {};
const DEFAULT_DETAILS: Information = {
Binaries: ["Node", "Yarn", "npm"],
Browsers: ["Chrome", "Firefox", "Safari"],
System: ["OS", "CPU", "Memory"],
npmGlobalPackages: ["webpack", "webpack-cli"],
npmPackages: "*webpack*"
};

let DETAILS_OBJ = {};

export function informationType(type: string): Information {
switch (type) {
case "system":
return { System: ["OS", "CPU", "Memory"] };
case "binaries":
return { Binaries: ["Node", "Yarn", "npm"] };
case "browsers":
return { Browsers: ["Chrome", "Firefox", "Safari"] };
case "npmg":
return { npmGlobalPackages: ["webpack", "webpack-cli"] };
case "npm":
return { npmPackages: "*webpack*" };
}
}
export default async function info(CustomArgv: object): Promise<void> {
const CUSTOM_AGRUMENTS: boolean = typeof CustomArgv === "object";
const args = CUSTOM_AGRUMENTS ? CustomArgv : argv;

Object.keys(args).forEach(
(flag): void => {
if (IGNORE_FLAGS.includes(flag)) {
return;
} else if (AVAILABLE_COMMANDS.includes(flag)) {
const flagVal = informationType(flag);
DETAILS_OBJ = { ...DETAILS_OBJ, ...flagVal };
} else if (AVAILABLE_FORMATS.includes(flag)) {
CONFIG[flag] = true;
} else {
// Invalid option
process.stdout.write("\n" + chalk.bgRed(flag) + chalk.red(" is an invalid option" + "\n"));
return;
}
}
);

const OUTPUT = await envinfo.run(Object.keys(DETAILS_OBJ).length ? DETAILS_OBJ : DEFAULT_DETAILS, CONFIG);
!CUSTOM_AGRUMENTS ? process.stdout.write(OUTPUT + "\n") : null;

export default async function info(): Promise<void> {
process.stdout.write(await envinfo.run(information()));
return OUTPUT;
}
46 changes: 46 additions & 0 deletions packages/info/options.ts
@@ -0,0 +1,46 @@
import * as yargs from "yargs";
export const argv = yargs
.option("system", {
alias: "sys",
demandOption: false,
describe: "System information (OS, CPU)",
type: "boolean"
})
.option("binaries", {
alias: "bin",
demandOption: false,
describe: "Installed binaries",
type: "boolean"
})

.option("browsers", {
demandOption: false,
describe: "Installed web browsers",
type: "boolean"
})
.option("npmg", {
demandOption: false,
describe: "Globally installed NPM packages (webpack & webpack-cli only)",
type: "boolean"
})
.option("npmPackages", {
demandOption: false,
describe: "Info about webpack installed in the project",
type: "boolean"
})
.option("json", {
demandOption: false,
describe: "To get the output as JSON",
type: "boolean"
})
.option("json", {
demandOption: false,
describe: "To get the output as JSON",
type: "boolean"
})
.option("markdown", {
demandOption: false,
describe: "To get the output as markdown",
type: "boolean"
})
.group(["json", "markdown"], `Output format`).argv;