@yassidev/nuxt-directus 0.0.9 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "directus",
3
3
  "configKey": "directus",
4
- "version": "0.0.9",
4
+ "version": "0.0.11",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { defineNuxtModule, useLogger, updateRuntimeConfig, hasNuxtModule, createResolver, addImports, addServerImports, addTemplate, addTypeTemplate } from 'nuxt/kit';
2
2
  import { generateDirectusTypes } from 'directus-sdk-typegen';
3
3
  import { fetchTranslations, syncTranslations } from '../dist/runtime/server.js';
4
- import { readFileSync } from 'node:fs';
4
+ import { readFileSync, existsSync } from 'node:fs';
5
5
  import { NAME } from '../dist/runtime/constants.js';
6
6
  import { resolve, join, relative, sep } from 'node:path';
7
7
  import { unwatchFile, watchFile, watch as watch$1, stat as stat$2 } from 'fs';
@@ -1849,30 +1849,35 @@ function setupI18n(config, nuxt, logger) {
1849
1849
  i18nPrefix: config.i18n.prefix
1850
1850
  };
1851
1851
  const path = "directus/locales";
1852
- const watcher = chokidar.watch(resolve(nuxt.options.buildDir, path, "*.json"), { ignoreInitial: true });
1853
- codes.map((code) => {
1854
- const { dst } = addTemplate({
1852
+ const result = codes.map((code) => {
1853
+ const { filename } = addTemplate({
1855
1854
  write: true,
1856
1855
  filename: join(path, `${code}.json`),
1857
1856
  getContents: () => fetchTranslations(code, runtimeConfig).then((translations) => {
1858
1857
  return JSON.stringify(Object.fromEntries(translations.map((translation) => [translation.key, translation.value])), null, 2);
1859
1858
  })
1860
1859
  });
1860
+ return { code, filename };
1861
+ });
1862
+ if (nuxt.options.dev && !nuxt.options._prepare) {
1863
+ const watcher = chokidar.watch(path, { cwd: nuxt.options.buildDir, ignoreInitial: true });
1861
1864
  watcher.on("change", async (filePath) => {
1862
- if (filePath !== dst) return;
1863
- const translations = JSON.parse(readFileSync(filePath, "utf-8"));
1865
+ const code = result.find((i) => i.filename === filePath)?.code;
1866
+ if (!code) return;
1867
+ const translations = JSON.parse(readFileSync(resolve(nuxt.options.buildDir, filePath), "utf-8"));
1864
1868
  const done = await syncTranslations(code, translations, runtimeConfig);
1865
1869
  if (!done) return;
1866
1870
  logger.info(`Synced translations for locale: ${code}`);
1867
1871
  });
1868
- });
1872
+ }
1869
1873
  }
1870
1874
  nuxt.hook("i18n:registerModule", (register) => {
1875
+ const isStubbing = existsSync(resolve("./runtime/lang/index.ts"));
1871
1876
  const locales = codes.map((code) => ({
1872
1877
  code,
1873
- file: resolve("./runtime/lang/index")
1878
+ file: isStubbing ? "index.ts" : "index.js"
1874
1879
  }));
1875
- register({ langDir: "", locales });
1880
+ register({ langDir: resolve("./runtime/lang"), locales });
1876
1881
  logger.success("Locales have been registered: " + codes.join(", "));
1877
1882
  });
1878
1883
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yassidev/nuxt-directus",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "A Nuxt module for better integration with Directus CMS.",
5
5
  "repository": "yassilah/nuxt-directus",
6
6
  "license": "MIT",