firebase-tools 10.3.0 → 10.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/lib/accountExporter.js +95 -84
  2. package/lib/commands/deploy.js +1 -1
  3. package/lib/commands/experimental-functions-shell.js +1 -1
  4. package/lib/commands/ext-configure.js +13 -6
  5. package/lib/commands/ext-export.js +7 -1
  6. package/lib/commands/ext-install.js +12 -7
  7. package/lib/commands/ext-update.js +5 -3
  8. package/lib/commands/functions-config-export.js +5 -3
  9. package/lib/commands/functions-shell.js +1 -1
  10. package/lib/commands/hosting-channel-create.js +2 -2
  11. package/lib/commands/hosting-channel-delete.js +2 -2
  12. package/lib/commands/hosting-channel-deploy.js +2 -2
  13. package/lib/commands/hosting-channel-list.js +2 -2
  14. package/lib/commands/hosting-channel-open.js +2 -2
  15. package/lib/commands/hosting-sites-delete.js +2 -2
  16. package/lib/commands/serve.js +1 -1
  17. package/lib/commands/target-apply.js +2 -2
  18. package/lib/commands/target-clear.js +2 -2
  19. package/lib/commands/target-remove.js +2 -2
  20. package/lib/commands/target.js +2 -2
  21. package/lib/config.js +14 -4
  22. package/lib/deploy/extensions/planner.js +9 -3
  23. package/lib/deploy/functions/deploy.js +3 -7
  24. package/lib/deploy/functions/prepare.js +7 -5
  25. package/lib/deploy/functions/prepareFunctionsUpload.js +7 -13
  26. package/lib/deploy/functions/release/fabricator.js +13 -1
  27. package/lib/deploy/functions/release/index.js +1 -1
  28. package/lib/deploy/functions/runtimes/node/parseTriggers.js +12 -5
  29. package/lib/deploy/hosting/deploy.js +10 -0
  30. package/lib/emulator/auth/apiSpec.js +37 -0
  31. package/lib/emulator/commandUtils.js +2 -2
  32. package/lib/emulator/controller.js +14 -8
  33. package/lib/emulator/downloadableEmulators.js +5 -5
  34. package/lib/emulator/extensionsEmulator.js +3 -0
  35. package/lib/emulator/functionsEmulator.js +4 -4
  36. package/lib/emulator/functionsEmulatorShared.js +17 -1
  37. package/lib/emulator/storage/apis/firebase.js +4 -6
  38. package/lib/emulator/storage/files.js +5 -5
  39. package/lib/emulator/storage/index.js +6 -9
  40. package/lib/emulator/storage/rules/config.js +6 -5
  41. package/lib/emulator/storage/rules/manager.js +49 -32
  42. package/lib/emulator/storage/rules/runtime.js +4 -0
  43. package/lib/emulator/storage/rules/utils.js +2 -2
  44. package/lib/emulator/storage/server.js +1 -1
  45. package/lib/extensions/askUserForParam.js +103 -28
  46. package/lib/extensions/manifest.js +38 -6
  47. package/lib/extensions/paramHelper.js +28 -6
  48. package/lib/fsutils.js +14 -1
  49. package/lib/functions/projectConfig.js +34 -0
  50. package/lib/gcp/cloudfunctions.js +5 -4
  51. package/lib/init/features/functions/index.js +4 -2
  52. package/lib/init/features/hosting/index.js +32 -41
  53. package/lib/init/features/index.js +22 -12
  54. package/lib/init/index.js +28 -11
  55. package/lib/requireConfig.js +11 -9
  56. package/lib/serve/functions.js +5 -5
  57. package/npm-shrinkwrap.json +2 -2
  58. package/package.json +1 -1
  59. package/schema/firebase-config.json +93 -36
  60. package/lib/prepareUpload.js +0 -44
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeAndValidate = exports.validate = exports.normalize = void 0;
4
+ const error_1 = require("../error");
5
+ function normalize(config) {
6
+ if (!config) {
7
+ throw new error_1.FirebaseError("No valid functions configuration detected in firebase.json");
8
+ }
9
+ if (Array.isArray(config)) {
10
+ if (config.length < 1) {
11
+ throw new error_1.FirebaseError("Requires at least one functions.source in firebase.json.");
12
+ }
13
+ return config;
14
+ }
15
+ return [config];
16
+ }
17
+ exports.normalize = normalize;
18
+ function validateSingle(config) {
19
+ if (!config.source) {
20
+ throw new error_1.FirebaseError("functions.source must be specified");
21
+ }
22
+ return Object.assign(Object.assign({}, config), { source: config.source });
23
+ }
24
+ function validate(config) {
25
+ if (config.length > 1) {
26
+ throw new error_1.FirebaseError("More than one functions.source detected in firebase.json.");
27
+ }
28
+ return [validateSingle(config[0])];
29
+ }
30
+ exports.validate = validate;
31
+ function normalizeAndValidate(config) {
32
+ return validate(normalize(config));
33
+ }
34
+ exports.normalizeAndValidate = normalizeAndValidate;
@@ -202,7 +202,7 @@ async function listAllFunctions(projectId) {
202
202
  }
