@@ -28,6 +28,8 @@ import JSON5 from 'json5'
2828import yaml from 'js-yaml'
2929import deepmerge from 'deepmerge'
3030import { promisify } from 'util'
31+ import ignore from 'ignore'
32+ import type { Ignore } from 'ignore'
3133
3234import { debug as Debug } from 'debug'
3335const debug = Debug ( 'vue-i18n-locale-message:utils' )
@@ -139,15 +141,26 @@ export function stringifyContent (content: any, lang: string, options?: FormatOp
139141 return result
140142}
141143
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+ }
144157 debug ( 'readSFC: targets = ' , targets )
145158
146159 // 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 )
149162 return {
150- path : target ,
163+ path : t ,
151164 content : data . toString ( )
152165 }
153166 } )
@@ -420,3 +433,30 @@ export function splitLocaleMessages (
420433
421434 return { sfc : messages , external : metaExternalLocaleMessages }
422435}
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