powerplatform-review-tool
Version:
Evaluate Power Platform solution zip files based on best practice patterns
73 lines (72 loc) • 2.69 kB
JavaScript
import { Command } from 'commander';
import fs from 'fs';
import path from 'path';
import { startReview, extractSolutionDetail, generateSarifFromReview } from 'powerplatform-review-tool-shared';
const program = new Command();
program
.name('pp-review')
.description('Power Platform solution review CLI')
.version('1.0.28');
// Command 1: Review
program
.command('review')
.description('Evaluate a solution zip file for best practices')
.requiredOption('-f, --file <path>', 'Path to solution zip')
.option('-o, --output <path>', 'Path to output JSON file')
.action(async ({ file, output }) => {
try {
const zipPath = path.resolve(process.cwd(), file);
console.log(`Reading file from: ${zipPath}`);
if (!fs.existsSync(zipPath)) {
console.error(`File not found: ${zipPath}`);
process.exit(1);
}
const buffer = fs.readFileSync(zipPath);
let result = await startReview(buffer);
if (result) {
result = generateSarifFromReview(result);
}
// DEBUG: Log the result
console.log('Review result preview:', result);
if (output) {
const outPath = path.resolve(process.cwd(), output);
fs.writeFileSync(outPath, JSON.stringify(result, null, 2));
console.log(`Review result saved to: ${outPath}`);
}
}
catch (error) {
console.error('Error during review process:', error instanceof Error ? error.message : String(error));
process.exit(1);
}
});
// Command 2: Extract
program
.command('extract')
.description('Extract solution metadata (e.g., apps, flows, bots)')
.requiredOption('-f, --file <path>', 'Path to solution zip')
.option('-o, --output <path>', 'Path to output JSON file')
.action(async ({ file, output }) => {
try {
const zipPath = path.resolve(process.cwd(), file);
if (!fs.existsSync(zipPath)) {
console.error(`File not found: ${zipPath}`);
process.exit(1);
}
const buffer = fs.readFileSync(zipPath);
const result = await extractSolutionDetail(buffer);
if (output) {
const outPath = path.resolve(process.cwd(), output);
fs.writeFileSync(outPath, JSON.stringify(result, null, 2));
console.log(`Metadata written to ${outPath}`);
}
else {
console.log(JSON.stringify(result, null, 2));
}
}
catch (error) {
console.error('Error during extraction process:', error instanceof Error ? error.message : String(error));
process.exit(1);
}
});
program.parse();