Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 512301b

Browse files
authored
Merge pull request #197 from thicodes/feat/sync-fixture-from-ts
Make syncFixtures flexible to get fixtures from other paths
2 parents b9b38ac + 1f98f3a commit 512301b

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"prettier": "prettier --write '{src,types,test}/**/*.ts'",
3939
"prepublish": "npm run build",
4040
"relay": "node bin/relay-compiler.js --schema test/schema.graphql --src test/ --outputDir __generated__",
41-
"sync-fixtures": "rsync -avh --delete --stats --progress ../relay/packages/relay-compiler/language/javascript/__tests__/fixtures/flow-generator/**/*.graphql test/fixtures/type-generator",
41+
"sync-fixtures": "ts-node ./syncFixtures.ts",
4242
"test": "npm run type-check && jest",
4343
"watch": "concurrently 'tsc --watch' 'chokidar \"lib/**/*.js\" -c \"yalc publish --force --push\"'",
4444
"type-check": "tsc --noEmit --pretty"
@@ -85,6 +85,7 @@
8585
"babel-plugin-relay": "^9.0.0",
8686
"chokidar-cli": "^2.0.0",
8787
"concurrently": "^5.0.0",
88+
"glob": "^7.1.6",
8889
"graphql": "^14.5.8",
8990
"husky": "^3.0.2",
9091
"jest": "^24.8.0",
@@ -95,6 +96,7 @@
9596
"relay-runtime": "^9.0.0",
9697
"relay-test-utils-internal": "^8.0.0",
9798
"ts-jest": "^22.0.1",
99+
"ts-node": "^8.10.2",
98100
"tslint": "^5.18.0",
99101
"tslint-config-prettier": "^1.18.0",
100102
"typescript": "3.6.4"

syncFixtures.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as fs from "fs";
2+
import * as glob from "glob";
3+
import * as path from "path";
4+
5+
type SyncFixturesType = {
6+
souceFilePaths: Array<{
7+
cwd: string;
8+
pattern: string;
9+
}>;
10+
dest: string;
11+
};
12+
13+
const syncFixtures = ({ souceFilePaths, dest }: SyncFixturesType) => {
14+
souceFilePaths.forEach(({ cwd, pattern }) => {
15+
glob
16+
.sync(pattern, {
17+
cwd
18+
})
19+
.forEach(filePath => {
20+
const file = getFileNameFromPath(filePath);
21+
try {
22+
fs.copyFileSync(
23+
path.join(__dirname, `${cwd}/${filePath}`),
24+
`${dest}/${file}`
25+
);
26+
console.log(`${filePath} was copied`);
27+
} catch (error) {
28+
console.error(error);
29+
}
30+
});
31+
});
32+
};
33+
34+
const getFileNameFromPath = (filePath: string) => filePath.split("/").pop();
35+
36+
const souceFilePaths = [
37+
{
38+
cwd:
39+
"../relay/packages/relay-compiler/language/javascript/__tests__/fixtures/flow-generator",
40+
pattern: "**/*.graphql"
41+
}
42+
];
43+
44+
syncFixtures({ souceFilePaths, dest: "./test/fixtures/type-generator" });

yarn.lock

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,11 @@ are-we-there-yet@~1.1.2:
941941
delegates "^1.0.0"
942942
readable-stream "^2.0.6"
943943

944+
arg@^4.1.0:
945+
version "4.1.3"
946+
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
947+
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
948+
944949
argparse@^1.0.7:
945950
version "1.0.10"
946951
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
@@ -2542,6 +2547,18 @@ glob@^7.0.5, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3:
25422547
once "^1.3.0"
25432548
path-is-absolute "^1.0.0"
25442549

2550+
glob@^7.1.6:
2551+
version "7.1.6"
2552+
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
2553+
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
2554+
dependencies:
2555+
fs.realpath "^1.0.0"
2556+
inflight "^1.0.4"
2557+
inherits "2"
2558+
minimatch "^3.0.4"
2559+
once "^1.3.0"
2560+
path-is-absolute "^1.0.0"
2561+
25452562
globals@^11.1.0:
25462563
version "11.12.0"
25472564
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
@@ -4054,6 +4071,11 @@ make-dir@^2.1.0:
40544071
pify "^4.0.1"
40554072
semver "^5.6.0"
40564073

4074+
make-error@^1.1.1:
4075+
version "1.3.6"
4076+
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
4077+
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
4078+
40574079
40584080
version "1.0.11"
40594081
resolved "https://registry.yarnpkg.com/makeerror/-/makeerror-1.0.11.tgz#e01a5c9109f2af79660e4e8b9587790184f5a96c"
@@ -5483,6 +5505,14 @@ source-map-support@^0.5.0, source-map-support@^0.5.5, source-map-support@^0.5.6:
54835505
buffer-from "^1.0.0"
54845506
source-map "^0.6.0"
54855507

5508+
source-map-support@^0.5.17:
5509+
version "0.5.19"
5510+
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
5511+
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
5512+
dependencies:
5513+
buffer-from "^1.0.0"
5514+
source-map "^0.6.0"
5515+
54865516
source-map-url@^0.4.0:
54875517
version "0.4.0"
54885518
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
@@ -5872,6 +5902,17 @@ ts-jest@^22.0.1:
58725902
source-map-support "^0.5.5"
58735903
yargs "^11.0.0"
58745904

5905+
ts-node@^8.10.2:
5906+
version "8.10.2"
5907+
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.10.2.tgz#eee03764633b1234ddd37f8db9ec10b75ec7fb8d"
5908+
integrity sha512-ISJJGgkIpDdBhWVu3jufsWpK3Rzo7bdiIXJjQc0ynKxVOVcg2oIrf2H2cejminGrptVc6q6/uynAHNCuWGbpVA==
5909+
dependencies:
5910+
arg "^4.1.0"
5911+
diff "^4.0.1"
5912+
make-error "^1.1.1"
5913+
source-map-support "^0.5.17"
5914+
yn "3.1.1"
5915+
58755916
tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0:
58765917
version "1.10.0"
58775918
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
@@ -6292,3 +6333,8 @@ yargs@^14.2.0:
62926333
which-module "^2.0.0"
62936334
y18n "^4.0.0"
62946335
yargs-parser "^15.0.0"
6336+
6337+
6338+
version "3.1.1"
6339+
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
6340+
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

0 commit comments

Comments
 (0)