firebase-tools 12.7.0 → 12.8.0
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/commands/frameworks-stacks-create.js +14 -0
- package/lib/commands/frameworks-stacks-delete.js +38 -0
- package/lib/commands/frameworks-stacks-get.js +29 -0
- package/lib/commands/frameworks-stacks-list.js +24 -0
- package/lib/commands/index.js +8 -0
- package/lib/functions/env.js +1 -0
- package/lib/gcp/cloudfunctionsv2.js +2 -1
- package/lib/gcp/frameworks.js +17 -6
- package/lib/hosting/api.js +1 -1
- package/lib/init/features/frameworks/index.js +16 -12
- package/lib/init/features/frameworks/repo.js +9 -5
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const command_1 = require("../command");
|
|
5
|
+
const projectUtils_1 = require("../projectUtils");
|
|
6
|
+
const requireInteractive_1 = require("../requireInteractive");
|
|
7
|
+
const frameworks_1 = require("../init/features/frameworks");
|
|
8
|
+
exports.command = new command_1.Command("stacks:create")
|
|
9
|
+
.description("Create a stack in a Firebase project")
|
|
10
|
+
.before(requireInteractive_1.default)
|
|
11
|
+
.action(async (options) => {
|
|
12
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
13
|
+
await (0, frameworks_1.doSetup)(options, projectId);
|
|
14
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const command_1 = require("../command");
|
|
5
|
+
const projectUtils_1 = require("../projectUtils");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
const gcp = require("../gcp/frameworks");
|
|
8
|
+
const prompt_1 = require("../prompt");
|
|
9
|
+
const utils = require("../utils");
|
|
10
|
+
exports.command = new command_1.Command("stacks:delete")
|
|
11
|
+
.description("Delete a stack from a Firebase project")
|
|
12
|
+
.option("-l, --location <location>", "App Backend location", "us-central1")
|
|
13
|
+
.option("-s, --stackId <stackId>", "Stack Id", "")
|
|
14
|
+
.withForce()
|
|
15
|
+
.action(async (options) => {
|
|
16
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
17
|
+
const location = options.location;
|
|
18
|
+
const stackId = options.stackId;
|
|
19
|
+
if (!stackId) {
|
|
20
|
+
throw new error_1.FirebaseError("Stack id can't be empty.");
|
|
21
|
+
}
|
|
22
|
+
const confirmDeletion = await (0, prompt_1.promptOnce)({
|
|
23
|
+
type: "confirm",
|
|
24
|
+
name: "force",
|
|
25
|
+
default: false,
|
|
26
|
+
message: "You are about to delete the Stack with id: " + stackId + "\n Are you sure?",
|
|
27
|
+
}, options);
|
|
28
|
+
if (!confirmDeletion) {
|
|
29
|
+
throw new error_1.FirebaseError("Deletion aborted.");
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
await gcp.deleteStack(projectId, location, stackId);
|
|
33
|
+
utils.logSuccess(`Successfully deleted the stack: ${stackId}`);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
throw new error_1.FirebaseError(`Failed to delete stack: ${stackId}. Please check the parameters you have provided.`, { original: err });
|
|
37
|
+
}
|
|
38
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const command_1 = require("../command");
|
|
5
|
+
const projectUtils_1 = require("../projectUtils");
|
|
6
|
+
const gcp = require("../gcp/frameworks");
|
|
7
|
+
const error_1 = require("../error");
|
|
8
|
+
const logger_1 = require("../logger");
|
|
9
|
+
exports.command = new command_1.Command("stacks:get")
|
|
10
|
+
.description("Get stack details of a Firebase project")
|
|
11
|
+
.option("-l, --location <location>", "App Backend location", "us-central1")
|
|
12
|
+
.option("--s, --stackId <stackId>", "Stack Id", "")
|
|
13
|
+
.action(async (options) => {
|
|
14
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
15
|
+
const location = options.location;
|
|
16
|
+
const stackId = options.stackId;
|
|
17
|
+
if (!stackId) {
|
|
18
|
+
throw new error_1.FirebaseError("Stack id can't be empty.");
|
|
19
|
+
}
|
|
20
|
+
let stack;
|
|
21
|
+
try {
|
|
22
|
+
stack = await gcp.getStack(projectId, location, stackId);
|
|
23
|
+
logger_1.logger.info(stack);
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
throw new error_1.FirebaseError(`Failed to get stack: ${stackId}. Please check the parameters you have provided.`, { original: err });
|
|
27
|
+
}
|
|
28
|
+
return stack;
|
|
29
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const command_1 = require("../command");
|
|
5
|
+
const projectUtils_1 = require("../projectUtils");
|
|
6
|
+
const gcp = require("../gcp/frameworks");
|
|
7
|
+
const error_1 = require("../error");
|
|
8
|
+
const logger_1 = require("../logger");
|
|
9
|
+
exports.command = new command_1.Command("stacks:list")
|
|
10
|
+
.description("List stacks of a Firebase project.")
|
|
11
|
+
.option("-l, --location <location>", "App Backend location", "us-central1")
|
|
12
|
+
.action(async (options) => {
|
|
13
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
14
|
+
const location = options.location;
|
|
15
|
+
let stacks;
|
|
16
|
+
try {
|
|
17
|
+
stacks = await gcp.listStack(projectId, location);
|
|
18
|
+
logger_1.logger.info(stacks);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
throw new error_1.FirebaseError(`Unable to list stacks present in project: ${projectId}. Please check the parameters you have provided.`, { original: err });
|
|
22
|
+
}
|
|
23
|
+
return stacks;
|
|
24
|
+
});
|
package/lib/commands/index.js
CHANGED
|
@@ -145,6 +145,14 @@ function load(client) {
|
|
|
145
145
|
client.internaltesting.functions = {};
|
|
146
146
|
client.internaltesting.functions.discover = loadCommand("internaltesting-functions-discover");
|
|
147
147
|
}
|
|
148
|
+
if (experiments.isEnabled("internalframeworks")) {
|
|
149
|
+
client.frameworks = {};
|
|
150
|
+
client.frameworks.stacks = {};
|
|
151
|
+
client.frameworks.stacks.list = loadCommand("frameworks-stacks-list");
|
|
152
|
+
client.frameworks.stacks.create = loadCommand("frameworks-stacks-create");
|
|
153
|
+
client.frameworks.stacks.create = loadCommand("frameworks-stacks-get");
|
|
154
|
+
client.frameworks.stacks.create = loadCommand("frameworks-stacks-delete");
|
|
155
|
+
}
|
|
148
156
|
client.login = loadCommand("login");
|
|
149
157
|
client.login.add = loadCommand("login-add");
|
|
150
158
|
client.login.ci = loadCommand("login-ci");
|
package/lib/functions/env.js
CHANGED
|
@@ -304,7 +304,8 @@ function endpointFromFunction(gcfFunction) {
|
|
|
304
304
|
else if (gcfFunction.eventTrigger) {
|
|
305
305
|
const eventFilters = {};
|
|
306
306
|
const eventFilterPathPatterns = {};
|
|
307
|
-
if (gcfFunction.eventTrigger.pubsubTopic
|
|
307
|
+
if (gcfFunction.eventTrigger.pubsubTopic &&
|
|
308
|
+
gcfFunction.eventTrigger.eventType === v2_1.PUBSUB_PUBLISH_EVENT) {
|
|
308
309
|
eventFilters.topic = gcfFunction.eventTrigger.pubsubTopic;
|
|
309
310
|
}
|
|
310
311
|
else {
|
package/lib/gcp/frameworks.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createBuild = exports.getStack = exports.createStack = exports.API_VERSION = void 0;
|
|
3
|
+
exports.createBuild = exports.deleteStack = exports.listStack = exports.getStack = exports.createStack = exports.API_VERSION = void 0;
|
|
4
4
|
const apiv2_1 = require("../apiv2");
|
|
5
5
|
const api_1 = require("../api");
|
|
6
6
|
exports.API_VERSION = "v1alpha";
|
|
@@ -9,21 +9,32 @@ const client = new apiv2_1.Client({
|
|
|
9
9
|
auth: true,
|
|
10
10
|
apiVersion: exports.API_VERSION,
|
|
11
11
|
});
|
|
12
|
-
async function createStack(projectId, location,
|
|
13
|
-
const
|
|
14
|
-
const res = await client.post(`projects/${projectId}/locations/${location}/stacks`, stackInput, { queryParams: { stackId } });
|
|
12
|
+
async function createStack(projectId, location, stackReqBoby, backendId) {
|
|
13
|
+
const res = await client.post(`projects/${projectId}/locations/${location}/backends`, stackReqBoby, { queryParams: { backendId } });
|
|
15
14
|
return res.body;
|
|
16
15
|
}
|
|
17
16
|
exports.createStack = createStack;
|
|
18
17
|
async function getStack(projectId, location, stackId) {
|
|
19
|
-
const name = `projects/${projectId}/locations/${location}/
|
|
18
|
+
const name = `projects/${projectId}/locations/${location}/backends/${stackId}`;
|
|
20
19
|
const res = await client.get(name);
|
|
21
20
|
return res.body;
|
|
22
21
|
}
|
|
23
22
|
exports.getStack = getStack;
|
|
23
|
+
async function listStack(projectId, location) {
|
|
24
|
+
const name = `projects/${projectId}/locations/${location}/backends`;
|
|
25
|
+
const res = await client.get(name);
|
|
26
|
+
return res.body;
|
|
27
|
+
}
|
|
28
|
+
exports.listStack = listStack;
|
|
29
|
+
async function deleteStack(projectId, location, stackId) {
|
|
30
|
+
const name = `projects/${projectId}/locations/${location}/backends/${stackId}`;
|
|
31
|
+
const res = await client.delete(name);
|
|
32
|
+
return res.body;
|
|
33
|
+
}
|
|
34
|
+
exports.deleteStack = deleteStack;
|
|
24
35
|
async function createBuild(projectId, location, stackId, buildInput) {
|
|
25
36
|
const buildId = buildInput.name;
|
|
26
|
-
const res = await client.post(`projects/${projectId}/locations/${location}/
|
|
37
|
+
const res = await client.post(`projects/${projectId}/locations/${location}/backends/${stackId}/builds`, buildInput, { queryParams: { buildId } });
|
|
27
38
|
return res.body;
|
|
28
39
|
}
|
|
29
40
|
exports.createBuild = createBuild;
|
package/lib/hosting/api.js
CHANGED
|
@@ -217,7 +217,7 @@ async function getCleanDomains(project, site) {
|
|
|
217
217
|
acc[current] = true;
|
|
218
218
|
return acc;
|
|
219
219
|
}, {});
|
|
220
|
-
const siteMatch = new RegExp(
|
|
220
|
+
const siteMatch = new RegExp(`^${site}--`, "i");
|
|
221
221
|
const firebaseAppMatch = new RegExp(/firebaseapp.com$/);
|
|
222
222
|
const domains = await (0, auth_1.getAuthDomains)(project);
|
|
223
223
|
const authDomains = [];
|
|
@@ -18,9 +18,7 @@ const frameworksPollerOptions = {
|
|
|
18
18
|
masterTimeout: 25 * 60 * 1000,
|
|
19
19
|
maxBackoff: 10000,
|
|
20
20
|
};
|
|
21
|
-
async function doSetup(setup) {
|
|
22
|
-
var _a, _b;
|
|
23
|
-
const projectId = (_b = (_a = setup === null || setup === void 0 ? void 0 : setup.rcfile) === null || _a === void 0 ? void 0 : _a.projects) === null || _b === void 0 ? void 0 : _b.default;
|
|
21
|
+
async function doSetup(setup, projectId) {
|
|
24
22
|
setup.frameworks = {};
|
|
25
23
|
utils.logBullet("First we need a few details to create your service.");
|
|
26
24
|
await (0, prompt_1.promptOnce)({
|
|
@@ -46,12 +44,18 @@ async function doSetup(setup) {
|
|
|
46
44
|
message: "How do you want to deploy",
|
|
47
45
|
choices: constants_1.ALLOWED_DEPLOY_METHODS,
|
|
48
46
|
}, setup.frameworks);
|
|
49
|
-
await getOrCreateStack(projectId, setup);
|
|
47
|
+
const stack = await getOrCreateStack(projectId, setup);
|
|
48
|
+
if (stack) {
|
|
49
|
+
utils.logSuccess(`Successfully created a stack: ${stack.name}`);
|
|
50
|
+
}
|
|
50
51
|
}
|
|
51
52
|
exports.doSetup = doSetup;
|
|
52
|
-
function toStack(cloudBuildConnRepo
|
|
53
|
+
function toStack(cloudBuildConnRepo) {
|
|
53
54
|
return {
|
|
54
|
-
|
|
55
|
+
codebase: {
|
|
56
|
+
repository: `${cloudBuildConnRepo.name}`,
|
|
57
|
+
rootDirectory: "/",
|
|
58
|
+
},
|
|
55
59
|
labels: {},
|
|
56
60
|
};
|
|
57
61
|
}
|
|
@@ -65,9 +69,9 @@ async function getOrCreateStack(projectId, setup) {
|
|
|
65
69
|
if (err.status === 404) {
|
|
66
70
|
logger_1.logger.info("Creating new stack.");
|
|
67
71
|
if (deployMethod === "github") {
|
|
68
|
-
const cloudBuildConnRepo = await repo.linkGitHubRepository(projectId, location
|
|
69
|
-
const stackDetails = toStack(cloudBuildConnRepo
|
|
70
|
-
return await createStack(projectId, location, stackDetails);
|
|
72
|
+
const cloudBuildConnRepo = await repo.linkGitHubRepository(projectId, location);
|
|
73
|
+
const stackDetails = toStack(cloudBuildConnRepo);
|
|
74
|
+
return await createStack(projectId, location, stackDetails, setup.frameworks.serviceName);
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
77
|
else {
|
|
@@ -102,9 +106,9 @@ async function getExistingStack(projectId, setup, location) {
|
|
|
102
106
|
}
|
|
103
107
|
return stack;
|
|
104
108
|
}
|
|
105
|
-
async function createStack(projectId, location,
|
|
106
|
-
const op = await gcp.createStack(projectId, location,
|
|
107
|
-
const stack = await poller.pollOperation(Object.assign(Object.assign({}, frameworksPollerOptions), { pollerName: `create-${projectId}-${location}-${
|
|
109
|
+
async function createStack(projectId, location, stackReqBoby, stackId) {
|
|
110
|
+
const op = await gcp.createStack(projectId, location, stackReqBoby, stackId);
|
|
111
|
+
const stack = await poller.pollOperation(Object.assign(Object.assign({}, frameworksPollerOptions), { pollerName: `create-${projectId}-${location}-${stackId}`, operationResourceName: op.name }));
|
|
108
112
|
return stack;
|
|
109
113
|
}
|
|
110
114
|
exports.createStack = createStack;
|
|
@@ -21,11 +21,15 @@ function extractRepoSlugFromURI(remoteUri) {
|
|
|
21
21
|
}
|
|
22
22
|
return match[1];
|
|
23
23
|
}
|
|
24
|
-
function generateRepositoryId() {
|
|
25
|
-
|
|
24
|
+
function generateRepositoryId(remoteUri) {
|
|
25
|
+
var _a;
|
|
26
|
+
return (_a = extractRepoSlugFromURI(remoteUri)) === null || _a === void 0 ? void 0 : _a.replaceAll("/", "-");
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
function generateConnectionId(location) {
|
|
29
|
+
return `frameworks-${location}`;
|
|
30
|
+
}
|
|
31
|
+
async function linkGitHubRepository(projectId, location) {
|
|
32
|
+
const connectionId = generateConnectionId(location);
|
|
29
33
|
await getOrCreateConnection(projectId, location, connectionId);
|
|
30
34
|
let remoteUri = await promptRepositoryURI(projectId, location, connectionId);
|
|
31
35
|
while (remoteUri === "") {
|
|
@@ -92,7 +96,7 @@ async function getOrCreateConnection(projectId, location, connectionId) {
|
|
|
92
96
|
}
|
|
93
97
|
exports.getOrCreateConnection = getOrCreateConnection;
|
|
94
98
|
async function getOrCreateRepository(projectId, location, connectionId, remoteUri) {
|
|
95
|
-
const repositoryId = generateRepositoryId();
|
|
99
|
+
const repositoryId = generateRepositoryId(remoteUri);
|
|
96
100
|
if (!repositoryId) {
|
|
97
101
|
throw new error_1.FirebaseError(`Failed to generate repositoryId for URI "${remoteUri}".`);
|
|
98
102
|
}
|