Skip to content

Commit b006ba2

Browse files
authored
fix: debug verbose (#259)
* fix: add debug verbose for infuse * fix: add others
1 parent f5e4de8 commit b006ba2

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/commands/infuse.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import {
2828

2929
import { debug as Debug } from 'debug'
3030
import ignore from 'ignore'
31+
32+
const VERBOSE = process.env.DEBUG_VERBOSE
3133
const debug = Debug('vue-i18n-locale-message:commands:infuse')
3234

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

135137
const { sfc, external } = splitLocaleMessages(messages, nsDictionary, args.unbundleTo, args.unbundleMatch)
136-
debug('sfc', sfc)
137-
debug('external', external)
138+
VERBOSE && debug('sfc', sfc)
139+
VERBOSE && debug('external', external)
138140

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

188190
const collectMessages = getTargetLocaleMessages(messages, hierarchy)
189-
debug('collect messages', JSON.stringify(collectMessages, null, 2))
191+
VERBOSE && debug('collect messages', JSON.stringify(collectMessages, null, 2))
190192

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

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

244246
const obj = messages[locale]
245247
if (obj) {
@@ -253,7 +255,7 @@ function getTargetLocaleMessages (messages: LocaleMessages, hierarchy: string[])
253255
if (!key || !o) { break }
254256
o = o[key]
255257
prev = o
256-
debug(`processing o = ${JSON.stringify(o)}, prev = ${JSON.stringify(prev)}`)
258+
VERBOSE && debug(`processing o = ${JSON.stringify(o)}, prev = ${JSON.stringify(prev)}`)
257259
}
258260

259261
if (!o && !prev) {

src/squeezer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import { MetaLocaleMessage, I18nLang, SFCFileInfo, SFCI18nBlock } from '../types
44
import { reflectSFCDescriptor, parseContent } from './utils'
55

66
import { debug as Debug } from 'debug'
7+
8+
const VERBOSE = process.env.DEBUG_VERBOSE
79
const debug = Debug('vue-i18n-locale-message:squeezer')
810

911
export default function squeeze (basePath: string, files: SFCFileInfo[]): MetaLocaleMessage {
1012
const descriptors = reflectSFCDescriptor(basePath, files)
1113
return descriptors.reduce((meta, descriptor) => {
1214
descriptor.customBlocks.sort((a, b) => { return (a.start as number) - (b.start as number) })
1315
const i18nBlocks = squeezeFromCustomBlocks(descriptor.customBlocks)
14-
debug('squeezeFromCustomBlocks: i18nBlocks', JSON.stringify(i18nBlocks, null, 2))
16+
VERBOSE && debug('squeezeFromCustomBlocks: i18nBlocks', JSON.stringify(i18nBlocks, null, 2))
1517
meta.components[descriptor.contentPath] = i18nBlocks
1618
return meta
1719
}, { target: basePath, components: {}} as MetaLocaleMessage)

0 commit comments

Comments
 (0)