From a58c286ba869811b63ebb604e1a9e796a2b06f22 Mon Sep 17 00:00:00 2001 From: Pranshu Chittora Date: Wed, 24 Jul 2019 23:22:48 +0530 Subject: [PATCH] chore(info): changes base --- packages/info/README.md | 63 ++- packages/info/__tests__/index.test.ts | 54 ++- packages/info/commands.ts | 13 + packages/info/configParser.ts | 57 +++ packages/info/index.ts | 99 ++++- packages/info/options.ts | 42 ++ packages/info/package-lock.json | 527 ++++++++++++++++++++++++++ packages/info/package.json | 45 ++- packages/info/renderTable.ts | 15 + 9 files changed, 861 insertions(+), 54 deletions(-) create mode 100644 packages/info/commands.ts create mode 100644 packages/info/configParser.ts create mode 100644 packages/info/options.ts create mode 100644 packages/info/renderTable.ts diff --git a/packages/info/README.md b/packages/info/README.md index a1258e1affa..60b155c86e7 100644 --- a/packages/info/README.md +++ b/packages/info/README.md @@ -9,22 +9,79 @@ 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 + +#npx +npx webpack info [options] + ``` ## Usage +### Args / Flags + +#### Output format + +| Flag | Description | Type | +| ------------------- | ----------------------------- | ----------- | +| `--output-json` | To get the output as JSON | [ boolean ] | +| `--output-markdown` | To get the output as markdown | [ boolean ] | + +#### Options + +| Flag | Description | Type | +| ------------------- | --------------------------------------------------------------- | ----------- | +| `--help` | Show help | [ boolean ] | +| `--version` | Show version number of `webpack-cli` | [ boolean ] | +| `--system` , `-s` | System information ( OS, CPU ) | [ boolean ] | +| `--binaries` , `-b` | Installed binaries (Node, yarn, npm) | [ boolean ] | +| `--browsers` | Installed web browsers | [ boolean ] | +| `--npmg` | Globally installed NPM packages ( webpack & webpack-cli only ) | [ boolean ] | +| `--npmPackages` | Info about packages related to webpack installed in the project | [ boolean ] | + ### Node ```js -const envinfo = require("@webpack-cli/info").default; -envinfo(); +const info = require('@webpack-cli/info').default; + +async function wrapperFunc() { + await info({ + /* Custom Config */ + }); +} +wrapperFunc(); ``` +#### Custom config + +> Config has higher precedence than system flags + +```json +// Config's relative path +{ + + "config": [string] +} + // System info +{ + "binaries": [boolean], + "system": [boolean], + "browsers": [boolean], + "npmg": [boolean], + "npmPackages": [boolean], +} +``` + +The function returns `string` for `system` info, and returns an array of strings (`string[]`) for `config` + ### 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 diff --git a/packages/info/__tests__/index.test.ts b/packages/info/__tests__/index.test.ts index 7ddb1dae791..d0c1e95c002 100644 --- a/packages/info/__tests__/index.test.ts +++ b/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("npmPackages"); + const expectedInformation = { npmPackages: "*webpack*" }; expect(returnedInformation).toEqual(expectedInformation); }); diff --git a/packages/info/commands.ts b/packages/info/commands.ts new file mode 100644 index 00000000000..b5333ac05ca --- /dev/null +++ b/packages/info/commands.ts @@ -0,0 +1,13 @@ +export const AVAILABLE_COMMANDS: string[] = [ + "binaries", + "system", + "browsers", + "npmGlobalPackages", + "npmPackages", + "npmg", + "npm", + "b", + "s" +]; +export const AVAILABLE_FORMATS: string[] = ["output-json", "output-markdown"]; +export const IGNORE_FLAGS: string[] = ["_", "$0", "outputMarkdown", "outputJson", "npm-packages"]; diff --git a/packages/info/configParser.ts b/packages/info/configParser.ts new file mode 100644 index 00000000000..c44650e200c --- /dev/null +++ b/packages/info/configParser.ts @@ -0,0 +1,57 @@ +import * as path from 'path'; +import chalk from 'chalk'; +import * as prettyjson from 'prettyjson'; + +export function getNameFromPath(fullPath: string): string { + const filename = fullPath.replace(/^.*[\\\/]/, ''); + return filename; +} + +export function resolveFilePath(relativeFilePath: string): string { + const configPath = path.resolve(process.cwd() + '/' + relativeFilePath); + return configPath; +} + +export function fetchConfig(configPath: string): object { + let config = null; + try { + config = require(configPath); + } catch (e) { + process.stdout.write(chalk.red(`Error:`, e.code) + `\n` + e); + } + return config; +} + +const CONFIG_SCHEMA = { + plugins: 'Array', +}; + +function modifyConfig(config, key) { + switch (CONFIG_SCHEMA[key]) { + case 'Array': + config[key].forEach((element, idx) => { + config[key][idx] = { + name: chalk.greenBright(element.constructor.name), + ...element, + }; + }); + } +} + +export function configReader(config): string[] { + let filteredArray = []; + + let options = { + noColor: true, + }; + Object.keys(config).map((key): void => { + if (CONFIG_SCHEMA[key]) { + modifyConfig(config, key); + } + let rowArray = [key]; + rowArray.push(prettyjson.render(config[key], options)); + filteredArray = [...filteredArray, rowArray]; + }); + + return filteredArray; +} diff --git a/packages/info/index.ts b/packages/info/index.ts index 496e13c736e..4f78f78a630 100644 --- a/packages/info/index.ts +++ b/packages/info/index.ts @@ -1,29 +1,90 @@ +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"; +import { configReader, fetchConfig, resolveFilePath, getNameFromPath } from "./configParser"; +import { renderTable } from "./renderTable"; interface Information { - Binaries: string[]; - Browsers: string[]; - System: string[]; - npmGlobalPackages: string[]; - npmPackages: string | string[]; + Binaries?: string[]; + Browsers?: string[]; + System?: string[]; + npmGlobalPackages?: string[]; + npmPackages?: string | string[]; } +interface ArgvI { + _?: string[]; + bin?: boolean; + binaries?: boolean; + config?: string; +} + +const CONFIG = {}; +const DEFAULT_DETAILS: Information = { + Binaries: ["Node", "Yarn", "npm"], + Browsers: ["Chrome", "Firefox", "Safari"], + System: ["OS", "CPU", "Memory"], + npmGlobalPackages: ["webpack", "webpack-cli"], + npmPackages: "*webpack*" +}; -// 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*" - }; +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 "npmPackages": + return { npmPackages: "*webpack*" }; + } } +export default async function info(CustomArgv: object): Promise { + const CUSTOM_AGRUMENTS: boolean = typeof CustomArgv === "object"; + const args: ArgvI = CUSTOM_AGRUMENTS ? CustomArgv : argv; + const configRelativePath = argv._[1] ? argv._[1] : args.config; + if (configRelativePath) { + const fullConfigPath = resolveFilePath(configRelativePath); + const fileName = getNameFromPath(fullConfigPath); + const config = fetchConfig(fullConfigPath); + const parsedConfig = configReader(config); + + const stringifiedTable = renderTable(parsedConfig, fileName); + if (args.config) return parsedConfig; + else process.stdout.write(stringifiedTable + "\n"); + } else { + Object.keys(args).forEach((flag: string) => { + 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)) { + switch (flag) { + case "output-json": + CONFIG["json"] = true; + break; + case "output-markdown": + CONFIG["markdown"] = true; + break; + } + } else { + // Invalid option + process.stdout.write("\n" + chalk.bgRed(flag) + chalk.red(" is an invalid option" + "\n")); + return; + } + }); -export default async function info(): Promise { - process.stdout.write(await envinfo.run(information())); + const OUTPUT = await envinfo.run(Object.keys(DETAILS_OBJ).length ? DETAILS_OBJ : DEFAULT_DETAILS, CONFIG); + !CUSTOM_AGRUMENTS ? process.stdout.write(OUTPUT + "\n") : null; + return OUTPUT; + } + process.exit(0); } diff --git a/packages/info/options.ts b/packages/info/options.ts new file mode 100644 index 00000000000..1677fc51ab5 --- /dev/null +++ b/packages/info/options.ts @@ -0,0 +1,42 @@ +import * as yargs from "yargs"; +export const argv = yargs + .option("system", { + alias: "s", + demandOption: false, + describe: "System information (OS, CPU)", + type: "boolean" + }) + .option("binaries", { + alias: "b", + demandOption: false, + describe: "Installed binaries (Node, yarn, npm)", + 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 packages related to webpack installed in the project", + type: "boolean" + }) + .option("output-json", { + demandOption: false, + describe: "To get the output as JSON", + type: "boolean" + }) + .option("output-markdown", { + demandOption: false, + describe: "To get the output as markdown", + type: "boolean" + }) + .group(["output-json", "output-markdown"], `Output format`).argv; diff --git a/packages/info/package-lock.json b/packages/info/package-lock.json index 697a80284a0..e5602fd9cc9 100644 --- a/packages/info/package-lock.json +++ b/packages/info/package-lock.json @@ -10,16 +10,543 @@ "integrity": "sha512-b8bbUOTwzIY3V5vDTY1fIJ+ePKDUBqt2hC2woVGotdQQhG/2Sh62HOKHrT7ab+VerXAcPyAiTEipPu/FsreUtg==", "dev": true }, + "@types/yargs": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.0.tgz", + "integrity": "sha512-hY0o+kcz9M6kH32NUeb6VURghqMuCVkiUx+8Btsqhj4Hhov/hVGUx9DmBJeIkzlp1uAQK4wngQBCjqWdUUkFyA==", + "requires": { + "@types/yargs-parser": "*" + } + }, + "@types/yargs-parser": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-13.0.0.tgz", + "integrity": "sha512-wBlsw+8n21e6eTd4yVv8YD/E3xq0O6nNnJIquutAsFGE7EyMKz7W6RNT6BRu1SmdgmlCZ9tb0X+j+D6HGr8pZw==" + }, + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "requires": { + "color-convert": "^1.9.0" + } + }, + "camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==" + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "cli-table3": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.5.1.tgz", + "integrity": "sha512-7Qg2Jrep1S/+Q3EceiZtQcDPWxhAvBw+ERf1162v4sikJrvojMHFqXt8QIVha8UlH9rgU0BeWPytZ9/TzYqlUw==", + "requires": { + "colors": "^1.1.2", + "object-assign": "^4.1.0", + "string-width": "^2.1.1" + }, + "dependencies": { + "string-width": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "requires": { + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^4.0.0" + } + } + } + }, + "cliui": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", + "integrity": "sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ==", + "requires": { + "string-width": "^2.1.1", + "strip-ansi": "^4.0.0", + "wrap-ansi": "^2.0.0" + }, + "dependencies": { + "string-width": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "requires": { + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^4.0.0" + } + } + } + }, + "code-point-at": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", + "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + }, + "colors": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.3.3.tgz", + "integrity": "sha512-mmGt/1pZqYRjMxB1axhTo16/snVZ5krrKkcmMeVKxzECMMXoCgnvTPp10QgHfcbQZw8Dq2jMNG6je4JlWU0gWg==" + }, + "cross-spawn": { + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", + "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", + "requires": { + "nice-try": "^1.0.4", + "path-key": "^2.0.1", + "semver": "^5.5.0", + "shebang-command": "^1.2.0", + "which": "^1.2.9" + } + }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" + }, + "emoji-regex": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", + "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==" + }, + "end-of-stream": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", + "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", + "requires": { + "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==" }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" + }, + "execa": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", + "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", + "requires": { + "cross-spawn": "^6.0.0", + "get-stream": "^4.0.0", + "is-stream": "^1.1.0", + "npm-run-path": "^2.0.0", + "p-finally": "^1.0.0", + "signal-exit": "^3.0.0", + "strip-eof": "^1.0.0" + } + }, + "find-up": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "requires": { + "locate-path": "^3.0.0" + } + }, + "get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" + }, + "get-stream": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", + "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", + "requires": { + "pump": "^3.0.0" + } + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" + }, + "invert-kv": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", + "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==" + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" + }, + "is-stream": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" + }, + "isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" + }, + "lcid": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", + "integrity": "sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA==", + "requires": { + "invert-kv": "^2.0.0" + } + }, + "locate-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", + "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "requires": { + "p-locate": "^3.0.0", + "path-exists": "^3.0.0" + } + }, + "map-age-cleaner": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz", + "integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==", + "requires": { + "p-defer": "^1.0.0" + } + }, + "mem": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/mem/-/mem-4.3.0.tgz", + "integrity": "sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w==", + "requires": { + "map-age-cleaner": "^0.1.1", + "mimic-fn": "^2.0.0", + "p-is-promise": "^2.0.0" + } + }, + "mimic-fn": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==" + }, + "minimist": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" + }, + "nice-try": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", + "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" + }, + "npm-run-path": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", + "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", + "requires": { + "path-key": "^2.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1" + } + }, + "os-locale": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz", + "integrity": "sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q==", + "requires": { + "execa": "^1.0.0", + "lcid": "^2.0.0", + "mem": "^4.0.0" + } + }, + "p-defer": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", + "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=" + }, + "p-finally": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", + "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=" + }, + "p-is-promise": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.1.0.tgz", + "integrity": "sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg==" + }, + "p-limit": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.0.tgz", + "integrity": "sha512-pZbTJpoUsCzV48Mc9Nh51VbwO0X9cuPFE8gYwx9BTCt9SF8/b7Zljd2fVgOxhIF/HDTKgpVzs+GPhyKfjLLFRQ==", + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", + "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "requires": { + "p-limit": "^2.0.0" + } + }, + "p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" + }, + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" + }, + "path-key": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", + "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=" + }, + "prettyjson": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prettyjson/-/prettyjson-1.2.1.tgz", + "integrity": "sha1-/P+rQdGcq0365eV15kJGYZsS0ok=", + "requires": { + "colors": "^1.1.2", + "minimist": "^1.2.0" + } + }, + "pump": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", + "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", + "requires": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, + "require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" + }, + "require-main-filename": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" + }, + "semver": { + "version": "5.7.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", + "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==" + }, + "set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" + }, + "shebang-command": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", + "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", + "requires": { + "shebang-regex": "^1.0.0" + } + }, + "shebang-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", + "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" + }, + "signal-exit": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + }, + "dependencies": { + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==" + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "requires": { + "ansi-regex": "^4.1.0" + } + } + } + }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "requires": { + "ansi-regex": "^3.0.0" + } + }, + "strip-eof": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", + "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=" + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "requires": { + "has-flag": "^3.0.0" + } + }, "typescript": { "version": "3.5.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.2.tgz", "integrity": "sha512-7KxJovlYhTX5RaRbUdkAXN1KUZ8PwWlTzQdHV6xNqvuFOs7+WBo10TQUqT19Q/Jz2hk5v9TQDIhyLhhJY4p5AA==", "dev": true + }, + "which": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "requires": { + "isexe": "^2.0.0" + } + }, + "which-module": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", + "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" + }, + "wrap-ansi": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", + "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", + "requires": { + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1" + }, + "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", + "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "requires": { + "number-is-nan": "^1.0.0" + } + }, + "string-width": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", + "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "requires": { + "code-point-at": "^1.0.0", + "is-fullwidth-code-point": "^1.0.0", + "strip-ansi": "^3.0.0" + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "requires": { + "ansi-regex": "^2.0.0" + } + } + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + }, + "y18n": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", + "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==" + }, + "yargs": { + "version": "13.2.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.2.2.tgz", + "integrity": "sha512-WyEoxgyTD3w5XRpAQNYUB9ycVH/PQrToaTXdYXRdOXvEy1l19br+VJsc0vcO8PTGg5ro/l/GY7F/JMEBmI0BxA==", + "requires": { + "cliui": "^4.0.0", + "find-up": "^3.0.0", + "get-caller-file": "^2.0.1", + "os-locale": "^3.1.0", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^3.0.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^13.0.0" + } + }, + "yargs-parser": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.0.0.tgz", + "integrity": "sha512-w2LXjoL8oRdRQN+hOyppuXs+V/fVAYtpcrRxZuF7Kt/Oc+Jr2uAcVntaUTNT6w5ihoWfFDpNY8CPx1QskxZ/pw==", + "requires": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + } } } } diff --git a/packages/info/package.json b/packages/info/package.json index c9737930222..2042487e773 100644 --- a/packages/info/package.json +++ b/packages/info/package.json @@ -1,22 +1,27 @@ { - "name": "@webpack-cli/info", - "version": "0.1.6", - "description": "Outputs env info for the ease of debug", - "main": "index.js", - "author": "", - "license": "MIT", - "publishConfig": { - "access": "public" - }, - "dependencies": { - "envinfo": "7.3.1" - }, - "devDependencies": { - "@types/node": "12.0.8", - "typescript": "3.5.2" - }, - "scripts": { - "build": "tsc", - "watch": "npm run build && tsc -w" - } + "name": "@webpack-cli/info", + "version": "0.1.6", + "description": "Outputs info about system and webpack config", + "main": "index.js", + "author": "", + "license": "MIT", + "publishConfig": { + "access": "public" + }, + "dependencies": { + "@types/yargs": "13.0.0", + "chalk": "2.4.2", + "cli-table3": "0.5.1", + "envinfo": "7.3.1", + "prettyjson": "1.2.1", + "yargs": "13.2.2" + }, + "devDependencies": { + "@types/node": "12.0.8", + "typescript": "3.5.2" + }, + "scripts": { + "build": "tsc", + "watch": "npm run build && tsc -w" + } } diff --git a/packages/info/renderTable.ts b/packages/info/renderTable.ts new file mode 100644 index 00000000000..daff83aa609 --- /dev/null +++ b/packages/info/renderTable.ts @@ -0,0 +1,15 @@ +import * as Table from "cli-table3"; +import chalk from "chalk"; +export function renderTable(data, fileName): string { + let table = new Table({ + head: [chalk.blueBright("Config"), chalk.blueBright(fileName)] + }); + + data.map( + (elm: Table.Cell[] & Table.VerticalTableRow & Table.CrossTableRow): void => { + table.push(elm); + } + ); + + return table.toString(); +}