@@ -32,13 +32,15 @@ import JSON5 from 'json5'
32
32
import yaml from 'js-yaml'
33
33
import deepmerge from 'deepmerge'
34
34
import { promisify } from 'util'
35
- import type { Ignore } from 'ignore'
36
35
import querystring from 'query-string'
36
+ import { debug as Debug } from 'debug'
37
+ import ignore from 'ignore'
37
38
import { flatten , unflatten } from 'flat'
38
39
import { cosmiconfig } from 'cosmiconfig'
39
40
const jsonDiff = require ( 'json-diff' ) // NOTE: not provided type definition ...
40
41
41
- import { debug as Debug } from 'debug'
42
+ import type { Ignore } from 'ignore'
43
+
42
44
const debug = Debug ( 'vue-i18n-locale-message:utils' )
43
45
44
46
const readFile = promisify ( fs . readFile )
@@ -478,32 +480,43 @@ export function splitLocaleMessages (
478
480
return { sfc : messages , external : metaExternalLocaleMessages }
479
481
}
480
482
481
- export function readIgnoreFile ( target : string , ignoreFileName : string ) : string [ ] {
482
- const ignoreFiles = glob . sync ( `${ target } /**/${ ignoreFileName } ` )
483
- console . log ( `ignoreFiles ${ ignoreFiles } ` )
484
- const ignoreTargets = [ ] as string [ ]
485
- ignoreFiles . forEach ( ignoreFile => {
486
- fs . readFileSync ( ignoreFile , 'utf8' )
487
- . split ( / \r ? \n / g)
488
- . filter ( Boolean )
489
- . forEach ( ignoreTarget => {
490
- ignoreTargets . push ( formatPath ( ignoreFile , ignoreTarget ) )
491
- } )
483
+ export function getIgnore ( target :string , ignoreFileNames : string ) : Ignore {
484
+ const ig = ignore ( )
485
+ const files = ignoreFileNames . split ( ',' ) . filter ( Boolean )
486
+ files . forEach ( file => {
487
+ const fullPath = resolve ( path . join ( target , path . normalize ( file ) ) )
488
+ console . log ( 'fullpaht' , fullPath , fs . existsSync ( fullPath ) )
489
+ if ( fs . existsSync ( fullPath ) ) {
490
+ const ignoreFiles = readIgnoreFile ( fullPath )
491
+ returnIgnoreInstance ( ig , ignoreFiles )
492
+ }
492
493
} )
493
- console . log ( `ignoreTargets ${ ignoreTargets } ` )
494
- return ignoreTargets
494
+ return ig
495
495
}
496
496
497
- function formatPath ( ignoreFile : string , ignoreTarget : string ) : string {
498
- return path . join ( path . relative ( process . cwd ( ) , path . dirname ( ignoreFile ) ) , ignoreTarget )
497
+ function readIgnoreFile ( ignoreFile : string ) : string [ ] {
498
+ console . log ( 'readIgnoreFile: ignoreFile' , ignoreFile )
499
+ const ignoreTargets = [ ] as string [ ]
500
+ fs . readFileSync ( ignoreFile , 'utf8' )
501
+ . split ( / \r ? \n / g)
502
+ . filter ( Boolean )
503
+ . forEach ( ignoreTarget => {
504
+ ignoreTargets . push ( formatPath ( ignoreFile , ignoreTarget ) )
505
+ } )
506
+ console . log ( `ignoreTargets ${ ignoreTargets } ` )
507
+ return ignoreTargets
499
508
}
500
509
501
- export function returnIgnoreInstance ( ig : Ignore , ignoreFiles : string [ ] ) : void {
510
+ function returnIgnoreInstance ( ig : Ignore , ignoreFiles : string [ ] ) : void {
502
511
ignoreFiles . forEach ( ignoreRule => {
503
512
ig . add ( ignoreRule )
504
513
} )
505
514
}
506
515
516
+ function formatPath ( ignoreFile : string , ignoreTarget : string ) : string {
517
+ return path . join ( path . relative ( process . cwd ( ) , path . dirname ( ignoreFile ) ) , ignoreTarget )
518
+ }
519
+
507
520
export async function returnDiff ( options : DiffOptions ) : Promise < DiffInfo > {
508
521
const format = 'json'
509
522
const ProviderFactory = loadProvider ( options . provider )
0 commit comments