firebase-tools-with-isolate 13.15.0-0 → 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.
Files changed (48) hide show
  1. package/lib/commands/deploy.js +3 -1
  2. package/lib/dataconnect/client.js +2 -1
  3. package/lib/dataconnect/fileUtils.js +52 -11
  4. package/lib/dataconnect/provisionCloudSql.js +5 -1
  5. package/lib/deploy/extensions/planner.js +52 -1
  6. package/lib/deploy/extensions/prepare.js +98 -23
  7. package/lib/deploy/extensions/release.js +6 -0
  8. package/lib/deploy/functions/build.js +5 -5
  9. package/lib/deploy/functions/deploy.js +12 -12
  10. package/lib/deploy/functions/params.js +5 -3
  11. package/lib/deploy/functions/prepare.js +8 -1
  12. package/lib/deploy/functions/release/index.js +4 -0
  13. package/lib/deploy/functions/runtimes/discovery/parsing.js +1 -1
  14. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +46 -0
  15. package/lib/emulator/constants.js +7 -0
  16. package/lib/emulator/controller.js +11 -1
  17. package/lib/emulator/downloadableEmulators.js +12 -12
  18. package/lib/emulator/env.js +3 -0
  19. package/lib/emulator/functionsEmulator.js +30 -1
  20. package/lib/emulator/functionsEmulatorShared.js +16 -0
  21. package/lib/emulator/portUtils.js +1 -0
  22. package/lib/emulator/registry.js +1 -0
  23. package/lib/emulator/taskQueue.js +348 -0
  24. package/lib/emulator/tasksEmulator.js +237 -0
  25. package/lib/emulator/types.js +3 -0
  26. package/lib/extensions/askUserForEventsConfig.js +18 -8
  27. package/lib/extensions/askUserForParam.js +2 -1
  28. package/lib/extensions/displayExtensionInfo.js +5 -5
  29. package/lib/extensions/extensionsApi.js +1 -1
  30. package/lib/extensions/extensionsHelper.js +25 -3
  31. package/lib/extensions/localHelper.js +1 -1
  32. package/lib/extensions/refs.js +26 -11
  33. package/lib/extensions/runtimes/common.js +75 -0
  34. package/lib/extensions/types.js +56 -1
  35. package/lib/frameworks/constants.js +1 -1
  36. package/lib/frameworks/next/constants.js +1 -1
  37. package/lib/frameworks/next/index.js +35 -15
  38. package/lib/frameworks/next/utils.js +51 -1
  39. package/lib/init/features/dataconnect/index.js +14 -8
  40. package/lib/init/features/dataconnect/sdk.js +64 -48
  41. package/lib/prompt.js +22 -1
  42. package/package.json +3 -3
  43. package/schema/firebase-config.json +12 -0
  44. package/templates/init/dataconnect/connector.yaml +5 -3
  45. package/templates/init/dataconnect/dataconnect.yaml +5 -5
  46. package/templates/init/dataconnect/mutations.gql +44 -29
  47. package/templates/init/dataconnect/queries.gql +66 -38
  48. package/templates/init/dataconnect/schema.gql +38 -21
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParamType = exports.FUNCTIONS_V2_RESOURCE_TYPE = exports.FUNCTIONS_RESOURCE_TYPE = exports.Visibility = exports.RegistryLaunchStage = void 0;
3
+ exports.isExtensionSpec = exports.isResource = exports.isParam = exports.ParamType = exports.FUNCTIONS_V2_RESOURCE_TYPE = exports.FUNCTIONS_RESOURCE_TYPE = exports.Visibility = exports.RegistryLaunchStage = void 0;
4
4
  var RegistryLaunchStage;
5
5
  (function (RegistryLaunchStage) {
6
6
  RegistryLaunchStage["EXPERIMENTAL"] = "EXPERIMENTAL";
@@ -21,5 +21,60 @@ var ParamType;
21
21
  ParamType["STRING"] = "STRING";
22
22
  ParamType["SELECT"] = "SELECT";
23
23
  ParamType["MULTISELECT"] = "MULTISELECT";
24
+ ParamType["SELECT_RESOURCE"] = "SELECT_RESOURCE";
24
25
  ParamType["SECRET"] = "SECRET";
25
26
  })(ParamType = exports.ParamType || (exports.ParamType = {}));
