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

Update copyright and replace kleur ​​​​with styleText #440

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022-2024 NodeSecure
Copyright (c) 2022-2025 NodeSecure

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 7 additions & 5 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ dotenv.config();
import path from "node:path";
import { createRequire } from "node:module";
import { fileURLToPath } from "node:url";
import { styleText } from "node:util";

// Import Third-party Dependencies
import kleur from "kleur";
import sade from "sade";
import semver from "semver";
import * as i18n from "@nodesecure/i18n";
Expand All @@ -30,11 +30,13 @@ await i18n.extendFromSystemPath(
path.join(__dirname, "..", "i18n")
);

console.log(kleur.grey().bold(`\n > ${i18n.getTokenSync("cli.executing_at")}: ${kleur.yellow().bold(process.cwd())}\n`));
console.log(
styleText(["gray", "bold"], `\n > ${i18n.getTokenSync("cli.executing_at")}: ${styleText(["yellow", "bold"], process.cwd())}\n`)
);

const minVersion = semver.minVersion(manifest.engines.node);
if (semver.lt(process.versions.node, minVersion)) {
console.log(kleur.red().bold(` [!] ${i18n.getTokenSync("cli.min_nodejs_version", minVersion)}\n`));
console.log(styleText(["red", "bold"], ` [!] ${i18n.getTokenSync("cli.min_nodejs_version", minVersion)}\n`));
process.exit(0);
}

