-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_artifact_directory.js
80 lines (71 loc) · 2.3 KB
/
setup_artifact_directory.js
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
import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const artifactTypes = {
'pre-build-scan': [
'container-spec.txt',
'hadolint.txt',
'semgrep.txt',
'trufflehog.txt'
],
'build': [
'build-container.txt',
'build-container-report.txt'
],
'post-build-scan': [
'clamav.txt',
'stig-check.txt',
'syft-grype.txt',
'threat-assessment.txt',
'web-scan.txt'
],
'clean': [
'clean-container.txt'
],
'review': [
'review.txt'
]
};
async function setupArtifactDirectory(projectName) {
try {
// Create base directory
const baseDir = path.join(__dirname, projectName);
await fs.mkdir(baseDir, { recursive: true });
console.log(`Created directory: ${baseDir}`);
// Create all artifact files
for (const [phase, artifacts] of Object.entries(artifactTypes)) {
console.log(`\nSetting up ${phase} artifacts:`);
for (const artifact of artifacts) {
const filePath = path.join(baseDir, artifact);
try {
// Check if file exists
await fs.access(filePath);
console.log(` ⚠️ ${artifact} already exists, skipping`);
} catch {
// File doesn't exist, create it
await fs.writeFile(filePath, '');
console.log(` ✅ Created ${artifact}`);
}
}
}
console.log('\n✨ Setup complete! Directory structure:');
const files = await fs.readdir(baseDir);
console.log('\n' + projectName + '/');
for (const file of files.sort()) {
console.log(` └─ ${file}`);
}
} catch (error) {
console.error('Error setting up artifact directory:', error);
process.exit(1);
}
}
// Get project name from command line argument
const projectName = process.argv[2];
if (!projectName) {
console.error('Please provide a project name.');
console.log('Usage: node setup_artifact_directory.js <project-name>');
process.exit(1);
}
setupArtifactDirectory(projectName);