暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

firebaseConfigValidate.js 1.1KB

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getErrorMessage = exports.getValidator = void 0;
  4. const fs = require("fs");
  5. const path = require("path");
  6. const Ajv = require("ajv");
  7. const ajv = new Ajv();
  8. let _VALIDATOR = undefined;
  9. function getValidator() {
  10. if (!_VALIDATOR) {
  11. const schemaStr = fs.readFileSync(path.resolve(__dirname, "../schema/firebase-config.json"), "utf-8");
  12. const schema = JSON.parse(schemaStr);
  13. _VALIDATOR = ajv.compile(schema);
  14. }
  15. return _VALIDATOR;
  16. }
  17. exports.getValidator = getValidator;
  18. function getErrorMessage(e) {
  19. if (e.keyword === "additionalProperties") {
  20. return `Object "${e.dataPath}" in "firebase.json" has unknown property: ${JSON.stringify(e.params)}`;
  21. }
  22. else if (e.keyword === "required") {
  23. return `Object "${e.dataPath}" in "firebase.json" is missing required property: ${JSON.stringify(e.params)}`;
  24. }
  25. else {
  26. return `Field "${e.dataPath}" in "firebase.json" is possibly invalid: ${e.message}`;
  27. }
  28. }
  29. exports.getErrorMessage = getErrorMessage;