firebase-tools 11.0.1 → 11.2.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.
- package/lib/accountExporter.js +11 -4
- package/lib/accountImporter.js +93 -95
- package/lib/api.js +77 -218
- package/lib/apiv2.js +5 -4
- package/lib/appdistribution/client.js +7 -9
- package/lib/auth.js +72 -52
- package/lib/bin/firebase.js +42 -47
- package/lib/checkValidTargetFilters.js +36 -25
- package/lib/commands/appdistribution-distribute.js +2 -1
- package/lib/commands/appdistribution-testers-add.js +2 -1
- package/lib/commands/appdistribution-testers-remove.js +2 -1
- package/lib/commands/apps-android-sha-create.js +2 -1
- package/lib/commands/apps-android-sha-delete.js +2 -1
- package/lib/commands/apps-android-sha-list.js +2 -1
- package/lib/commands/apps-create.js +2 -1
- package/lib/commands/apps-list.js +2 -1
- package/lib/commands/apps-sdkconfig.js +2 -1
- package/lib/commands/auth-export.js +2 -1
- package/lib/commands/auth-import.js +7 -10
- package/lib/commands/crashlytics-symbols-upload.js +2 -1
- package/lib/commands/database-get.js +4 -3
- package/lib/commands/database-instances-create.js +2 -1
- package/lib/commands/database-instances-list.js +3 -3
- package/lib/commands/database-profile.js +4 -4
- package/lib/commands/database-push.js +4 -4
- package/lib/commands/database-remove.js +3 -3
- package/lib/commands/database-rules-canary.js +2 -1
- package/lib/commands/database-rules-get.js +2 -1
- package/lib/commands/database-rules-list.js +2 -1
- package/lib/commands/database-rules-release.js +2 -1
- package/lib/commands/database-rules-stage.js +2 -1
- package/lib/commands/database-set.js +3 -3
- package/lib/commands/database-settings-get.js +2 -1
- package/lib/commands/database-settings-set.js +2 -1
- package/lib/commands/database-update.js +2 -1
- package/lib/commands/deploy.js +26 -25
- package/lib/commands/emulators-exec.js +2 -1
- package/lib/commands/emulators-export.js +2 -1
- package/lib/commands/emulators-start.js +2 -1
- package/lib/commands/experimental-functions-shell.js +10 -8
- package/lib/commands/ext-configure.js +2 -1
- package/lib/commands/ext-dev-deprecate.js +2 -1
- package/lib/commands/ext-dev-emulators-exec.js +3 -2
- package/lib/commands/ext-dev-emulators-start.js +3 -2
- package/lib/commands/ext-dev-extension-delete.js +2 -1
- package/lib/commands/ext-dev-init.js +2 -1
- package/lib/commands/ext-dev-list.js +8 -8
- package/lib/commands/ext-dev-publish.js +2 -1
- package/lib/commands/ext-dev-register.js +2 -1
- package/lib/commands/ext-dev-undeprecate.js +2 -1
- package/lib/commands/ext-dev-unpublish.js +2 -1
- package/lib/commands/ext-dev-usage.js +2 -1
- package/lib/commands/ext-export.js +2 -1
- package/lib/commands/ext-info.js +14 -14
- package/lib/commands/ext-install.js +2 -1
- package/lib/commands/ext-list.js +2 -1
- package/lib/commands/ext-sources-create.js +2 -1
- package/lib/commands/ext-uninstall.js +2 -1
- package/lib/commands/ext-update.js +2 -1
- package/lib/commands/ext.js +4 -4
- package/lib/commands/firestore-delete.js +2 -1
- package/lib/commands/firestore-indexes-list.js +2 -1
- package/lib/commands/functions-config-clone.js +4 -3
- package/lib/commands/functions-config-export.js +2 -1
- package/lib/commands/functions-config-get.js +2 -1
- package/lib/commands/functions-config-set.js +2 -1
- package/lib/commands/functions-config-unset.js +2 -1
- package/lib/commands/functions-delete.js +3 -8
- package/lib/commands/functions-deletegcfartifacts.js +2 -1
- package/lib/commands/functions-list.js +2 -1
- package/lib/commands/functions-log.js +2 -1
- package/lib/commands/functions-secrets-access.js +2 -1
- package/lib/commands/functions-secrets-destroy.js +2 -1
- package/lib/commands/functions-secrets-get.js +2 -1
- package/lib/commands/functions-secrets-prune.js +2 -1
- package/lib/commands/functions-secrets-set.js +2 -1
- package/lib/commands/functions-shell.js +12 -10
- package/lib/commands/help.js +2 -1
- package/lib/commands/hosting-channel-create.js +2 -1
- package/lib/commands/hosting-channel-delete.js +2 -1
- package/lib/commands/hosting-channel-deploy.js +2 -1
- package/lib/commands/hosting-channel-list.js +2 -1
- package/lib/commands/hosting-channel-open.js +2 -1
- package/lib/commands/hosting-clone.js +2 -1
- package/lib/commands/hosting-disable.js +2 -1
- package/lib/commands/hosting-sites-create.js +2 -1
- package/lib/commands/hosting-sites-delete.js +2 -1
- package/lib/commands/hosting-sites-get.js +2 -1
- package/lib/commands/hosting-sites-list.js +2 -1
- package/lib/commands/index.js +23 -13
- package/lib/commands/init.js +47 -43
- package/lib/commands/login-add.js +2 -1
- package/lib/commands/login-ci.js +2 -1
- package/lib/commands/login-list.js +2 -1
- package/lib/commands/login-use.js +2 -1
- package/lib/commands/login.js +2 -1
- package/lib/commands/logout.js +2 -1
- package/lib/commands/open.js +7 -7
- package/lib/commands/projects-addfirebase.js +2 -1
- package/lib/commands/projects-create.js +2 -1
- package/lib/commands/projects-list.js +2 -1
- package/lib/commands/remoteconfig-get.js +2 -1
- package/lib/commands/remoteconfig-rollback.js +2 -1
- package/lib/commands/remoteconfig-versions-list.js +2 -1
- package/lib/commands/serve.js +30 -30
- package/lib/commands/setup-emulators-database.js +2 -1
- package/lib/commands/setup-emulators-firestore.js +2 -1
- package/lib/commands/setup-emulators-pubsub.js +2 -1
- package/lib/commands/setup-emulators-storage.js +2 -1
- package/lib/commands/setup-emulators-ui.js +2 -1
- package/lib/commands/target-apply.js +2 -1
- package/lib/commands/target-clear.js +2 -1
- package/lib/commands/target-remove.js +2 -1
- package/lib/commands/target.js +2 -1
- package/lib/commands/use.js +54 -53
- package/lib/config.js +7 -6
- package/lib/deploy/database/deploy.js +3 -2
- package/lib/deploy/database/index.js +8 -5
- package/lib/deploy/database/prepare.js +22 -20
- package/lib/deploy/database/release.js +12 -9
- package/lib/deploy/extensions/secrets.js +3 -3
- package/lib/deploy/firestore/prepare.js +2 -2
- package/lib/deploy/functions/build.js +33 -20
- package/lib/deploy/functions/ensure.js +1 -11
- package/lib/deploy/functions/prepare.js +3 -13
- package/lib/deploy/functions/prepareFunctionsUpload.js +2 -3
- package/lib/deploy/functions/release/fabricator.js +0 -1
- package/lib/deploy/functions/release/index.js +1 -5
- package/lib/deploy/functions/runtimes/discovery/index.js +18 -3
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +188 -54
- package/lib/deploy/functions/runtimes/golang/index.js +2 -22
- package/lib/deploy/functions/runtimes/node/index.js +3 -7
- package/lib/deploy/functions/runtimes/node/parseTriggers.js +16 -4
- package/lib/deploy/functions/services/database.js +14 -0
- package/lib/deploy/functions/services/index.js +14 -0
- package/lib/deploy/index.js +3 -3
- package/lib/deploy/lifecycleHooks.js +27 -27
- package/lib/deploy/remoteconfig/prepare.js +2 -2
- package/lib/deploy/storage/prepare.js +1 -1
- package/lib/emulator/auth/apiSpec.js +14 -46
- package/lib/emulator/auth/index.js +1 -1
- package/lib/emulator/auth/operations.js +342 -93
- package/lib/emulator/auth/server.js +2 -2
- package/lib/emulator/auth/state.js +34 -32
- package/lib/emulator/commandUtils.js +1 -1
- package/lib/emulator/constants.js +1 -1
- package/lib/emulator/controller.js +7 -6
- package/lib/emulator/databaseEmulator.js +4 -4
- package/lib/emulator/download.js +1 -1
- package/lib/emulator/downloadableEmulators.js +5 -5
- package/lib/emulator/events/types.js +2 -3
- package/lib/emulator/firestoreEmulator.js +2 -2
- package/lib/emulator/functionsEmulator.js +31 -45
- package/lib/emulator/functionsEmulatorRuntime.js +12 -16
- package/lib/emulator/functionsEmulatorShared.js +7 -5
- package/lib/emulator/functionsRuntimeWorker.js +0 -6
- package/lib/emulator/hostingEmulator.js +1 -1
- package/lib/emulator/hub.js +1 -1
- package/lib/emulator/loggingEmulator.js +1 -1
- package/lib/emulator/pubsubEmulator.js +1 -1
- package/lib/emulator/storage/crc.js +4 -4
- package/lib/emulator/storage/index.js +1 -1
- package/lib/emulator/types.js +1 -1
- package/lib/errorOut.js +2 -2
- package/lib/extensions/askUserForConsent.js +1 -2
- package/lib/extensions/askUserForParam.js +15 -18
- package/lib/extensions/emulator/optionsHelper.js +4 -4
- package/lib/extensions/extensionsApi.js +1 -22
- package/lib/extensions/extensionsHelper.js +6 -6
- package/lib/extensions/listExtensions.js +9 -10
- package/lib/extensions/manifest.js +2 -2
- package/lib/extensions/resolveSource.js +11 -7
- package/lib/extensions/secretsUtils.js +3 -3
- package/lib/extensions/types.js +24 -0
- package/lib/extensions/updateHelper.js +1 -1
- package/lib/extensions/utils.js +1 -2
- package/lib/extensions/warnings.js +3 -3
- package/lib/firestore/encodeFirestoreValue.js +11 -8
- package/lib/fsAsync.js +3 -3
- package/lib/functions/events/v2.js +7 -1
- package/lib/functionsConfig.js +17 -14
- package/lib/functionsConfigClone.js +46 -46
- package/lib/gcp/cloudfunctions.js +2 -15
- package/lib/gcp/cloudfunctionsv2.js +17 -2
- package/lib/gcp/iam.js +1 -1
- package/lib/gcp/index.js +10 -10
- package/lib/gcp/rules.js +1 -1
- package/lib/gcp/runtimeconfig.js +45 -47
- package/lib/hosting/proxy.js +1 -1
- package/lib/index.js +29 -28
- package/lib/init/features/database.js +10 -2
- package/lib/init/features/functions/index.js +1 -1
- package/lib/init/features/functions/javascript.js +23 -20
- package/lib/init/features/functions/npm-dependencies.js +17 -14
- package/lib/init/features/functions/typescript.js +27 -24
- package/lib/init/features/hosting/github.js +6 -5
- package/lib/init/features/hosting/index.js +2 -2
- package/lib/loadCJSON.js +9 -6
- package/lib/localFunction.js +4 -4
- package/lib/logError.js +15 -12
- package/lib/parseBoltRules.js +15 -14
- package/lib/previews.js +1 -1
- package/lib/profileReport.js +504 -512
- package/lib/profiler.js +4 -4
- package/lib/prompt.js +1 -2
- package/lib/rc.js +1 -1
- package/lib/requireAuth.js +0 -1
- package/lib/responseToError.js +8 -5
- package/lib/rulesDeploy.js +2 -2
- package/lib/scopes.js +9 -9
- package/lib/serve/index.js +4 -5
- package/lib/utils.js +30 -6
- package/npm-shrinkwrap.json +537 -193
- package/package.json +17 -14
package/lib/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
const program = require("commander");
|
|
3
|
+
const clc = require("cli-color");
|
|
4
|
+
const leven = require("leven");
|
|
5
|
+
const logger_1 = require("./logger");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const pkg = require("../package.json");
|
|
8
8
|
program.version(pkg.version);
|
|
9
9
|
program.option("-P, --project <alias_or_project_id>", "the Firebase project to use for this command");
|
|
10
10
|
program.option("--account <email>", "the Google account to use for authorization");
|
|
@@ -14,33 +14,34 @@ program.option("--non-interactive", "error out of the command instead of waiting
|
|
|
14
14
|
program.option("-i, --interactive", "force prompts to be displayed");
|
|
15
15
|
program.option("--debug", "print verbose debug output and keep a debug log file");
|
|
16
16
|
program.option("-c, --config <path>", "path to the firebase.json file to use for configuration");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
const client = {
|
|
18
|
+
cli: program,
|
|
19
|
+
logger: require("./logger"),
|
|
20
|
+
errorOut: require("./errorOut").errorOut,
|
|
21
|
+
getCommand: (name) => {
|
|
22
|
+
for (let i = 0; i < client.cli.commands.length; i++) {
|
|
23
|
+
if (client.cli.commands[i]._name === name) {
|
|
24
|
+
return client.cli.commands[i];
|
|
25
|
+
}
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
return;
|
|
28
|
+
},
|
|
28
29
|
};
|
|
29
|
-
require("./commands")(client);
|
|
30
|
+
require("./commands").load(client);
|
|
30
31
|
function suggestCommands(cmd, cmdList) {
|
|
31
|
-
|
|
32
|
+
const suggestion = cmdList.find((c) => {
|
|
32
33
|
return leven(c, cmd) < c.length * 0.4;
|
|
33
34
|
});
|
|
34
35
|
if (suggestion) {
|
|
35
|
-
logger.error();
|
|
36
|
-
logger.error("Did you mean " + clc.bold(suggestion) + "?");
|
|
36
|
+
logger_1.logger.error();
|
|
37
|
+
logger_1.logger.error("Did you mean " + clc.bold(suggestion) + "?");
|
|
37
38
|
return suggestion;
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
+
const commandNames = program.commands.map((cmd) => {
|
|
41
42
|
return cmd._name;
|
|
42
43
|
});
|
|
43
|
-
|
|
44
|
+
const RENAMED_COMMANDS = {
|
|
44
45
|
"delete-site": "hosting:disable",
|
|
45
46
|
"disable:hosting": "hosting:disable",
|
|
46
47
|
"data:get": "database:get",
|
|
@@ -52,13 +53,13 @@ var RENAMED_COMMANDS = {
|
|
|
52
53
|
"deploy:database": "deploy --only database",
|
|
53
54
|
"prefs:token": "login:ci",
|
|
54
55
|
};
|
|
55
|
-
program.action(
|
|
56
|
-
setupLoggers();
|
|
57
|
-
|
|
58
|
-
logger.error(clc.bold.red("Error:"), clc.bold(cmd), "is not a Firebase command");
|
|
56
|
+
program.action((_, args) => {
|
|
57
|
+
(0, utils_1.setupLoggers)();
|
|
58
|
+
const cmd = args[0];
|
|
59
|
+
logger_1.logger.error(clc.bold.red("Error:"), clc.bold(cmd), "is not a Firebase command");
|
|
59
60
|
if (RENAMED_COMMANDS[cmd]) {
|
|
60
|
-
logger.error();
|
|
61
|
-
logger.error(clc.bold(cmd) + " has been renamed, please run", clc.bold("firebase " + RENAMED_COMMANDS[cmd]), "instead");
|
|
61
|
+
logger_1.logger.error();
|
|
62
|
+
logger_1.logger.error(clc.bold(cmd) + " has been renamed, please run", clc.bold("firebase " + RENAMED_COMMANDS[cmd]), "instead");
|
|
62
63
|
}
|
|
63
64
|
else {
|
|
64
65
|
if (!suggestCommands(cmd, commandNames)) {
|
|
@@ -18,8 +18,16 @@ async function getDBRules(instanceDetails) {
|
|
|
18
18
|
return DEFAULT_RULES;
|
|
19
19
|
}
|
|
20
20
|
const client = new apiv2_1.Client({ urlPrefix: instanceDetails.databaseUrl });
|
|
21
|
-
const response = await client.
|
|
22
|
-
|
|
21
|
+
const response = await client.request({
|
|
22
|
+
method: "GET",
|
|
23
|
+
path: "/.settings/rules.json",
|
|
24
|
+
responseType: "stream",
|
|
25
|
+
resolveOnHTTPError: true,
|
|
26
|
+
});
|
|
27
|
+
if (response.status !== 200) {
|
|
28
|
+
throw new error_1.FirebaseError(`Failed to fetch current rules. Code: ${response.status}`);
|
|
29
|
+
}
|
|
30
|
+
return await response.response.text();
|
|
23
31
|
}
|
|
24
32
|
function writeDBRules(rules, logMessagePrefix, filename, config) {
|
|
25
33
|
config.writeProjectFile(filename, rules);
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setup = void 0;
|
|
4
|
+
const _ = require("lodash");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const npm_dependencies_1 = require("./npm-dependencies");
|
|
8
|
+
const prompt_1 = require("../../../prompt");
|
|
9
|
+
const TEMPLATE_ROOT = path.resolve(__dirname, "../../../../templates/init/functions/javascript/");
|
|
10
|
+
const INDEX_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "index.js"), "utf8");
|
|
11
|
+
const PACKAGE_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "package.lint.json"), "utf8");
|
|
12
|
+
const PACKAGE_NO_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "package.nolint.json"), "utf8");
|
|
13
|
+
const ESLINT_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "_eslintrc"), "utf8");
|
|
14
|
+
const GITIGNORE_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "_gitignore"), "utf8");
|
|
15
|
+
function setup(setup, config) {
|
|
16
|
+
return (0, prompt_1.prompt)(setup.functions, [
|
|
15
17
|
{
|
|
16
18
|
name: "lint",
|
|
17
19
|
type: "confirm",
|
|
@@ -19,24 +21,25 @@ module.exports = function (setup, config) {
|
|
|
19
21
|
default: false,
|
|
20
22
|
},
|
|
21
23
|
])
|
|
22
|
-
.then(
|
|
24
|
+
.then(() => {
|
|
23
25
|
if (setup.functions.lint) {
|
|
24
26
|
_.set(setup, "config.functions.predeploy", ['npm --prefix "$RESOURCE_DIR" run lint']);
|
|
25
27
|
return config
|
|
26
28
|
.askWriteProjectFile("functions/package.json", PACKAGE_LINTING_TEMPLATE)
|
|
27
|
-
.then(
|
|
29
|
+
.then(() => {
|
|
28
30
|
config.askWriteProjectFile("functions/.eslintrc.js", ESLINT_TEMPLATE);
|
|
29
31
|
});
|
|
30
32
|
}
|
|
31
33
|
return config.askWriteProjectFile("functions/package.json", PACKAGE_NO_LINTING_TEMPLATE);
|
|
32
34
|
})
|
|
33
|
-
.then(
|
|
35
|
+
.then(() => {
|
|
34
36
|
return config.askWriteProjectFile("functions/index.js", INDEX_TEMPLATE);
|
|
35
37
|
})
|
|
36
|
-
.then(
|
|
38
|
+
.then(() => {
|
|
37
39
|
return config.askWriteProjectFile("functions/.gitignore", GITIGNORE_TEMPLATE);
|
|
38
40
|
})
|
|
39
|
-
.then(
|
|
40
|
-
return
|
|
41
|
+
.then(() => {
|
|
42
|
+
return (0, npm_dependencies_1.askInstallDependencies)(setup.functions, config);
|
|
41
43
|
});
|
|
42
|
-
}
|
|
44
|
+
}
|
|
45
|
+
exports.setup = setup;
|
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.askInstallDependencies = void 0;
|
|
4
|
+
const spawn = require("cross-spawn");
|
|
5
|
+
const logger_1 = require("../../../logger");
|
|
6
|
+
const prompt_1 = require("../../../prompt");
|
|
7
|
+
function askInstallDependencies(setup, config) {
|
|
8
|
+
return (0, prompt_1.prompt)(setup, [
|
|
7
9
|
{
|
|
8
10
|
name: "npm",
|
|
9
11
|
type: "confirm",
|
|
10
12
|
message: "Do you want to install dependencies with npm now?",
|
|
11
13
|
default: true,
|
|
12
14
|
},
|
|
13
|
-
]).then(
|
|
15
|
+
]).then(() => {
|
|
14
16
|
if (setup.npm) {
|
|
15
|
-
return new Promise(
|
|
16
|
-
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
const installer = spawn("npm", ["install"], {
|
|
17
19
|
cwd: config.projectDir + "/functions",
|
|
18
20
|
stdio: "inherit",
|
|
19
21
|
});
|
|
20
|
-
installer.on("error",
|
|
21
|
-
logger.debug(err.stack);
|
|
22
|
+
installer.on("error", (err) => {
|
|
23
|
+
logger_1.logger.debug(err.stack);
|
|
22
24
|
});
|
|
23
|
-
installer.on("close",
|
|
25
|
+
installer.on("close", (code) => {
|
|
24
26
|
if (code === 0) {
|
|
25
27
|
return resolve();
|
|
26
28
|
}
|
|
27
|
-
logger.info();
|
|
28
|
-
logger.error("NPM install failed, continuing with Firebase initialization...");
|
|
29
|
+
logger_1.logger.info();
|
|
30
|
+
logger_1.logger.error("NPM install failed, continuing with Firebase initialization...");
|
|
29
31
|
return resolve();
|
|
30
32
|
});
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
35
|
});
|
|
34
|
-
}
|
|
36
|
+
}
|
|
37
|
+
exports.askInstallDependencies = askInstallDependencies;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setup = void 0;
|
|
4
|
+
const _ = require("lodash");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const npm_dependencies_1 = require("./npm-dependencies");
|
|
8
|
+
const prompt_1 = require("../../../prompt");
|
|
9
|
+
const TEMPLATE_ROOT = path.resolve(__dirname, "../../../../templates/init/functions/typescript/");
|
|
10
|
+
const PACKAGE_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "package.lint.json"), "utf8");
|
|
11
|
+
const PACKAGE_NO_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "package.nolint.json"), "utf8");
|
|
12
|
+
const ESLINT_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "_eslintrc"), "utf8");
|
|
13
|
+
const TSCONFIG_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "tsconfig.json"), "utf8");
|
|
14
|
+
const TSCONFIG_DEV_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "tsconfig.dev.json"), "utf8");
|
|
15
|
+
const INDEX_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "index.ts"), "utf8");
|
|
16
|
+
const GITIGNORE_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "_gitignore"), "utf8");
|
|
17
|
+
function setup(setup, config) {
|
|
18
|
+
return (0, prompt_1.prompt)(setup.functions, [
|
|
17
19
|
{
|
|
18
20
|
name: "lint",
|
|
19
21
|
type: "confirm",
|
|
@@ -21,7 +23,7 @@ module.exports = function (setup, config) {
|
|
|
21
23
|
default: true,
|
|
22
24
|
},
|
|
23
25
|
])
|
|
24
|
-
.then(
|
|
26
|
+
.then(() => {
|
|
25
27
|
if (setup.functions.lint) {
|
|
26
28
|
_.set(setup, "config.functions.predeploy", [
|
|
27
29
|
'npm --prefix "$RESOURCE_DIR" run lint',
|
|
@@ -29,28 +31,29 @@ module.exports = function (setup, config) {
|
|
|
29
31
|
]);
|
|
30
32
|
return config
|
|
31
33
|
.askWriteProjectFile("functions/package.json", PACKAGE_LINTING_TEMPLATE)
|
|
32
|
-
.then(
|
|
34
|
+
.then(() => {
|
|
33
35
|
return config.askWriteProjectFile("functions/.eslintrc.js", ESLINT_TEMPLATE);
|
|
34
36
|
});
|
|
35
37
|
}
|
|
36
38
|
_.set(setup, "config.functions.predeploy", 'npm --prefix "$RESOURCE_DIR" run build');
|
|
37
39
|
return config.askWriteProjectFile("functions/package.json", PACKAGE_NO_LINTING_TEMPLATE);
|
|
38
40
|
})
|
|
39
|
-
.then(
|
|
41
|
+
.then(() => {
|
|
40
42
|
return config.askWriteProjectFile("functions/tsconfig.json", TSCONFIG_TEMPLATE);
|
|
41
43
|
})
|
|
42
|
-
.then(
|
|
44
|
+
.then(() => {
|
|
43
45
|
if (setup.functions.lint) {
|
|
44
46
|
return config.askWriteProjectFile("functions/tsconfig.dev.json", TSCONFIG_DEV_TEMPLATE);
|
|
45
47
|
}
|
|
46
48
|
})
|
|
47
|
-
.then(
|
|
49
|
+
.then(() => {
|
|
48
50
|
return config.askWriteProjectFile("functions/src/index.ts", INDEX_TEMPLATE);
|
|
49
51
|
})
|
|
50
|
-
.then(
|
|
52
|
+
.then(() => {
|
|
51
53
|
return config.askWriteProjectFile("functions/.gitignore", GITIGNORE_TEMPLATE);
|
|
52
54
|
})
|
|
53
|
-
.then(
|
|
54
|
-
return
|
|
55
|
+
.then(() => {
|
|
56
|
+
return (0, npm_dependencies_1.askInstallDependencies)(setup.functions, config);
|
|
55
57
|
});
|
|
56
|
-
}
|
|
58
|
+
}
|
|
59
|
+
exports.setup = setup;
|
|
@@ -7,7 +7,7 @@ const yaml = require("js-yaml");
|
|
|
7
7
|
const js_yaml_1 = require("js-yaml");
|
|
8
8
|
const ora = require("ora");
|
|
9
9
|
const path = require("path");
|
|
10
|
-
const
|
|
10
|
+
const libsodium = require("libsodium-wrappers");
|
|
11
11
|
const auth_1 = require("../../../auth");
|
|
12
12
|
const fsutils_1 = require("../../../fsutils");
|
|
13
13
|
const iam_1 = require("../../../gcp/iam");
|
|
@@ -27,7 +27,7 @@ const YML_MERGE_FILENAME = "firebase-hosting-merge.yml";
|
|
|
27
27
|
const CHECKOUT_GITHUB_ACTION_NAME = "actions/checkout@v2";
|
|
28
28
|
const HOSTING_GITHUB_ACTION_NAME = "FirebaseExtended/action-hosting-deploy@v0";
|
|
29
29
|
const githubApiClient = new apiv2_1.Client({ urlPrefix: api_1.githubApiOrigin, auth: false });
|
|
30
|
-
async function initGitHub(setup
|
|
30
|
+
async function initGitHub(setup) {
|
|
31
31
|
if (!setup.projectId) {
|
|
32
32
|
return (0, utils_1.reject)("Could not determine Project ID, can't set up GitHub workflow.", { exit: 1 });
|
|
33
33
|
}
|
|
@@ -60,7 +60,7 @@ async function initGitHub(setup, config, options) {
|
|
|
60
60
|
const spinnerSecrets = ora(`Uploading service account secrets to repository: ${repo}`);
|
|
61
61
|
spinnerSecrets.start();
|
|
62
62
|
const encryptedServiceAccountJSON = encryptServiceAccountJSON(serviceAccountJSON, key);
|
|
63
|
-
await uploadSecretToGitHub(repo, ghAccessToken, encryptedServiceAccountJSON, keyId, githubSecretName);
|
|
63
|
+
await uploadSecretToGitHub(repo, ghAccessToken, await encryptedServiceAccountJSON, keyId, githubSecretName);
|
|
64
64
|
spinnerSecrets.stop();
|
|
65
65
|
(0, utils_1.logSuccess)(`Uploaded service account JSON to GitHub as secret ${(0, cli_color_1.bold)(githubSecretName)}.`);
|
|
66
66
|
(0, utils_1.logBullet)(`You can manage your secrets at https://github.com/${repo}/settings/secrets.`);
|
|
@@ -374,9 +374,10 @@ async function createServiceAccountAndKey(options, repo, accountId) {
|
|
|
374
374
|
const serviceAccountJSON = buf.toString();
|
|
375
375
|
return serviceAccountJSON;
|
|
376
376
|
}
|
|
377
|
-
function encryptServiceAccountJSON(serviceAccountJSON, key) {
|
|
377
|
+
async function encryptServiceAccountJSON(serviceAccountJSON, key) {
|
|
378
378
|
const messageBytes = Buffer.from(serviceAccountJSON);
|
|
379
379
|
const keyBytes = Buffer.from(key, "base64");
|
|
380
|
-
|
|
380
|
+
await libsodium.ready;
|
|
381
|
+
const encryptedBytes = libsodium.crypto_box_seal(messageBytes, keyBytes);
|
|
381
382
|
return Buffer.from(encryptedBytes).toString("base64");
|
|
382
383
|
}
|
|
@@ -10,7 +10,7 @@ const logger_1 = require("../../../logger");
|
|
|
10
10
|
const INDEX_TEMPLATE = fs.readFileSync(__dirname + "/../../../../templates/init/hosting/index.html", "utf8");
|
|
11
11
|
const MISSING_TEMPLATE = fs.readFileSync(__dirname + "/../../../../templates/init/hosting/404.html", "utf8");
|
|
12
12
|
const DEFAULT_IGNORES = ["firebase.json", "**/.*", "**/node_modules/**"];
|
|
13
|
-
async function doSetup(setup, config
|
|
13
|
+
async function doSetup(setup, config) {
|
|
14
14
|
setup.hosting = {};
|
|
15
15
|
logger_1.logger.info();
|
|
16
16
|
logger_1.logger.info(`Your ${clc.bold("public")} directory is the folder (relative to your project directory) that`);
|
|
@@ -51,7 +51,7 @@ async function doSetup(setup, config, options) {
|
|
|
51
51
|
const response = await c.get("/firebasejs/releases.json");
|
|
52
52
|
await config.askWriteProjectFile(`${setup.hosting.public}/index.html`, INDEX_TEMPLATE.replace(/{{VERSION}}/g, response.body.current.version));
|
|
53
53
|
if (setup.hosting.github) {
|
|
54
|
-
return (0, github_1.initGitHub)(setup
|
|
54
|
+
return (0, github_1.initGitHub)(setup);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
exports.doSetup = doSetup;
|
package/lib/loadCJSON.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadCJSON = void 0;
|
|
4
|
+
const error_1 = require("./error");
|
|
5
|
+
const cjson = require("cjson");
|
|
6
|
+
function loadCJSON(path) {
|
|
5
7
|
try {
|
|
6
8
|
return cjson.load(path);
|
|
7
9
|
}
|
|
8
10
|
catch (e) {
|
|
9
11
|
if (e.code === "ENOENT") {
|
|
10
|
-
throw new FirebaseError(
|
|
12
|
+
throw new error_1.FirebaseError(`File ${path} does not exist`);
|
|
11
13
|
}
|
|
12
|
-
throw new FirebaseError(
|
|
14
|
+
throw new error_1.FirebaseError(`Parse Error in ${path}:\n\n${e.message}`);
|
|
13
15
|
}
|
|
14
|
-
}
|
|
16
|
+
}
|
|
17
|
+
exports.loadCJSON = loadCJSON;
|
package/lib/localFunction.js
CHANGED
|
@@ -38,13 +38,13 @@ LocalFunction.prototype._substituteParams = function (resource, params) {
|
|
|
38
38
|
return resource.replace(wildcardRegex, function (wildcard) {
|
|
39
39
|
var wildcardNoBraces = wildcard.slice(1, -1);
|
|
40
40
|
var sub = _.get(params, wildcardNoBraces);
|
|
41
|
-
return sub || wildcardNoBraces +
|
|
41
|
+
return sub || wildcardNoBraces + utils.randomInt(1, 9);
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
LocalFunction.prototype._constructCallableFunc = function (data, opts) {
|
|
45
45
|
opts = opts || {};
|
|
46
46
|
var headers = {};
|
|
47
|
-
if (
|
|
47
|
+
if (opts.instanceIdToken) {
|
|
48
48
|
headers["Firebase-Instance-ID-Token"] = opts.instanceIdToken;
|
|
49
49
|
}
|
|
50
50
|
return request.post({
|
|
@@ -134,7 +134,7 @@ LocalFunction.prototype._call = function (data, opts) {
|
|
|
134
134
|
}
|
|
135
135
|
else if (this.eventTrigger) {
|
|
136
136
|
if (this._isDatabaseFunc(this.eventTrigger)) {
|
|
137
|
-
operationType =
|
|
137
|
+
operationType = utils.last(this.eventTrigger.eventType.split("."));
|
|
138
138
|
switch (operationType) {
|
|
139
139
|
case "create":
|
|
140
140
|
dataPayload = {
|
|
@@ -159,7 +159,7 @@ LocalFunction.prototype._call = function (data, opts) {
|
|
|
159
159
|
this.controller.call(this.name, dataPayload, opts);
|
|
160
160
|
}
|
|
161
161
|
else if (this._isFirestoreFunc(this.eventTrigger)) {
|
|
162
|
-
operationType =
|
|
162
|
+
operationType = utils.last(this.eventTrigger.eventType.split("."));
|
|
163
163
|
switch (operationType) {
|
|
164
164
|
case "create":
|
|
165
165
|
dataPayload = {
|
package/lib/logError.js
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logError = void 0;
|
|
4
|
+
const logger_1 = require("./logger");
|
|
5
|
+
const clc = require("cli-color");
|
|
6
|
+
function logError(error) {
|
|
5
7
|
if (error.children && error.children.length) {
|
|
6
|
-
logger.error(clc.bold.red("Error:"), clc.underline(error.message) + ":");
|
|
7
|
-
error.children.forEach(
|
|
8
|
-
|
|
8
|
+
logger_1.logger.error(clc.bold.red("Error:"), clc.underline(error.message) + ":");
|
|
9
|
+
error.children.forEach((child) => {
|
|
10
|
+
let out = "- ";
|
|
9
11
|
if (child.name) {
|
|
10
12
|
out += clc.bold(child.name) + " ";
|
|
11
13
|
}
|
|
12
14
|
out += child.message;
|
|
13
|
-
logger.error(out);
|
|
15
|
+
logger_1.logger.error(out);
|
|
14
16
|
});
|
|
15
17
|
}
|
|
16
18
|
else {
|
|
17
19
|
if (error.original) {
|
|
18
|
-
logger.debug(error.original.stack);
|
|
20
|
+
logger_1.logger.debug(error.original.stack);
|
|
19
21
|
}
|
|
20
|
-
logger.error();
|
|
21
|
-
logger.error(clc.bold.red("Error:"), error.message);
|
|
22
|
+
logger_1.logger.error();
|
|
23
|
+
logger_1.logger.error(clc.bold.red("Error:"), error.message);
|
|
22
24
|
}
|
|
23
25
|
if (error.context) {
|
|
24
|
-
logger.debug("Error Context:", JSON.stringify(error.context, undefined, 2));
|
|
26
|
+
logger_1.logger.debug("Error Context:", JSON.stringify(error.context, undefined, 2));
|
|
25
27
|
}
|
|
26
|
-
}
|
|
28
|
+
}
|
|
29
|
+
exports.logError = logError;
|
package/lib/parseBoltRules.js
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseBoltRules = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const spawn = require("cross-spawn");
|
|
6
|
+
const clc = require("cli-color");
|
|
7
|
+
const _ = require("lodash");
|
|
8
|
+
const error_1 = require("./error");
|
|
9
|
+
function parseBoltRules(filename) {
|
|
10
|
+
const ruleSrc = fs.readFileSync(filename, "utf8");
|
|
11
|
+
const result = spawn.sync("npx", ["--no-install", "firebase-bolt"], {
|
|
10
12
|
input: ruleSrc,
|
|
11
13
|
timeout: 10000,
|
|
12
14
|
encoding: "utf-8",
|
|
13
15
|
});
|
|
14
16
|
if (result.error && _.get(result.error, "code") === "ENOENT") {
|
|
15
|
-
throw new FirebaseError("Bolt not installed, run " + clc.bold("npm install -g firebase-bolt")
|
|
16
|
-
exit: 1,
|
|
17
|
-
});
|
|
17
|
+
throw new error_1.FirebaseError("Bolt not installed, run " + clc.bold("npm install -g firebase-bolt"));
|
|
18
18
|
}
|
|
19
19
|
else if (result.error) {
|
|
20
|
-
throw new FirebaseError("Unexpected error parsing Bolt rules file", {
|
|
20
|
+
throw new error_1.FirebaseError("Unexpected error parsing Bolt rules file", {
|
|
21
21
|
exit: 2,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
else if (result.status != null && result.status > 0) {
|
|
25
|
-
throw new FirebaseError(result.stderr.toString(), { exit: 1 });
|
|
25
|
+
throw new error_1.FirebaseError(result.stderr.toString(), { exit: 1 });
|
|
26
26
|
}
|
|
27
27
|
return result.stdout;
|
|
28
|
-
}
|
|
28
|
+
}
|
|
29
|
+
exports.parseBoltRules = parseBoltRules;
|
package/lib/previews.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.previews = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
5
|
const configstore_1 = require("./configstore");
|
|
6
|
-
exports.previews = Object.assign({ rtdbrules: false, ext: false, extdev: false, rtdbmanagement: false, golang: false, deletegcfartifacts: false,
|
|
6
|
+
exports.previews = Object.assign({ rtdbrules: false, ext: false, extdev: false, rtdbmanagement: false, golang: false, deletegcfartifacts: false, emulatoruisnapshot: false, frameworkawareness: false, functionsparams: false }, configstore_1.configstore.get("previews"));
|
|
7
7
|
if (process.env.FIREBASE_CLI_PREVIEWS) {
|
|
8
8
|
process.env.FIREBASE_CLI_PREVIEWS.split(",").forEach((feature) => {
|
|
9
9
|
if ((0, lodash_1.has)(exports.previews, feature)) {
|