@nu-art/build-and-install 0.204.23 → 0.204.25
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Package_FirebaseFunctionsApp, Package_FirebaseHostingAndFunctionApp, Package_FirebaseHostingApp } from '../types';
|
|
1
|
+
import { FirebaseEnvConfig, Package_FirebaseFunctionsApp, Package_FirebaseHostingAndFunctionApp, Package_FirebaseHostingApp } from '../types';
|
|
2
2
|
export declare function createFirebaseHostingConfig<Env extends string>(pkg: Package_FirebaseHostingApp, env: Env): {
|
|
3
3
|
projects: {
|
|
4
4
|
default: string;
|
|
@@ -20,3 +20,5 @@ export declare function createFirebaseFullJSON<Env extends string>(pkg: Package_
|
|
|
20
20
|
finally(onfinally?: (() => void) | null | undefined): Promise<void>;
|
|
21
21
|
[Symbol.toStringTag]: string;
|
|
22
22
|
};
|
|
23
|
+
export declare function getEnvConfig(pkg: Package_FirebaseHostingApp | Package_FirebaseFunctionsApp | Package_FirebaseHostingAndFunctionApp): FirebaseEnvConfig<string>;
|
|
24
|
+
export declare function generateProxyFile(firebasePkg: Package_FirebaseHostingApp | Package_FirebaseFunctionsApp, pathToFile: string): Promise<void>;
|
package/core/package/generate.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createFirebaseFullJSON = exports.writeToFile_FunctionFirebaseJSON = exports.writeToFile_functionFirebaseConfigJSON = exports.writeToFile_HostingFirebaseConfigJSON = exports.writeToFile_HostingFirebaseJSON = exports.createFirebaseRC = exports.createFirebaseFunctionConfig = exports.createFirebaseHostingConfig = void 0;
|
|
3
|
+
exports.generateProxyFile = exports.getEnvConfig = exports.createFirebaseFullJSON = exports.writeToFile_FunctionFirebaseJSON = exports.writeToFile_functionFirebaseConfigJSON = exports.writeToFile_HostingFirebaseConfigJSON = exports.writeToFile_HostingFirebaseJSON = exports.createFirebaseRC = exports.createFirebaseFunctionConfig = exports.createFirebaseHostingConfig = void 0;
|
|
4
4
|
const ts_common_1 = require("@nu-art/ts-common");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const consts_1 = require("../consts");
|
|
7
|
+
const consts_2 = require("../../defaults/consts");
|
|
8
|
+
const params_1 = require("../params/params");
|
|
7
9
|
function createFirebaseHostingConfig(pkg, env) {
|
|
8
10
|
const envConfig = pkg.envConfig.envs.find(_env => _env.env === env);
|
|
9
11
|
if (!envConfig)
|
|
@@ -62,7 +64,7 @@ async function writeToFile_HostingFirebaseConfigJSON(pkg, env) {
|
|
|
62
64
|
appName: `${pkg.name} - (${env})`
|
|
63
65
|
},
|
|
64
66
|
ModuleFE_XHR: {
|
|
65
|
-
origin: envConfig.isLocal ? `https://localhost:${pkg.envConfig.basePort
|
|
67
|
+
origin: envConfig.isLocal ? `https://localhost:${pkg.envConfig.basePort}` : envConfig.backend.url,
|
|
66
68
|
timeout: envConfig.backend.timeout || 30000,
|
|
67
69
|
compress: envConfig.backend.compress || false,
|
|
68
70
|
minLogLevel: envConfig.backend.minLogLevel || false,
|
|
@@ -139,9 +141,7 @@ function getFunctionConfig(pkg, envConfig) {
|
|
|
139
141
|
}
|
|
140
142
|
}
|
|
141
143
|
async function writeToFile_FunctionFirebaseJSON(pkg, env) {
|
|
142
|
-
const envConfig = pkg
|
|
143
|
-
if (!envConfig)
|
|
144
|
-
throw new ts_common_1.BadImplementationException(`Could not find env: ${env}`);
|
|
144
|
+
const envConfig = getEnvConfig(pkg);
|
|
145
145
|
const fileContent = getFunctionConfig(pkg, envConfig);
|
|
146
146
|
await fs_1.promises.writeFile(`${pkg.path}/${consts_1.CONST_FirebaseJSON}`, JSON.stringify(fileContent, null, 2), { encoding: 'utf-8' });
|
|
147
147
|
}
|
|
@@ -155,3 +155,24 @@ function createFirebaseFullJSON(pkg, env) {
|
|
|
155
155
|
return Object.assign(Object.assign({}, hosting), functions);
|
|
156
156
|
}
|
|
157
157
|
exports.createFirebaseFullJSON = createFirebaseFullJSON;
|
|
158
|
+
function getEnvConfig(pkg) {
|
|
159
|
+
const env = params_1.RuntimeParams.environment;
|
|
160
|
+
const envConfig = pkg.envConfig.envs.find(_env => _env.env === env);
|
|
161
|
+
if (!envConfig)
|
|
162
|
+
throw new ts_common_1.BadImplementationException(`No env config for env ${env} in package ${pkg.name}`);
|
|
163
|
+
return envConfig;
|
|
164
|
+
}
|
|
165
|
+
exports.getEnvConfig = getEnvConfig;
|
|
166
|
+
async function generateProxyFile(firebasePkg, pathToFile) {
|
|
167
|
+
var _a, _b;
|
|
168
|
+
const envConfig = getEnvConfig(firebasePkg);
|
|
169
|
+
const defaultFiles = consts_2.MemKey_DefaultFiles.get();
|
|
170
|
+
let fileContent = await fs_1.promises.readFile(defaultFiles.backend.proxy, { encoding: 'utf-8' });
|
|
171
|
+
fileContent = fileContent.replace(/PROJECT_ID/g, `${envConfig.projectId}`);
|
|
172
|
+
fileContent = fileContent.replace(/PROXY_PORT/g, `${firebasePkg.envConfig.basePort}`);
|
|
173
|
+
fileContent = fileContent.replace(/SERVER_PORT/g, `${firebasePkg.envConfig.basePort + 1}`);
|
|
174
|
+
fileContent = fileContent.replace(/PATH_TO_SSL_KEY/g, `${(_a = firebasePkg.envConfig.ssl) === null || _a === void 0 ? void 0 : _a.pathToKey}`);
|
|
175
|
+
fileContent = fileContent.replace(/PATH_TO_SSL_CERTIFICATE/g, `${(_b = firebasePkg.envConfig.ssl) === null || _b === void 0 ? void 0 : _b.pathToCertificate}`);
|
|
176
|
+
await fs_1.promises.writeFile(pathToFile, fileContent, { encoding: 'utf-8' });
|
|
177
|
+
}
|
|
178
|
+
exports.generateProxyFile = generateProxyFile;
|
|
@@ -10,9 +10,9 @@ _express.all('*', (req, res) => {
|
|
|
10
10
|
const qMark = req.originalUrl.indexOf('?');
|
|
11
11
|
const query = qMark > 1 ? req.originalUrl.substring(qMark) : '';
|
|
12
12
|
const path = req.path;
|
|
13
|
-
let url = `http://127.0.0.1:SERVER_PORT/
|
|
13
|
+
let url = `http://127.0.0.1:SERVER_PORT/PROJECT_ID/us-central1/api${path}${query}`;
|
|
14
14
|
if (path.startsWith('/emulatorDownload') || path.startsWith('/emulatorUpload'))
|
|
15
|
-
url = `http://127.0.0.1:SERVER_PORT/
|
|
15
|
+
url = `http://127.0.0.1:SERVER_PORT/PROJECT_ID/us-central1${path}${query}`;
|
|
16
16
|
|
|
17
17
|
console.log(`PROXY ${counter} - [${req.method}] ${url}`);
|
|
18
18
|
|
|
@@ -60,5 +60,5 @@ const options = {
|
|
|
60
60
|
requestCert: false,
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
-
require('https').createServer(options, _express).listen(
|
|
63
|
+
require('https').createServer(options, _express).listen(PROXY_PORT);
|
|
64
64
|
console.log('SSL proxy started!!!');
|
package/package.json
CHANGED
package/phases/phases.js
CHANGED
|
@@ -177,7 +177,6 @@ exports.Phase_ResolveEnv = {
|
|
|
177
177
|
mandatoryPhases: [exports.Phase_ResolveTemplate, exports.Phase_PrepareParams, exports.Phase_SetupProject, exports.Phase_SetWithThunderstorm],
|
|
178
178
|
filter: async (pkg) => pkg.type === 'firebase-functions-app' || pkg.type === 'firebase-hosting-app',
|
|
179
179
|
action: async (pkg) => {
|
|
180
|
-
var _a, _b;
|
|
181
180
|
const firebasePkg = pkg;
|
|
182
181
|
await fs_1.promises.writeFile(`${firebasePkg.path}/${consts_1.CONST_FirebaseRC}`, JSON.stringify((0, generate_1.createFirebaseRC)(firebasePkg, params_1.RuntimeParams.environment), null, 2), { encoding: 'utf-8' });
|
|
183
182
|
const defaultFiles = consts_2.MemKey_DefaultFiles.get();
|
|
@@ -196,14 +195,8 @@ exports.Phase_ResolveEnv = {
|
|
|
196
195
|
catch (e) {
|
|
197
196
|
await fs_1.promises.mkdir(pathToFirebaseConfigFolder, { recursive: true });
|
|
198
197
|
}
|
|
199
|
-
if (firebasePkg.envConfig.ssl)
|
|
200
|
-
|
|
201
|
-
let defaultFileContent = await fs_1.promises.readFile(defaultFiles.backend.proxy, { encoding: 'utf-8' });
|
|
202
|
-
defaultFileContent = defaultFileContent.replace(/SERVER_PORT/g, `${firebasePkg.envConfig.basePort}`);
|
|
203
|
-
defaultFileContent = defaultFileContent.replace(/PATH_TO_SSL_KEY/g, `${(_a = firebasePkg.envConfig.ssl) === null || _a === void 0 ? void 0 : _a.pathToKey}`);
|
|
204
|
-
defaultFileContent = defaultFileContent.replace(/PATH_TO_SSL_CERTIFICATE/g, `${(_b = firebasePkg.envConfig.ssl) === null || _b === void 0 ? void 0 : _b.pathToCertificate}`);
|
|
205
|
-
await fs_1.promises.writeFile(pathToProxyFile, defaultFileContent, { encoding: 'utf-8' });
|
|
206
|
-
}
|
|
198
|
+
if (firebasePkg.envConfig.ssl)
|
|
199
|
+
await (0, generate_1.generateProxyFile)(firebasePkg, `${firebaseFunctionPkg.path}/src/main/proxy.ts`);
|
|
207
200
|
await Promise.all(consts_2.Const_FirebaseConfigKeys.map(async (firebaseConfigKey) => {
|
|
208
201
|
const pathToConfigFile = `${pathToFirebaseConfigFolder}/${consts_2.Const_FirebaseDefaultsKeyToFile[firebaseConfigKey]}`;
|
|
209
202
|
try {
|
|
@@ -620,23 +613,32 @@ exports.Phase_Launch = {
|
|
|
620
613
|
if (pkg.type === 'firebase-functions-app') {
|
|
621
614
|
await (0, ts_common_1.sleep)(1000 * counter++);
|
|
622
615
|
const allPorts = Array.from({ length: 10 }, (_, i) => `${pkg.envConfig.basePort + i}`);
|
|
623
|
-
|
|
616
|
+
runningAppsLogs.registerApp(pkg.name, logClient);
|
|
617
|
+
await nvm_1.NVM.createCommando(basic_1.Cli_Basic)
|
|
624
618
|
.setUID(pkg.name)
|
|
625
|
-
.cd(pkg.path)
|
|
626
|
-
.append(`nvm use`)
|
|
627
619
|
.append(`array=($(lsof -ti:${allPorts.join(',')}))`)
|
|
628
|
-
.append(`((\${#array[@]} > 0)) && kill -9 "\${array[@]}"`)
|
|
629
|
-
command.append(`firebase emulators:start --export-on-exit --import=.trash/data ${runInDebug ? `--inspect-functions ${pkg.envConfig.ssl}` : ''}`);
|
|
630
|
-
runningAppsLogs.registerApp(pkg.name, logClient);
|
|
631
|
-
return command
|
|
620
|
+
.append(`((\${#array[@]} > 0)) && kill -9 "\${array[@]}"`)
|
|
632
621
|
.execute();
|
|
622
|
+
await nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic)
|
|
623
|
+
.setUID(pkg.name)
|
|
624
|
+
.cd(pkg.path)
|
|
625
|
+
.append(`ts-node src/main/proxy.ts`)
|
|
626
|
+
.execute();
|
|
627
|
+
await nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic)
|
|
628
|
+
.setUID(pkg.name)
|
|
629
|
+
.cd(pkg.path)
|
|
630
|
+
.append(`firebase emulators:start --export-on-exit --import=.trash/data ${runInDebug ? `--inspect-functions ${pkg.envConfig.ssl}` : ''}`)
|
|
631
|
+
.execute();
|
|
632
|
+
return;
|
|
633
633
|
}
|
|
634
634
|
if (pkg.type === 'firebase-hosting-app') {
|
|
635
635
|
runningAppsLogs.registerApp(pkg.name, logClient);
|
|
636
|
+
if (!pkg.envConfig.hostingPort)
|
|
637
|
+
throw new ts_common_1.BadImplementationException('Missing hosting port in envConfig');
|
|
636
638
|
return nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic)
|
|
637
639
|
.setUID(pkg.name)
|
|
638
640
|
.cd(pkg.path)
|
|
639
|
-
.append(`array=($(lsof -ti:${[pkg.envConfig.
|
|
641
|
+
.append(`array=($(lsof -ti:${[pkg.envConfig.hostingPort].join(',')}))`)
|
|
640
642
|
.append(`((\${#array[@]} > 0)) && kill -9 "\${array[@]}"`)
|
|
641
643
|
.append(`nvm use`)
|
|
642
644
|
.append(`npm run start`)
|