27
+ function isObject(value) {
28
+ return typeof value === "object" && value !== null;
29
+ }
30
+ const isParam = (param) => {
31
+ return (isObject(param) && typeof param["param"] === "string" && typeof param["label"] === "string");
32
+ };
33
+ exports.isParam = isParam;
34
+ const isResource = (res) => {
35
+ return isObject(res) && typeof res["name"] === "string";
36
+ };
37
+ exports.isResource = isResource;
38
+ const isExtensionSpec = (spec) => {
39
+ if (!isObject(spec) || typeof spec.name !== "string" || typeof spec.version !== "string") {
40
+ return false;
41
+ }
42
+ let validResources = true;
43
+ if (spec.resources && Array.isArray(spec.resources)) {
44
+ for (const res of spec.resources) {
45
+ validResources = validResources && (0, exports.isResource)(res);
46
+ if (!validResources) {
47
+ break;
48
+ }
49
+ }
50
+ }
51
+ else {
52
+ return false;
53
+ }
54
+ let validParams = true;
55
+ if (spec.params && Array.isArray(spec.params)) {
56
+ for (const param of spec.params) {
57
+ validParams = validParams && (0, exports.isParam)(param);
58
+ if (!validParams) {
59
+ break;
60
+ }
61
+ }
62
+ }
63
+ else {
64
+ return false;
65
+ }
66
+ let validSysParams = true;
67
+ if (spec.systemParams && Array.isArray(spec.systemParams)) {
68
+ for (const param of spec.systemParams) {
69
+ validSysParams = validSysParams && (0, exports.isParam)(param);
70
+ if (!validSysParams) {
71
+ break;
72
+ }
73
+ }
74
+ }
75
+ else {
76
+ return false;
77
+ }
78
+ return true;
79
+ };
80
+ exports.isExtensionSpec = isExtensionSpec;
@@ -20,7 +20,7 @@ exports.FIREBASE_FRAMEWORKS_VERSION = (experiments.isEnabled("internaltesting")
20
20
  DEFAULT_FIREBASE_FRAMEWORKS_VERSION;
21
21
  exports.FIREBASE_FUNCTIONS_VERSION = "^4.5.0";
22
22
  exports.FIREBASE_ADMIN_VERSION = "^11.11.1";
23
- exports.SHARP_VERSION = "^0.32.1";
23
+ exports.SHARP_VERSION = "^0.32 || ^0.33";
24
24
  exports.NODE_VERSION = parseInt(process.versions.node, 10);
25
25
  exports.VALID_ENGINES = { node: [16, 18, 20] };
26
26
  exports.VALID_LOCALE_FORMATS = [/^ALL_[a-z]+$/, /^[a-z]+_ALL$/, /^[a-z]+(_[a-z]+)?$/];
@@ -11,7 +11,7 @@ exports.ROUTES_MANIFEST = "routes-manifest.json";
11
11
  exports.APP_PATHS_MANIFEST = "app-paths-manifest.json";
12
12
  exports.SERVER_REFERENCE_MANIFEST = "server-reference-manifest.json";
13
13
  exports.CONFIG_FILES = ["next.config.js", "next.config.mjs"];
14
- exports.ESBUILD_VERSION = "0.19.2";
14
+ exports.ESBUILD_VERSION = "^0.19.2";
15
15
  const WEBPACK_LAYERS_NAMES = {
16
16
  shared: "shared",
17
17
  reactServerComponents: "rsc",
@@ -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
- const env = { ...process.env };
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 = productionDeps
362
- .map((it) => `--external:${it}`)
363
- .concat("--bundle", "--platform=node", `--target=node${constants_1.NODE_VERSION}`, "--log-level=error");
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.push(...[`--outfile=${(0, path_1.join)(destDir, configFile)}`, "--format=esm"]);
366
- }
367
- else {
368
- esbuildArgs.push(`--outfile=${(0, path_1.join)(destDir, configFile)}`);
391
+ esbuildArgs.format = "esm";
369
392
  }
370
- const bundle = (0, cross_spawn_1.sync)("npx", ["--yes", `esbuild@${constants_2.ESBUILD_VERSION}`, configFile, ...esbuildArgs], {
371
- cwd: sourceDir,
372
- timeout: BUNDLE_NEXT_CONFIG_TIMEOUT,
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,6 +1,6 @@
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");
@@ -11,6 +11,8 @@ const utils_1 = require("../utils");
11
11
  const constants_1 = require("./constants");
12
12
  const fsutils_1 = require("../../fsutils");
13
13
  const utils_2 = require("../../utils");
14
+ const child_process_1 = require("child_process");
15
+ const error_1 = require("../../error");
14
16
  exports.I18N_SOURCE = /\/:nextInternalLocale(\([^\)]+\))?/;
15
17
  function cleanEscapedChars(path) {
16
18
  return path.replace(/\\([(){}:+?*])/g, (a, b) => b);
@@ -244,3 +246,51 @@ async function whichNextConfigFile(dir) {
244
246
  return null;
245
247
  }
246
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;
@@ -21,6 +21,7 @@ const QUERIES_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/que
21
21
  const MUTATIONS_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/mutations.gql");
22
22
  const defaultConnector = {
23
23
  id: "default",
24
+ path: "./connector",
24
25
  files: [
25
26
  {
26
27
  path: "queries.gql",
@@ -94,7 +95,7 @@ async function writeFiles(config, info) {
94
95
  console.log(dir);
95
96
  const subbedDataconnectYaml = subDataconnectYamlValues({
96
97
  ...info,
97
- connectorIds: info.connectors.map((c) => `"./${c.id}"`).join(", "),
98
+ connectorDirs: info.connectors.map((c) => c.path),
98
99
  });
99
100
  config.set("dataconnect", { source: dir });
100
101
  await config.askWriteProjectFile((0, path_1.join)(dir, "dataconnect.yaml"), subbedDataconnectYaml);
@@ -114,9 +115,9 @@ async function writeFiles(config, info) {
114
115
  async function writeConnectorFiles(config, connectorInfo) {
115
116
  const subbedConnectorYaml = subConnectorYamlValues({ connectorId: connectorInfo.id });
116
117
  const dir = config.get("dataconnect.source") || "dataconnect";
117
- await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.id, "connector.yaml"), subbedConnectorYaml);
118
+ await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.path, "connector.yaml"), subbedConnectorYaml);
118
119
  for (const f of connectorInfo.files) {
119
- await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.id, f.path), f.content);
120
+ await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.path, f.path), f.content);
120
121
  }
121
122
  }
