|
1 | 1 | import * as fs from "fs-extra"
|
2 |
| -import { join } from "./path" |
| 2 | +import { join, relative } from "./path" |
3 | 3 |
|
4 | 4 | function _getPatchFiles(
|
5 |
| - rootPatchesDir: string, |
| 5 | + currentPatchesDir: string, |
6 | 6 | scopedDir: string = "",
|
7 | 7 | acc: string[] = [],
|
| 8 | + rootPatchesDir: string, |
8 | 9 | ) {
|
9 |
| - fs.readdirSync(join(rootPatchesDir, scopedDir)).forEach(filename => { |
| 10 | + fs.readdirSync(join(currentPatchesDir, scopedDir)).forEach(filename => { |
10 | 11 | if (filename.endsWith(".patch")) {
|
11 |
| - acc.push(join(scopedDir, filename)) |
12 |
| - } else if ( |
13 |
| - filename.startsWith("@") && |
14 |
| - fs.statSync(join(rootPatchesDir, filename)).isDirectory() |
15 |
| - ) { |
16 |
| - _getPatchFiles(rootPatchesDir, filename, acc) |
| 12 | + acc.push( |
| 13 | + relative(rootPatchesDir, join(currentPatchesDir, scopedDir, filename)), |
| 14 | + ) |
| 15 | + } else if (fs.statSync(join(currentPatchesDir, filename)).isDirectory()) { |
| 16 | + _getPatchFiles(join(currentPatchesDir, filename), "", acc, rootPatchesDir) |
17 | 17 | }
|
18 | 18 | })
|
19 | 19 | return acc
|
20 | 20 | }
|
21 | 21 |
|
22 | 22 | export const getPatchFiles = (patchesDir: string) => {
|
23 |
| - return _getPatchFiles(patchesDir).filter(filename => |
24 |
| - filename.match(/^.+(:|\+).+\.patch$/), |
| 23 | + return _getPatchFiles(patchesDir, undefined, [], patchesDir).filter( |
| 24 | + filename => filename.match(/^.+(:|\+).+\.patch$/), |
25 | 25 | )
|
26 | 26 | }
|
0 commit comments