firebase-tools-with-isolate 13.11.2 → 13.16.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/api.js +4 -2
- package/lib/apphosting/githubConnections.js +125 -37
- package/lib/apphosting/index.js +3 -8
- package/lib/auth.js +14 -15
- package/lib/bin/firebase.js +7 -5
- package/lib/commands/dataconnect-sdk-generate.js +5 -9
- package/lib/commands/dataconnect-services-list.js +1 -1
- package/lib/commands/deploy.js +10 -2
- package/lib/commands/ext-configure.js +1 -6
- package/lib/commands/ext-dev-init.js +27 -30
- package/lib/commands/ext-dev-upload.js +4 -6
- package/lib/commands/ext-info.js +3 -5
- package/lib/commands/ext-install.js +0 -5
- package/lib/commands/ext-uninstall.js +0 -5
- package/lib/commands/ext-update.js +0 -5
- package/lib/commands/firestore-backups-schedules-create.js +11 -14
- package/lib/commands/firestore-backups-schedules-list.js +1 -1
- package/lib/commands/firestore-backups-schedules-update.js +4 -3
- package/lib/commands/firestore-databases-create.js +24 -7
- package/lib/commands/firestore-databases-restore.js +4 -4
- package/lib/commands/firestore-databases-update.js +5 -6
- package/lib/commands/functions-secrets-set.js +9 -6
- package/lib/commands/help.js +2 -0
- package/lib/commands/hosting-channel-create.js +1 -1
- package/lib/commands/hosting-channel-delete.js +1 -1
- package/lib/commands/hosting-channel-deploy.js +1 -1
- package/lib/commands/hosting-clone.js +1 -2
- package/lib/commands/index.js +9 -11
- package/lib/commands/init.js +16 -12
- package/lib/commands/login.js +1 -2
- package/lib/commands/setup-emulators-dataconnect.js +22 -3
- package/lib/config.js +5 -0
- package/lib/crashlytics/buildToolsJarHelper.js +1 -1
- package/lib/dataconnect/client.js +57 -9
- package/lib/dataconnect/fileUtils.js +71 -7
- package/lib/dataconnect/filters.js +12 -1
- package/lib/dataconnect/load.js +9 -7
- package/lib/dataconnect/provisionCloudSql.js +5 -1
- package/lib/dataconnect/schemaMigration.js +21 -0
- package/lib/dataconnect/types.js +8 -1
- package/lib/deploy/dataconnect/prepare.js +16 -2
- package/lib/deploy/extensions/planner.js +52 -1
- package/lib/deploy/extensions/prepare.js +98 -23
- package/lib/deploy/extensions/release.js +6 -0
- package/lib/deploy/functions/build.js +15 -6
- package/lib/deploy/functions/deploy.js +12 -12
- package/lib/deploy/functions/params.js +5 -3
- package/lib/deploy/functions/prepare.js +8 -1
- package/lib/deploy/functions/release/index.js +4 -0
- package/lib/deploy/functions/runtimes/discovery/parsing.js +1 -1
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +46 -0
- package/lib/emulator/adminSdkConfig.test.js +16 -0
- package/lib/emulator/constants.js +8 -0
- package/lib/emulator/controller.js +14 -10
- package/lib/emulator/dataconnectEmulator.js +122 -18
- package/lib/emulator/downloadableEmulators.js +24 -25
- package/lib/emulator/env.js +3 -0
- package/lib/emulator/eventarcEmulator.js +68 -18
- package/lib/emulator/functionsEmulator.js +119 -1
- package/lib/emulator/functionsEmulatorShared.js +20 -0
- package/lib/emulator/hub.js +1 -1
- package/lib/emulator/portUtils.js +10 -0
- package/lib/emulator/pubsubEmulator.js +1 -1
- package/lib/emulator/registry.js +2 -1
- package/lib/emulator/storage/apis/shared.js +2 -1
- package/lib/emulator/storage/persistence.js +5 -13
- package/lib/emulator/storage/rfc.js +9 -0
- package/lib/emulator/storage/rules/config.js +4 -2
- package/lib/emulator/taskQueue.js +348 -0
- package/lib/emulator/tasksEmulator.js +237 -0
- package/lib/emulator/types.js +3 -0
- package/lib/experiments.js +8 -3
- package/lib/extensions/askUserForEventsConfig.js +18 -8
- package/lib/extensions/askUserForParam.js +3 -2
- package/lib/extensions/change-log.js +2 -4
- package/lib/extensions/displayExtensionInfo.js +5 -10
- package/lib/extensions/extensionsApi.js +1 -1
- package/lib/extensions/extensionsHelper.js +30 -10
- package/lib/extensions/localHelper.js +1 -1
- package/lib/extensions/provisioningHelper.js +1 -1
- package/lib/extensions/refs.js +26 -11
- package/lib/extensions/runtimes/common.js +75 -0
- package/lib/extensions/types.js +56 -1
- package/lib/extensions/updateHelper.js +1 -2
- package/lib/extensions/warnings.js +2 -7
- package/lib/firestore/api-sort.test.js +74 -0
- package/lib/firestore/api.js +8 -7
- package/lib/firestore/backupUtils.test.js +18 -0
- package/lib/firestore/pretty-print.js +21 -1
- package/lib/firestore/pretty-print.test.js +61 -0
- package/lib/firestore/util.test.js +42 -0
- package/lib/frameworks/angular/utils.js +13 -5
- package/lib/frameworks/compose/discover/mockFileSystem.js +36 -0
- package/lib/frameworks/constants.js +1 -1
- package/lib/frameworks/index.js +2 -6
- package/lib/frameworks/next/constants.js +1 -1
- package/lib/frameworks/next/index.js +35 -15
- package/lib/frameworks/next/utils.js +53 -9
- package/lib/frameworks/nuxt/index.js +3 -3
- package/lib/functions/events/v2.js +2 -1
- package/lib/gcp/cloudsql/cloudsqladmin.js +6 -1
- package/lib/gcp/devConnect.js +36 -1
- package/lib/hosting/implicitInit.js +2 -2
- package/lib/init/features/dataconnect/index.js +104 -32
- package/lib/init/features/dataconnect/sdk.js +147 -0
- package/lib/init/features/firestore/indexes.js +2 -2
- package/lib/init/features/firestore/rules.js +2 -2
- package/lib/init/features/functions/javascript.js +6 -8
- package/lib/init/features/functions/python.js +4 -6
- package/lib/init/features/functions/typescript.js +8 -10
- package/lib/init/features/hosting/github.js +43 -21
- package/lib/init/features/hosting/index.js +3 -3
- package/lib/init/features/index.js +3 -1
- package/lib/init/features/storage.js +2 -2
- package/lib/init/index.js +1 -0
- package/lib/listFiles.js +1 -1
- package/lib/management/apps.js +2 -2
- package/lib/prompt.js +22 -1
- package/lib/rc.js +1 -0
- package/lib/requireAuth.js +8 -3
- package/lib/rulesDeploy.js +14 -12
- package/lib/templates.js +23 -0
- package/lib/utils.js +2 -2
- package/package.json +25 -24
- package/schema/connector-yaml.json +36 -4
- package/schema/dataconnect-yaml.json +4 -0
- package/schema/firebase-config.json +12 -8
- package/templates/_gitignore +3 -0
- package/templates/init/dataconnect/connector.yaml +15 -2
- package/templates/init/dataconnect/dataconnect.yaml +5 -4
- package/templates/init/dataconnect/mutations.gql +45 -25
- package/templates/init/dataconnect/queries.gql +69 -36
- package/templates/init/dataconnect/schema.gql +38 -21
- package/lib/extensions/billingMigrationHelper.js +0 -61
|
@@ -22,6 +22,7 @@ const constants_1 = require("../constants");
|
|
|
22
22
|
const constants_2 = require("./constants");
|
|
23
23
|
const api_1 = require("../../hosting/api");
|
|
24
24
|
const logger_1 = require("../../logger");
|
|
25
|
+
const env_1 = require("../../functions/env");
|
|
25
26
|
const DEFAULT_BUILD_SCRIPT = ["next build"];
|
|
26
27
|
const PUBLIC_DIR = "public";
|
|
27
28
|
exports.supportedRange = "12 - 14.0";
|
|
@@ -29,7 +30,6 @@ exports.name = "Next.js";
|
|
|
29
30
|
exports.support = "preview";
|
|
30
31
|
exports.type = 2;
|
|
31
32
|
exports.docsUrl = "https://firebase.google.com/docs/hosting/frameworks/nextjs";
|
|
32
|
-
const BUNDLE_NEXT_CONFIG_TIMEOUT = 60000;
|
|
33
33
|
const DEFAULT_NUMBER_OF_REASONS_TO_LIST = 5;
|
|
34
34
|
function getReactVersion(cwd) {
|
|
35
35
|
return (0, utils_1.findDependency)("react-dom", { cwd, omitDev: false })?.version;
|
|
@@ -49,7 +49,14 @@ async function build(dir, target, context) {
|
|
|
49
49
|
if (reactVersion && (0, semver_1.gte)(reactVersion, "18.0.0")) {
|
|
50
50
|
process.env.__NEXT_REACT_ROOT = "true";
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
let env = { ...process.env };
|
|
53
|
+
if (context?.projectId) {
|
|
54
|
+
const projectEnvPath = (0, path_1.join)(dir, `.env.${context.projectId}`);
|
|
55
|
+
if (await (0, fs_extra_1.pathExists)(projectEnvPath)) {
|
|
56
|
+
const projectEnvVars = (0, env_1.parseStrict)((await (0, fs_extra_1.readFile)(projectEnvPath)).toString());
|
|
57
|
+
env = { ...projectEnvVars, ...env };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
53
60
|
if (context?.projectId && context?.site) {
|
|
54
61
|
const deploymentDomain = await (0, api_1.getDeploymentDomain)(context.projectId, context.site, context.hostingChannel);
|
|
55
62
|
if (deploymentDomain) {
|
|
@@ -337,6 +344,19 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir, target, context)
|
|
|
337
344
|
const configFile = await (0, utils_2.whichNextConfigFile)(sourceDir);
|
|
338
345
|
if (configFile) {
|
|
339
346
|
try {
|
|
347
|
+
let esbuildPath = (0, utils_2.findEsbuildPath)();
|
|
348
|
+
if (!esbuildPath || !(0, fs_extra_1.pathExistsSync)(esbuildPath)) {
|
|
349
|
+
console.warn("esbuild not found, installing...");
|
|
350
|
+
(0, utils_2.installEsbuild)(constants_2.ESBUILD_VERSION);
|
|
351
|
+
esbuildPath = (0, utils_2.findEsbuildPath)();
|
|
352
|
+
if (!esbuildPath || !(0, fs_extra_1.pathExistsSync)(esbuildPath)) {
|
|
353
|
+
throw new error_1.FirebaseError("Failed to locate esbuild after installation.");
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
const esbuild = require(esbuildPath);
|
|
357
|
+
if (!esbuild) {
|
|
358
|
+
throw new error_1.FirebaseError(`Failed to load esbuild from path: ${esbuildPath}`);
|
|
359
|
+
}
|
|
340
360
|
const productionDeps = await new Promise((resolve) => {
|
|
341
361
|
const dependencies = [];
|
|
342
362
|
const npmLs = (0, cross_spawn_1.spawn)("npm", ["ls", "--omit=dev", "--all", "--json=true"], {
|
|
@@ -358,21 +378,21 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir, target, context)
|
|
|
358
378
|
resolve([...new Set(dependencies)]);
|
|
359
379
|
});
|
|
360
380
|
});
|
|
361
|
-
const esbuildArgs =
|
|
362
|
-
.
|
|
363
|
-
|
|
381
|
+
const esbuildArgs = {
|
|
382
|
+
entryPoints: [(0, path_1.join)(sourceDir, configFile)],
|
|
383
|
+
outfile: (0, path_1.join)(destDir, configFile),
|
|
384
|
+
bundle: true,
|
|
385
|
+
platform: "node",
|
|
386
|
+
target: `node${constants_1.NODE_VERSION}`,
|
|
387
|
+
logLevel: "error",
|
|
388
|
+
external: productionDeps,
|
|
389
|
+
};
|
|
364
390
|
if (configFile === "next.config.mjs") {
|
|
365
|
-
esbuildArgs.
|
|
366
|
-
}
|
|
367
|
-
else {
|
|
368
|
-
esbuildArgs.push(`--outfile=${(0, path_1.join)(destDir, configFile)}`);
|
|
391
|
+
esbuildArgs.format = "esm";
|
|
369
392
|
}
|
|
370
|
-
const bundle =
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
});
|
|
374
|
-
if (bundle.status !== 0) {
|
|
375
|
-
throw new error_1.FirebaseError(bundle.stderr.toString());
|
|
393
|
+
const bundle = await esbuild.build(esbuildArgs);
|
|
394
|
+
if (bundle.errors && bundle.errors.length > 0) {
|
|
395
|
+
throw new error_1.FirebaseError(bundle.errors.toString());
|
|
376
396
|
}
|
|
377
397
|
}
|
|
378
398
|
catch (e) {
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.whichNextConfigFile = exports.getProductionDistDirFiles = exports.getRoutesWithServerAction = exports.hasStaticAppNotFoundComponent = exports.getNextVersion = exports.getBuildId = exports.getHeadersFromMetaFiles = exports.getNonStaticServerComponents = exports.getNonStaticRoutes = exports.getMiddlewareMatcherRegexes = exports.allDependencyNames = exports.isUsingAppDirectory = exports.isUsingNextImageInAppDirectory = exports.isUsingImageOptimization = exports.isUsingMiddleware = exports.hasUnoptimizedImage = exports.usesNextImage = exports.usesAppDirRouter = exports.getNextjsRewritesToUse = exports.isHeaderSupportedByHosting = exports.isRedirectSupportedByHosting = exports.isRewriteSupportedByHosting = exports.cleanI18n = exports.cleanCustomRouteI18n = exports.cleanEscapedChars = exports.I18N_SOURCE = void 0;
|
|
3
|
+
exports.installEsbuild = exports.getGlobalEsbuildVersion = exports.findEsbuildPath = exports.whichNextConfigFile = exports.getProductionDistDirFiles = exports.getRoutesWithServerAction = exports.hasStaticAppNotFoundComponent = exports.getNextVersion = exports.getBuildId = exports.getHeadersFromMetaFiles = exports.getNonStaticServerComponents = exports.getNonStaticRoutes = exports.getMiddlewareMatcherRegexes = exports.allDependencyNames = exports.isUsingAppDirectory = exports.isUsingNextImageInAppDirectory = exports.isUsingImageOptimization = exports.isUsingMiddleware = exports.hasUnoptimizedImage = exports.usesNextImage = exports.usesAppDirRouter = exports.getNextjsRewritesToUse = exports.isHeaderSupportedByHosting = exports.isRedirectSupportedByHosting = exports.isRewriteSupportedByHosting = exports.cleanI18n = exports.cleanCustomRouteI18n = exports.cleanEscapedChars = exports.I18N_SOURCE = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const fs_extra_1 = require("fs-extra");
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const promises_1 = require("fs/promises");
|
|
8
8
|
const glob_1 = require("glob");
|
|
9
|
-
const glob = require("glob");
|
|
10
9
|
const semver_1 = require("semver");
|
|
11
10
|
const utils_1 = require("../utils");
|
|
12
11
|
const constants_1 = require("./constants");
|
|
13
12
|
const fsutils_1 = require("../../fsutils");
|
|
14
13
|
const utils_2 = require("../../utils");
|
|
14
|
+
const child_process_1 = require("child_process");
|
|
15
|
+
const error_1 = require("../../error");
|
|
15
16
|
exports.I18N_SOURCE = /\/:nextInternalLocale(\([^\)]+\))?/;
|
|
16
17
|
function cleanEscapedChars(path) {
|
|
17
18
|
return path.replace(/\\([(){}:+?*])/g, (a, b) => b);
|
|
@@ -229,17 +230,12 @@ function getRoutesWithServerAction(serverReferenceManifest, appPathRoutesManifes
|
|
|
229
230
|
}
|
|
230
231
|
exports.getRoutesWithServerAction = getRoutesWithServerAction;
|
|
231
232
|
async function getProductionDistDirFiles(sourceDir, distDir) {
|
|
232
|
-
|
|
233
|
+
return (0, glob_1.glob)("**", {
|
|
233
234
|
ignore: [(0, path_1.join)("cache", "webpack", "*-development", "**"), (0, path_1.join)("cache", "eslint", "**")],
|
|
234
235
|
cwd: (0, path_1.join)(sourceDir, distDir),
|
|
235
236
|
nodir: true,
|
|
236
237
|
absolute: false,
|
|
237
|
-
}
|
|
238
|
-
if (err)
|
|
239
|
-
reject(err);
|
|
240
|
-
resolve(matches);
|
|
241
|
-
}));
|
|
242
|
-
return productionDistDirFiles;
|
|
238
|
+
});
|
|
243
239
|
}
|
|
244
240
|
exports.getProductionDistDirFiles = getProductionDistDirFiles;
|
|
245
241
|
async function whichNextConfigFile(dir) {
|
|
@@ -250,3 +246,51 @@ async function whichNextConfigFile(dir) {
|
|
|
250
246
|
return null;
|
|
251
247
|
}
|
|
252
248
|
exports.whichNextConfigFile = whichNextConfigFile;
|
|
249
|
+
function findEsbuildPath() {
|
|
250
|
+
try {
|
|
251
|
+
const esbuildBinPath = (0, child_process_1.execSync)("npx which esbuild", { encoding: "utf8" })?.trim();
|
|
252
|
+
if (!esbuildBinPath) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
const globalVersion = getGlobalEsbuildVersion(esbuildBinPath);
|
|
256
|
+
if (globalVersion && !(0, semver_1.satisfies)(globalVersion, constants_1.ESBUILD_VERSION)) {
|
|
257
|
+
console.warn(`Warning: Global esbuild version (${globalVersion}) does not match the required version (${constants_1.ESBUILD_VERSION}).`);
|
|
258
|
+
}
|
|
259
|
+
return (0, path_1.resolve)((0, path_1.dirname)(esbuildBinPath), "../esbuild");
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
console.error(`Failed to find esbuild with npx which: ${error}`);
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
exports.findEsbuildPath = findEsbuildPath;
|
|
267
|
+
function getGlobalEsbuildVersion(binPath) {
|
|
268
|
+
try {
|
|
269
|
+
const versionOutput = (0, child_process_1.execSync)(`${binPath} --version`, { encoding: "utf8" })?.trim();
|
|
270
|
+
if (!versionOutput) {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
const versionMatch = versionOutput.match(/(\d+\.\d+\.\d+)/);
|
|
274
|
+
return versionMatch ? versionMatch[0] : null;
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
console.error(`Failed to get global esbuild version: ${error}`);
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
exports.getGlobalEsbuildVersion = getGlobalEsbuildVersion;
|
|
282
|
+
function installEsbuild(version) {
|
|
283
|
+
const installCommand = `npm install esbuild@${version} --no-save`;
|
|
284
|
+
try {
|
|
285
|
+
(0, child_process_1.execSync)(installCommand, { stdio: "inherit" });
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
if (error instanceof error_1.FirebaseError) {
|
|
289
|
+
throw error;
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
throw new error_1.FirebaseError(`Failed to install esbuild: ${error}`, { original: error });
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
exports.installEsbuild = installEsbuild;
|
|
@@ -87,9 +87,9 @@ async function getDevModeHandle(cwd) {
|
|
|
87
87
|
return (0, utils_1.simpleProxy)(await host);
|
|
88
88
|
}
|
|
89
89
|
exports.getDevModeHandle = getDevModeHandle;
|
|
90
|
-
async function getConfig(
|
|
91
|
-
const { loadNuxtConfig } = await (0, utils_1.relativeRequire)(
|
|
92
|
-
return await loadNuxtConfig(
|
|
90
|
+
async function getConfig(cwd) {
|
|
91
|
+
const { loadNuxtConfig } = await (0, utils_1.relativeRequire)(cwd, "@nuxt/kit");
|
|
92
|
+
return await loadNuxtConfig({ cwd });
|
|
93
93
|
}
|
|
94
94
|
exports.getConfig = getConfig;
|
|
95
95
|
function init(setup, config) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FIRESTORE_EVENT_WITH_AUTH_CONTEXT_REGEX = exports.FIRESTORE_EVENT_REGEX = exports.FIRESTORE_EVENTS = exports.TEST_LAB_EVENT = exports.REMOTE_CONFIG_EVENT = exports.DATABASE_EVENTS = exports.FIREBASE_ALERTS_PUBLISH_EVENT = exports.STORAGE_EVENTS = exports.PUBSUB_PUBLISH_EVENT = void 0;
|
|
3
|
+
exports.FIRESTORE_EVENT_WITH_AUTH_CONTEXT_REGEX = exports.FIRESTORE_EVENT_REGEX = exports.FIREALERTS_EVENT = exports.FIRESTORE_EVENTS = exports.TEST_LAB_EVENT = exports.REMOTE_CONFIG_EVENT = exports.DATABASE_EVENTS = exports.FIREBASE_ALERTS_PUBLISH_EVENT = exports.STORAGE_EVENTS = exports.PUBSUB_PUBLISH_EVENT = void 0;
|
|
4
4
|
exports.PUBSUB_PUBLISH_EVENT = "google.cloud.pubsub.topic.v1.messagePublished";
|
|
5
5
|
exports.STORAGE_EVENTS = [
|
|
6
6
|
"google.cloud.storage.object.v1.finalized",
|
|
@@ -27,5 +27,6 @@ exports.FIRESTORE_EVENTS = [
|
|
|
27
27
|
"google.cloud.firestore.document.v1.updated.withAuthContext",
|
|
28
28
|
"google.cloud.firestore.document.v1.deleted.withAuthContext",
|
|
29
29
|
];
|
|
30
|
+
exports.FIREALERTS_EVENT = "google.firebase.firebasealerts.alerts.v1.published";
|
|
30
31
|
exports.FIRESTORE_EVENT_REGEX = /^google\.cloud\.firestore\.document\.v1\.[^\.]*$/;
|
|
31
32
|
exports.FIRESTORE_EVENT_WITH_AUTH_CONTEXT_REGEX = /^google\.cloud\.firestore\.document\.v1\..*\.withAuthContext$/;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.listUsers = exports.deleteUser = exports.getUser = exports.createUser = exports.createDatabase = exports.getDatabase = exports.listDatabases = exports.updateInstanceForDataConnect = exports.createInstance = exports.instanceConsoleLink = exports.getInstance = exports.listInstances = void 0;
|
|
3
|
+
exports.listUsers = exports.deleteUser = exports.getUser = exports.createUser = exports.deleteDatabase = exports.createDatabase = exports.getDatabase = exports.listDatabases = exports.updateInstanceForDataConnect = exports.createInstance = exports.instanceConsoleLink = exports.getInstance = exports.listInstances = void 0;
|
|
4
4
|
const apiv2_1 = require("../../apiv2");
|
|
5
5
|
const api_1 = require("../../api");
|
|
6
6
|
const operationPoller = require("../../operation-poller");
|
|
@@ -124,6 +124,11 @@ async function createDatabase(projectId, instanceId, databaseId) {
|
|
|
124
124
|
return pollRes;
|
|
125
125
|
}
|
|
126
126
|
exports.createDatabase = createDatabase;
|
|
127
|
+
async function deleteDatabase(projectId, instanceId, databaseId) {
|
|
128
|
+
const res = await client.delete(`projects/${projectId}/instances/${instanceId}/databases/${databaseId}`);
|
|
129
|
+
return res.body;
|
|
130
|
+
}
|
|
131
|
+
exports.deleteDatabase = deleteDatabase;
|
|
127
132
|
async function createUser(projectId, instanceId, type, username, password) {
|
|
128
133
|
const maxRetries = 3;
|
|
129
134
|
let retries = 0;
|
package/lib/gcp/devConnect.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateP4SA = exports.serviceAgentEmail = exports.getGitRepositoryLink = exports.createGitRepositoryLink = exports.listAllLinkableGitRepositories = exports.listAllConnections = exports.getConnection = exports.deleteConnection = exports.createConnection = exports.client = void 0;
|
|
3
|
+
exports.generateP4SA = exports.serviceAgentEmail = exports.sortConnectionsByCreateTime = exports.getGitRepositoryLink = exports.createGitRepositoryLink = exports.fetchGitHubInstallations = exports.listAllBranches = exports.listAllLinkableGitRepositories = exports.listAllConnections = exports.getConnection = exports.deleteConnection = exports.createConnection = exports.client = void 0;
|
|
4
4
|
const apiv2_1 = require("../apiv2");
|
|
5
5
|
const api_1 = require("../api");
|
|
6
6
|
const serviceusage_1 = require("./serviceusage");
|
|
@@ -75,6 +75,35 @@ async function listAllLinkableGitRepositories(projectId, location, connectionId)
|
|
|
75
75
|
return repos;
|
|
76
76
|
}
|
|
77
77
|
exports.listAllLinkableGitRepositories = listAllLinkableGitRepositories;
|
|
78
|
+
async function listAllBranches(repoLinkName) {
|
|
79
|
+
const branches = new Set();
|
|
80
|
+
const getNextPage = async (pageToken = "") => {
|
|
81
|
+
const res = await exports.client.get(`${repoLinkName}:fetchGitRefs`, {
|
|
82
|
+
queryParams: {
|
|
83
|
+
refType: "BRANCH",
|
|
84
|
+
pageSize: PAGE_SIZE_MAX,
|
|
85
|
+
pageToken,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
if (Array.isArray(res.body.refNames)) {
|
|
89
|
+
res.body.refNames.forEach((branch) => {
|
|
90
|
+
branches.add(branch);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (res.body.nextPageToken) {
|
|
94
|
+
await getNextPage(res.body.nextPageToken);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
await getNextPage();
|
|
98
|
+
return branches;
|
|
99
|
+
}
|
|
100
|
+
exports.listAllBranches = listAllBranches;
|
|
101
|
+
async function fetchGitHubInstallations(projectId, location, connectionId) {
|
|
102
|
+
const name = `projects/${projectId}/locations/${LOCATION_OVERRIDE ?? location}/connections/${connectionId}:fetchGitHubInstallations`;
|
|
103
|
+
const res = await exports.client.get(name);
|
|
104
|
+
return res.body.installations;
|
|
105
|
+
}
|
|
106
|
+
exports.fetchGitHubInstallations = fetchGitHubInstallations;
|
|
78
107
|
async function createGitRepositoryLink(projectId, location, connectionId, gitRepositoryLinkId, cloneUri) {
|
|
79
108
|
const res = await exports.client.post(`projects/${projectId}/locations/${LOCATION_OVERRIDE ?? location}/connections/${connectionId}/gitRepositoryLinks`, { cloneUri }, { queryParams: { gitRepositoryLinkId } });
|
|
80
109
|
return res.body;
|
|
@@ -86,6 +115,12 @@ async function getGitRepositoryLink(projectId, location, connectionId, gitReposi
|
|
|
86
115
|
return res.body;
|
|
87
116
|
}
|
|
88
117
|
exports.getGitRepositoryLink = getGitRepositoryLink;
|
|
118
|
+
function sortConnectionsByCreateTime(connections) {
|
|
119
|
+
return connections.sort((a, b) => {
|
|
120
|
+
return Date.parse(a.createTime) - Date.parse(b.createTime);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
exports.sortConnectionsByCreateTime = sortConnectionsByCreateTime;
|
|
89
124
|
function serviceAgentEmail(projectNumber) {
|
|
90
125
|
return `service-${projectNumber}@${(0, api_1.developerConnectP4SADomain)()}`;
|
|
91
126
|
}
|
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.implicitInit = void 0;
|
|
4
4
|
const _ = require("lodash");
|
|
5
5
|
const clc = require("colorette");
|
|
6
|
-
const fs = require("fs");
|
|
7
6
|
const fetchWebSetup_1 = require("../fetchWebSetup");
|
|
8
7
|
const utils = require("../utils");
|
|
9
8
|
const logger_1 = require("../logger");
|
|
10
9
|
const registry_1 = require("../emulator/registry");
|
|
11
10
|
const types_1 = require("../emulator/types");
|
|
12
|
-
const
|
|
11
|
+
const templates_1 = require("../templates");
|
|
12
|
+
const INIT_TEMPLATE = (0, templates_1.readTemplateSync)("hosting/init.js");
|
|
13
13
|
async function implicitInit(options) {
|
|
14
14
|
let config;
|
|
15
15
|
try {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.doSetup = void 0;
|
|
3
|
+
exports.actuate = exports.doSetup = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
+
const clc = require("colorette");
|
|
5
6
|
const prompt_1 = require("../../../prompt");
|
|
6
|
-
const fs_1 = require("fs");
|
|
7
7
|
const provisionCloudSql_1 = require("../../../dataconnect/provisionCloudSql");
|
|
8
8
|
const freeTrial_1 = require("../../../dataconnect/freeTrial");
|
|
9
9
|
const cloudsql = require("../../../gcp/cloudsql/cloudsqladmin");
|
|
@@ -12,13 +12,35 @@ const client_1 = require("../../../dataconnect/client");
|
|
|
12
12
|
const emulators_1 = require("../emulators");
|
|
13
13
|
const names_1 = require("../../../dataconnect/names");
|
|
14
14
|
const logger_1 = require("../../../logger");
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
15
|
+
const templates_1 = require("../../../templates");
|
|
16
|
+
const utils_1 = require("../../../utils");
|
|
17
|
+
const DATACONNECT_YAML_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/dataconnect.yaml");
|
|
18
|
+
const CONNECTOR_YAML_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/connector.yaml");
|
|
19
|
+
const SCHEMA_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/schema.gql");
|
|
20
|
+
const QUERIES_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/queries.gql");
|
|
21
|
+
const MUTATIONS_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/mutations.gql");
|
|
22
|
+
const defaultConnector = {
|
|
23
|
+
id: "default",
|
|
24
|
+
path: "./connector",
|
|
25
|
+
files: [
|
|
26
|
+
{
|
|
27
|
+
path: "queries.gql",
|
|
28
|
+
content: QUERIES_TEMPLATE,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
path: "mutations.gql",
|
|
32
|
+
content: MUTATIONS_TEMPLATE,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
21
36
|
async function doSetup(setup, config) {
|
|
37
|
+
const info = await askQuestions(setup, config);
|
|
38
|
+
await actuate(setup, config, info);
|
|
39
|
+
logger_1.logger.info("");
|
|
40
|
+
(0, utils_1.logSuccess)(`If you'd like to generate an SDK for your new connector, run ${clc.bold("firebase init dataconnect:sdk")}`);
|
|
41
|
+
}
|
|
42
|
+
exports.doSetup = doSetup;
|
|
43
|
+
async function askQuestions(setup, config) {
|
|
22
44
|
let info = {
|
|
23
45
|
serviceId: "",
|
|
24
46
|
locationId: "",
|
|
@@ -26,7 +48,9 @@ async function doSetup(setup, config) {
|
|
|
26
48
|
isNewInstance: false,
|
|
27
49
|
cloudSqlDatabase: "",
|
|
28
50
|
isNewDatabase: false,
|
|
29
|
-
|
|
51
|
+
connectors: [defaultConnector],
|
|
52
|
+
schemaGql: [],
|
|
53
|
+
shouldProvisionCSQL: false,
|
|
30
54
|
};
|
|
31
55
|
info = await promptForService(setup, info);
|
|
32
56
|
if (info.cloudSqlInstanceId === "") {
|
|
@@ -44,24 +68,17 @@ async function doSetup(setup, config) {
|
|
|
44
68
|
default: defaultConnectionString,
|
|
45
69
|
});
|
|
46
70
|
setup.rcfile.dataconnectEmulatorConfig = { postgres: { localConnectionString } };
|
|
47
|
-
|
|
48
|
-
const subbedDataconnectYaml = subValues(DATACONNECT_YAML_TEMPLATE, info);
|
|
49
|
-
const subbedConnectorYaml = subValues(CONNECTOR_YAML_TEMPLATE, info);
|
|
50
|
-
if (!config.has("dataconnect")) {
|
|
51
|
-
config.set("dataconnect.source", dir);
|
|
52
|
-
config.set("dataconnect.location", info.locationId);
|
|
53
|
-
}
|
|
54
|
-
await config.askWriteProjectFile((0, path_1.join)(dir, "dataconnect.yaml"), subbedDataconnectYaml);
|
|
55
|
-
await config.askWriteProjectFile((0, path_1.join)(dir, "schema", "schema.gql"), SCHEMA_TEMPLATE);
|
|
56
|
-
await config.askWriteProjectFile((0, path_1.join)(dir, info.connectorId, "connector.yaml"), subbedConnectorYaml);
|
|
57
|
-
await config.askWriteProjectFile((0, path_1.join)(dir, info.connectorId, "queries.gql"), QUERIES_TEMPLATE);
|
|
58
|
-
await config.askWriteProjectFile((0, path_1.join)(dir, info.connectorId, "mutations.gql"), MUTATIONS_TEMPLATE);
|
|
59
|
-
if (setup.projectId &&
|
|
71
|
+
info.shouldProvisionCSQL = !!(setup.projectId &&
|
|
60
72
|
(info.isNewInstance || info.isNewDatabase) &&
|
|
61
73
|
(await (0, prompt_1.confirm)({
|
|
62
74
|
message: "Would you like to provision your CloudSQL instance and database now? This will take a few minutes.",
|
|
63
75
|
default: true,
|
|
64
|
-
})))
|
|
76
|
+
})));
|
|
77
|
+
return info;
|
|
78
|
+
}
|
|
79
|
+
async function actuate(setup, config, info) {
|
|
80
|
+
await writeFiles(config, info);
|
|
81
|
+
if (setup.projectId && info.shouldProvisionCSQL) {
|
|
65
82
|
await (0, provisionCloudSql_1.provisionCloudSql)({
|
|
66
83
|
projectId: setup.projectId,
|
|
67
84
|
locationId: info.locationId,
|
|
@@ -72,17 +89,58 @@ async function doSetup(setup, config) {
|
|
|
72
89
|
});
|
|
73
90
|
}
|
|
74
91
|
}
|
|
75
|
-
exports.
|
|
76
|
-
function
|
|
92
|
+
exports.actuate = actuate;
|
|
93
|
+
async function writeFiles(config, info) {
|
|
94
|
+
const dir = config.get("dataconnect.source") || "dataconnect";
|
|
95
|
+
console.log(dir);
|
|
96
|
+
const subbedDataconnectYaml = subDataconnectYamlValues({
|
|
97
|
+
...info,
|
|
98
|
+
connectorDirs: info.connectors.map((c) => c.path),
|
|
99
|
+
});
|
|
100
|
+
config.set("dataconnect", { source: dir });
|
|
101
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, "dataconnect.yaml"), subbedDataconnectYaml);
|
|
102
|
+
if (info.schemaGql.length) {
|
|
103
|
+
(0, utils_1.logSuccess)("The service you chose already has GQL files deployed. We'll use those instead of the default templates.");
|
|
104
|
+
for (const f of info.schemaGql) {
|
|
105
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, "schema", f.path), f.content);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, "schema", "schema.gql"), SCHEMA_TEMPLATE);
|
|
110
|
+
}
|
|
111
|
+
for (const c of info.connectors) {
|
|
112
|
+
await writeConnectorFiles(config, c);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async function writeConnectorFiles(config, connectorInfo) {
|
|
116
|
+
const subbedConnectorYaml = subConnectorYamlValues({ connectorId: connectorInfo.id });
|
|
117
|
+
const dir = config.get("dataconnect.source") || "dataconnect";
|
|
118
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.path, "connector.yaml"), subbedConnectorYaml);
|
|
119
|
+
for (const f of connectorInfo.files) {
|
|
120
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.path, f.path), f.content);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function subDataconnectYamlValues(replacementValues) {
|
|
77
124
|
const replacements = {
|
|
78
125
|
serviceId: "__serviceId__",
|
|
79
126
|
cloudSqlDatabase: "__cloudSqlDatabase__",
|
|
80
127
|
cloudSqlInstanceId: "__cloudSqlInstanceId__",
|
|
128
|
+
connectorDirs: "__connectorDirs__",
|
|
129
|
+
locationId: "__location__",
|
|
130
|
+
};
|
|
131
|
+
let replaced = DATACONNECT_YAML_TEMPLATE;
|
|
132
|
+
for (const [k, v] of Object.entries(replacementValues)) {
|
|
133
|
+
replaced = replaced.replace(replacements[k], JSON.stringify(v));
|
|
134
|
+
}
|
|
135
|
+
return replaced;
|
|
136
|
+
}
|
|
137
|
+
function subConnectorYamlValues(replacementValues) {
|
|
138
|
+
const replacements = {
|
|
81
139
|
connectorId: "__connectorId__",
|
|
82
140
|
};
|
|
83
|
-
let replaced =
|
|
141
|
+
let replaced = CONNECTOR_YAML_TEMPLATE;
|
|
84
142
|
for (const [k, v] of Object.entries(replacementValues)) {
|
|
85
|
-
replaced = replaced.replace(replacements[k], v);
|
|
143
|
+
replaced = replaced.replace(replacements[k], JSON.stringify(v));
|
|
86
144
|
}
|
|
87
145
|
return replaced;
|
|
88
146
|
}
|
|
@@ -96,11 +154,8 @@ async function promptForService(setup, info) {
|
|
|
96
154
|
schema: await (0, client_1.getSchema)(s.name),
|
|
97
155
|
};
|
|
98
156
|
}));
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
102
|
-
if (existingFreshServicesAndSchemas.length) {
|
|
103
|
-
const choices = existingFreshServicesAndSchemas.map((s) => {
|
|
157
|
+
if (existingServicesAndSchemas.length) {
|
|
158
|
+
const choices = existingServicesAndSchemas.map((s) => {
|
|
104
159
|
const serviceName = (0, names_1.parseServiceName)(s.service.name);
|
|
105
160
|
return {
|
|
106
161
|
name: `${serviceName.location}/${serviceName.serviceId}`,
|
|
@@ -122,7 +177,24 @@ async function promptForService(setup, info) {
|
|
|
122
177
|
const instanceName = (0, names_1.parseCloudSQLInstanceName)(choice.schema.primaryDatasource.postgresql?.cloudSql.instance);
|
|
123
178
|
info.cloudSqlInstanceId = instanceName.instanceId;
|
|
124
179
|
}
|
|
180
|
+
if (choice.schema.source.files) {
|
|
181
|
+
info.schemaGql = choice.schema.source.files;
|
|
182
|
+
}
|
|
125
183
|
info.cloudSqlDatabase = choice.schema.primaryDatasource.postgresql?.database ?? "";
|
|
184
|
+
const connectors = await (0, client_1.listConnectors)(choice.service.name, [
|
|
185
|
+
"connectors.name",
|
|
186
|
+
"connectors.source.files",
|
|
187
|
+
]);
|
|
188
|
+
if (connectors.length) {
|
|
189
|
+
info.connectors = connectors.map((c) => {
|
|
190
|
+
const id = c.name.split("/").pop();
|
|
191
|
+
return {
|
|
192
|
+
id,
|
|
193
|
+
path: `./${id}`,
|
|
194
|
+
files: c.source.files || [],
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
}
|
|
126
198
|
}
|
|
127
199
|
}
|
|
128
200
|
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.actuate = exports.doSetup = void 0;
|
|
4
|
+
const yaml = require("yaml");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const clc = require("colorette");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const prompt_1 = require("../../../prompt");
|
|
9
|
+
const fileUtils_1 = require("../../../dataconnect/fileUtils");
|
|
10
|
+
const load_1 = require("../../../dataconnect/load");
|
|
11
|
+
const types_1 = require("../../../dataconnect/types");
|
|
12
|
+
const dataconnectEmulator_1 = require("../../../emulator/dataconnectEmulator");
|
|
13
|
+
const error_1 = require("../../../error");
|
|
14
|
+
const lodash_1 = require("lodash");
|
|
15
|
+
const utils_1 = require("../../../utils");
|
|
16
|
+
async function doSetup(setup, config) {
|
|
17
|
+
const sdkInfo = await askQuestions(setup, config);
|
|
18
|
+
await actuate(sdkInfo, setup.projectId);
|
|
19
|
+
}
|
|
20
|
+
exports.doSetup = doSetup;
|
|
21
|
+
async function askQuestions(setup, config) {
|
|
22
|
+
const serviceCfgs = (0, fileUtils_1.readFirebaseJson)(config);
|
|
23
|
+
const serviceInfos = await Promise.all(serviceCfgs.map((c) => (0, load_1.load)(setup.projectId || "", config, c.source)));
|
|
24
|
+
const connectorChoices = serviceInfos
|
|
25
|
+
.map((si) => {
|
|
26
|
+
return si.connectorInfo.map((ci) => {
|
|
27
|
+
return {
|
|
28
|
+
name: `${si.dataConnectYaml.serviceId}/${ci.connectorYaml.connectorId}`,
|
|
29
|
+
value: ci,
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
})
|
|
33
|
+
.flat();
|
|
34
|
+
if (!connectorChoices.length) {
|
|
35
|
+
throw new error_1.FirebaseError(`Your config has no connectors to set up SDKs for. Run ${clc.bold("firebase init dataconnect")} to set up a service and conenctors.`);
|
|
36
|
+
}
|
|
37
|
+
const connectorInfo = await (0, prompt_1.promptOnce)({
|
|
38
|
+
message: "Which connector do you want set up a generated SDK for?",
|
|
39
|
+
type: "list",
|
|
40
|
+
choices: connectorChoices,
|
|
41
|
+
});
|
|
42
|
+
let targetPlatform = types_1.Platform.UNDETERMINED;
|
|
43
|
+
let appDir;
|
|
44
|
+
const cwdPlatformGuess = await (0, fileUtils_1.getPlatformFromFolder)(process.cwd());
|
|
45
|
+
if (cwdPlatformGuess !== types_1.Platform.UNDETERMINED) {
|
|
46
|
+
(0, utils_1.logSuccess)(`Detected ${cwdPlatformGuess} app in current directory ${process.cwd()}`);
|
|
47
|
+
targetPlatform = cwdPlatformGuess;
|
|
48
|
+
appDir = process.cwd();
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
(0, utils_1.logBullet)(`Couldn't automatically detect your app directory.`);
|
|
52
|
+
appDir = await (0, prompt_1.promptForDirectory)({
|
|
53
|
+
config,
|
|
54
|
+
message: "Where is your app directory?",
|
|
55
|
+
});
|
|
56
|
+
const platformGuess = await (0, fileUtils_1.getPlatformFromFolder)(appDir);
|
|
57
|
+
if (platformGuess !== types_1.Platform.UNDETERMINED) {
|
|
58
|
+
(0, utils_1.logSuccess)(`Detected ${platformGuess} app in directory ${appDir}`);
|
|
59
|
+
targetPlatform = platformGuess;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
(0, utils_1.logBullet)("Couldn't automatically detect your app's platform.");
|
|
63
|
+
targetPlatform = await (0, prompt_1.promptOnce)({
|
|
64
|
+
message: "Which platform do you want to set up a generated SDK for?",
|
|
65
|
+
type: "list",
|
|
66
|
+
choices: [
|
|
67
|
+
{ name: "iOS (Swift)", value: types_1.Platform.IOS },
|
|
68
|
+
{ name: "Web (JavaScript)", value: types_1.Platform.WEB },
|
|
69
|
+
{ name: "Android (Kotlin)", value: types_1.Platform.ANDROID },
|
|
70
|
+
],
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const newConnectorYaml = JSON.parse(JSON.stringify(connectorInfo.connectorYaml));
|
|
75
|
+
if (!newConnectorYaml.generate) {
|
|
76
|
+
newConnectorYaml.generate = {};
|
|
77
|
+
}
|
|
78
|
+
let displayIOSWarning = false;
|
|
79
|
+
if (targetPlatform === types_1.Platform.IOS) {
|
|
80
|
+
const outputDir = newConnectorYaml.generate.swiftSdk?.outputDir ||
|
|
81
|
+
path.relative(connectorInfo.directory, path.join(appDir, `generated/swift`));
|
|
82
|
+
const pkg = newConnectorYaml.generate.swiftSdk?.package ??
|
|
83
|
+
(0, lodash_1.upperFirst)((0, lodash_1.camelCase)(newConnectorYaml.connectorId));
|
|
84
|
+
const swiftSdk = { outputDir, package: pkg };
|
|
85
|
+
newConnectorYaml.generate.swiftSdk = swiftSdk;
|
|
86
|
+
displayIOSWarning = true;
|
|
87
|
+
}
|
|
88
|
+
if (targetPlatform === types_1.Platform.WEB) {
|
|
89
|
+
const outputDir = newConnectorYaml.generate.javascriptSdk?.outputDir ||
|
|
90
|
+
path.relative(connectorInfo.directory, path.join(appDir, `generated/javascript/${newConnectorYaml.connectorId}`));
|
|
91
|
+
const pkg = newConnectorYaml.generate.javascriptSdk?.package ??
|
|
92
|
+
`@firebasegen/${connectorInfo.connectorYaml.connectorId}`;
|
|
93
|
+
const javascriptSdk = {
|
|
94
|
+
outputDir,
|
|
95
|
+
package: pkg,
|
|
96
|
+
};
|
|
97
|
+
if ((await (0, fileUtils_1.directoryHasPackageJson)(appDir)) &&
|
|
98
|
+
(await (0, prompt_1.confirm)({
|
|
99
|
+
message: "Would you like to add a dependency on the generated SDK to your package.json?",
|
|
100
|
+
}))) {
|
|
101
|
+
javascriptSdk.packageJsonDir = path.relative(connectorInfo.directory, appDir);
|
|
102
|
+
}
|
|
103
|
+
newConnectorYaml.generate.javascriptSdk = javascriptSdk;
|
|
104
|
+
}
|
|
105
|
+
if (targetPlatform === types_1.Platform.ANDROID) {
|
|
106
|
+
let baseDir = path.join(appDir, `generated/kotlin`);
|
|
107
|
+
for (const candidateSubdir of ["app/src/main/java", "app/src/main/kotlin"]) {
|
|
108
|
+
const candidateDir = path.join(appDir, candidateSubdir);
|
|
109
|
+
if (fs.existsSync(candidateDir)) {
|
|
110
|
+
baseDir = candidateDir;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const outputDir = newConnectorYaml.generate.kotlinSdk?.outputDir ||
|
|
114
|
+
path.relative(connectorInfo.directory, baseDir);
|
|
115
|
+
const pkg = newConnectorYaml.generate.kotlinSdk?.package ??
|
|
116
|
+
`connectors.${(0, lodash_1.snakeCase)(connectorInfo.connectorYaml.connectorId)}`;
|
|
117
|
+
const kotlinSdk = {
|
|
118
|
+
outputDir,
|
|
119
|
+
package: pkg,
|
|
120
|
+
};
|
|
121
|
+
newConnectorYaml.generate.kotlinSdk = kotlinSdk;
|
|
122
|
+
}
|
|
123
|
+
const shouldGenerate = !!(setup.projectId &&
|
|
124
|
+
(await (0, prompt_1.confirm)({
|
|
125
|
+
message: "Would you like to generate SDK code now?",
|
|
126
|
+
default: true,
|
|
127
|
+
})));
|
|
128
|
+
const connectorYamlContents = yaml.stringify(newConnectorYaml);
|
|
129
|
+
connectorInfo.connectorYaml = newConnectorYaml;
|
|
130
|
+
return { connectorYamlContents, connectorInfo, shouldGenerate, displayIOSWarning };
|
|
131
|
+
}
|
|
132
|
+
async function actuate(sdkInfo, projectId) {
|
|
133
|
+
const connectorYamlPath = `${sdkInfo.connectorInfo.directory}/connector.yaml`;
|
|
134
|
+
fs.writeFileSync(connectorYamlPath, sdkInfo.connectorYamlContents, "utf8");
|
|
135
|
+
(0, utils_1.logBullet)(`Wrote new config to ${connectorYamlPath}`);
|
|
136
|
+
if (projectId && sdkInfo.shouldGenerate) {
|
|
137
|
+
await dataconnectEmulator_1.DataConnectEmulator.generate({
|
|
138
|
+
configDir: sdkInfo.connectorInfo.directory,
|
|
139
|
+
connectorId: sdkInfo.connectorInfo.connectorYaml.connectorId,
|
|
140
|
+
});
|
|
141
|
+
(0, utils_1.logBullet)(`Generated SDK code for ${sdkInfo.connectorInfo.connectorYaml.connectorId}`);
|
|
142
|
+
}
|
|
143
|
+
if (sdkInfo.connectorInfo.connectorYaml.generate?.swiftSdk && sdkInfo.displayIOSWarning) {
|
|
144
|
+
(0, utils_1.logBullet)(clc.bold("Please follow the instructions here to add your generated sdk to your XCode project:\n\thttps://firebase.google.com/docs/data-connect/gp/ios-sdk#set-client"));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.actuate = actuate;
|