(file?: string)
| 14 | import { CliError } from '../cli-error'; |
| 15 | |
| 16 | export function getSchemaFile(file?: string) { |
| 17 | if (file) { |
| 18 | if (!fs.existsSync(file)) { |
| 19 | throw new CliError(`Schema file not found: ${file}`); |
| 20 | } |
| 21 | return file; |
| 22 | } |
| 23 | |
| 24 | const pkgJsonConfig = getPkgJsonConfig(process.cwd()); |
| 25 | if (pkgJsonConfig.schema) { |
| 26 | if (!fs.existsSync(pkgJsonConfig.schema)) { |
| 27 | throw new CliError(`Schema file not found: ${pkgJsonConfig.schema}`); |
| 28 | } |
| 29 | if (fs.statSync(pkgJsonConfig.schema).isDirectory()) { |
| 30 | const schemaPath = path.join(pkgJsonConfig.schema, 'schema.zmodel'); |
| 31 | if (!fs.existsSync(schemaPath)) { |
| 32 | throw new CliError(`Schema file not found: ${schemaPath}`); |
| 33 | } |
| 34 | return schemaPath; |
| 35 | } else { |
| 36 | return pkgJsonConfig.schema; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | if (fs.existsSync('./schema.zmodel')) { |
| 41 | return './schema.zmodel'; |
| 42 | } else if (fs.existsSync('./zenstack/schema.zmodel')) { |
| 43 | return './zenstack/schema.zmodel'; |
| 44 | } else { |
| 45 | throw new CliError( |
| 46 | 'Schema file not found in default locations ("./schema.zmodel" or "./zenstack/schema.zmodel").', |
| 47 | ); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | export async function loadSchemaDocument( |
| 52 | schemaFile: string, |
no test coverage detected