@@ -28,7 +28,6 @@ import JSON5 from 'json5'
28
28
import yaml from 'js-yaml'
29
29
import deepmerge from 'deepmerge'
30
30
import { promisify } from 'util'
31
- import ignore from 'ignore'
32
31
import type { Ignore } from 'ignore'
33
32
34
33
import { debug as Debug } from 'debug'
@@ -141,18 +140,15 @@ export function stringifyContent (content: any, lang: string, options?: FormatOp
141
140
return result
142
141
}
143
142
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 )
153
149
154
150
// TODO: async implementation
155
- return targets . map ( t => {
151
+ return cookedTargets . map ( t => {
156
152
const data = fs . readFileSync ( t )
157
153
return {
158
154
path : t ,
@@ -162,8 +158,9 @@ export function readSFC (target: string, ignorePath?: string): SFCFileInfo[] {
162
158
}
163
159
164
160
function resolveGlob ( target : string ) {
161
+ const relativeTarget = path . relative ( process . cwd ( ) , target )
165
162
// TODO: async implementation
166
- return glob . sync ( `${ target } /**/*.vue` )
163
+ return glob . sync ( `${ relativeTarget } /**/*.vue` )
167
164
}
168
165
169
166
export const DEFUALT_CONF = { provider : { } } as ProviderConfiguration
@@ -344,14 +341,16 @@ function getLocaleMessagePathInfo (fullPath: string, bundleMatch?: string): Pars
344
341
}
345
342
346
343
export function getExternalLocaleMessages (
347
- dictionary : NamespaceDictionary , bundleWith ?: string , bundleMatch ?: string
344
+ dictionary : NamespaceDictionary , ig : Ignore , bundleWith ?: string , bundleMatch ?: string
348
345
) {
349
346
if ( ! bundleWith ) { return { } }
350
347
351
348
const bundleTargetPaths = bundleWith . split ( ',' ) . filter ( p => p )
352
349
return bundleTargetPaths . reduce ( ( messages , targetPath ) => {
353
350
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 ) )
355
354
return globedPaths . reduce ( ( messages , fullPath ) => {
356
355
const { locale, filename } = getLocaleMessagePathInfo ( fullPath , bundleMatch )
357
356
if ( ! locale ) { return messages }
@@ -429,29 +428,16 @@ export function splitLocaleMessages (
429
428
return { sfc : messages , external : metaExternalLocaleMessages }
430
429
}
431
430
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 [ ] {
443
432
const ignoreFiles = fs . readFileSync ( ignorePath , 'utf8' )
444
433
. split ( / \r ? \n / g)
445
434
. filter ( Boolean )
446
435
console . log ( `ignoreFiles ${ ignoreFiles } ` )
447
436
return ignoreFiles
448
437
}
449
438
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 => {
455
441
ig . add ( ignoreRule )
456
- )
442
+ } )
457
443
}
0 commit comments