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