| 449 | |
| 450 | // walk path |
| 451 | function walkPath( |
| 452 | globInfo: { base: string; pattern: string; ignore?: string }, |
| 453 | callback: (filepath: string) => void, |
| 454 | onFinish: () => void |
| 455 | ) { |
| 456 | let base: string = globInfo.base |
| 457 | const pattern = globInfo.pattern |
| 458 | const ignore: string | undefined = globInfo.ignore |
| 459 | const arrIgnores = ['**/node_modules/**'] |
| 460 | |
| 461 | if (ignore) { |
| 462 | ignore.split(',').forEach((pattern) => { |
| 463 | arrIgnores.push(pattern) |
| 464 | }) |
| 465 | } |
| 466 | |
| 467 | const walk = globStream(pattern, { |
| 468 | cwd: base, |
| 469 | dot: false, |
| 470 | ignore: arrIgnores, |
| 471 | nodir: true, |
| 472 | }) |
| 473 | |
| 474 | walk.on('data', (file: string) => { |
| 475 | base = base.replace(/^.\//, '') |
| 476 | |
| 477 | if (sep !== '/') { |
| 478 | base = base.replace(/\//g, sep) |
| 479 | } |
| 480 | |
| 481 | callback(base + file) |
| 482 | }) |
| 483 | |
| 484 | walk.on('end', () => { |
| 485 | onFinish() |
| 486 | }) |
| 487 | |
| 488 | walk.on('error', () => { |
| 489 | onFinish() |
| 490 | }) |
| 491 | } |
| 492 | |
| 493 | // hint file |
| 494 | function hintFile(filepath: string, ruleset?: Ruleset) { |