UNPKG

next-intl

Version:

Internationalization (i18n) for Next.js

2 lines (1 loc) 1.07 kB
import e from"fs";import t from"path";import{once as s,throwError as o}from"../utils.js";import n from"../watchFile.js";const i=s("_NEXT_INTL_COMPILE_MESSAGES");function r(s){["info","start"].some((e=>process.argv.includes(e)))||i((()=>{for(const n of s){const s=t.resolve(n);e.existsSync(s)||o(`\`createMessagesDeclaration\` points to a non-existent file: ${s}`),s.endsWith(".json")||o(`\`createMessagesDeclaration\` needs to point to a JSON file. Received: ${s}`);const i=process.env["NODE_ENV".trim()];a(n),"development"===i&&c(n)}}))}function c(e){const t=n(e,(()=>{a(e,!0)}));process.on("exit",(()=>{t.close()}))}function a(t,s=!1){const o=t.replace(/\.json$/,".d.json.ts");function n(e){return`// This file is auto-generated by next-intl, do not edit directly.\n// See: https://next-intl.dev/docs/workflows/typescript#messages-arguments\n\ndeclare const messages: ${e.trim()};\nexport default messages;`}if(s)return e.promises.readFile(t,"utf-8").then((t=>e.promises.writeFile(o,n(t))));const i=e.readFileSync(t,"utf-8");e.writeFileSync(o,n(i))}export{r as default};