analyze-project-structure
Version:
CLI tool for analyzing and printing the folder structure of a project, extracting details about files (such as functions, variables, routes, and imports/exports), and summarizing the project's code organization.
34 lines (26 loc) • 1.2 kB
JavaScript
const fs = require("fs");
const path = require("path");
const detectProjectType = require("./lib/detectProjectType");
const printFolderStructure = require("./lib/printFolderStructure");
// Get CLI arguments:
// - outputFile (defaults to 'folder-structure-output.txt')
// - outputFormat (defaults to 'text', can be 'json')
const [, , outputFile = "folder-structure-output.txt", outputFormat = "text"] =
process.argv;
const outputPath = path.join(process.cwd(), outputFile);
const sourcePath = path.join(process.cwd(), "src");
const projectType = detectProjectType();
let output;
if (outputFormat === "json") {
// For JSON output, printFolderStructure should return an object, not string
output = printFolderStructure(sourcePath, "", {}, projectType, true); // 'true' flag means 'return object'
fs.writeFileSync(outputPath, JSON.stringify(output, null, 2));
} else {
// For text output, keep existing string behavior
output = printFolderStructure(sourcePath, "", "", projectType, false);
fs.writeFileSync(outputPath, output);
}
console.log(
`Folder structure and details saved to ${outputFile} (${outputFormat} format)`
);