firebase-tools
Version:
Command-Line Interface for Firebase
43 lines (42 loc) • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.tryCreateDelegate = tryCreateDelegate;
const fs = require("fs-extra");
const path = require("path");
const yaml = require("js-yaml");
const discovery = require("./discovery");
async function tryCreateDelegate(context) {
const yamlPath = path.join(context.sourceDir, "functions.yaml");
if (!(await fs.pathExists(yamlPath))) {
return undefined;
}
const runtime = context.runtime || "dart3";
return {
language: "dart",
runtime: runtime,
bin: "",
validate: async () => {
try {
const content = await fs.readFile(yamlPath, "utf8");
yaml.load(content);
}
catch (e) {
throw new Error(`Failed to parse functions.yaml: ${e.message}`);
}
},
build: async () => {
return Promise.resolve();
},
watch: async () => {
return Promise.resolve(async () => {
});
},
discoverBuild: async () => {
const build = await discovery.detectFromYaml(context.sourceDir, context.projectId, runtime);
if (!build) {
throw new Error("Could not find functions.yaml");
}
return build;
},
};
}