async function convertSingleDashboard()

in scripts/dashboard-importer/src/dashboards/cli.ts [84:133]


async function convertSingleDashboard(
  filePath: string,
  fileName: string,
  report: DashboardsConversionReport,
): Promise<DashboardConversionResult> {
  const jsonFilePath = `${filePath}${fileName}`;
  const jsonFileContents = fs.readFileSync(jsonFilePath);
  const dashboard = JSON.parse(jsonFileContents.toString());
  const conversionResult: DashboardConversionResult = {
    displayName: dashboard.title,
    sourcePath: jsonFilePath,
    warnings: [],
    errors: [],
  };

  let converted: Dashboard | null = null;

  try {
    const converter: GrafanaDashboardConverter = new GrafanaDashboardConverter(
      dashboard,
      fileName,
    );
    converter.convert();
    converted = converter.converted;
    const fileNameLabel = getSystemFileNameLabel(fileName);
    if (converted?.labels && fileNameLabel) {
      converted.labels[fileNameLabel] = ''
    }
    conversionResult.warnings.push(...converter.warnings);
    conversionResult.errors.push(...converter.errors);
  } catch (e) {
    logError(
      `✘ ${dashboard.title} encountered an error, and was unable to be converted. Please see report for full details.`,
    );
    conversionResult.errors.push(e as string);
  }

  if (conversionResult.warnings.length) {
    logWarning(
      `Conversion generated ${conversionResult.warnings.length} warnings, please see report for full details.`,
    );
  }
  logSuccess(`✓ ${dashboard.title} converted successfully`);
  const jsonFilepath = `${report.outputPath}${fileName}`;
  conversionResult.outputPath = jsonFilepath;
  const jsonString = JSON.stringify(converted, null, 4);

  fs.writeFileSync(jsonFilepath, jsonString);
  return conversionResult;
}