@@ -26,7 +26,6 @@ import JSON5 from 'json5'
26
26
import yaml from 'js-yaml'
27
27
import deepmerge from 'deepmerge'
28
28
import { promisify } from 'util'
29
- import ignore from 'ignore'
30
29
import type { Ignore } from 'ignore'
31
30
32
31
import { debug as Debug } from 'debug'
@@ -134,18 +133,15 @@ export function stringifyContent (content: any, lang: string, options?: FormatOp
134
133
return result
135
134
}
136
135
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 )
146
142
147
143
// TODO: async implementation
148
- return targets . map ( t => {
144
+ return cookedTargets . map ( t => {
149
145
const data = fs . readFileSync ( t )
150
146
return {
151
147
path : t ,
@@ -155,8 +151,9 @@ export function readSFC (target: string, ignorePath?: string): SFCFileInfo[] {
155
151
}
156
152
157
153
function resolveGlob ( target : string ) {
154
+ const relativeTarget = path . relative ( process . cwd ( ) , target )
158
155
// TODO: async implementation
159
- return glob . sync ( `${ target } /**/*.vue` )
156
+ return glob . sync ( `${ relativeTarget } /**/*.vue` )
160
157
}
161
158
162
159
export const DEFUALT_CONF = { provider : { } } as ProviderConfiguration
@@ -337,14 +334,16 @@ function getLocaleMessagePathInfo (fullPath: string, bundleMatch?: string): Pars
337
334
}
338
335
339
336
export function getExternalLocaleMessages (
340
- dictionary : NamespaceDictionary , bundleWith ?: string , bundleMatch ?: string
337
+ dictionary : NamespaceDictionary , ig : Ignore , bundleWith ?: string , bundleMatch ?: string
341
338
) {
342
339
if ( ! bundleWith ) { return { } }
343
340
344
341
const bundleTargetPaths = bundleWith . split ( ',' ) . filter ( p => p )
345
342
return bundleTargetPaths . reduce ( ( messages , targetPath ) => {
346
343
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 ) )
348
347
return globedPaths . reduce ( ( messages , fullPath ) => {
349
348
const { locale, filename } = getLocaleMessagePathInfo ( fullPath , bundleMatch )
350
349
if ( ! locale ) { return messages }
@@ -422,29 +421,16 @@ export function splitLocaleMessages (
422
421
return { sfc : messages , external : metaExternalLocaleMessages }
423
422
}
424
423
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 [ ] {
436
425
const ignoreFiles = fs . readFileSync ( ignorePath , 'utf8' )
437
426
. split ( / \r ? \n / g)
438
427
. filter ( Boolean )
439
428
console . log ( `ignoreFiles ${ ignoreFiles } ` )
440
429
return ignoreFiles
441
430
}
442
431
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 => {
448
434
ig . add ( ignoreRule )
449
- )
435
+ } )
450
436
}
0 commit comments