122
123
  function subDataconnectYamlValues(replacementValues) {
@@ -124,12 +125,12 @@ function subDataconnectYamlValues(replacementValues) {
124
125
  serviceId: "__serviceId__",
125
126
  cloudSqlDatabase: "__cloudSqlDatabase__",
126
127
  cloudSqlInstanceId: "__cloudSqlInstanceId__",
127
- connectorIds: "__connectorIds__",
128
+ connectorDirs: "__connectorDirs__",
128
129
  locationId: "__location__",
129
130
  };
130
131
  let replaced = DATACONNECT_YAML_TEMPLATE;
131
132
  for (const [k, v] of Object.entries(replacementValues)) {
132
- replaced = replaced.replace(replacements[k], v);
133
+ replaced = replaced.replace(replacements[k], JSON.stringify(v));
133
134
  }
134
135
  return replaced;
135
136
  }
@@ -139,7 +140,7 @@ function subConnectorYamlValues(replacementValues) {
139
140
  };
140
141
  let replaced = CONNECTOR_YAML_TEMPLATE;
141
142
  for (const [k, v] of Object.entries(replacementValues)) {
142
- replaced = replaced.replace(replacements[k], v);
143
+ replaced = replaced.replace(replacements[k], JSON.stringify(v));
143
144
  }
