Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | /** * Health Check Integration Script for spec-up-t * * This script integrates the spec-up-t-healthcheck tool to validate consuming projects. * It runs FROM spec-up-t (menu option 7) but checks the CONSUMING project (current directory). * * Usage (from consuming project): * npm run healthCheck * * Or via spec-up-t menu: * npm run menu -> [7] Run health check * * Options: * --format text|json|html Output format (default: html) * --output <file> Output file path * --checks <checks> Comma-separated list of specific checks * * Examples: * node run-healthcheck.js * node run-healthcheck.js --format json * node run-healthcheck.js --format html --output health-report.html */ const fs = require('node:fs').promises; const path = require('node:path'); /** * Parse command line arguments * Handles both direct node invocations and npm script invocations * * @returns {Object} Parsed arguments */ function parseArgs() { const args = process.argv.slice(2); const options = { format: 'html', // Changed default to HTML for better user experience output: null, checks: null }; for (let i = 0; i < args.length; i++) { if (args[i] === '--format' && args[i + 1]) { options.format = args[i + 1]; i++; } else if (args[i] === '--output' && args[i + 1]) { options.output = args[i + 1]; i++; } else if (args[i] === '--checks' && args[i + 1]) { options.checks = args[i + 1].split(','); i++; } } return options; } /** * Main execution function * * Runs health checks on the CONSUMING PROJECT (current working directory). * This script is part of spec-up-t but validates the project that uses spec-up-t. */ async function main() { try { console.log('š„ Spec-Up-T Health Check\n'); console.log('š Checking consuming project in:', process.cwd()); console.log(''); // Parse command line arguments const options = parseArgs(); // Import the health check tool const { createProvider, runHealthChecks, formatResultsAsText, formatResultsAsJson, formatResultsAsHtml } = await import('spec-up-t-healthcheck'); // Create a provider for the CURRENT WORKING DIRECTORY (the consuming project) const provider = createProvider(process.cwd()); // Run health checks on the consuming project console.log('š Running health checks on consuming project...'); const healthCheckOptions = {}; if (options.checks) { healthCheckOptions.checks = options.checks; } const results = await runHealthChecks(provider, healthCheckOptions); // Display summary console.log('\nš Health Check Summary:'); console.log(` Total Checks: ${results.summary.total}`); console.log(` ā Passed: ${results.summary.passed}`); console.log(` ā Failed: ${results.summary.failed}`); console.log(` ā ļø Warnings: ${results.summary.warnings}`); console.log(` āļø Skipped: ${results.summary.skipped}`); console.log(` š Health Score: ${results.summary.score}%\n`); // Format results based on requested format let output; let defaultFilename; switch (options.format) { case 'json': output = formatResultsAsJson(results); defaultFilename = 'health-report.json'; break; case 'html': output = formatResultsAsHtml(results, { title: 'Spec-Up-T Project Health Check', repositoryUrl: results.provider.repoPath ? `file://${results.provider.repoPath}` : undefined }); defaultFilename = 'health-report.html'; break; case 'text': default: output = formatResultsAsText(results); defaultFilename = 'health-report.txt'; break; } // Determine output path const outputPath = options.output || defaultFilename; // Save to file await fs.writeFile(outputPath, output); console.log(`š Report saved to: ${outputPath}`); // For HTML format, try to open in browser if (options.format === 'html' && !options.output) { try { const { openHtmlFile } = require('./utils/file-opener'); await openHtmlFile(path.resolve(outputPath)); console.log('š Opening report in browser...'); } catch (error) { console.log('ā¹ļø Tip: Open the report manually in your browser'); } } // For text format, also print to console if (options.format === 'text') { console.log('\n' + output); } // Exit with appropriate code if (results.summary.hasErrors) { console.error('\nā Health check completed with errors'); console.error(' Please review the report for details'); process.exit(1); } else if (results.summary.hasWarnings) { console.warn('\nā ļø Health check completed with warnings'); process.exit(0); } else { console.log('\nā Health check completed successfully'); console.log(' All checks passed!'); process.exit(0); } } catch (error) { console.error('\nā Health check failed:', error.message); console.error('\nDetails:', error.stack); console.error('\nTroubleshooting:'); console.error(' - Ensure you are running this from a consuming project directory'); console.error(' - Check that spec-up-t-healthcheck is properly installed'); console.error(' - Verify the consuming project has a valid package.json'); process.exit(1); } } // Run the script main(); |