Spaces:
Running
Running
File size: 1,372 Bytes
b39afbe |
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 |
const { spawn } = require('child_process');
const fs = require('fs');
const fsPromises = fs.promises;
// Check if .fossa.yml exists
if (!fs.existsSync('.fossa.yml')) {
console.warn('.fossa.yml does not exist!');
}
// Function to execute a command and stream the output
function execute(command, args) {
return new Promise((resolve, reject) => {
const proc = spawn(command, args, { stdio: [process.stdin, process.stdout, process.stderr] });
proc.on('close', (code) => {
if (code !== 0) {
reject(new Error(`${command} exited with code ${code}`));
} else {
resolve();
}
});
});
}
// Run fossa analyze
execute('fossa', ['analyze'])
.then(() => {
// Run fossa report and redirect output to THIRD_PARTIES.md
return new Promise((resolve, reject) => {
console.log("Generating THIRD_PARTIES.md");
const report = spawn('fossa', ['report', 'attribution', '--format', 'markdown']);
const fileStream = fs.createWriteStream('THIRD_PARTIES.md');
report.stdout.pipe(fileStream);
report.on('close', (code) => {
if (code !== 0) {
reject(new Error(`fossa report exited with code ${code}`));
} else {
console.log('THIRD_PARTIES.md has been generated');
resolve();
}
});
});
})
.catch((error) => {
console.error(error);
});
|