No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

validate.js 1.5KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.packageJsonIsValid = void 0;
  4. const path = require("path");
  5. const error_1 = require("../../../../error");
  6. const logger_1 = require("../../../../logger");
  7. const fsutils = require("../../../../fsutils");
  8. const cjson = require("cjson");
  9. function assertFunctionsSourcePresent(data, sourceDir, projectDir) {
  10. const indexJsFile = path.join(sourceDir, data.main || "index.js");
  11. if (!fsutils.fileExistsSync(indexJsFile)) {
  12. const relativeMainPath = path.relative(projectDir, indexJsFile);
  13. const msg = `${relativeMainPath} does not exist, can't deploy Cloud Functions`;
  14. throw new error_1.FirebaseError(msg);
  15. }
  16. }
  17. function packageJsonIsValid(sourceDirName, sourceDir, projectDir) {
  18. const packageJsonFile = path.join(sourceDir, "package.json");
  19. if (!fsutils.fileExistsSync(packageJsonFile)) {
  20. const msg = `No npm package found in functions source directory ${sourceDirName}.`;
  21. throw new error_1.FirebaseError(msg);
  22. }
  23. let data;
  24. try {
  25. data = cjson.load(packageJsonFile);
  26. logger_1.logger.debug("> [functions] package.json contents:", JSON.stringify(data, null, 2));
  27. assertFunctionsSourcePresent(data, sourceDir, projectDir);
  28. }
  29. catch (e) {
  30. const msg = `There was an error reading ${sourceDirName}${path.sep}package.json:\n\n ${e.message}`;
  31. throw new error_1.FirebaseError(msg);
  32. }
  33. }
  34. exports.packageJsonIsValid = packageJsonIsValid;