@nu-art/build-and-install 0.204.35 → 0.204.37

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.
@@ -0,0 +1,21 @@
1
+ import { Package_FirebaseFunctionsApp } from '../../core/types';
2
+ export declare class CommandExecutor_FirebaseFunction {
3
+ static staggerCount: number;
4
+ private readonly PROXY_PID_LOG;
5
+ private readonly PROXY_KILL_LOG;
6
+ private readonly EMULATOR_PID_LOG;
7
+ private readonly EMULATOR_KILL_LOG;
8
+ private readonly pkg;
9
+ private readonly commandos;
10
+ private listeners;
11
+ private debugMode?;
12
+ constructor(pkg: Package_FirebaseFunctionsApp);
13
+ private initListeners;
14
+ private clearPorts;
15
+ private runProxy;
16
+ private runEmulator;
17
+ private getPID;
18
+ execute(): Promise<this>;
19
+ kill(): Promise<void>;
20
+ setDebug(debug: boolean): void;
21
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandExecutor_FirebaseFunction = void 0;
4
+ const nvm_1 = require("@nu-art/commando/cli/nvm");
5
+ const basic_1 = require("@nu-art/commando/cli/basic");
6
+ const cli_1 = require("@nu-art/commando/core/cli");
7
+ const ts_common_1 = require("@nu-art/ts-common");
8
+ class CommandExecutor_FirebaseFunction {
9
+ constructor(pkg) {
10
+ this.PROXY_PID_LOG = '_PROXY_PID_';
11
+ this.PROXY_KILL_LOG = '_PROXY_KILLED_';
12
+ this.EMULATOR_PID_LOG = '_EMULATOR_PID_';
13
+ this.EMULATOR_KILL_LOG = '_EMULATOR_KILLED_';
14
+ this.pkg = pkg;
15
+ this.commandos = {
16
+ emulator: nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic),
17
+ proxy: nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic),
18
+ };
19
+ this.initListeners();
20
+ }
21
+ //######################### Inner Logic #########################
22
+ initListeners() {
23
+ this.listeners = {
24
+ proxy: {
25
+ pid: new cli_1.CommandoCLIKeyValueListener(new RegExp(`${this.PROXY_PID_LOG}=(\\d+)`)),
26
+ kill: new cli_1.CommandoCLIListener(() => this.commandos.proxy.close(), this.PROXY_KILL_LOG),
27
+ },
28
+ emulator: {
29
+ pid: new cli_1.CommandoCLIKeyValueListener(new RegExp(`${this.EMULATOR_PID_LOG}=(\\d+)`)),
30
+ kill: new cli_1.CommandoCLIListener(() => this.commandos.emulator.close(), this.EMULATOR_KILL_LOG),
31
+ }
32
+ };
33
+ this.listeners.proxy.kill.listen(this.commandos.proxy);
34
+ this.listeners.proxy.pid.listen(this.commandos.proxy);
35
+ this.listeners.emulator.kill.listen(this.commandos.emulator);
36
+ this.listeners.emulator.pid.listen(this.commandos.emulator);
37
+ }
38
+ async clearPorts() {
39
+ const allPorts = Array.from({ length: 10 }, (_, i) => `${this.pkg.envConfig.basePort + i}`);
40
+ await nvm_1.NVM.createCommando(basic_1.Cli_Basic)
41
+ .setUID(this.pkg.name)
42
+ .debug()
43
+ .append(`array=($(lsof -ti:${allPorts.join(',')}))`)
44
+ .append(`((\${#array[@]} > 0)) && kill -9 "\${array[@]}"`)
45
+ .append('echo ')
46
+ .execute();
47
+ }
48
+ async runProxy() {
49
+ await this.commandos.proxy
50
+ .setUID(this.pkg.name)
51
+ .cd(this.pkg.path)
52
+ .append('ts-node src/main/proxy.ts &')
53
+ .append('pid=$!')
54
+ .append(`echo "${this.PROXY_PID_LOG}=\${pid}"`)
55
+ .append(`wait \$pid`)
56
+ .append(`echo "${this.PROXY_KILL_LOG} \${pid}"`)
57
+ .execute();
58
+ }
59
+ async runEmulator() {
60
+ await this.commandos.emulator
61
+ .setUID(this.pkg.name)
62
+ .cd(this.pkg.path)
63
+ .append(`firebase emulators:start --export-on-exit --import=.trash/data ${this.debugMode ? `--inspect-functions ${this.pkg.envConfig.ssl}` : ''} &`)
64
+ .append('pid=$!')
65
+ .append(`echo "${this.EMULATOR_PID_LOG}=\${pid}"`)
66
+ .append(`wait \$pid`)
67
+ .append(`echo "${this.EMULATOR_KILL_LOG} \${pid}"`)
68
+ .execute();
69
+ }
70
+ getPID(listener) {
71
+ const pid = Number(listener.getValue());
72
+ return isNaN(pid) ? undefined : pid;
73
+ }
74
+ //######################### Functions #########################
75
+ async execute() {
76
+ await (0, ts_common_1.sleep)(ts_common_1.Second * CommandExecutor_FirebaseFunction.staggerCount++);
77
+ await this.clearPorts();
78
+ await this.runProxy();
79
+ await this.runEmulator();
80
+ return this;
81
+ }
82
+ async kill() {
83
+ const emulatorPid = this.getPID(this.listeners.emulator.pid);
84
+ const proxyPid = this.getPID(this.listeners.proxy.pid);
85
+ await this.commandos.emulator.gracefullyKill(emulatorPid);
86
+ await this.commandos.proxy.gracefullyKill(proxyPid);
87
+ }
88
+ setDebug(debug) {
89
+ this.debugMode = debug;
90
+ }
91
+ }
92
+ CommandExecutor_FirebaseFunction.staggerCount = 0;
93
+ exports.CommandExecutor_FirebaseFunction = CommandExecutor_FirebaseFunction;
@@ -0,0 +1,15 @@
1
+ import { Package_FirebaseHostingApp } from '../../core/types';
2
+ export declare class CommandExecutor_FirebaseHosting {
3
+ private readonly APP_PID_LOG;
4
+ private readonly APP_KILL_LOG;
5
+ private readonly pkg;
6
+ private readonly commando;
7
+ private listeners;
8
+ constructor(pkg: Package_FirebaseHostingApp);
9
+ private initListeners;
10
+ private getPID;
11
+ private clearPorts;
12
+ private runApp;
13
+ execute(): Promise<this>;
14
+ kill(): Promise<void>;
15
+ }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandExecutor_FirebaseHosting = void 0;
4
+ const nvm_1 = require("@nu-art/commando/cli/nvm");
5
+ const ts_common_1 = require("@nu-art/ts-common");
6
+ const basic_1 = require("@nu-art/commando/cli/basic");
7
+ const cli_1 = require("@nu-art/commando/core/cli");
8
+ class CommandExecutor_FirebaseHosting {
9
+ constructor(pkg) {
10
+ this.APP_PID_LOG = '_APP_PID_';
11
+ this.APP_KILL_LOG = '_APP_KILLED_';
12
+ if (!pkg.envConfig.hostingPort)
13
+ throw new ts_common_1.BadImplementationException(`Package ${pkg.name} missing hosting port in envConfig`);
14
+ this.pkg = pkg;
15
+ this.commando = nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic);
16
+ this.initListeners();
17
+ }
18
+ //######################### Inner Logic #########################
19
+ initListeners() {
20
+ this.listeners = {
21
+ pid: new cli_1.CommandoCLIKeyValueListener(new RegExp(`${this.APP_PID_LOG}=(\\d+)`)),
22
+ kill: new cli_1.CommandoCLIListener(() => this.commando.close(), this.APP_KILL_LOG),
23
+ };
24
+ this.listeners.pid.listen(this.commando);
25
+ this.listeners.kill.listen(this.commando);
26
+ }
27
+ getPID() {
28
+ const pid = Number(this.listeners.pid.getValue());
29
+ return isNaN(pid) ? undefined : pid;
30
+ }
31
+ async clearPorts() {
32
+ await nvm_1.NVM.createCommando(basic_1.Cli_Basic)
33
+ .setUID(this.pkg.name)
34
+ .debug()
35
+ .append(`array=($(lsof -ti:${[this.pkg.envConfig.hostingPort].join(',')}))`)
36
+ .append(`((\${#array[@]} > 0)) && kill -9 "\${array[@]}"`)
37
+ .append('echo ')
38
+ .execute();
39
+ }
40
+ async runApp() {
41
+ await this.commando
42
+ .setUID(this.pkg.name)
43
+ .cd(this.pkg.path)
44
+ .append(`npm run start &`)
45
+ .append('pid=$!')
46
+ .append(`echo "${this.APP_PID_LOG}=\${pid}"`)
47
+ .append(`wait \$pid`)
48
+ .append(`echo "${this.APP_KILL_LOG} \${pid}"`)
49
+ .execute();
50
+ }
51
+ //######################### Functions #########################
52
+ async execute() {
53
+ await this.clearPorts();
54
+ await this.runApp();
55
+ return this;
56
+ }
57
+ async kill() {
58
+ const appPid = this.getPID();
59
+ await this.commando.gracefullyKill(appPid);
60
+ }
61
+ }
62
+ exports.CommandExecutor_FirebaseHosting = CommandExecutor_FirebaseHosting;
@@ -0,0 +1,2 @@
1
+ export * from './CommandExecutor_FirebaseFunction';
2
+ export * from './CommandExecutor_FirebaseHosting';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./CommandExecutor_FirebaseFunction"), exports);
18
+ __exportStar(require("./CommandExecutor_FirebaseHosting"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/build-and-install",
3
- "version": "0.204.35",
3
+ "version": "0.204.37",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "TacB0sS",
package/phases/phases.js CHANGED
@@ -43,6 +43,7 @@ const project_manager_1 = require("../project-manager");
43
43
  const ProjectScreen_1 = require("../screen/ProjectScreen");
44
44
  const cli_1 = require("@nu-art/commando/core/cli");
45
45
  const RunningProcessLogs_1 = require("../screen/RunningProcessLogs");
46
+ const command_executors_1 = require("../logic/command-executors");
46
47
  const CONST_ThunderstormVersionKey = 'THUNDERSTORM_SDK_VERSION';
47
48
  const CONST_ThunderstormDependencyKey = 'THUNDERSTORM_DEPENDENCY_VERSION';
48
49
  const CONST_ProjectVersionKey = 'APP_VERSION';
@@ -52,7 +53,6 @@ const CONST_RunningRoot = process.cwd();
52
53
  const CONST_VersionApp = 'version-app.json';
53
54
  const pathToProjectTS_Config = (0, tools_1.convertToFullPath)(`./.config/${CONST_TS_Config}`);
54
55
  const pathToProjectEslint = (0, tools_1.convertToFullPath)('./.config/.eslintrc.js');
55
- const runInDebug = false;
56
56
  const CommandoLibs = ['commando', 'build-and-install', 'ts-common'];
57
57
  exports.Phase_PrintHelp = {
58
58
  type: 'project',
@@ -582,7 +582,6 @@ exports.Phase_CompileWatch = {
582
582
  }
583
583
  };
584
584
  let runningAppsLogs;
585
- let counter = 0;
586
585
  exports.Phase_Launch = {
587
586
  type: 'package',
588
587
  name: 'launch',
@@ -611,70 +610,21 @@ exports.Phase_Launch = {
611
610
  ts_common_1.BeLogged.addClient(logClient);
612
611
  projectScreen.updateOrCreatePackage(pkg.name, 'Launching...');
613
612
  if (pkg.type === 'firebase-functions-app') {
614
- //Stagger app initialization
615
- await (0, ts_common_1.sleep)(1000 * counter++);
616
613
  runningAppsLogs.registerApp(pkg.name, logClient);
617
- //Make sure app ports are released
618
- const allPorts = Array.from({ length: 10 }, (_, i) => `${pkg.envConfig.basePort + i}`);
619
- await nvm_1.NVM.createCommando(basic_1.Cli_Basic)
620
- .setUID(pkg.name).debug()
621
- .append(`array=($(lsof -ti:${allPorts.join(',')}))`)
622
- .append(`((\${#array[@]} > 0)) && kill -9 "\${array[@]}"`)
623
- .append('echo ')
624
- .execute();
625
- const KILL_CONFIRM_LOG = `KILL PROCESS`;
626
- const PROXY_PID_PROCESS = 'PROXY_PID_PROCESS';
627
- const EMULATOR_PID_PROCESS = 'EMULATOR_PID_PROCESS';
628
- const proxyCommando = nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic);
629
- //Listen on proxy kill command & proxy pid
630
- const proxyPIDListener = new cli_1.CommandoCLIKeyValueListener(new RegExp(`${PROXY_PID_PROCESS}=(\\d+)`));
631
- new cli_1.CommandoCLIListener(() => proxyCommando.close(), KILL_CONFIRM_LOG).listen(proxyCommando);
632
- proxyPIDListener.listen(proxyCommando)
633
- .setUID(pkg.name)
634
- .cd(pkg.path)
635
- .append('echo ZE ZEVEL1')
636
- .append('ts-node src/main/proxy.ts &')
637
- .append('pid=$!')
638
- .append(`echo "${PROXY_PID_PROCESS}=\${pid}"`)
639
- .append(`wait \$pid`)
640
- .append(`echo "${KILL_CONFIRM_LOG} \${pid}"`);
641
- const emulatorCommando = nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic);
642
- //Listen on emulator kill command & emulator pid
643
- const emulatorPIDListener = new cli_1.CommandoCLIKeyValueListener(new RegExp(`${EMULATOR_PID_PROCESS}=(\\d+)`));
644
- new cli_1.CommandoCLIListener(() => emulatorCommando.close(), KILL_CONFIRM_LOG).listen(emulatorCommando);
645
- emulatorPIDListener.listen(emulatorCommando)
646
- .setUID(pkg.name)
647
- .cd(pkg.path)
648
- .append('echo ZE ZEVEL2')
649
- .append(`firebase emulators:start --export-on-exit --import=.trash/data ${runInDebug ? `--inspect-functions ${pkg.envConfig.ssl}` : ''} &`)
650
- .append('pid=$!')
651
- .append(`echo "${EMULATOR_PID_PROCESS}=\${pid}"`)
652
- .append(`wait \$pid`)
653
- .append(`echo "${KILL_CONFIRM_LOG} \${pid}"`);
654
- await proxyCommando.execute();
655
- await emulatorCommando.execute();
614
+ const executor = await new command_executors_1.CommandExecutor_FirebaseFunction(pkg).execute();
656
615
  runningAppsLogs.addOnTerminateCallback(async () => {
657
- const emulatorPid = Number(emulatorPIDListener.getValue());
658
- const proxyPid = Number(proxyPIDListener.getValue());
659
- await emulatorCommando.gracefullyKill(isNaN(emulatorPid) ? undefined : emulatorPid);
660
- await proxyCommando.gracefullyKill(isNaN(proxyPid) ? undefined : proxyPid);
616
+ await executor.kill();
661
617
  runningAppsLogs.unregisterApp(pkg.name);
662
618
  });
663
619
  return;
664
620
  }
665
621
  if (pkg.type === 'firebase-hosting-app') {
666
622
  runningAppsLogs.registerApp(pkg.name, logClient);
667
- if (!pkg.envConfig.hostingPort)
668
- throw new ts_common_1.BadImplementationException('Missing hosting port in envConfig');
669
- return nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic)
670
- .setUID(pkg.name).debug()
671
- .cd(pkg.path)
672
- .append('echo ZE ZEVEL3')
673
- .append(`array=($(lsof -ti:${[pkg.envConfig.hostingPort].join(',')}))`)
674
- .append(`((\${#array[@]} > 0)) && kill -9 "\${array[@]}"`)
675
- .append(`nvm use`)
676
- .append(`npm run start`)
677
- .execute();
623
+ const executor = await new command_executors_1.CommandExecutor_FirebaseHosting(pkg).execute();
624
+ runningAppsLogs.addOnTerminateCallback(async () => {
625
+ await executor.kill();
626
+ runningAppsLogs.unregisterApp(pkg.name);
627
+ });
678
628
  }
679
629
  projectScreen.updateOrCreatePackage(pkg.name, 'Died');
680
630
  }