(sourceFilePaths: string[], moreSchemas: TableSchema[] = [])
| 56 | } |
| 57 | |
| 58 | function run(sourceFilePaths: string[], moreSchemas: TableSchema[] = []) { |
| 59 | let allQueries: QueryInvocation[] = [] |
| 60 | let allTableSchemas: TableSchema[] = [...moreSchemas] |
| 61 | |
| 62 | sourceFilePaths = sourceFilePaths.map(filePath => path.relative(process.cwd(), filePath)) |
| 63 | |
| 64 | try { |
| 65 | for (const filePath of sourceFilePaths) { |
| 66 | const { queries, tableSchemas } = parseSourceFile(loadSourceFile(filePath)) |
| 67 | // TODO: Check that no table is defined twice |
| 68 | |
| 69 | allQueries = [...allQueries, ...queries] |
| 70 | allTableSchemas = [...allTableSchemas, ...tableSchemas] |
| 71 | } |
| 72 | |
| 73 | checkSchemasForDuplicates(allTableSchemas) |
| 74 | |
| 75 | for (const query of allQueries) { |
| 76 | validateQuery(query, allTableSchemas) |
| 77 | } |
| 78 | |
| 79 | console.log( |
| 80 | format.success( |
| 81 | `${logSymbols.success} Validated ${allQueries.length} queries against ${ |
| 82 | allTableSchemas.length |
| 83 | } table schemas. All fine!` |
| 84 | ) |
| 85 | ) |
| 86 | } catch (error) { |
| 87 | if (isAugmentedError(error)) { |
| 88 | const [firstLine, ...lines] = String(error.message).split("\n") |
| 89 | const linesIndented = lines.map(line => (line.match(/^>?\s*\d*\s*\|/) ? line : ` ${line}`)) |
| 90 | console.error(`${logSymbols.error} ${[firstLine, ...linesIndented].join("\n")}`) |
| 91 | } else { |
| 92 | console.error(error.stack) |
| 93 | } |
| 94 | if (!watchMode) { |
| 95 | process.exit(1) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | return { |
| 100 | queries: allQueries, |
| 101 | schemas: allTableSchemas |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | let { schemas } = run(cli.input) |
| 106 |
no test coverage detected