Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

791 B
Raw Blame
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
import path from 'node:path';

import type { Resources } from './extractI18n';

export const renderResourcesModule = (resources: Resources, exportName = 'resources') =>
  `// Generated by i18n-extract. Do not edit.\nexport const ${exportName} = ${JSON.stringify(resources)};\n`;

export const writeIfChanged = async (file: string, content: string) => {
  try {
    if ((await readFile(file, 'utf8')) === content) return false;
  } catch (error) {
    if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;
  }
  await mkdir(path.dirname(file), { recursive: true });
  const temporary = `${file}.${process.pid}.tmp`;
  await writeFile(temporary, content);
  await rename(temporary, file);
  return true;
};