dryrun-ci
Version:
DryRun CI - Local GitLab CI/CD pipeline testing tool with Docker execution, performance monitoring, and security sandboxing
81 lines (80 loc) • 2.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProjectScanner = void 0;
const toml_1 = require("@iarna/toml");
class ProjectScanner {
async scanDirectory(handle, path = '') {
const files = [];
for await (const [name, entry] of handle.entries()) {
const fullPath = path ? `${path}/${name}` : name;
if (entry.kind === 'file') {
const file = await entry.getFile();
files.push({
name: fullPath,
type: 'file',
size: file.size
});
}
else if (entry.kind === 'directory') {
files.push({
name: fullPath,
type: 'directory'
});
const subFiles = await this.scanDirectory(entry, fullPath);
files.push(...subFiles);
}
}
return files;
}
async scanProject(handle) {
const context = {
rootPath: handle.name,
files: []
};
try {
context.files = await this.scanDirectory(handle);
for await (const [name, entry] of handle.entries()) {
if (entry.kind === 'file') {
const file = await entry.getFile();
const content = await file.text();
switch (name) {
case '.gitlab-ci.yml':
case '.gitlab-ci.yaml':
context.gitlabCi = JSON.parse(content);
break;
case 'nixpacks.toml':
try {
context.nixpacksConfig = (0, toml_1.parse)(content);
}
catch (error) {
console.error('Error parsing nixpacks.toml:', error);
}
break;
case 'Dockerfile':
context.dockerfile = content;
break;
case 'package.json':
context.packageJson = JSON.parse(content);
break;
}
}
}
}
catch (error) {
console.error('Error scanning project:', error);
throw error;
}
return context;
}
async scan(stage) {
return {
logs: [
`🔍 Scanning project files for stage '${stage}'...`,
'✅ Scan completed successfully'
],
files: [],
errors: []
};
}
}
exports.ProjectScanner = ProjectScanner;