@@ -28,7 +28,6 @@ import JSON5 from 'json5'
2828import yaml from 'js-yaml'
2929import deepmerge from 'deepmerge'
3030import { promisify } from 'util'
31- import ignore from 'ignore'
3231import type { Ignore } from 'ignore'
3332
3433import { debug as Debug } from 'debug'
@@ -141,18 +140,15 @@ export function stringifyContent (content: any, lang: string, options?: FormatOp
141140 return result
142141}
143142
144- export function readSFC ( target : string , ignorePath ?: string ) : SFCFileInfo [ ] {
145- let targets = resolveGlob ( path . relative ( process . cwd ( ) , target ) )
146- if ( ( ignorePath !== undefined ) ) {
147- const ig = returnIgnoreInstance ( ignorePath )
148- targets = targets . filter ( t => {
149- return ! ig . ignores ( path . relative ( process . cwd ( ) , t ) )
150- } )
151- }
152- debug ( 'readSFC: targets = ' , targets )
143+ export function readSFC ( target : string , ig : Ignore ) : SFCFileInfo [ ] {
144+ const targets = resolveGlob ( target )
145+ const cookedTargets = targets . filter ( t => {
146+ return ! ig . ignores ( path . relative ( process . cwd ( ) , t ) )
147+ } ) . map ( p => path . resolve ( p ) )
148+ debug ( 'readSFC: targets = ' , cookedTargets )
153149
154150 // TODO: async implementation
155- return targets . map ( t => {
151+ return cookedTargets . map ( t => {
156152 const data = fs . readFileSync ( t )
157153 return {
158154 path : t ,
@@ -162,8 +158,9 @@ export function readSFC (target: string, ignorePath?: string): SFCFileInfo[] {
162158}
163159
164160function resolveGlob ( target : string ) {
161+ const relativeTarget = path . relative ( process . cwd ( ) , target )
165162 // TODO: async implementation
166- return glob . sync ( `${ target } /**/*.vue` )
163+ return glob . sync ( `${ relativeTarget } /**/*.vue` )
167164}
168165
169166export const DEFUALT_CONF = { provider : { } } as ProviderConfiguration
@@ -344,14 +341,16 @@ function getLocaleMessagePathInfo (fullPath: string, bundleMatch?: string): Pars
344341}
345342
346343export function getExternalLocaleMessages (
347- dictionary : NamespaceDictionary , bundleWith ?: string , bundleMatch ?: string
344+ dictionary : NamespaceDictionary , ig : Ignore , bundleWith ?: string , bundleMatch ?: string
348345) {
349346 if ( ! bundleWith ) { return { } }
350347
351348 const bundleTargetPaths = bundleWith . split ( ',' ) . filter ( p => p )
352349 return bundleTargetPaths . reduce ( ( messages , targetPath ) => {
353350 const namespace = dictionary [ targetPath ] || ''
354- const globedPaths = glob . sync ( targetPath ) . map ( p => resolve ( p ) )
351+ const globedPaths = glob . sync ( path . relative ( process . cwd ( ) , targetPath ) ) . filter ( t => {
352+ return ! ig . ignores ( t )
353+ } ) . map ( p => resolve ( p ) )
355354 return globedPaths . reduce ( ( messages , fullPath ) => {
356355 const { locale, filename } = getLocaleMessagePathInfo ( fullPath , bundleMatch )
357356 if ( ! locale ) { return messages }
@@ -429,29 +428,16 @@ export function splitLocaleMessages (
429428 return { sfc : messages , external : metaExternalLocaleMessages }
430429}
431430
432- function returnIgnoreInstance ( ignorePath : string ) : Ignore {
433- const ig = ignore ( )
434- if ( fs . existsSync ( ignorePath ) ) {
435- addIgnoreFile ( ig , ignorePath )
436- } else {
437- console . warn ( 'cannot find ignore file.' )
438- }
439- return ig
440- }
441-
442- function readIgnoreFile ( ignorePath : string ) : string [ ] {
431+ export function readIgnoreFile ( ignorePath : string ) : string [ ] {
443432 const ignoreFiles = fs . readFileSync ( ignorePath , 'utf8' )
444433 . split ( / \r ? \n / g)
445434 . filter ( Boolean )
446435 console . log ( `ignoreFiles ${ ignoreFiles } ` )
447436 return ignoreFiles
448437}
449438
450- function addIgnoreFile (
451- ig : Ignore ,
452- ignorePath : string
453- ) : void {
454- readIgnoreFile ( ignorePath ) . forEach ( ignoreRule =>
439+ export function returnIgnoreInstance ( ig : Ignore , ignoreFiles : string [ ] ) : void {
440+ ignoreFiles . forEach ( ignoreRule => {
455441 ig . add ( ignoreRule )
456- )
442+ } )
457443}
0 commit comments