This document provides instructions for integrating the SpiceCode CLI with the SpiceCode Dashboard.
The SpiceCode Dashboard is a web application that displays code metrics collected by the SpiceCode CLI. The dashboard allows you to:
- View metrics for all your projects and files
- Track metrics over time with historical data visualization
- Identify code quality trends and issues
- Log in to the SpiceCode Dashboard using GitHub authentication
- Navigate to your Profile page
- Copy your API key or generate a new one
To update your SpiceCode CLI to send metrics to the dashboard:
// Example modification to spicecode/index.js
const axios = require('axios');
// After metrics are calculated
async function sendMetricsToDashboard(filePath, fileName, metrics, apiKey) {
try {
const projectName = process.cwd().split('/').pop(); // Get current directory name as project name
const response = await axios.post('https://your-dashboard-url.com/api/metrics/submit', {
projectName,
filePath,
fileName,
metrics
}, {
headers: {
'X-API-Key': apiKey
}
});
console.log('Metrics sent to dashboard:', response.data.message);
} catch (error) {
console.error('Failed to send metrics to dashboard:', error.message);
}
}
// Add a command line option for the API key
program
.option('--api-key <key>', 'API key for SpiceCode Dashboard')
.option('--project <name>', 'Project name for dashboard');
// In your main function
if (program.apiKey) {
await sendMetricsToDashboard(filePath, fileName, metrics, program.apiKey);
}Run SpiceCode CLI with your API key:
spicecode analyze --api-key YOUR_API_KEY path/to/file.js- Log in to the SpiceCode Dashboard
- Navigate to the Projects page
- You should see your project and file metrics displayed
The metrics should be sent in the following format:
{
"projectName": "your-project-name",
"filePath": "/path/to/file.js",
"fileName": "file.js",
"metrics": {
"complexity": 5,
"maintainability": 85,
"linesOfCode": 120,
"commentPercentage": 15,
"duplications": 2,
"bugs": 0,
"vulnerabilities": 0,
"codeSmells": 3
}
}The dashboard automatically deduplicates metrics based on their content. If you submit identical metrics for the same file, they will not be duplicated in the database.
Each time you submit different metrics for the same file, a new entry is created with a timestamp. This allows you to track changes over time and visualize trends in your code quality.