forked from relay-tools/relay-compiler-language-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyncFixtures.ts
44 lines (39 loc) · 1.03 KB
/
syncFixtures.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as fs from "fs";
import * as glob from "glob";
import * as path from "path";
type SyncFixturesType = {
souceFilePaths: Array<{
cwd: string;
pattern: string;
}>;
dest: string;
};
const syncFixtures = ({ souceFilePaths, dest }: SyncFixturesType) => {
souceFilePaths.forEach(({ cwd, pattern }) => {
glob
.sync(pattern, {
cwd
})
.forEach(filePath => {
const file = getFileNameFromPath(filePath);
try {
fs.copyFileSync(
path.join(__dirname, `${cwd}/${filePath}`),
`${dest}/${file}`
);
console.log(`${filePath} was copied`);
} catch (error) {
console.error(error);
}
});
});
};
const getFileNameFromPath = (filePath: string) => filePath.split("/").pop();
const souceFilePaths = [
{
cwd:
"../relay/packages/relay-compiler/language/javascript/__tests__/fixtures/flow-generator",
pattern: "**/*.graphql"
}
];
syncFixtures({ souceFilePaths, dest: "./test/fixtures/type-generator" });