in scripts/dashboard-importer/src/dashboards/cli.ts [33:66]
export default async function handleDashboardsCommand(jsonFilePath: string) {
if (!jsonFilePath) {
logInfo('No input JSON file path was received');
process.exit(9);
}
const report: DashboardsConversionReport = generateEmptyReport(jsonFilePath);
const outputPath = report.outputPath;
if (!fs.existsSync(outputPath)) {
fs.mkdirSync(outputPath, {recursive: true});
}
if (fs.lstatSync(jsonFilePath).isDirectory()) {
const formattedFilePath = jsonFilePath.slice(-1) === '/' ? jsonFilePath : `${jsonFilePath}/`;
const results = await convertAllDashboardsInDirectory(formattedFilePath, report);
report.results = [...results];
} else if (jsonFilePath.endsWith('.json')) {
const fileName = jsonFilePath.replace(/^.*[\\\/]/, '');
const filePath = jsonFilePath.split(fileName)[0];
const result = await convertSingleDashboard(filePath, fileName, report);
report.results.push(result);
} else {
throw new Error(`Path ${jsonFilePath} is not a directory or a json file.`);
}
const jsonFilepath = `${outputPath}report.json`;
const jsonString = JSON.stringify(report, null, 4);
fs.writeFileSync(jsonFilepath, jsonString);
logInfo(
`\nConversion of ${report.sourcePath} complete. Conversion Report located at: \x1b[34m${outputPath}report.json\x1b[0m`,
);
logInfo(
`\n\nTo upload these dashboard(s) manually, you can run: \n\x1b[34m./upload.sh ${outputPath} <PROJECT_ID>\x1b[0m\n`,
);
}