203
203
  exports.listAllFunctions = listAllFunctions;
204
204
  function endpointFromFunction(gcfFunction) {
205
- var _a, _b, _c, _d;
205
+ var _a, _b, _c, _d, _e;
206
206
  const [, project, , region, , id] = gcfFunction.name.split("/");
207
207
  let trigger;
208
208
  let uri;
@@ -217,7 +217,8 @@ function endpointFromFunction(gcfFunction) {
217
217
  taskQueueTrigger: {},
218
218
  };
219
219
  }
220
- else if ((_c = gcfFunction.labels) === null || _c === void 0 ? void 0 : _c["deployment-callable"]) {
220
+ else if (((_c = gcfFunction.labels) === null || _c === void 0 ? void 0 : _c["deployment-callable"]) ||
221
+ ((_d = gcfFunction.labels) === null || _d === void 0 ? void 0 : _d["deployment-callabled"])) {
221
222
  trigger = {
222
223
  callableTrigger: {},
223
224
  };
@@ -237,7 +238,7 @@ function endpointFromFunction(gcfFunction) {
237
238
  value: gcfFunction.eventTrigger.resource,
238
239
  },
239
240
  ],
240
- retry: !!((_d = gcfFunction.eventTrigger.failurePolicy) === null || _d === void 0 ? void 0 : _d.retry),
241
+ retry: !!((_e = gcfFunction.eventTrigger.failurePolicy) === null || _e === void 0 ? void 0 : _e.retry),
241
242
  },
242
243
  };
243
244
  }
@@ -304,7 +305,7 @@ function functionFromEndpoint(endpoint, sourceUploadUrl) {
304
305
  else {
305
306
  gcfFunction.httpsTrigger = {};
306
307
  if (backend.isCallableTriggered(endpoint)) {
307
- gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { "deployment-callabled": "true" });
308
+ gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { "deployment-callable": "true" });
308
309
  }
309
310
  if (endpoint.securityLevel) {
310
311
  gcfFunction.httpsTrigger.securityLevel = endpoint.securityLevel;
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.doSetup = void 0;
3
4
  const clc = require("cli-color");
4
5
  const logger_1 = require("../../../logger");
5
6
  const prompt_1 = require("../../../prompt");
6
7
  const requirePermissions_1 = require("../../../requirePermissions");
7
8
  const previews_1 = require("../../../previews");
8
9
  const ensureApiEnabled_1 = require("../../../ensureApiEnabled");
9
- module.exports = async function (setup, config, options) {
10
+ async function doSetup(setup, config, options) {
10
11
  var _a, _b;
11
12
  logger_1.logger.info();
12
13
  logger_1.logger.info("A " + clc.bold("functions") + " directory will be created in your project with sample code");
@@ -44,4 +45,5 @@ module.exports = async function (setup, config, options) {
44
45
  choices,
45
46
  });
46
47
  return require("./" + language)(setup, config);
47
- };
48
+ }
49
+ exports.doSetup = doSetup;
@@ -1,23 +1,23 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.doSetup = void 0;
2
4
  const clc = require("cli-color");
3
5
  const fs = require("fs");
