UNPKG

adam-java-analytics

Version:

Java code analyzer for detecting package dependencies and circular references

91 lines (75 loc) 2.73 kB
#!/usr/bin/env node const { execSync, spawn } = require("child_process") const path = require("path") const fs = require("fs") const javaProjectPath = process.env.NEXT_PUBLIC_PROJECT_PATH || process.cwd() const PORT = 3333 const maxDepth = 9999 function isJavaProject(directory) { try { const command = process.platform === "win32" ? `dir /s /b "${directory}\\*.java" | findstr /r ".*" > nul` : `find "${directory}" -name "*.java" -type f -maxdepth ${maxDepth} | head -n 1` execSync(command, { stdio: "ignore" }) return true } catch (error) { return false } } async function main() { console.log("\x1b[36m%s\x1b[0m", "🔍 Adam Evaluation - Java Code Analyzer") if (!isJavaProject(javaProjectPath)) { console.error( "\x1b[31m%s\x1b[0m", "❌ No Java files found in this directory. Make sure you're in a Java project root.", ) process.exit(1) } console.log("\x1b[32m%s\x1b[0m", "✅ Java project detected") console.log("\x1b[33m%s\x1b[0m", "⚙️ Analyzing project structure...") // Path inside your CLI package to save config const configPath = path.join(javaProjectPath, "..", ".project-config.json") fs.writeFileSync(configPath, JSON.stringify({ projectPath: javaProjectPath }, null, 2)) console.log("\x1b[36m%s\x1b[0m", "🚀 Starting analyzer web interface...") try { // Root of your CLI package const realPackageRoot = fs.realpathSync(path.resolve(__dirname, "..")) const nextProcess = spawn("npx", ["next", "dev", "-p", PORT.toString()], { cwd: realPackageRoot, // run next inside the CLI project, not the Java project env: { ...process.env, PROJECT_PATH: javaProjectPath, }, stdio: "inherit", shell: true, }) // Try to open browser (cross-platform) setTimeout(() => { const openCommand = process.platform === "win32" ? "start" : process.platform === "darwin" ? "open" : "xdg-open" try { execSync(`${openCommand} http://localhost:${PORT}`) console.log("\x1b[33m%s\x1b[0m", "⚠️ Press Ctrl+C to stop the server when done") } catch { console.log("\x1b[31m%s\x1b[0m", "❌ Couldn't open the browser automatically.") } }, 2000) process.on("SIGINT", () => { console.log("\x1b[36m%s\x1b[0m", "👋 Shutting down server...") nextProcess.kill() process.exit(0) }) } catch (error) { console.error("\x1b[31m%s\x1b[0m", "❌ Failed to start analyzer:", error.message) process.exit(1) } } main().catch((error) => { console.error("\x1b[31m%s\x1b[0m", "❌ An error occurred:", error.message) process.exit(1) })