Skip to content
12 changes: 5 additions & 7 deletions src/dataconnect/fileUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from "fs-extra";
import * as path from "path";
import * as clc from "colorette";
import { glob } from "glob";

import { FirebaseError } from "../error";
import {
Expand All @@ -17,19 +18,19 @@
import { load } from "./load";
import { PackageJSON } from "../frameworks/compose/discover/runtime/node";

export function readFirebaseJson(config?: Config): DataConnectMultiple {

Check warning on line 21 in src/dataconnect/fileUtils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
if (!config?.has("dataconnect")) {
return [];
}
const validator = (cfg: any) => {

Check warning on line 25 in src/dataconnect/fileUtils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 25 in src/dataconnect/fileUtils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function
if (!cfg["source"]) {

Check warning on line 26 in src/dataconnect/fileUtils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access ["source"] on an `any` value
throw new FirebaseError("Invalid firebase.json: DataConnect requires `source`");
}
return {
source: cfg["source"],

Check warning on line 30 in src/dataconnect/fileUtils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access ["source"] on an `any` value

Check warning on line 30 in src/dataconnect/fileUtils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
};
};
const configs = config.get("dataconnect");

Check warning on line 33 in src/dataconnect/fileUtils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
if (typeof configs === "object" && !Array.isArray(configs)) {
return [validator(configs)];
} else if (Array.isArray(configs)) {
Expand All @@ -41,13 +42,13 @@
}
}

export async function readDataConnectYaml(sourceDirectory: string): Promise<DataConnectYaml> {

Check warning on line 45 in src/dataconnect/fileUtils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
const file = await readFileFromDirectory(sourceDirectory, "dataconnect.yaml");
const dataconnectYaml = await wrappedSafeLoad(file.source);

Check warning on line 47 in src/dataconnect/fileUtils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
return validateDataConnectYaml(dataconnectYaml);
}

function validateDataConnectYaml(unvalidated: any): DataConnectYaml {

Check warning on line 51 in src/dataconnect/fileUtils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
// TODO: Use json schema for validation here!
if (!unvalidated["location"]) {
throw new FirebaseError("Missing required field 'location' in dataconnect.yaml");
Expand All @@ -70,15 +71,12 @@
if (!fs.existsSync(sourceDir)) {
return [];
}
const files = await fs.readdir(sourceDir);
// TODO: Handle files in subdirectories such as `foo/a.gql` and `bar/baz/b.gql`.
return files
.filter((f) => f.endsWith(".gql") || f.endsWith(".graphql"))
.map((f) => toFile(sourceDir, f));
const files = await glob(`${sourceDir}/**/*.{gql,graphql}`);
Comment thread
fredzqm marked this conversation as resolved.
Outdated
return files.map((f) => toFile(sourceDir, f));
}

function toFile(sourceDir: string, relPath: string): File {
const fullPath = path.join(sourceDir, relPath);
function toFile(sourceDir: string, fullPath: string): File {
const relPath = path.relative(sourceDir, fullPath);
if (!fs.existsSync(fullPath)) {
throw new FirebaseError(`file ${fullPath} not found`);
}
Expand Down
Loading