4
- const { Client } = require("../../../apiv2");
5
- const { initGitHub } = require("./github");
6
- const { prompt } = require("../../../prompt");
7
- const { logger } = require("../../../logger");
6
+ const apiv2_1 = require("../../../apiv2");
7
+ const github_1 = require("./github");
8
+ const prompt_1 = require("../../../prompt");
9
+ const logger_1 = require("../../../logger");
8
10
  const INDEX_TEMPLATE = fs.readFileSync(__dirname + "/../../../../templates/init/hosting/index.html", "utf8");
9
11
  const MISSING_TEMPLATE = fs.readFileSync(__dirname + "/../../../../templates/init/hosting/404.html", "utf8");
10
12
  const DEFAULT_IGNORES = ["firebase.json", "**/.*", "**/node_modules/**"];
11
- module.exports = function (setup, config, options) {
13
+ async function doSetup(setup, config, options) {
12
14
  setup.hosting = {};
13
- logger.info();
14
- logger.info("Your " +
15
- clc.bold("public") +
16
- " directory is the folder (relative to your project directory) that");
17
- logger.info("will contain Hosting assets to be uploaded with " + clc.bold("firebase deploy") + ". If you");
18
- logger.info("have a build process for your assets, use your build's output directory.");
19
- logger.info();
20
- return prompt(setup.hosting, [
15
+ logger_1.logger.info();
16
+ logger_1.logger.info(`Your ${clc.bold("public")} directory is the folder (relative to your project directory) that`);
17
+ logger_1.logger.info(`will contain Hosting assets to be uploaded with ${clc.bold("firebase deploy")}. If you`);
18
+ logger_1.logger.info("have a build process for your assets, use your build's output directory.");
19
+ logger_1.logger.info();
20
+ await (0, prompt_1.prompt)(setup.hosting, [
21
21
  {
22
22
  name: "public",
23
23
  type: "input",
@@ -36,31 +36,22 @@ module.exports = function (setup, config, options) {
36
36
  default: false,
37
37
  message: "Set up automatic builds and deploys with GitHub?",
38
38
  },
39
- ]).then(function () {
40
- setup.config.hosting = {
41
- public: setup.hosting.public,
42
- ignore: DEFAULT_IGNORES,
43
- };
44
- let next;
45
- if (setup.hosting.spa) {
46
- setup.config.hosting.rewrites = [{ source: "**", destination: "/index.html" }];
47
- next = Promise.resolve();
48
- }
49
- else {
50
- next = config.askWriteProjectFile(setup.hosting.public + "/404.html", MISSING_TEMPLATE);
51
- }
52
- return next
53
- .then(() => {
54
- const c = new Client({ urlPrefix: "https://www.gstatic.com", auth: false });
55
- return c.get("/firebasejs/releases.json");
56
- })
57
- .then((response) => {
58
- return config.askWriteProjectFile(setup.hosting.public + "/index.html", INDEX_TEMPLATE.replace(/{{VERSION}}/g, response.body.current.version));
59
- })
60
- .then(() => {
61
- if (setup.hosting.github) {
62
- return initGitHub(setup, config, options);
63
- }
64
- });
65
- });
66
- };
39
+ ]);
40
+ setup.config.hosting = {
41
+ public: setup.hosting.public,
42
+ ignore: DEFAULT_IGNORES,
43
+ };
44
+ if (setup.hosting.spa) {
45
+ setup.config.hosting.rewrites = [{ source: "**", destination: "/index.html" }];
46
+ }
47
+ else {
48
+ await config.askWriteProjectFile(`${setup.hosting.public}/404.html`, MISSING_TEMPLATE);
49
+ }
50
+ const c = new apiv2_1.Client({ urlPrefix: "https://www.gstatic.com", auth: false });
51
+ const response = await c.get("/firebasejs/releases.json");
52
+ await config.askWriteProjectFile(`${setup.hosting.public}/index.html`, INDEX_TEMPLATE.replace(/{{VERSION}}/g, response.body.current.version));
53
+ if (setup.hosting.github) {
54
+ return (0, github_1.initGitHub)(setup, config, options);
55
+ }
56
+ }
57
+ exports.doSetup = doSetup;
@@ -1,13 +1,23 @@
1
1
  "use strict";
2
- module.exports = {
3
- account: require("./account").doSetup,
4
- database: require("./database").doSetup,
5
- firestore: require("./firestore").doSetup,
6
- functions: require("./functions"),
7
- hosting: require("./hosting"),
8
- storage: require("./storage").doSetup,
9
- emulators: require("./emulators").doSetup,
10
- project: require("./project").doSetup,
11
- remoteconfig: require("./remoteconfig").doSetup,
12
- "hosting:github": require("./hosting/github").initGitHub,
13
- };
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hostingGithub = exports.remoteconfig = exports.project = exports.emulators = exports.storage = exports.hosting = exports.functions = exports.firestore = exports.database = exports.account = void 0;
4
+ var account_1 = require("./account");
5
+ Object.defineProperty(exports, "account", { enumerable: true, get: function () { return account_1.doSetup; } });
6
+ var database_1 = require("./database");
7
+ Object.defineProperty(exports, "database", { enumerable: true, get: function () { return database_1.doSetup; } });
8
+ var firestore_1 = require("./firestore");
9
+ Object.defineProperty(exports, "firestore", { enumerable: true, get: function () { return firestore_1.doSetup; } });
10
+ var functions_1 = require("./functions");
11
+ Object.defineProperty(exports, "functions", { enumerable: true, get: function () { return functions_1.doSetup; } });
12
+ var hosting_1 = require("./hosting");
13
+ Object.defineProperty(exports, "hosting", { enumerable: true, get: function () { return hosting_1.doSetup; } });
14
+ var storage_1 = require("./storage");
15
+ Object.defineProperty(exports, "storage", { enumerable: true, get: function () { return storage_1.doSetup; } });
16
+ var emulators_1 = require("./emulators");
17
+ Object.defineProperty(exports, "emulators", { enumerable: true, get: function () { return emulators_1.doSetup; } });
18
+ var project_1 = require("./project");
19
+ Object.defineProperty(exports, "project", { enumerable: true, get: function () { return project_1.doSetup; } });
20
+ var remoteconfig_1 = require("./remoteconfig");
21
+ Object.defineProperty(exports, "remoteconfig", { enumerable: true, get: function () { return remoteconfig_1.doSetup; } });
22
+ var github_1 = require("./hosting/github");
23
+ Object.defineProperty(exports, "hostingGithub", { enumerable: true, get: function () { return github_1.initGitHub; } });
package/lib/init/index.js CHANGED
@@ -1,22 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.init = void 0;
4
- const _ = require("lodash");
4
+ const lodash_1 = require("lodash");
5
5
  const clc = require("cli-color");
6
+ const error_1 = require("../error");
6
7
  const logger_1 = require("../logger");
7
- const _features = require("./features");
8
- const utils = require("../utils");
9
- const features = _features;
8
+ const features = require("./features");
9
+ const featureFns = new Map([
10
+ ["account", features.account],
11
+ ["database", features.database],
12
+ ["firestore", features.firestore],
13
+ ["functions", features.functions],
14
+ ["hosting", features.hosting],
15
+ ["storage", features.storage],
16
+ ["emulators", features.emulators],
17
+ ["project", features.project],
18
+ ["remoteconfig", features.remoteconfig],
19
+ ["hosting:github", features.hostingGithub],
20
+ ]);
10
21
  async function init(setup, config, options) {
11
- const nextFeature = setup.features ? setup.features.shift() : undefined;
22
+ var _a;
23
+ const nextFeature = (_a = setup.features) === null || _a === void 0 ? void 0 : _a.shift();
12
24
  if (nextFeature) {
13
- if (!features[nextFeature]) {
14
- return utils.reject(clc.bold(nextFeature) +
15
- " is not a valid feature. Must be one of " +
16
- _.without(_.keys(features), "project").join(", "));
25
+ if (!featureFns.has(nextFeature)) {
26
+ const availableFeatures = Object.keys(features)
27
+ .filter((f) => f !== "project")
28
+ .join(", ");
29
+ throw new error_1.FirebaseError(`${clc.bold(nextFeature)} is not a valid feature. Must be one of ${availableFeatures}`);
17
30
  }
18
- logger_1.logger.info(clc.bold("\n" + clc.white("=== ") + _.capitalize(nextFeature) + " Setup"));
19
- await Promise.resolve(features[nextFeature](setup, config, options));
31
+ logger_1.logger.info(clc.bold(`\n${clc.white("===")} ${(0, lodash_1.capitalize)(nextFeature)} Setup`));
32
+ const fn = featureFns.get(nextFeature);
33
+ if (!fn) {
34
+ throw new error_1.FirebaseError(`We've lost the function to init ${nextFeature}`, { exit: 2 });
35
+ }
36
+ await fn(setup, config, options);
20
37
  return init(setup, config, options);
21
38
  }
22
39
  }
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
- var { FirebaseError } = require("./error");
3
- module.exports = function (options) {
4
- if (options.config) {
5
- return Promise.resolve();
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requireConfig = void 0;
4
+ const error_1 = require("./error");
5
+ async function requireConfig(options) {
6
+ await Promise.resolve();
7
+ if (!options.config) {
8
+ throw options.configError
9
+ ? options.configError
10
+ : new error_1.FirebaseError("Not in a Firebase project directory (could not locate firebase.json)");
6
11
  }
7
- return Promise.reject(options.configError ||
8
- new FirebaseError("Not in a Firebase project directory (could not locate firebase.json)", {
9
- exit: 1,
10
- }));
11
- };
12
+ }
13
+ exports.requireConfig = requireConfig;
@@ -7,6 +7,7 @@ const emulatorServer_1 = require("../emulator/emulatorServer");
7
7
  const functionsEmulatorUtils_1 = require("../emulator/functionsEmulatorUtils");
8
8
  const projectUtils_1 = require("../projectUtils");
9
9
  const auth_1 = require("../auth");
10
+ const projectConfig = require("../functions/projectConfig");
10
11
  const utils = require("../utils");
11
12
  class FunctionsServer {
12
13
  constructor() {
@@ -20,11 +21,10 @@ class FunctionsServer {
20
21
  }
21
22
  async start(options, partialArgs) {
22
23
  const projectId = (0, projectUtils_1.needProjectId)(options);
23
- utils.assertDefined(options.config.src.functions);
24
- utils.assertDefined(options.config.src.functions.source, "Error: 'functions.source' is not defined");
25
- const functionsDir = path.join(options.config.projectDir, options.config.src.functions.source);
24
+ const config = projectConfig.normalizeAndValidate(options.config.src.functions)[0];
25
+ const functionsDir = path.join(options.config.projectDir, config.source);
26
26
  const account = (0, auth_1.getProjectDefaultAccount)(options.config.projectDir);
27
- const nodeMajorVersion = (0, functionsEmulatorUtils_1.parseRuntimeVersion)(options.config.get("functions.runtime"));
27
+ const nodeMajorVersion = (0, functionsEmulatorUtils_1.parseRuntimeVersion)(config.runtime);
28
28
  this.backend = {
29
29
  functionsDir,
30
30
  nodeMajorVersion,
@@ -40,7 +40,7 @@ class FunctionsServer {
40
40
  utils.assertIsNumber(options.port);
41
41
  const targets = options.targets;
42
42
  const port = options.port;
43
- const hostingRunning = targets && targets.indexOf("hosting") >= 0;
43
+ const hostingRunning = targets && targets.includes("hosting");
44
44
  if (hostingRunning) {
45
45
  args.port = port + 1;
46
46
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "firebase-tools",
3
- "version": "10.3.0",
3
+ "version": "10.4.1",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "firebase-tools",
9
- "version": "10.3.0",
9
+ "version": "10.4.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@google-cloud/pubsub": "^2.18.4",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-tools",
3
- "version": "10.3.0",
3
+ "version": "10.4.1",
4
4
  "description": "Command-Line Interface for Firebase",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -326,54 +326,111 @@
326
326
  "type": "object"
327
327
  },
328
328
  "functions": {
329
- "additionalProperties": false,
330
- "properties": {
331
- "ignore": {
332
- "items": {
333
- "type": "string"
334
- },
335
- "type": "array"
336
- },
337
- "postdeploy": {
338
- "anyOf": [
339
- {
329
+ "anyOf": [
330
+ {
331
+ "additionalProperties": false,
332
+ "properties": {
333
+ "ignore": {
340
334
  "items": {
341
335
  "type": "string"
342
336
  },
343
337
  "type": "array"
344
338
  },
345
- {
339
+ "postdeploy": {
340
+ "anyOf": [
341
+ {
342
+ "items": {
343
+ "type": "string"
344
+ },
345
+ "type": "array"
346
+ },
347
+ {
348
+ "type": "string"
349
+ }
350
+ ]
351
+ },
352
+ "predeploy": {
353
+ "anyOf": [
354
+ {
355
+ "items": {
356
+ "type": "string"
357
+ },
358
+ "type": "array"
359
+ },
360
+ {
361
+ "type": "string"
362
+ }
363
+ ]
364
+ },
365
+ "runtime": {
366
+ "enum": [
367
+ "nodejs10",
368
+ "nodejs12",
369
+ "nodejs14",
370
+ "nodejs16"
371
+ ],
372
+ "type": "string"
373
+ },
374
+ "source": {
346
375
  "type": "string"
347
376
  }
348
- ]
377
+ },
378
+ "type": "object"
349
379
  },
350
- "predeploy": {
351
- "anyOf": [
352
- {
353
- "items": {
380
+ {
381
+ "items": {
382
+ "additionalProperties": false,
383
+ "properties": {
384
+ "ignore": {
385
+ "items": {
386
+ "type": "string"
387
+ },
388
+ "type": "array"
389
+ },
390
+ "postdeploy": {
391
+ "anyOf": [
392
+ {
393
+ "items": {
394
+ "type": "string"
395
+ },
396
+ "type": "array"
397
+ },
398
+ {
399
+ "type": "string"
400
+ }
401
+ ]
402
+ },
403
+ "predeploy": {
404
+ "anyOf": [
405
+ {
406
+ "items": {
407
+ "type": "string"
408
+ },
409
+ "type": "array"
410
+ },
411
+ {
412
+ "type": "string"
413
+ }
414
+ ]
415
+ },
416
+ "runtime": {
417
+ "enum": [
418
+ "nodejs10",
419
+ "nodejs12",
420
+ "nodejs14",
421
+ "nodejs16"
422
+ ],
354
423
  "type": "string"
355
424
  },
356
- "type": "array"
425
+ "source": {
426
+ "type": "string"
427
+ }
357
428
  },
358
- {
359
- "type": "string"
360
- }
361
- ]
362
- },
363
- "runtime": {
364
- "enum": [
365
- "nodejs10",
366
- "nodejs12",
367
- "nodejs14",
368
- "nodejs16"
369
- ],
370
- "type": "string"
371
- },
372
- "source": {
373
- "type": "string"
429
+ "type": "object"
430
+ },
431
+ "type": "array"
374
432
  }
375
- },
376
- "type": "object"
433
+ ]
377
434
  },
378
435
  "hosting": {
379
436
  "anyOf": [
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var fs = require("fs");
3
- var path = require("path");
4
- var tar = require("tar");
5
- var tmp = require("tmp");
6
- var { listFiles } = require("./listFiles");
7
- var { FirebaseError } = require("./error");
8
- var fsutils = require("./fsutils");
9
- module.exports = function (options) {
10
- var hostingConfig = options.config.get("hosting");
11
- var publicDir = options.config.path(hostingConfig.public);
12
- var indexPath = path.join(publicDir, "index.html");
13
- var tmpFile = tmp.fileSync({
14
- prefix: "firebase-upload-",
15
- postfix: ".tar.gz",
16
- });
17
- var manifest = listFiles(publicDir, hostingConfig.ignore);
18
- return tar
19
- .c({
20
- gzip: true,
21
- file: tmpFile.name,
22
- cwd: publicDir,
23
- prefix: "public",
24
- follow: true,
25
- noDirRecurse: true,
26
- portable: true,
27
- }, manifest.slice(0))
28
- .then(function () {
29
- var stats = fs.statSync(tmpFile.name);
30
- return {
31
- file: tmpFile.name,
32
- stream: fs.createReadStream(tmpFile.name),
33
- manifest: manifest,
34
- foundIndex: fsutils.fileExistsSync(indexPath),
35
- size: stats.size,
36
- };
37
- })
38
- .catch(function (err) {
39
- return Promise.reject(new FirebaseError("There was an issue preparing Hosting files for upload.", {
40
- original: err,
41
- exit: 2,
42
- }));
43
- });
44
- };