MCPcopy Index your code
hub / github.com/zenstackhq/zenstack / getSchemaFile

Function getSchemaFile

packages/cli/src/actions/action-utils.ts:16–49  ·  view source on GitHub ↗
(file?: string)

Source from the content-addressed store, hash-verified

14import { CliError } from '../cli-error';
15
16export 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
51export async function loadSchemaDocument(
52 schemaFile: string,

Callers 7

runFunction · 0.90
pureGenerateFunction · 0.90
runPushFunction · 0.90
runPullFunction · 0.90
runFunction · 0.90
runFunction · 0.90
runFunction · 0.90

Calls 1

getPkgJsonConfigFunction · 0.85

Tested by

no test coverage detected