firebase-tools 12.4.7 → 12.5.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/bin/firebase.js +0 -0
- package/lib/deploy/functions/release/fabricator.js +8 -6
- package/lib/deploy/functions/release/sourceTokenScraper.js +9 -2
- package/lib/deploy/lifecycleHooks.js +6 -7
- package/lib/emulator/auth/apiSpec.js +712 -51
- package/lib/emulator/extensionsEmulator.js +1 -5
- package/lib/emulator/functionsEmulatorRuntime.js +5 -4
- package/lib/extensions/emulator/optionsHelper.js +4 -130
- package/lib/extensions/emulator/specHelper.js +12 -1
- package/lib/frameworks/astro/index.js +1 -5
- package/lib/frameworks/astro/utils.js +22 -4
- package/lib/frameworks/next/constants.js +2 -1
- package/lib/frameworks/next/index.js +2 -2
- package/lib/gcp/frameworks.js +8 -2
- package/lib/init/features/frameworks/index.js +52 -8
- package/lib/init/features/frameworks/repo.js +1 -1
- package/lib/utils.js +5 -1
- package/package.json +1 -1
|
@@ -92,11 +92,7 @@ class ExtensionsEmulator {
|
|
|
92
92
|
this.installAndBuildSourceCode(sourceCodePath);
|
|
93
93
|
}
|
|
94
94
|
hasValidSource(args) {
|
|
95
|
-
const requiredFiles = [
|
|
96
|
-
"./extension.yaml",
|
|
97
|
-
"./functions/package.json",
|
|
98
|
-
"./functions/node_modules",
|
|
99
|
-
];
|
|
95
|
+
const requiredFiles = ["./extension.yaml", "./functions/package.json"];
|
|
100
96
|
if (!fs.existsSync(args.path)) {
|
|
101
97
|
return false;
|
|
102
98
|
}
|
|
@@ -642,22 +642,23 @@ async function main() {
|
|
|
642
642
|
}
|
|
643
643
|
const app = express();
|
|
644
644
|
app.enable("trust proxy");
|
|
645
|
+
const bodyParserLimit = "32mb";
|
|
645
646
|
app.use(bodyParser.json({
|
|
646
|
-
limit:
|
|
647
|
+
limit: bodyParserLimit,
|
|
647
648
|
verify: rawBodySaver,
|
|
648
649
|
}));
|
|
649
650
|
app.use(bodyParser.text({
|
|
650
|
-
limit:
|
|
651
|
+
limit: bodyParserLimit,
|
|
651
652
|
verify: rawBodySaver,
|
|
652
653
|
}));
|
|
653
654
|
app.use(bodyParser.urlencoded({
|
|
654
655
|
extended: true,
|
|
655
|
-
limit:
|
|
656
|
+
limit: bodyParserLimit,
|
|
656
657
|
verify: rawBodySaver,
|
|
657
658
|
}));
|
|
658
659
|
app.use(bodyParser.raw({
|
|
659
660
|
type: "*/*",
|
|
660
|
-
limit:
|
|
661
|
+
limit: bodyParserLimit,
|
|
661
662
|
verify: rawBodySaver,
|
|
662
663
|
}));
|
|
663
664
|
app.get("/__/health", (req, res) => {
|
|
@@ -1,42 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getParams = exports.getSecretEnvVars = exports.getNonSecretEnv = exports.getExtensionFunctionInfo =
|
|
4
|
-
const fs = require("fs-extra");
|
|
5
|
-
const path = require("path");
|
|
3
|
+
exports.getParams = exports.getSecretEnvVars = exports.getNonSecretEnv = exports.getExtensionFunctionInfo = void 0;
|
|
6
4
|
const paramHelper = require("../paramHelper");
|
|
7
5
|
const specHelper = require("./specHelper");
|
|
8
|
-
const localHelper = require("../localHelper");
|
|
9
6
|
const triggerHelper = require("./triggerHelper");
|
|
10
7
|
const types_1 = require("../types");
|
|
11
8
|
const extensionsHelper = require("../extensionsHelper");
|
|
12
9
|
const planner = require("../../deploy/extensions/planner");
|
|
13
|
-
const config_1 = require("../../config");
|
|
14
|
-
const error_1 = require("../../error");
|
|
15
|
-
const emulatorLogger_1 = require("../../emulator/emulatorLogger");
|
|
16
10
|
const projectUtils_1 = require("../../projectUtils");
|
|
17
|
-
const types_2 = require("../../emulator/types");
|
|
18
|
-
async function buildOptions(options) {
|
|
19
|
-
const extDevDir = localHelper.findExtensionYaml(process.cwd());
|
|
20
|
-
options.extDevDir = extDevDir;
|
|
21
|
-
const spec = await specHelper.readExtensionYaml(extDevDir);
|
|
22
|
-
extensionsHelper.validateSpec(spec);
|
|
23
|
-
const params = getParams(options, spec);
|
|
24
|
-
extensionsHelper.validateCommandLineParams(params, spec.params);
|
|
25
|
-
const functionResources = specHelper.getFunctionResourcesWithParamSubstitution(spec, params);
|
|
26
|
-
let testConfig;
|
|
27
|
-
if (options.testConfig) {
|
|
28
|
-
testConfig = readTestConfigFile(options.testConfig);
|
|
29
|
-
checkTestConfig(testConfig, functionResources);
|
|
30
|
-
}
|
|
31
|
-
options.config = buildConfig(functionResources, testConfig);
|
|
32
|
-
options.extDevEnv = params;
|
|
33
|
-
const functionEmuTriggerDefs = functionResources.map((r) => triggerHelper.functionResourceToEmulatedTriggerDefintion(r));
|
|
34
|
-
options.extDevTriggers = functionEmuTriggerDefs;
|
|
35
|
-
options.extDevRuntime = specHelper.getRuntime(functionResources);
|
|
36
|
-
return options;
|
|
37
|
-
}
|
|
38
|
-
exports.buildOptions = buildOptions;
|
|
39
11
|
async function getExtensionFunctionInfo(instance, paramValues) {
|
|
12
|
+
var _a, _b;
|
|
40
13
|
const spec = await planner.getExtensionSpec(instance);
|
|
41
14
|
const functionResources = specHelper.getFunctionResourcesWithParamSubstitution(spec, paramValues);
|
|
42
15
|
const extensionTriggers = functionResources
|
|
@@ -46,8 +19,8 @@ async function getExtensionFunctionInfo(instance, paramValues) {
|
|
|
46
19
|
return trigger;
|
|
47
20
|
});
|
|
48
21
|
const runtime = specHelper.getRuntime(functionResources);
|
|
49
|
-
const nonSecretEnv = getNonSecretEnv(spec.params, paramValues);
|
|
50
|
-
const secretEnvVariables = getSecretEnvVars(spec.params, paramValues);
|
|
22
|
+
const nonSecretEnv = getNonSecretEnv((_a = spec.params) !== null && _a !== void 0 ? _a : [], paramValues);
|
|
23
|
+
const secretEnvVariables = getSecretEnvVars((_b = spec.params) !== null && _b !== void 0 ? _b : [], paramValues);
|
|
51
24
|
return {
|
|
52
25
|
extensionTriggers,
|
|
53
26
|
runtime,
|
|
@@ -98,102 +71,3 @@ function getParams(options, extensionSpec) {
|
|
|
98
71
|
return extensionsHelper.substituteParams(unsubbedParams, unsubbedParams);
|
|
99
72
|
}
|
|
100
73
|
exports.getParams = getParams;
|
|
101
|
-
function checkTestConfig(testConfig, functionResources) {
|
|
102
|
-
const logger = emulatorLogger_1.EmulatorLogger.forEmulator(types_2.Emulators.FUNCTIONS);
|
|
103
|
-
if (!testConfig.functions && functionResources.length) {
|
|
104
|
-
logger.log("WARN", "This extension uses functions," +
|
|
105
|
-
"but 'firebase.json' provided by --test-config is missing a top-level 'functions' object." +
|
|
106
|
-
"Functions will not be emulated.");
|
|
107
|
-
}
|
|
108
|
-
if (!testConfig.firestore && shouldEmulateFirestore(functionResources)) {
|
|
109
|
-
logger.log("WARN", "This extension interacts with Cloud Firestore," +
|
|
110
|
-
"but 'firebase.json' provided by --test-config is missing a top-level 'firestore' object." +
|
|
111
|
-
"Cloud Firestore will not be emulated.");
|
|
112
|
-
}
|
|
113
|
-
if (!testConfig.database && shouldEmulateDatabase(functionResources)) {
|
|
114
|
-
logger.log("WARN", "This extension interacts with Realtime Database," +
|
|
115
|
-
"but 'firebase.json' provided by --test-config is missing a top-level 'database' object." +
|
|
116
|
-
"Realtime Database will not be emulated.");
|
|
117
|
-
}
|
|
118
|
-
if (!testConfig.storage && shouldEmulateStorage(functionResources)) {
|
|
119
|
-
logger.log("WARN", "This extension interacts with Cloud Storage," +
|
|
120
|
-
"but 'firebase.json' provided by --test-config is missing a top-level 'storage' object." +
|
|
121
|
-
"Cloud Storage will not be emulated.");
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function readTestConfigFile(testConfigPath) {
|
|
125
|
-
try {
|
|
126
|
-
const buf = fs.readFileSync(path.resolve(testConfigPath));
|
|
127
|
-
return JSON.parse(buf.toString());
|
|
128
|
-
}
|
|
129
|
-
catch (err) {
|
|
130
|
-
throw new error_1.FirebaseError(`Error reading --test-config file: ${err.message}\n`, {
|
|
131
|
-
original: err,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
function buildConfig(functionResources, testConfig) {
|
|
136
|
-
const config = new config_1.Config(testConfig || {}, { projectDir: process.cwd(), cwd: process.cwd() });
|
|
137
|
-
const emulateFunctions = shouldEmulateFunctions(functionResources);
|
|
138
|
-
if (!testConfig) {
|
|
139
|
-
if (emulateFunctions) {
|
|
140
|
-
config.set("functions", {});
|
|
141
|
-
}
|
|
142
|
-
if (shouldEmulateFirestore(functionResources)) {
|
|
143
|
-
config.set("firestore", {});
|
|
144
|
-
}
|
|
145
|
-
if (shouldEmulateDatabase(functionResources)) {
|
|
146
|
-
config.set("database", {});
|
|
147
|
-
}
|
|
148
|
-
if (shouldEmulatePubsub(functionResources)) {
|
|
149
|
-
config.set("pubsub", {});
|
|
150
|
-
}
|
|
151
|
-
if (shouldEmulateStorage(functionResources)) {
|
|
152
|
-
config.set("storage", {});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (config.src.functions) {
|
|
156
|
-
const sourceDirectory = getFunctionSourceDirectory(functionResources);
|
|
157
|
-
config.set("functions.source", sourceDirectory);
|
|
158
|
-
}
|
|
159
|
-
return config;
|
|
160
|
-
}
|
|
161
|
-
function getFunctionSourceDirectory(functionResources) {
|
|
162
|
-
var _a;
|
|
163
|
-
let sourceDirectory;
|
|
164
|
-
for (const r of functionResources) {
|
|
165
|
-
const dir = ((_a = r.properties) === null || _a === void 0 ? void 0 : _a.sourceDirectory) || "functions";
|
|
166
|
-
if (!sourceDirectory) {
|
|
167
|
-
sourceDirectory = dir;
|
|
168
|
-
}
|
|
169
|
-
else if (sourceDirectory !== dir) {
|
|
170
|
-
throw new error_1.FirebaseError(`Found function resources with different sourceDirectories: '${sourceDirectory}' and '${dir}'. The extensions emulator only supports a single sourceDirectory.`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return sourceDirectory || "functions";
|
|
174
|
-
}
|
|
175
|
-
function shouldEmulateFunctions(resources) {
|
|
176
|
-
return resources.length > 0;
|
|
177
|
-
}
|
|
178
|
-
function shouldEmulate(emulatorName, resources) {
|
|
179
|
-
var _a, _b;
|
|
180
|
-
for (const r of resources) {
|
|
181
|
-
const eventType = ((_b = (_a = r.properties) === null || _a === void 0 ? void 0 : _a.eventTrigger) === null || _b === void 0 ? void 0 : _b.eventType) || "";
|
|
182
|
-
if (eventType.includes(emulatorName)) {
|
|
183
|
-
return true;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
function shouldEmulateFirestore(resources) {
|
|
189
|
-
return shouldEmulate("cloud.firestore", resources);
|
|
190
|
-
}
|
|
191
|
-
function shouldEmulateDatabase(resources) {
|
|
192
|
-
return shouldEmulate("google.firebase.database", resources);
|
|
193
|
-
}
|
|
194
|
-
function shouldEmulatePubsub(resources) {
|
|
195
|
-
return shouldEmulate("google.pubsub", resources);
|
|
196
|
-
}
|
|
197
|
-
function shouldEmulateStorage(resources) {
|
|
198
|
-
return shouldEmulate("google.storage", resources);
|
|
199
|
-
}
|
|
@@ -26,9 +26,20 @@ function wrappedSafeLoad(source) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
async function readExtensionYaml(directory) {
|
|
29
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
29
30
|
const extensionYaml = await readFileFromDirectory(directory, SPEC_FILE);
|
|
30
31
|
const source = extensionYaml.source;
|
|
31
|
-
|
|
32
|
+
const spec = wrappedSafeLoad(source);
|
|
33
|
+
spec.params = (_a = spec.params) !== null && _a !== void 0 ? _a : [];
|
|
34
|
+
spec.systemParams = (_b = spec.systemParams) !== null && _b !== void 0 ? _b : [];
|
|
35
|
+
spec.resources = (_c = spec.resources) !== null && _c !== void 0 ? _c : [];
|
|
36
|
+
spec.apis = (_d = spec.apis) !== null && _d !== void 0 ? _d : [];
|
|
37
|
+
spec.roles = (_e = spec.roles) !== null && _e !== void 0 ? _e : [];
|
|
38
|
+
spec.externalServices = (_f = spec.externalServices) !== null && _f !== void 0 ? _f : [];
|
|
39
|
+
spec.events = (_g = spec.events) !== null && _g !== void 0 ? _g : [];
|
|
40
|
+
spec.lifecycleEvents = (_h = spec.lifecycleEvents) !== null && _h !== void 0 ? _h : [];
|
|
41
|
+
spec.contributors = (_j = spec.contributors) !== null && _j !== void 0 ? _j : [];
|
|
42
|
+
return spec;
|
|
32
43
|
}
|
|
33
44
|
exports.readExtensionYaml = readExtensionYaml;
|
|
34
45
|
async function readPostinstall(directory) {
|
|
@@ -10,14 +10,10 @@ const utils_2 = require("./utils");
|
|
|
10
10
|
exports.name = "Astro";
|
|
11
11
|
exports.support = "experimental";
|
|
12
12
|
exports.type = 2;
|
|
13
|
-
function getAstroVersion(cwd) {
|
|
14
|
-
var _a;
|
|
15
|
-
return (_a = (0, utils_1.findDependency)("astro", { cwd, depth: 0, omitDev: false })) === null || _a === void 0 ? void 0 : _a.version;
|
|
16
|
-
}
|
|
17
13
|
async function discover(dir) {
|
|
18
14
|
if (!(0, fs_extra_1.existsSync)((0, path_1.join)(dir, "package.json")))
|
|
19
15
|
return;
|
|
20
|
-
if (!getAstroVersion(dir))
|
|
16
|
+
if (!(0, utils_2.getAstroVersion)(dir))
|
|
21
17
|
return;
|
|
22
18
|
const { output, publicDir: publicDirectory } = await (0, utils_2.getConfig)(dir);
|
|
23
19
|
return {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getConfig = exports.getBootstrapScript = void 0;
|
|
3
|
+
exports.getAstroVersion = exports.getConfig = exports.getBootstrapScript = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const semver_1 = require("semver");
|
|
5
7
|
const { dynamicImport } = require(true && "../../dynamicImport");
|
|
6
8
|
function getBootstrapScript() {
|
|
7
9
|
return `const entry = import('./entry.mjs');\nexport const handle = async (req, res) => (await entry).handler(req, res)`;
|
|
@@ -9,9 +11,20 @@ function getBootstrapScript() {
|
|
|
9
11
|
exports.getBootstrapScript = getBootstrapScript;
|
|
10
12
|
async function getConfig(cwd) {
|
|
11
13
|
const astroDirectory = (0, path_1.dirname)(require.resolve("astro/package.json", { paths: [cwd] }));
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const
|
|
14
|
+
const version = getAstroVersion(cwd);
|
|
15
|
+
let config;
|
|
16
|
+
const configPath = (0, path_1.join)(astroDirectory, "dist", "core", "config", "config.js");
|
|
17
|
+
if ((0, semver_1.gte)(version, "2.9.7")) {
|
|
18
|
+
const { resolveConfig } = await dynamicImport(configPath);
|
|
19
|
+
const { astroConfig } = await resolveConfig({ root: cwd }, "build");
|
|
20
|
+
config = astroConfig;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const { openConfig } = await dynamicImport(configPath);
|
|
24
|
+
const logging = undefined;
|
|
25
|
+
const { astroConfig } = await openConfig({ cmd: "build", cwd, logging });
|
|
26
|
+
config = astroConfig;
|
|
27
|
+
}
|
|
15
28
|
return {
|
|
16
29
|
outDir: (0, path_1.relative)(cwd, config.outDir.pathname),
|
|
17
30
|
publicDir: (0, path_1.relative)(cwd, config.publicDir.pathname),
|
|
@@ -20,3 +33,8 @@ async function getConfig(cwd) {
|
|
|
20
33
|
};
|
|
21
34
|
}
|
|
22
35
|
exports.getConfig = getConfig;
|
|
36
|
+
function getAstroVersion(cwd) {
|
|
37
|
+
var _a;
|
|
38
|
+
return (_a = (0, utils_1.findDependency)("astro", { cwd, depth: 0, omitDev: false })) === null || _a === void 0 ? void 0 : _a.version;
|
|
39
|
+
}
|
|
40
|
+
exports.getAstroVersion = getAstroVersion;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.APP_PATHS_MANIFEST = exports.ROUTES_MANIFEST = exports.PRERENDER_MANIFEST = exports.PAGES_MANIFEST = exports.MIDDLEWARE_MANIFEST = exports.IMAGES_MANIFEST = exports.EXPORT_MARKER = exports.APP_PATH_ROUTES_MANIFEST = void 0;
|
|
3
|
+
exports.ESBUILD_VERSION = exports.APP_PATHS_MANIFEST = exports.ROUTES_MANIFEST = exports.PRERENDER_MANIFEST = exports.PAGES_MANIFEST = exports.MIDDLEWARE_MANIFEST = exports.IMAGES_MANIFEST = exports.EXPORT_MARKER = exports.APP_PATH_ROUTES_MANIFEST = void 0;
|
|
4
4
|
exports.APP_PATH_ROUTES_MANIFEST = "app-path-routes-manifest.json";
|
|
5
5
|
exports.EXPORT_MARKER = "export-marker.json";
|
|
6
6
|
exports.IMAGES_MANIFEST = "images-manifest.json";
|
|
@@ -9,3 +9,4 @@ exports.PAGES_MANIFEST = "pages-manifest.json";
|
|
|
9
9
|
exports.PRERENDER_MANIFEST = "prerender-manifest.json";
|
|
10
10
|
exports.ROUTES_MANIFEST = "routes-manifest.json";
|
|
11
11
|
exports.APP_PATHS_MANIFEST = "app-paths-manifest.json";
|
|
12
|
+
exports.ESBUILD_VERSION = "0.19.2";
|
|
@@ -29,6 +29,7 @@ exports.name = "Next.js";
|
|
|
29
29
|
exports.support = "preview";
|
|
30
30
|
exports.type = 2;
|
|
31
31
|
exports.docsUrl = "https://firebase.google.com/docs/hosting/frameworks/nextjs";
|
|
32
|
+
const BUNDLE_NEXT_CONFIG_TIMEOUT = 60000;
|
|
32
33
|
const DEFAULT_NUMBER_OF_REASONS_TO_LIST = 5;
|
|
33
34
|
function getReactVersion(cwd) {
|
|
34
35
|
var _a;
|
|
@@ -297,7 +298,6 @@ async function ɵcodegenPublicDirectory(sourceDir, destDir, _, context) {
|
|
|
297
298
|
}));
|
|
298
299
|
}
|
|
299
300
|
exports.ɵcodegenPublicDirectory = ɵcodegenPublicDirectory;
|
|
300
|
-
const BUNDLE_NEXT_CONFIG_TIMEOUT = 10000;
|
|
301
301
|
async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
|
|
302
302
|
const { distDir } = await getConfig(sourceDir);
|
|
303
303
|
const packageJson = await (0, utils_1.readJSON)((0, path_1.join)(sourceDir, "package.json"));
|
|
@@ -327,7 +327,7 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
|
|
|
327
327
|
const esbuildArgs = productionDeps
|
|
328
328
|
.map((it) => `--external:${it}`)
|
|
329
329
|
.concat("--bundle", "--platform=node", `--target=node${constants_1.NODE_VERSION}`, `--outdir=${destDir}`, "--log-level=error");
|
|
330
|
-
const bundle = (0, cross_spawn_1.sync)("npx", ["--yes",
|
|
330
|
+
const bundle = (0, cross_spawn_1.sync)("npx", ["--yes", `esbuild@${constants_2.ESBUILD_VERSION}`, "next.config.js", ...esbuildArgs], {
|
|
331
331
|
cwd: sourceDir,
|
|
332
332
|
timeout: BUNDLE_NEXT_CONFIG_TIMEOUT,
|
|
333
333
|
});
|
package/lib/gcp/frameworks.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createBuild = exports.createStack = exports.API_VERSION = void 0;
|
|
3
|
+
exports.createBuild = exports.getStack = exports.createStack = exports.API_VERSION = void 0;
|
|
4
4
|
const apiv2_1 = require("../apiv2");
|
|
5
5
|
const api_1 = require("../api");
|
|
6
|
-
exports.API_VERSION = "
|
|
6
|
+
exports.API_VERSION = "v1alpha";
|
|
7
7
|
const client = new apiv2_1.Client({
|
|
8
8
|
urlPrefix: api_1.frameworksOrigin,
|
|
9
9
|
auth: true,
|
|
@@ -15,6 +15,12 @@ async function createStack(projectId, location, stackInput) {
|
|
|
15
15
|
return res.body;
|
|
16
16
|
}
|
|
17
17
|
exports.createStack = createStack;
|
|
18
|
+
async function getStack(projectId, location, stackId) {
|
|
19
|
+
const name = `projects/${projectId}/locations/${location}/stacks/${stackId}`;
|
|
20
|
+
const res = await client.get(name);
|
|
21
|
+
return res.body;
|
|
22
|
+
}
|
|
23
|
+
exports.getStack = getStack;
|
|
18
24
|
async function createBuild(projectId, location, stackId, buildInput) {
|
|
19
25
|
const buildId = buildInput.name;
|
|
20
26
|
const res = await client.post(`projects/${projectId}/locations/${location}/stacks/${stackId}/builds`, buildInput, { queryParams: { buildId } });
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createStack = exports.doSetup = void 0;
|
|
3
|
+
exports.createStack = exports.getOrCreateStack = exports.doSetup = void 0;
|
|
4
4
|
const clc = require("colorette");
|
|
5
5
|
const utils = require("../../../utils");
|
|
6
6
|
const logger_1 = require("../../../logger");
|
|
7
7
|
const prompt_1 = require("../../../prompt");
|
|
8
8
|
const constants_1 = require("./constants");
|
|
9
|
-
const
|
|
9
|
+
const repo = require("./repo");
|
|
10
10
|
const poller = require("../../../operation-poller");
|
|
11
11
|
const api_1 = require("../../../api");
|
|
12
12
|
const gcp = require("../../../gcp/frameworks");
|
|
13
13
|
const frameworks_1 = require("../../../gcp/frameworks");
|
|
14
|
+
const error_1 = require("../../../error");
|
|
14
15
|
const frameworksPollerOptions = {
|
|
15
16
|
apiOrigin: api_1.frameworksOrigin,
|
|
16
17
|
apiVersion: frameworks_1.API_VERSION,
|
|
@@ -26,7 +27,7 @@ async function doSetup(setup) {
|
|
|
26
27
|
name: "serviceName",
|
|
27
28
|
type: "input",
|
|
28
29
|
default: "acme-inc-web",
|
|
29
|
-
message: "Create a name for your service [
|
|
30
|
+
message: "Create a name for your service [1-30 characters]",
|
|
30
31
|
}, setup.frameworks);
|
|
31
32
|
await (0, prompt_1.promptOnce)({
|
|
32
33
|
name: "region",
|
|
@@ -45,19 +46,62 @@ async function doSetup(setup) {
|
|
|
45
46
|
message: "How do you want to deploy",
|
|
46
47
|
choices: constants_1.ALLOWED_DEPLOY_METHODS,
|
|
47
48
|
}, setup.frameworks);
|
|
48
|
-
|
|
49
|
-
const cloudBuildConnRepo = await (0, repo_1.linkGitHubRepository)(projectId, setup.frameworks.region, setup.frameworks.serviceName);
|
|
50
|
-
toStack(cloudBuildConnRepo, setup.frameworks.serviceName);
|
|
51
|
-
}
|
|
49
|
+
await getOrCreateStack(projectId, setup);
|
|
52
50
|
}
|
|
53
51
|
exports.doSetup = doSetup;
|
|
54
52
|
function toStack(cloudBuildConnRepo, stackId) {
|
|
55
53
|
return {
|
|
56
54
|
name: stackId,
|
|
57
|
-
codebase: { repository: cloudBuildConnRepo.name, rootDirectory: "/" },
|
|
58
55
|
labels: {},
|
|
59
56
|
};
|
|
60
57
|
}
|
|
58
|
+
async function getOrCreateStack(projectId, setup) {
|
|
59
|
+
const location = setup.frameworks.region;
|
|
60
|
+
const deployMethod = setup.frameworks.deployMethod;
|
|
61
|
+
try {
|
|
62
|
+
return await getExistingStack(projectId, setup, location);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
if (err.status === 404) {
|
|
66
|
+
logger_1.logger.info("Creating new stack.");
|
|
67
|
+
if (deployMethod === "github") {
|
|
68
|
+
const cloudBuildConnRepo = await repo.linkGitHubRepository(projectId, location, setup.frameworks.serviceName);
|
|
69
|
+
const stackDetails = toStack(cloudBuildConnRepo, setup.frameworks.serviceName);
|
|
70
|
+
return await createStack(projectId, location, stackDetails);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
throw new error_1.FirebaseError(`Failed to get or create a stack using the given initialization details: ${err}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
exports.getOrCreateStack = getOrCreateStack;
|
|
80
|
+
async function getExistingStack(projectId, setup, location) {
|
|
81
|
+
let stack = await gcp.getStack(projectId, location, setup.frameworks.serviceName);
|
|
82
|
+
while (stack) {
|
|
83
|
+
setup.frameworks.serviceName = undefined;
|
|
84
|
+
await (0, prompt_1.promptOnce)({
|
|
85
|
+
name: "existingStack",
|
|
86
|
+
type: "confirm",
|
|
87
|
+
default: true,
|
|
88
|
+
message: "A stack already exists for the given serviceName, do you want to use existing stack? (yes/no)",
|
|
89
|
+
}, setup.frameworks);
|
|
90
|
+
if (setup.frameworks.existingStack) {
|
|
91
|
+
logger_1.logger.info("Using the existing stack.");
|
|
92
|
+
return stack;
|
|
93
|
+
}
|
|
94
|
+
await (0, prompt_1.promptOnce)({
|
|
95
|
+
name: "serviceName",
|
|
96
|
+
type: "input",
|
|
97
|
+
default: "acme-inc-web",
|
|
98
|
+
message: "Please enter a new service name [1-30 characters]",
|
|
99
|
+
}, setup.frameworks);
|
|
100
|
+
stack = await gcp.getStack(projectId, location, setup.frameworks.serviceName);
|
|
101
|
+
setup.frameworks.existingStack = undefined;
|
|
102
|
+
}
|
|
103
|
+
return stack;
|
|
104
|
+
}
|
|
61
105
|
async function createStack(projectId, location, stackInput) {
|
|
62
106
|
const op = await gcp.createStack(projectId, location, stackInput);
|
|
63
107
|
const stack = await poller.pollOperation(Object.assign(Object.assign({}, frameworksPollerOptions), { pollerName: `create-${projectId}-${location}-${stackInput.name}`, operationResourceName: op.name }));
|
|
@@ -32,7 +32,7 @@ async function linkGitHubRepository(projectId, location, stackId) {
|
|
|
32
32
|
await utils.openInBrowser("https://github.com/apps/google-cloud-build/installations/new");
|
|
33
33
|
await (0, prompt_1.promptOnce)({
|
|
34
34
|
type: "input",
|
|
35
|
-
message: "Press
|
|
35
|
+
message: "Press ENTER once you have finished configuring your installation's access settings.",
|
|
36
36
|
});
|
|
37
37
|
remoteUri = await promptRepositoryURI(projectId, location, connectionId);
|
|
38
38
|
}
|
package/lib/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.openInBrowser = exports.connectableHostname = exports.randomInt = exports.debounce = exports.last = exports.cloneDeep = exports.groupBy = exports.assertIsStringOrUndefined = exports.assertIsNumber = exports.assertIsString = exports.thirtyDaysFromNow = exports.isRunningInWSL = exports.isCloudEnvironment = exports.datetimeString = exports.createDestroyer = exports.promiseWithSpinner = exports.setupLoggers = exports.tryParse = exports.tryStringify = exports.promiseProps = exports.withTimeout = exports.promiseWhile = exports.promiseAllSettled = exports.getFunctionsEventProvider = exports.endpoint = exports.makeActiveProject = exports.streamToString = exports.stringToStream = exports.explainStdin = exports.allSettled = exports.reject = exports.logLabeledError = exports.logLabeledWarning = exports.logWarning = exports.logLabeledBullet = exports.logBullet = exports.logLabeledSuccess = exports.logSuccess = exports.addSubdomain = exports.addDatabaseNamespace = exports.getDatabaseViewDataUrl = exports.getDatabaseUrl = exports.envOverride = exports.getInheritedOption = exports.consoleUrl = exports.envOverrides = void 0;
|
|
3
|
+
exports.openInBrowser = exports.connectableHostname = exports.randomInt = exports.debounce = exports.last = exports.cloneDeep = exports.groupBy = exports.assertIsStringOrUndefined = exports.assertIsNumber = exports.assertIsString = exports.thirtyDaysFromNow = exports.isRunningInWSL = exports.isVSCodeExtension = exports.isCloudEnvironment = exports.datetimeString = exports.createDestroyer = exports.promiseWithSpinner = exports.setupLoggers = exports.tryParse = exports.tryStringify = exports.promiseProps = exports.withTimeout = exports.promiseWhile = exports.promiseAllSettled = exports.getFunctionsEventProvider = exports.endpoint = exports.makeActiveProject = exports.streamToString = exports.stringToStream = exports.explainStdin = exports.allSettled = exports.reject = exports.logLabeledError = exports.logLabeledWarning = exports.logWarning = exports.logLabeledBullet = exports.logBullet = exports.logLabeledSuccess = exports.logSuccess = exports.addSubdomain = exports.addDatabaseNamespace = exports.getDatabaseViewDataUrl = exports.getDatabaseUrl = exports.envOverride = exports.getInheritedOption = exports.consoleUrl = exports.envOverrides = void 0;
|
|
4
4
|
const _ = require("lodash");
|
|
5
5
|
const url = require("url");
|
|
6
6
|
const clc = require("colorette");
|
|
@@ -367,6 +367,10 @@ function isCloudEnvironment() {
|
|
|
367
367
|
return !!process.env.CODESPACES || !!process.env.GOOGLE_CLOUD_WORKSTATIONS;
|
|
368
368
|
}
|
|
369
369
|
exports.isCloudEnvironment = isCloudEnvironment;
|
|
370
|
+
function isVSCodeExtension() {
|
|
371
|
+
return !!process.env.VSCODE_CWD;
|
|
372
|
+
}
|
|
373
|
+
exports.isVSCodeExtension = isVSCodeExtension;
|
|
370
374
|
function isRunningInWSL() {
|
|
371
375
|
return !!process.env.WSL_DISTRO_NAME;
|
|
372
376
|
}
|