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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve cliui design #129

Merged
merged 1 commit into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 77 additions & 10 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
"@nodesecure/utils": "^1.0.0",
"@nodesecure/vuln": "^1.7.0",
"@polka/send-type": "^0.5.2",
"@topcli/cliui": "^1.1.0",
"@topcli/spinner": "^1.1.0",
"cacache": "^17.0.2",
"cliui": "^7.0.4",
"dotenv": "^16.0.3",
"filenamify": "^5.1.1",
"kleur": "^4.1.4",
Expand Down
24 changes: 14 additions & 10 deletions src/commands/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@ import fs from "fs/promises";
import path from "path";

// Import Third-party Dependencies
import cliui from "cliui";
import cliui from "@topcli/cliui";
import kleur from "kleur";
import * as i18n from "@nodesecure/i18n";
import { formatBytes } from "@nodesecure/utils";

// VARS
const { yellow, gray, white, green, cyan, red } = kleur;
const { yellow, grey, white, green, cyan, red } = kleur;

function separatorLine() {
return grey("-".repeat(80));
}

export async function main(json = "nsecure-result.json") {
const dataFilePath = path.join(process.cwd(), json);
const rawAnalysis = await fs.readFile(dataFilePath, { encoding: "utf-8" });
const { rootDependencyName, dependencies } = JSON.parse(rawAnalysis);

const ui = cliui();
const ui = cliui({ width: 80 });
const title = `${white().bold(`${i18n.getToken("ui.stats.title")}:`)} ${cyan().bold(rootDependencyName)}`;
ui.div(
{ text: title, width: 50 }
);
ui.div({ text: gray("-------------------------------------------------------------------"), width: 70 });
ui.div({ text: separatorLine() });

if (dependencies) {
const {
Expand All @@ -34,15 +38,15 @@ export async function main(json = "nsecure-result.json") {

ui.div(
{ text: white().bold(`${i18n.getToken("ui.stats.total_packages")}:`), width: 60 },
{ text: green().bold(`${packagesCount}`), width: 20 }
{ text: green().bold(`${packagesCount}`), width: 20, align: "right" }
);
ui.div(
{ text: white().bold(`${i18n.getToken("ui.stats.total_size")}:`), width: 60 },
{ text: green().bold(`${formatBytes(totalSize)}`), width: 20 }
{ text: green().bold(`${formatBytes(totalSize)}`), width: 20, align: "right" }
);
ui.div(
{ text: white().bold(`${i18n.getToken("ui.stats.indirect_deps")}:`), width: 60 },
{ text: green().bold(`${packageWithIndirectDeps}`), width: 20 }
{ text: green().bold(`${packageWithIndirectDeps}`), width: 20, align: "right" }
);

ui.div("");
Expand All @@ -52,7 +56,7 @@ export async function main(json = "nsecure-result.json") {
const extensionEntries = Object.entries(extensionMap);
ui.div(
{
text: `${extensionEntries.reduce(buildStringFromEntries, "")}`, width: 70
text: `${extensionEntries.reduce(buildStringFromEntries, "")}`
}
);

Expand All @@ -63,7 +67,7 @@ export async function main(json = "nsecure-result.json") {
const licenceEntries = Object.entries(licenceMap);
ui.div(
{
text: yellow().bold(`${licenceEntries.reduce(buildStringFromEntries, "")}`), width: 70
text: yellow().bold(`${licenceEntries.reduce(buildStringFromEntries, "")}`)
}
);
}
Expand All @@ -73,7 +77,7 @@ export async function main(json = "nsecure-result.json") {
{ text: yellow().bold("No dependencies"), width: 30 }
);
}
ui.div({ text: gray("-------------------------------------------------------------------"), width: 70 });
ui.div({ text: separatorLine() });
console.log(ui.toString());

return void 0;
Expand Down
Loading