| 36 | } |
| 37 | |
| 38 | function syncTests(syncDir) { |
| 39 | const specFiles = fastGlob.sync( |
| 40 | path.join(FLOW_TESTS_DIR, "**", SPEC_FILE_NAME), |
| 41 | ); |
| 42 | const filesToCopy = fastGlob.sync(path.join(syncDir, "**/*.js")); |
| 43 | |
| 44 | if (filesToCopy.length === 0) { |
| 45 | throw new Error( |
| 46 | [ |
| 47 | "Couldn't find any files to copy.", |
| 48 | `Please make sure that \`${syncDir}\` exists and contains the flow tests.`, |
| 49 | ].join("\n"), |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | const specContents = specFiles.reduce((obj, specFile) => { |
| 54 | obj[specFile] = fs.readFileSync(specFile, "utf8"); |
| 55 | return obj; |
| 56 | }, {}); |
| 57 | |
| 58 | const skipped = []; |
| 59 | |
| 60 | fs.rmSync(FLOW_TESTS_DIR); |
| 61 | |
| 62 | for (const file of filesToCopy) { |
| 63 | const content = fs.readFileSync(file, "utf8"); |
| 64 | const parseError = tryParse(file, content); |
| 65 | |
| 66 | if (parseError) { |
| 67 | skipped.push(parseError); |
| 68 | continue; |
| 69 | } |
| 70 | |
| 71 | const newFile = path.join(FLOW_TESTS_DIR, path.relative(syncDir, file)); |
| 72 | const dirname = path.dirname(newFile); |
| 73 | const specFile = path.join(dirname, SPEC_FILE_NAME); |
| 74 | const specContent = specContents[specFile] || DEFAULT_SPEC_CONTENT; |
| 75 | |
| 76 | fs.mkdirSync(dirname, { recursive: true }); |
| 77 | fs.writeFileSync(newFile, content); |
| 78 | fs.writeFileSync(specFile, specContent); |
| 79 | } |
| 80 | |
| 81 | return skipped; |
| 82 | } |
| 83 | |
| 84 | function run(argv) { |
| 85 | if (argv.length !== 1) { |