get-markdown.ts 559 B

12345678910111213141516171819
  1. import fs from 'node:fs';
  2. import path from 'node:path';
  3. import { getStatus } from './get-status';
  4. export const getMarkdown = async (
  5. projectDirRoot: string,
  6. templateId: string,
  7. locale: string,
  8. ): Promise<string> => {
  9. const tplDir = path.resolve(projectDirRoot, 'dist', templateId, locale);
  10. const { isTemplateExists } = await getStatus(tplDir);
  11. if (!isTemplateExists) throw new Error("'template.md does not exist.");
  12. const markdownPath = path.resolve(tplDir, 'template.md');
  13. return fs.readFileSync(markdownPath, { encoding: 'utf-8' });
  14. };