Skip to content

Commit

Permalink
fix(dev): trying to generate locales when the module generate its own…
Browse files Browse the repository at this point in the history
… types
  • Loading branch information
samk-dev committed Apr 4, 2024
1 parent f8b373b commit 955da25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/generateLocales.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs'
import fs from 'node:fs'
import csv from 'csv-parser'
import logger from './logger'

Expand Down
21 changes: 16 additions & 5 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { relative, resolve as pathResolve } from 'node:path'
import fs from 'node:fs'
import { defineNuxtModule, createResolver } from '@nuxt/kit'
import { name, version } from '../package.json'
import generateLocales from './generateLocales'
Expand Down Expand Up @@ -49,14 +50,24 @@ export default defineNuxtModule<ModuleOptions>({
? resolve(options.outputDir)
: resolve(nuxt.options.srcDir, options.langDir as string)

try {
await generateLocales(csvFileFullPath, outputDir)
} catch (error) {
logger.error(error)
// dirty work around to not trigger the method when the module is
// generating it's own types then the method fails.
const currentDir = fs.readdirSync(resolve(nuxt.options.srcDir))
const isNuxtDir = currentDir.includes('app.vue')

if (isNuxtDir) {
try {
await generateLocales(csvFileFullPath, outputDir)
} catch (error) {
logger.error(error)
}
}

nuxt.hook('builder:watch', async (_event, path) => {
path = relative(nuxt.options.srcDir, pathResolve(nuxt.options.srcDir, path))
path = relative(
nuxt.options.srcDir,
pathResolve(nuxt.options.srcDir, path)
)
if (path === csvFilePath) {
try {
await generateLocales(csvFileFullPath, outputDir)
Expand Down

0 comments on commit 955da25

Please sign in to comment.