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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | /**
* Project Validation Tools
* Validates project structure and configuration
*/
import { existsSync, readFileSync } from 'fs';
import { resolve } from 'path';
export async function validateProject(_options = {}) {
const validation = {
timestamp: new Date().toISOString(),
type: 'project-validation',
summary: {},
checks: [],
issues: [],
recommendations: []
};
try {
// Check essential files
const essentialFiles = [
{ file: 'package.json', required: true, description: 'Project configuration' },
{ file: 'coherent.config.js', required: false, description: 'Coherent.js configuration' },
{ file: 'src/', required: false, description: 'Source directory' },
{ file: 'README.md', required: false, description: 'Project documentation' }
];
essentialFiles.forEach(({ file, required, description }) => {
const exists = existsSync(resolve(file));
const check = {
name: file,
description,
required,
status: exists ? 'pass' : (required ? 'fail' : 'warning'),
exists
};
validation.checks.push(check);
if (required && !exists) {
validation.issues.push({
type: 'missing-file',
message: `Required file missing: ${file}`,
suggestion: file === 'package.json' ? 'Run npm init to create package.json' : `Create ${file}`
});
}
});
// Validate package.json
if (existsSync('package.json')) {
const packageValidation = validatePackageJson();
validation.checks.push(...packageValidation.checks);
validation.issues.push(...packageValidation.issues);
validation.recommendations.push(...packageValidation.recommendations);
}
// Check project structure
const structureValidation = validateProjectStructure();
validation.checks.push(...structureValidation.checks);
validation.recommendations.push(...structureValidation.recommendations);
// Generate summary
const passedChecks = validation.checks.filter(c => c.status === 'pass').length;
const totalChecks = validation.checks.length;
const failedChecks = validation.checks.filter(c => c.status === 'fail').length;
validation.summary = {
status: failedChecks === 0 ? (validation.issues.length === 0 ? 'excellent' : 'good') : 'needs-attention',
passedChecks,
totalChecks,
failedChecks,
issuesFound: validation.issues.length,
score: Math.round((passedChecks / totalChecks) * 100)
};
} catch (error) {
validation.summary.status = 'error';
validation.summary.error = error.message;
}
return validation;
}
function validatePackageJson() {
const checks = [];
const issues = [];
const recommendations = [];
try {
const packageJson = JSON.parse(readFileSync('package.json', 'utf-8'));
// Check basic fields
const requiredFields = ['name', 'version', 'description'];
requiredFields.forEach(field => {
const hasField = packageJson[field];
checks.push({
name: `package.json.${field}`,
description: `Package ${field} is defined`,
required: true,
status: hasField ? 'pass' : 'fail',
value: hasField ? packageJson[field] : 'missing'
});
if (!hasField) {
issues.push({
type: 'package-field',
message: `package.json missing required field: ${field}`,
suggestion: `Add "${field}" field to package.json`
});
}
});
// Check for Coherent.js dependencies
const dependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
const hasCoherentDeps = Object.keys(dependencies).some(dep => dep.startsWith('@coherent.js/'));
checks.push({
name: 'coherent-dependencies',
description: 'Coherent.js dependencies present',
required: false,
status: hasCoherentDeps ? 'pass' : 'warning',
value: hasCoherentDeps ? 'found' : 'missing'
});
if (!hasCoherentDeps) {
recommendations.push({
type: 'dependencies',
priority: 'medium',
message: 'No Coherent.js dependencies found. Install with: npm install @coherent.js/core'
});
}
// Check scripts
const recommendedScripts = ['dev', 'build', 'start', 'test'];
const hasScripts = packageJson.scripts || {};
recommendedScripts.forEach(script => {
const hasScript = hasScripts[script];
checks.push({
name: `script.${script}`,
description: `${script} script defined`,
required: false,
status: hasScript ? 'pass' : 'warning',
value: hasScript ? hasScripts[script] : 'missing'
});
});
if (!hasScripts.dev && !hasScripts.start) {
recommendations.push({
type: 'scripts',
priority: 'medium',
message: 'Add dev/start scripts for easier development workflow'
});
}
} catch (error) {
issues.push({
type: 'package-validation',
message: `Invalid package.json: ${error.message}`,
suggestion: 'Check package.json syntax and formatting'
});
}
return { checks, issues, recommendations };
}
function validateProjectStructure() {
const checks = [];
const recommendations = [];
// Check common directory structure
const directories = [
{ name: 'src', description: 'Source code directory' },
{ name: 'src/components', description: 'Components directory' },
{ name: 'src/pages', description: 'Pages directory' },
{ name: 'public', description: 'Static assets directory' },
{ name: 'test', description: 'Test directory' },
{ name: 'dist', description: 'Build output directory' }
];
directories.forEach(({ name, description }) => {
const exists = existsSync(resolve(name));
checks.push({
name: `directory.${name}`,
description,
required: false,
status: exists ? 'pass' : 'info',
exists
});
});
// Check for common config files
const configFiles = [
'tsconfig.json',
'eslint.config.js',
'.eslintrc.js',
'prettier.config.js',
'.gitignore'
];
configFiles.forEach(file => {
const exists = existsSync(resolve(file));
checks.push({
name: `config.${file}`,
description: `${file} configuration`,
required: false,
status: exists ? 'pass' : 'info',
exists
});
});
// Generate structure recommendations
if (!existsSync('src')) {
recommendations.push({
type: 'structure',
priority: 'medium',
message: 'Consider creating a "src" directory to organize your source code'
});
}
if (!existsSync('src/components') && existsSync('src')) {
recommendations.push({
type: 'structure',
priority: 'low',
message: 'Create "src/components" directory to organize your components'
});
}
if (!existsSync('.gitignore')) {
recommendations.push({
type: 'version-control',
priority: 'medium',
message: 'Add .gitignore file to exclude node_modules and build files from version control'
});
}
if (!existsSync('README.md')) {
recommendations.push({
type: 'documentation',
priority: 'low',
message: 'Add README.md to document your project setup and usage'
});
}
return { checks, recommendations };
} |