libs/nx/src/executors/journal/compat/utils/generate-journal.ts
Properties |
blocks | |
Type |
BuildingBlockJournalRecord[]
|
import { BuildingBlockJournalRecord } from '@allianz/taly-core/schemas';
import { Logger } from '@angular-devkit/core/src/logger';
import { existsSync } from 'fs';
import { basename, join } from 'path';
import {
BuildingBlockFolderStats,
BuildingBlockFoldersCollection,
collectBuildingBlockFolders
} from '../../../shared/metadata-utils/collect-building-block-folders';
import { createJournalRecord } from './create-journal-record';
export interface JournalContent {
blocks: BuildingBlockJournalRecord[];
}
/**
* Create the Journal by following the following steps
* 1. Find all Building Blocks by searching for the Markdown Files
* 2. Extract the header data from each md file
* 3. Extract the selector from the component file
*/
export async function generateJournal({
libraryFolder,
packageName,
logger
}: {
libraryFolder: string;
packageName: string;
logger: Logger;
}): Promise<JournalContent> {
const buildingBlockRecords: BuildingBlockJournalRecord[] = [];
if (false === existsSync(join(libraryFolder, 'src', 'lib'))) {
logger.error(`Could not find folder 'src/lib' in given library folder`);
return {
blocks: buildingBlockRecords
};
}
const collection: BuildingBlockFoldersCollection = await collectBuildingBlockFolders(
libraryFolder
);
for (const stats of collection.skipped) {
logWarning({ stats, logger });
}
for (const directory of collection.result) {
logger.info(`└── ${basename(directory)}`);
const record = await createJournalRecord(directory, packageName, logger);
buildingBlockRecords.push(record);
}
return {
blocks: buildingBlockRecords
};
}
function logWarning({ stats, logger }: { stats: BuildingBlockFolderStats; logger: Logger }) {
if (logger) {
const warnings: string[] = [];
if (false === stats.componentExists) {
warnings.push('no component');
}
if (false === stats.moduleExists) {
warnings.push('no module');
}
if (false === stats.markdownExists) {
warnings.push('no markdown');
}
logger.warn(`└── ${stats.folderName}`);
logger.warn(` Not a Building Block, check the following reasons:`);
logger.warn(` ${warnings.map((v) => `'${v}'`).join(', ')} `);
}
}