@@ -28,6 +28,8 @@ 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
+ import type { Ignore } from 'ignore'
31
33
32
34
import { debug as Debug } from 'debug'
33
35
const debug = Debug ( 'vue-i18n-locale-message:utils' )
@@ -139,15 +141,26 @@ export function stringifyContent (content: any, lang: string, options?: FormatOp
139
141
return result
140
142
}
141
143
142
- export function readSFC ( target : string ) : SFCFileInfo [ ] {
143
- const targets = resolveGlob ( target )
144
+ export function readSFC ( target : string , ignorePath ?: string ) : SFCFileInfo [ ] {
145
+ let targets = resolveGlob ( target )
146
+ if ( ( ignorePath !== undefined ) ) {
147
+ const ig = returnIgnoreInstance ( ignorePath )
148
+ targets = targets . filter ( t => {
149
+ if ( path . isAbsolute ( t ) ) {
150
+ console . debug ( 'Target is absolute path. Please change relative path.' )
151
+ return ! ig . ignores ( path . relative ( '/' , t ) )
152
+ } else {
153
+ return ! ig . ignores ( path . relative ( './' , t ) )
154
+ }
155
+ } )
156
+ }
144
157
debug ( 'readSFC: targets = ' , targets )
145
158
146
159
// TODO: async implementation
147
- return targets . map ( target => {
148
- const data = fs . readFileSync ( target )
160
+ return targets . map ( t => {
161
+ const data = fs . readFileSync ( t )
149
162
return {
150
- path : target ,
163
+ path : t ,
151
164
content : data . toString ( )
152
165
}
153
166
} )
@@ -420,3 +433,30 @@ export function splitLocaleMessages (
420
433
421
434
return { sfc : messages , external : metaExternalLocaleMessages }
422
435
}
436
+
437
+ function returnIgnoreInstance ( ignorePath : string ) : Ignore {
438
+ const ig = ignore ( )
439
+ if ( fs . existsSync ( ignorePath ) ) {
440
+ addIgnoreFile ( ig , ignorePath )
441
+ } else {
442
+ console . warn ( 'cannot find ignore file.' )
443
+ }
444
+ return ig
445
+ }
446
+
447
+ function readIgnoreFile ( ignorePath : string ) : string [ ] {
448
+ const ignoreFiles = fs . readFileSync ( ignorePath , 'utf8' )
449
+ . split ( / \r ? \n / g)
450
+ . filter ( Boolean )
451
+ console . log ( `ignoreFiles ${ ignoreFiles } ` )
452
+ return ignoreFiles
453
+ }
454
+
455
+ function addIgnoreFile (
456
+ ig : Ignore ,
457
+ ignorePath : string
458
+ ) : void {
459
+ readIgnoreFile ( ignorePath ) . forEach ( ignoreRule =>
460
+ ig . add ( ignoreRule )
461
+ )
462
+ }
0 commit comments