Skip to content

Commit

Permalink
fix: debug verbose (#259)
Browse files Browse the repository at this point in the history
* fix: add debug verbose for infuse

* fix: add others
  • Loading branch information
kazupon committed May 12, 2023
1 parent f5e4de8 commit b006ba2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/commands/infuse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {

import { debug as Debug } from 'debug'
import ignore from 'ignore'

const VERBOSE = process.env.DEBUG_VERBOSE
const debug = Debug('vue-i18n-locale-message:commands:infuse')

type InfuseOptions = {
Expand Down Expand Up @@ -133,8 +135,8 @@ export const handler = async (args: Arguments<InfuseOptions>) => {
const messages = readLocaleMessages(messagesPath, args.match)

const { sfc, external } = splitLocaleMessages(messages, nsDictionary, args.unbundleTo, args.unbundleMatch)
debug('sfc', sfc)
debug('external', external)
VERBOSE && debug('sfc', sfc)
VERBOSE && debug('external', external)

const meta = squeeze(targetPath, sources)
apply(sfc, meta)
Expand Down Expand Up @@ -186,7 +188,7 @@ function apply (messages: LocaleMessages, meta: MetaLocaleMessage): MetaLocaleMe
const { hierarchy } = parsePath(target, component)

const collectMessages = getTargetLocaleMessages(messages, hierarchy)
debug('collect messages', JSON.stringify(collectMessages, null, 2))
VERBOSE && debug('collect messages', JSON.stringify(collectMessages, null, 2))

const sourceLocales: Locale[] = Object.keys(collectMessages)
const targetLocales = blocks.reduce((locales, block) => {
Expand Down Expand Up @@ -239,7 +241,7 @@ function apply (messages: LocaleMessages, meta: MetaLocaleMessage): MetaLocaleMe

function getTargetLocaleMessages (messages: LocaleMessages, hierarchy: string[]): LocaleMessages {
return Object.keys(messages).reduce((target, locale) => {
debug(`processing curernt: locale=${locale}, target=${JSON.stringify(target)}`)
VERBOSE && debug(`processing curernt: locale=${locale}, target=${JSON.stringify(target)}`)

const obj = messages[locale]
if (obj) {
Expand All @@ -253,7 +255,7 @@ function getTargetLocaleMessages (messages: LocaleMessages, hierarchy: string[])
if (!key || !o) { break }
o = o[key]
prev = o
debug(`processing o = ${JSON.stringify(o)}, prev = ${JSON.stringify(prev)}`)
VERBOSE && debug(`processing o = ${JSON.stringify(o)}, prev = ${JSON.stringify(prev)}`)
}

if (!o && !prev) {
Expand Down
4 changes: 3 additions & 1 deletion src/squeezer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { MetaLocaleMessage, I18nLang, SFCFileInfo, SFCI18nBlock } from '../types
import { reflectSFCDescriptor, parseContent } from './utils'

import { debug as Debug } from 'debug'

const VERBOSE = process.env.DEBUG_VERBOSE
const debug = Debug('vue-i18n-locale-message:squeezer')

export default function squeeze (basePath: string, files: SFCFileInfo[]): MetaLocaleMessage {
const descriptors = reflectSFCDescriptor(basePath, files)
return descriptors.reduce((meta, descriptor) => {
descriptor.customBlocks.sort((a, b) => { return (a.start as number) - (b.start as number) })
const i18nBlocks = squeezeFromCustomBlocks(descriptor.customBlocks)
debug('squeezeFromCustomBlocks: i18nBlocks', JSON.stringify(i18nBlocks, null, 2))
VERBOSE && debug('squeezeFromCustomBlocks: i18nBlocks', JSON.stringify(i18nBlocks, null, 2))
meta.components[descriptor.contentPath] = i18nBlocks
return meta
}, { target: basePath, components: {}} as MetaLocaleMessage)
Expand Down

0 comments on commit b006ba2

Please sign in to comment.