MCPcopy Create free account
hub / github.com/firebase/firebase-tools / parseFile

Method parseFile

src/config.ts:142–178  ·  view source on GitHub ↗
(target: string, filePath: string)

Source from the content-addressed store, hash-verified

140 }
141
142 parseFile(target: string, filePath: string) {
143 const fullPath = resolveProjectPath(this.options, filePath);
144 const ext = path.extname(filePath);
145 if (!fsutils.fileExistsSync(fullPath)) {
146 throw new FirebaseError("Parse Error: Imported file " + filePath + " does not exist", {
147 exit: 1,
148 });
149 }
150
151 switch (ext) {
152 case ".json":
153 if (target === "database") {
154 this.notes.databaseRules = "json";
155 } else if (target === "database.rules") {
156 this.notes.databaseRulesFile = filePath;
157 try {
158 return fs.readFileSync(fullPath, "utf8");
159 } catch (e: any) {
160 if (e.code === "ENOENT") {
161 throw new FirebaseError(`File not found: ${fullPath}`, { original: e });
162 }
163 throw e;
164 }
165 }
166 return loadCJSON(fullPath);
167 /* istanbul ignore-next */
168 case ".bolt":
169 throw new FirebaseError(
170 "As of firebase-tools@15.0.0, .bolt rules are no longer supported.",
171 );
172 default:
173 throw new FirebaseError(
174 "Parse Error: " + filePath + " is not of a supported config file type",
175 { exit: 1 },
176 );
177 }
178 }
179
180 get src(): FirebaseConfig {
181 // TODO(samstern): We should do JSON Schema validation on this at load time

Callers 2

materializeMethod · 0.95
config.spec.tsFile · 0.80

Calls 2

resolveProjectPathFunction · 0.90
loadCJSONFunction · 0.90

Tested by

no test coverage detected