Expand Down Expand Up @@ -138,10 +140,10 @@ function defaultScannerCommand(name, options = {}) {

function checkNodeSecureToken() {
if (!process.env.NODE_SECURE_TOKEN) {
const varEnvName = kleur.yellow().bold("NODE_SECURE_TOKEN");
const varEnvName = styleText(["yellow", "bold"], "NODE_SECURE_TOKEN");

console.log(
kleur.red().bold(`${i18n.getTokenSync("cli.missingEnv", varEnvName)}\n`)
styleText(["red", "bold"], `${i18n.getTokenSync("cli.missingEnv", varEnvName)}\n`)
);
}
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
"filenamify": "^6.0.0",
"highlightjs-line-numbers.js": "^2.8.0",
"ini": "^5.0.0",
"kleur": "^4.1.5",
"ms": "^2.1.3",
"open": "^10.1.0",
"pino": "^9.3.2",
Expand Down
32 changes: 9 additions & 23 deletions src/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import os from "node:os";
import path from "node:path";
import fs from "node:fs/promises";
import { existsSync } from "node:fs";
import { styleText } from "node:util";

// Import Third-party Dependencies
import * as RC from "@nodesecure/rc";
import kleur from "kleur";
import { spawn } from "node:child_process";

const K_HOME_PATH = path.join(os.homedir(), "nodesecure");
Expand All @@ -19,20 +19,12 @@ function spawnCodeAtNodeSecureRc(path, isCwd = false) {
}

console.log(
kleur
.white()
.bold(
`\n ${kleur.yellow().bold(`There is no .nodesecurerc here: ${path}`)}`
)
styleText(["white", "bold"], `\n ${styleText(["yellow", "bold"], `There is no .nodesecurerc here: ${path}`)}`)
);

if (isCwd) {
console.log(
kleur
.white()
.bold(
`\n ${kleur.yellow().bold("You must try to run nsecure config create")}`
)
styleText(["white", "bold"], `\n ${styleText(["yellow", "bold"], "You must try to run nsecure config create")}`)
);
}

Expand All @@ -43,12 +35,9 @@ export function editConfigFile() {
console.log("");

console.log(
kleur
.white()
.bold(
`\n ${kleur.yellow().bold("Try to opened up your Nodesecure configuration in vscode")}`
)
);
styleText(
["white", "bold"], `\n ${styleText(["yellow", "bold"], "Try to opened up your Nodesecure configuration in vscode")}`
));

const isNodeSecureRcAtHomeDir = spawnCodeAtNodeSecureRc(path.join(K_HOME_PATH, RC.CONSTANTS.CONFIGURATION_NAME));

Expand All @@ -63,12 +52,9 @@ export async function createConfigFile(configuration = "minimal", opts) {
const pathConfigFile = cwd ? process.cwd() : K_HOME_PATH;
console.log("");
console.log(
kleur
.white()
.bold(
`\n ${kleur.yellow().bold(`We are going to create the Nodesecure configuration file at: ${pathConfigFile}`)}`
)
);
styleText(["white", "bold"],
`\n ${styleText(["yellow", "bold"], `We are going to create the Nodesecure configuration file at: ${pathConfigFile}`)}`
));
await fs.mkdir(pathConfigFile, { recursive: true });

await RC.read(pathConfigFile, { createIfDoesNotExist: true, createMode: configuration });
Expand Down
8 changes: 4 additions & 4 deletions src/commands/http.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Import Node.js Dependencies
import fs from "node:fs";
import path from "node:path";
import { styleText } from "node:util";

// Import Third-party Dependencies
import * as SemVer from "semver";
import kleur from "kleur";
import * as i18n from "@nodesecure/i18n";

// Import Internal Dependencies
Expand Down Expand Up @@ -47,13 +47,13 @@ function assertScannerVersion(
if (!SemVer.satisfies(scannerVersion, kRequiredScannerRange)) {
const error = i18n.getTokenSync(
"cli.startHttp.invalidScannerVersion",
kleur.yellow(scannerVersion),
kleur.yellow(kRequiredScannerRange)
styleText("yellow", scannerVersion),
styleText("yellow", kRequiredScannerRange)
);
const regenerate = i18n.getTokenSync("cli.startHttp.regenerate");

console.log(" > " + path.basename(dataFilePath));
console.log(" > " + kleur.red().bold(error));
console.log(" > " + styleText(["red", "bold"], error));
console.log(` > ${regenerate}`);
console.log();

Expand Down
11 changes: 7 additions & 4 deletions src/commands/lang.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Import Node.js Dependencies
import { styleText } from "node:util";

// Import Third-party Dependencies
import * as i18n from "@nodesecure/i18n";
import { select } from "@topcli/prompts";
import kleur from "kleur";

export async function set() {
const langs = await i18n.getLanguages();
const selectedLang = await select(
kleur.green().bold(` ${i18n.getTokenSync("cli.commands.lang.question_text")}`),
styleText(["green", "bold"], ` ${i18n.getTokenSync("cli.commands.lang.question_text")}`),
{
choices: langs
}
Expand All @@ -16,7 +18,8 @@ export async function set() {
await i18n.getLocalLang();

console.log(
kleur.white().bold(`\n ${i18n.getTokenSync("cli.commands.lang.new_selection", kleur.yellow().bold(selectedLang))}`)
);
styleText(
["white", "bold"], `\n ${i18n.getTokenSync("cli.commands.lang.new_selection", styleText(["yellow", "bold"], selectedLang))}`
));
console.log();
}
36 changes: 22 additions & 14 deletions src/commands/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import fs from "node:fs";
import path from "node:path";
import events from "node:events";
import { styleText } from "node:util";

// Import Third-party Dependencies
import kleur from "kleur";
import filenamify from "filenamify";
import { Spinner } from "@topcli/spinner";
import ms from "ms";
Expand Down Expand Up @@ -108,11 +108,13 @@ function initLogger(spec, verbose = true) {

if (eventName === "fetchManifest") {
spinner[eventName]
.start(kleur.white().bold(i18n.getTokenSync(spinner.i18n.start[eventName], kleur.green().bold(spec))));
.start(
styleText(["white", "bold"], i18n.getTokenSync(spinner.i18n.start[eventName], styleText(["green", "bold"], spec)))
);
}
else {
spinner[eventName]
.start(kleur.white().bold(i18n.getTokenSync(spinner.i18n.start[eventName])));
.start(styleText(["white", "bold"], i18n.getTokenSync(spinner.i18n.start[eventName])));
}
});

Expand All @@ -121,8 +123,10 @@ function initLogger(spec, verbose = true) {
return;
}

const stats = kleur.gray().bold(`[${kleur.yellow().bold(logger.count(eventName))}/${logger.count("walkTree")}]`);
spinner[eventName].text = kleur.white().bold(`${i18n.getTokenSync(spinner.i18n.tick[eventName])} ${stats}`);
const stats = styleText(
["white", "bold"], `[${styleText(["yellow", "bold"], logger.count(eventName))}/${logger.count("walkTree")}]`
);
spinner[eventName].text = styleText(["white", "bold"], `${i18n.getTokenSync(spinner.i18n.tick[eventName])} ${stats}`);
});

logger.on("end", (eventName) => {
Expand All @@ -132,20 +136,23 @@ function initLogger(spec, verbose = true) {

const spin = spinner[eventName];
const tokenName = spinner.i18n.end[eventName];
const execTime = kleur.cyan().bold(ms(Number(spin.elapsedTime.toFixed(2))));
const execTime = styleText(["cyan", "bold"], ms(Number(spin.elapsedTime.toFixed(2))));

if (eventName === "walkTree") {
spin.succeed(kleur.white().bold(
i18n.getTokenSync(tokenName, kleur.yellow().bold(i18n.getTokenSync("depWalker.dep_tree")), execTime)));
spin.succeed(styleText(["white", "bold"],
i18n.getTokenSync(tokenName, styleText(["yellow", "bold"], i18n.getTokenSync("depWalker.dep_tree")), execTime)));
}
else if (eventName === "registry") {
spin.succeed(kleur.white().bold(i18n.getTokenSync(tokenName)));
spin.succeed(styleText(["white", "bold"], i18n.getTokenSync(tokenName)));
}
else if (eventName === "tarball") {
spin.succeed(kleur.white().bold(i18n.getTokenSync(tokenName, kleur.green().bold(logger.count("walkTree")), execTime)));
spin.succeed(
styleText(["white", "bold"],
i18n.getTokenSync(tokenName, styleText(["green", "bold"], logger.count("walkTree")), execTime)));
}
else if (eventName === "fetchManifest") {
spin.succeed(kleur.white().bold(i18n.getTokenSync(tokenName, kleur.green().bold(spec), execTime)));
spin.succeed(
styleText(["white", "bold"], i18n.getTokenSync(tokenName, styleText(["green", "bold"], spec), execTime)));
console.log("");
}
});
Expand All @@ -161,9 +168,9 @@ function logAndWrite(payload, output = "nsecure-result") {
}

if (payload.warnings.length > 0) {
console.log(`\n ${kleur.yellow().underline().bold("Global Warning:")}\n`);
console.log(`\n ${styleText(["yellow", "underline", "bold"], "Global Warning:")}\n`);
for (const warning of payload.warnings) {
console.log(kleur.red().bold(warning));
console.log(styleText(["red", "bold"], warning));
}
}

Expand All @@ -176,7 +183,8 @@ function logAndWrite(payload, output = "nsecure-result") {
fs.writeFileSync(filePath, ret);

console.log("");
console.log(kleur.white().bold(i18n.getTokenSync("cli.successfully_written_json", kleur.green().bold(filePath))));
console.log(
styleText(["white", "bold"], i18n.getTokenSync("cli.successfully_written_json", styleText(["green", "bold"], filePath))));
console.log("");

return filePath;
Expand Down
17 changes: 6 additions & 11 deletions src/commands/scorecard.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// Import Node.js Dependencies
import fs from "node:fs";
import { styleText } from "node:util";

// Import Third-party Dependencies
import cliui from "@topcli/cliui";
import kleur from "kleur";
import * as scorecard from "@nodesecure/ossf-scorecard-sdk";
import ini from "ini";
import { Ok, Err } from "@openally/result";
// VARS
const { yellow, grey, cyan, white } = kleur;

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

export function getCurrentRepository(vcs = "github") {
Expand Down Expand Up @@ -44,7 +42,7 @@ export async function main(repo, opts) {
platform = vcs.slice(-4) === ".com" ? vcs : `${vcs}.com`;
}
catch (error) {
console.log(white().bold(result.err));
console.log(styleText(["white", "bold"], result.err));

process.exit();
}
Expand All @@ -58,17 +56,14 @@ export async function main(repo, opts) {
}
catch (error) {
console.log(
kleur
.white()
.bold(white().bold(`${repository} is not part of the OSSF Scorecard BigQuery public dataset.`))
);
styleText(["white", "bold"], `${repository} is not part of the OSSF Scorecard BigQuery public dataset.`));

process.exit();
}

const ui = cliui({ width: 80 });

ui.div({ text: cyan("OSSF Scorecard"), align: "center", padding: [1, 1, 1, 1] });
ui.div({ text: styleText("cyan", "OSSF Scorecard"), align: "center", padding: [1, 1, 1, 1] });

ui.div(
{ text: "Repository", width: 20 },
Expand All @@ -87,7 +82,7 @@ export async function main(repo, opts) {
for (const check of data.checks) {
const { score, name, reason } = check;
ui.div(
{ text: yellow(name), width: 77 },
{ text: styleText("yellow", name), width: 77 },
{ text: !score || score < 0 ? 0 : score, width: 3, align: "right" }
);

Expand Down
Loading
Loading