144
145
  return replaced;
145
146
  }
@@ -180,11 +181,16 @@ async function promptForService(setup, info) {
180
181
  info.schemaGql = choice.schema.source.files;
181
182
  }
182
183
  info.cloudSqlDatabase = choice.schema.primaryDatasource.postgresql?.database ?? "";
183
- const connectors = await (0, client_1.listConnectors)(choice.service.name);
184
+ const connectors = await (0, client_1.listConnectors)(choice.service.name, [
185
+ "connectors.name",
186
+ "connectors.source.files",
187
+ ]);
184
188
  if (connectors.length) {
185
189
  info.connectors = connectors.map((c) => {
190
+ const id = c.name.split("/").pop();
186
191
  return {
187
- id: c.name.split("/").pop(),
192
+ id,
193
+ path: `./${id}`,
188
194
  files: c.source.files || [],
189
195
  };
190
196
  });
@@ -4,16 +4,15 @@ exports.actuate = exports.doSetup = void 0;
4
4
  const yaml = require("yaml");
5
5
  const fs = require("fs");
6
6
  const clc = require("colorette");
7
+ const path = require("path");
7
8
  const prompt_1 = require("../../../prompt");
8
9
  const fileUtils_1 = require("../../../dataconnect/fileUtils");
9
10
  const load_1 = require("../../../dataconnect/load");
10
- const logger_1 = require("../../../logger");
11
+ const types_1 = require("../../../dataconnect/types");
11
12
  const dataconnectEmulator_1 = require("../../../emulator/dataconnectEmulator");
12
13
  const error_1 = require("../../../error");
13
14
  const lodash_1 = require("lodash");
14
- const IOS = "ios";
15
- const WEB = "web";
16
- const ANDROID = "android";
15
+ const utils_1 = require("../../../utils");
17
16
  async function doSetup(setup, config) {
18
17
  const sdkInfo = await askQuestions(setup, config);
19
18
  await actuate(sdkInfo, setup.projectId);
@@ -40,66 +39,79 @@ async function askQuestions(setup, config) {
40
39
  type: "list",
41
40
  choices: connectorChoices,
42
41
  });
43
- let platforms = [];
44
- while (!platforms.length) {
45
- platforms = await (0, prompt_1.promptOnce)({
46
- message: "Which platforms do you want to set up a generated SDK for?",
47
- type: "checkbox",
48
- choices: [
49
- { name: "iOS (Swift)", value: IOS },
50
- { name: "Web (JavaScript)", value: WEB },
51
- { name: "Androd (Kotlin)", value: ANDROID },
52
- ],
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?",
53
55
  });
54
- if (!platforms.length) {
55
- logger_1.logger.info("You must pick at least one platform.");
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
+ });
56
72
  }
57
73
  }
58
74
  const newConnectorYaml = JSON.parse(JSON.stringify(connectorInfo.connectorYaml));
59
75
  if (!newConnectorYaml.generate) {
60
76
  newConnectorYaml.generate = {};
61
77
  }
62
- if (platforms.includes(IOS)) {
63
- const outputDir = await (0, prompt_1.promptOnce)({
64
- message: `What directory do you want to write your Swift SDK code to? (If not absolute, path will be relative to '${connectorInfo.directory}')`,
65
- type: "input",
66
- default: newConnectorYaml.generate.swiftSdk?.outputDir ||
67
- `./../gensdk/${newConnectorYaml.connectorId}/swift-sdk`,
68
- });
69
- const pkg = (0, lodash_1.camelCase)(newConnectorYaml.connectorId);
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));
70
84
  const swiftSdk = { outputDir, package: pkg };
71
85
  newConnectorYaml.generate.swiftSdk = swiftSdk;
86
+ displayIOSWarning = true;
72
87
  }
