@@ -26,7 +26,6 @@ import JSON5 from 'json5'
2626import yaml from 'js-yaml'
2727import deepmerge from 'deepmerge'
2828import { promisify } from 'util'
29- import ignore from 'ignore'
3029import type { Ignore } from 'ignore'
3130
3231import { debug as Debug } from 'debug'
@@ -134,18 +133,15 @@ export function stringifyContent (content: any, lang: string, options?: FormatOp
134133 return result
135134}
136135
137- export function readSFC ( target : string , ignorePath ?: string ) : SFCFileInfo [ ] {
138- let targets = resolveGlob ( path . relative ( process . cwd ( ) , target ) )
139- if ( ( ignorePath !== undefined ) ) {
140- const ig = returnIgnoreInstance ( ignorePath )
141- targets = targets . filter ( t => {
142- return ! ig . ignores ( path . relative ( process . cwd ( ) , t ) )
143- } )
144- }
145- debug ( 'readSFC: targets = ' , targets )
136+ export function readSFC ( target : string , ig : Ignore ) : SFCFileInfo [ ] {
137+ const targets = resolveGlob ( target )
138+ const cookedTargets = targets . filter ( t => {
139+ return ! ig . ignores ( path . relative ( process . cwd ( ) , t ) )
140+ } ) . map ( p => path . resolve ( p ) )
141+ debug ( 'readSFC: targets = ' , cookedTargets )
146142
147143 // TODO: async implementation
148- return targets . map ( t => {
144+ return cookedTargets . map ( t => {
149145 const data = fs . readFileSync ( t )
150146 return {
151147 path : t ,
@@ -155,8 +151,9 @@ export function readSFC (target: string, ignorePath?: string): SFCFileInfo[] {
155151}
156152
157153function resolveGlob ( target : string ) {
154+ const relativeTarget = path . relative ( process . cwd ( ) , target )
158155 // TODO: async implementation
159- return glob . sync ( `${ target } /**/*.vue` )
156+ return glob . sync ( `${ relativeTarget } /**/*.vue` )
160157}
161158
162159export const DEFUALT_CONF = { provider : { } } as ProviderConfiguration
@@ -337,14 +334,16 @@ function getLocaleMessagePathInfo (fullPath: string, bundleMatch?: string): Pars
337334}
338335
339336export function getExternalLocaleMessages (
340- dictionary : NamespaceDictionary , bundleWith ?: string , bundleMatch ?: string
337+ dictionary : NamespaceDictionary , ig : Ignore , bundleWith ?: string , bundleMatch ?: string
341338) {
342339 if ( ! bundleWith ) { return { } }
343340
344341 const bundleTargetPaths = bundleWith . split ( ',' ) . filter ( p => p )
345342 return bundleTargetPaths . reduce ( ( messages , targetPath ) => {
346343 const namespace = dictionary [ targetPath ] || ''
347- const globedPaths = glob . sync ( targetPath ) . map ( p => resolve ( p ) )
344+ const globedPaths = glob . sync ( path . relative ( process . cwd ( ) , targetPath ) ) . filter ( t => {
345+ return ! ig . ignores ( t )
346+ } ) . map ( p => resolve ( p ) )
348347 return globedPaths . reduce ( ( messages , fullPath ) => {
349348 const { locale, filename } = getLocaleMessagePathInfo ( fullPath , bundleMatch )
350349 if ( ! locale ) { return messages }
@@ -422,29 +421,16 @@ export function splitLocaleMessages (
422421 return { sfc : messages , external : metaExternalLocaleMessages }
423422}
424423
425- function returnIgnoreInstance ( ignorePath : string ) : Ignore {
426- const ig = ignore ( )
427- if ( fs . existsSync ( ignorePath ) ) {
428- addIgnoreFile ( ig , ignorePath )
429- } else {
430- console . warn ( 'cannot find ignore file.' )
431- }
432- return ig
433- }
434-
435- function readIgnoreFile ( ignorePath : string ) : string [ ] {
424+ export function readIgnoreFile ( ignorePath : string ) : string [ ] {
436425 const ignoreFiles = fs . readFileSync ( ignorePath , 'utf8' )
437426 . split ( / \r ? \n / g)
438427 . filter ( Boolean )
439428 console . log ( `ignoreFiles ${ ignoreFiles } ` )
440429 return ignoreFiles
441430}
442431
443- function addIgnoreFile (
444- ig : Ignore ,
445- ignorePath : string
446- ) : void {
447- readIgnoreFile ( ignorePath ) . forEach ( ignoreRule =>
432+ export function returnIgnoreInstance ( ig : Ignore , ignoreFiles : string [ ] ) : void {
433+ ignoreFiles . forEach ( ignoreRule => {
448434 ig . add ( ignoreRule )
449- )
435+ } )
450436}
0 commit comments