Skip to content

Commit

Permalink
feat: add option to run in debug mode (fix #375)
Browse files Browse the repository at this point in the history
* fix: repository name with spaces breaks git clone command
  • Loading branch information
ErwanRaulo committed Jul 23, 2024
1 parent cb5dd21 commit 31b287b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
26 changes: 24 additions & 2 deletions bin/commands/execute.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Import Node.js Dependencies
import fs from "node:fs/promises";
import { writeFileSync } from "node:fs";
import path from "node:path";
import { inspect } from "node:util";

// Import Third-party Dependencies
import * as rc from "@nodesecure/rc";
Expand All @@ -12,7 +15,13 @@ import { fetchPackagesAndRepositoriesData } from "../../src/analysis/fetch.js";
import * as CONSTANTS from "../../src/constants.js";
import * as reporting from "../../src/reporting/index.js";

export async function execute() {
export async function execute(options = {}) {
const { d: debugMode } = options;

if (debugMode) {
console.log(kleur.bgMagenta().bold(` > Debug mode enabled \n`));
}

const [configResult] = await Promise.all([
rc.read(
process.cwd()
Expand All @@ -22,6 +31,7 @@ export async function execute() {

const config = configResult.unwrap();
const { report } = config;

if (report.reporters.length === 0) {
throw new Error("At least one reporter must be selected (either 'HTML' or 'PDF')");
}
Expand All @@ -31,7 +41,13 @@ export async function execute() {

store.run(config, () => {
fetchPackagesAndRepositoriesData()
.then((data) => reporting.proceed(data))
.then((data) => {
if (debugMode) {
debug(data);
}

return reporting.proceed(data);
})
.catch((error) => {
console.error(error);
process.exit(0);
Expand Down Expand Up @@ -59,3 +75,9 @@ function teardown() {
recursive: true, force: true
});
}

function debug(obj) {
const filePath = path.join(CONSTANTS.DIRS.REPORTS, `debug-pkg-repo.txt`);
writeFileSync(filePath, inspect(obj, { showHidden: true, depth: null }), "utf8");
}

1 change: 1 addition & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const cli = sade("nreport").version(version);

cli
.command("execute")
.option("-d, --debug", "Enable debug mode", false)
.alias("exec")
.describe("Execute report at the current working dir with current configuration.")
.example("nreport exec")
Expand Down
12 changes: 8 additions & 4 deletions src/analysis/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ async function fetchRepositoriesStats(
},
async(spinner) => {
const repos = await Promise.all(
repositories.map((repositoryName) => utils.cloneGITRepository(
path.join(CONSTANTS.DIRS.CLONES, repositoryName),
`${organizationUrl}/${repositoryName}.git`
))
repositories.map((repositoryName) => {
const trimmedRepositoryName = repositoryName.trim();

return utils.cloneGITRepository(
path.join(CONSTANTS.DIRS.CLONES, trimmedRepositoryName),
`${organizationUrl}/${trimmedRepositoryName}.git`
);
})
);
spinner.text = "Fetching repositories metadata on the NPM Registry";

Expand Down

0 comments on commit 31b287b

Please sign in to comment.