73
- if (platforms.includes(WEB)) {
74
- const outputDir = await (0, prompt_1.promptOnce)({
75
- message: `What directory do you want to write your JavaScript SDK code to? (If not absolute, path will be relative to '${connectorInfo.directory}')`,
76
- type: "input",
77
- default: newConnectorYaml.generate.javascriptSdk?.outputDir ||
78
- `./../gensdk/${newConnectorYaml.connectorId}/javascript-sdk`,
79
- });
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}`));
80
91
  const pkg = newConnectorYaml.generate.javascriptSdk?.package ??
81
92
  `@firebasegen/${connectorInfo.connectorYaml.connectorId}`;
82
- const packageJSONDir = await (0, prompt_1.promptOnce)({
83
- message: "Which directory contains the package.json that you would like to add the JavaScript SDK dependency to? (Leave blank to skip)",
84
- type: "input",
85
- default: newConnectorYaml.generate.javascriptSdk?.packageJSONDir,
86
- });
87
93
  const javascriptSdk = {
88
94
  outputDir,
89
95
  package: pkg,
90
96
  };
91
- if (packageJSONDir) {
92
- javascriptSdk.packageJSONDir = packageJSONDir;
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);
93
102
  }
94
103
  newConnectorYaml.generate.javascriptSdk = javascriptSdk;
95
104
  }
96
- if (platforms.includes(ANDROID)) {
97
- const outputDir = await (0, prompt_1.promptOnce)({
98
- message: `What directory do you want to write your Kotlin SDK code to? (If not absolute, path will be relative to '${connectorInfo.directory}')`,
99
- type: "input",
100
- default: newConnectorYaml.generate.kotlinSdk?.outputDir ||
101
- `./../gensdk/${newConnectorYaml.connectorId}/kotlin-sdk`,
102
- });
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);
103
115
  const pkg = newConnectorYaml.generate.kotlinSdk?.package ??
104
116
  `connectors.${(0, lodash_1.snakeCase)(connectorInfo.connectorYaml.connectorId)}`;
105
117
  const kotlinSdk = {
@@ -114,18 +126,22 @@ async function askQuestions(setup, config) {
114
126
  default: true,
115
127
  })));
116
128
  const connectorYamlContents = yaml.stringify(newConnectorYaml);
117
- return { connectorYamlContents, connectorInfo, shouldGenerate };
129
+ connectorInfo.connectorYaml = newConnectorYaml;
130
+ return { connectorYamlContents, connectorInfo, shouldGenerate, displayIOSWarning };
118
131
  }
119
132
  async function actuate(sdkInfo, projectId) {
120
133
  const connectorYamlPath = `${sdkInfo.connectorInfo.directory}/connector.yaml`;
121
134
  fs.writeFileSync(connectorYamlPath, sdkInfo.connectorYamlContents, "utf8");
122
- logger_1.logger.info(`Wrote new config to ${connectorYamlPath}`);
135
+ (0, utils_1.logBullet)(`Wrote new config to ${connectorYamlPath}`);
123
136
  if (projectId && sdkInfo.shouldGenerate) {
124
137
  await dataconnectEmulator_1.DataConnectEmulator.generate({
125
138
  configDir: sdkInfo.connectorInfo.directory,
126
139
  connectorId: sdkInfo.connectorInfo.connectorYaml.connectorId,
127
140
  });
128
- logger_1.logger.info(`Generated SDK code for ${sdkInfo.connectorInfo.connectorYaml.connectorId}`);
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"));
129
145
  }
130
146
  }
131
147
  exports.actuate = actuate;
package/lib/prompt.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.confirm = exports.promptOnce = exports.prompt = void 0;
3
+ exports.promptForDirectory = exports.confirm = exports.promptOnce = exports.prompt = void 0;
4
4
  const inquirer = require("inquirer");
5
+ const fsutils_1 = require("./fsutils");
5
6
  const error_1 = require("./error");
7
+ const logger_1 = require("./logger");
6
8
  inquirer.registerPrompt("autocomplete", require("inquirer-autocomplete-prompt"));
7
9
  async function prompt(options, questions) {
8
10
  const prompts = [];
@@ -47,3 +49,22 @@ async function confirm(args) {
47
49
  }
48
50
  }
49
51
  exports.confirm = confirm;
52
+ async function promptForDirectory(args) {
53
+ let dir = "";
54
+ while (!dir) {
55
+ const target = args.config.path(await promptOnce({
56
+ message: "Where is your app directory?",
57
+ }));
58
+ if ((0, fsutils_1.fileExistsSync)(target)) {
59
+ logger_1.logger.error(`Expected a directory, but ${target} is a file. Please provide a path to a directory.`);
60
+ }
61
+ else if (!(0, fsutils_1.dirExistsSync)(target)) {
62
+ logger_1.logger.error(`Directory ${target} not found. Please provide a path to a directory`);
63
+ }
64
+ else {
65
+ dir = target;
66
+ }
67
+ }
68
+ return dir;
69
+ }
70
+ exports.promptForDirectory = promptForDirectory;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "firebase-tools-with-isolate",
3
+ "version": "13.16.0",
3
4
  "description": "Command-Line Interface for Firebase with monorepo support",
4
- "version": "13.15.0-0",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
7
7
  "firebase": "lib/bin/firebase.js"
@@ -127,7 +127,7 @@
127
127
  "google-auth-library": "^9.11.0",
128
128
  "inquirer": "^8.2.6",
129
129
  "inquirer-autocomplete-prompt": "^2.0.1",
130
- "isolate-package": "^1.20.0-0",
130
+ "isolate-package": "^1.18.0",
131
131
  "jsonwebtoken": "^9.0.0",
132
132
  "leven": "^3.1.0",
133
133
  "libsodium-wrappers": "^0.7.10",
@@ -162,7 +162,7 @@
162
162
  "uuid": "^8.3.2",
163
163
  "winston": "^3.0.0",
164
164
  "winston-transport": "^4.4.0",
165
- "ws": "^7.2.3",
165
+ "ws": "^7.5.10",
166
166
  "yaml": "^2.4.1"
167
167
  },
168
168
  "devDependencies": {
@@ -500,6 +500,18 @@
500
500
  },
501
501
  "type": "object"
502
502
  },
503
+ "tasks": {
504
+ "additionalProperties": false,
505
+ "properties": {
506
+ "host": {
507
+ "type": "string"
508
+ },
509
+ "port": {
510
+ "type": "number"
511
+ }
512
+ },
513
+ "type": "object"
514
+ },
503
515
  "ui": {
504
516
  "additionalProperties": false,
505
517
  "properties": {
@@ -1,13 +1,15 @@
1
- connectorId: "__connectorId__"
2
- authMode: "PUBLIC"
1
+ connectorId: __connectorId__
2
+ authMode: "PUBLIC"
3
3
  ## ## Here's an example of how to add generated SDKs.
4
4
  ## ## You'll need to replace the outputDirs with ones pointing to where you want the generated code in your app.
5
5
  # generate:
6
6
  # javascriptSdk:
7
7
  # outputDir: <Path where you want the generated SDK to be written to, relative to this file>
8
8
  # package: "@firebasegen/my-connector"
9
- # packageJSONDir: < Optional. Path to your Javascript app's package.json>
9
+ # packageJsonDir: < Optional. Path to your Javascript app's package.json>
10
10
  # swiftSdk:
11
11
  # outputDir: <Path where you want the generated SDK to be written to, relative to this file>
12
+ # package: "firebasegen/default"
12
13
  # kotlinSdk:
13
14
  # outputDir: <Path where you want the generated SDK to be written to, relative to this file>
15
+ # package: connectors.default
@@ -1,11 +1,11 @@
1
1
  specVersion: "v1alpha"
2
- serviceId: "__serviceId__"
3
- location: "__location__"
2
+ serviceId: __serviceId__
3
+ location: __location__
4
4
  schema:
5
5
  source: "./schema"
6
6
  datasource:
7
7
  postgresql:
8
- database: "__cloudSqlDatabase__"
8
+ database: __cloudSqlDatabase__
9
9
  cloudSql:
10
- instanceId: "__cloudSqlInstanceId__"
11
- connectorDirs: [__connectorIds__]
10
+ instanceId: __cloudSqlInstanceId__
11
+ connectorDirs: __connectorDirs__