@nu-art/build-and-install 0.204.91 → 0.204.93

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 (36) hide show
  1. package/build-and-install.js +0 -3
  2. package/package.json +1 -1
  3. package/v2/phase-runner/PhaseRunner.js +3 -3
  4. package/v2/unit/core/BaseUnit.d.ts +11 -4
  5. package/v2/unit/core/BaseUnit.js +61 -9
  6. package/v2/unit/core/Unit_Python.d.ts +0 -4
  7. package/v2/unit/core/Unit_Python.js +5 -19
  8. package/v2/unit/core/Unit_Typescript.js +3 -3
  9. package/v2/unit/core/Unit_TypescriptLib.d.ts +1 -0
  10. package/v2/unit/core/Unit_TypescriptLib.js +17 -22
  11. package/v2/unit/core/Unit_TypescriptProject.js +16 -10
  12. package/v2/unit/firebase-units/Unit_FirebaseFunctionsApp.js +17 -26
  13. package/v2/unit/firebase-units/Unit_FirebaseHostingApp.d.ts +1 -5
  14. package/v2/unit/firebase-units/Unit_FirebaseHostingApp.js +20 -35
  15. package/v2/unit/tools/tools.d.ts +2 -0
  16. package/v2/unit/tools/tools.js +16 -0
  17. package/logic/ProjectManager.d.ts +0 -49
  18. package/logic/ProjectManager.js +0 -271
  19. package/logic/command-executors/CommandExecutor_FirebaseFunction.d.ts +0 -21
  20. package/logic/command-executors/CommandExecutor_FirebaseFunction.js +0 -71
  21. package/logic/command-executors/CommandExecutor_FirebaseHosting.d.ts +0 -13
  22. package/logic/command-executors/CommandExecutor_FirebaseHosting.js +0 -48
  23. package/logic/command-executors/CommandExecutor_Python.d.ts +0 -15
  24. package/logic/command-executors/CommandExecutor_Python.js +0 -53
  25. package/logic/command-executors/index.d.ts +0 -2
  26. package/logic/command-executors/index.js +0 -18
  27. package/logic/map-project-packages.d.ts +0 -4
  28. package/logic/map-project-packages.js +0 -128
  29. package/phases/phases.d.ts +0 -24
  30. package/phases/phases.js +0 -775
  31. package/project-manager.d.ts +0 -4
  32. package/project-manager.js +0 -9
  33. package/screen/ProjectScreen.d.ts +0 -31
  34. package/screen/ProjectScreen.js +0 -140
  35. package/screen/RunningProcessLogs.d.ts +0 -17
  36. package/screen/RunningProcessLogs.js +0 -137
@@ -6,11 +6,11 @@ const params_1 = require("../../../core/params/params");
6
6
  const ts_common_1 = require("@nu-art/ts-common");
7
7
  const fs_1 = require("fs");
8
8
  const consts_1 = require("../../../core/consts");
9
- const nvm_1 = require("@nu-art/commando/cli/nvm");
10
- const basic_1 = require("@nu-art/commando/cli/basic");
11
9
  const RunnerParams_1 = require("../../phase-runner/RunnerParams");
12
10
  const tools_1 = require("@nu-art/commando/shell/tools");
13
11
  const runner_dispatchers_1 = require("../runner-dispatchers");
12
+ const nvm_1 = require("@nu-art/commando/shell/plugins/nvm");
13
+ const basic_1 = require("@nu-art/commando/shell/plugins/basic");
14
14
  const CONST_VersionApp = 'version-app.json';
15
15
  class Unit_FirebaseHostingApp extends core_1.Unit_TypescriptLib {
16
16
  constructor(config) {
@@ -18,6 +18,11 @@ class Unit_FirebaseHostingApp extends core_1.Unit_TypescriptLib {
18
18
  this.addToClassStack(Unit_FirebaseHostingApp);
19
19
  runner_dispatchers_1.dispatcher_WatchEvent.removeListener(this);
20
20
  }
21
+ async init(setInitialized = true) {
22
+ await super.init(setInitialized);
23
+ if (!this.config.firebaseConfig.hostingPort)
24
+ throw new ts_common_1.BadImplementationException(`Unit ${this.config.label} missing hosting port in firebaseConfig`);
25
+ }
21
26
  //######################### Phase Implementations #########################
22
27
  async resolveConfigs() {
23
28
  await this.resolveHostingRC();
@@ -25,17 +30,15 @@ class Unit_FirebaseHostingApp extends core_1.Unit_TypescriptLib {
25
30
  await this.resolveHostingRuntimeConfig();
26
31
  }
27
32
  async compile() {
28
- this.setStatus('Compile');
33
+ this.setStatus('Compiling', 'start');
29
34
  await this.resolveTSConfig();
30
35
  await this.clearOutputDir();
31
36
  await this.createAppVersionFile();
32
37
  await this.compileImpl();
33
- this.setStatus('Compiled');
38
+ this.setStatus('Compiled', 'end');
34
39
  }
35
40
  async launch() {
36
41
  this.setStatus('Launching');
37
- await this.initLaunch();
38
- await this.clearPorts();
39
42
  await this.runApp();
40
43
  }
41
44
  async deployFrontend() {
@@ -93,11 +96,10 @@ class Unit_FirebaseHostingApp extends core_1.Unit_TypescriptLib {
93
96
  }
94
97
  //######################### Compile Logic #########################
95
98
  async compileImpl() {
96
- await nvm_1.NVM
97
- .createInteractiveCommando(basic_1.Cli_Basic)
99
+ const commando = this.allocateCommando(nvm_1.Commando_NVM, basic_1.Commando_Basic).applyNVM()
98
100
  .cd(this.runtime.pathTo.pkg)
99
- .append(`ENV=${params_1.RuntimeParams.environment} npm run build`)
100
- .execute();
101
+ .append(`ENV=${params_1.RuntimeParams.environment} npm run build`);
102
+ await this.executeAsyncCommando(commando);
101
103
  }
102
104
  async createAppVersionFile() {
103
105
  //Writing the file to the package source instead of the output is fine,
@@ -108,39 +110,22 @@ class Unit_FirebaseHostingApp extends core_1.Unit_TypescriptLib {
108
110
  await fs_1.promises.writeFile(targetPath, fileContent, { encoding: 'utf-8' });
109
111
  }
110
112
  //######################### Launch Logic #########################
111
- async initLaunch() {
112
- if (!this.config.firebaseConfig.hostingPort)
113
- throw new ts_common_1.BadImplementationException(`Unit ${this.config.label} missing hosting port in firebaseConfig`);
114
- this.launchCommando = nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic)
113
+ async runApp() {
114
+ const commando = this.allocateCommando(nvm_1.Commando_NVM).applyNVM()
115
115
  .setUID(this.config.key)
116
- .cd(this.runtime.pathTo.pkg);
117
- }
118
- async clearPorts() {
119
- await this.launchCommando
116
+ .cd(this.runtime.pathTo.pkg)
120
117
  .append(`array=($(lsof -ti:${[this.config.firebaseConfig.hostingPort].join(',')}))`)
121
118
  .append(`((\${#array[@]} > 0)) && kill -9 "\${array[@]}"`)
122
119
  .append('echo ')
123
- .execute();
124
- }
125
- async runApp() {
126
- await this.launchCommando
127
- .append('npm run start')
128
- .executeAsync(pid => this.hostingPid = pid);
129
- }
130
- async kill() {
131
- var _a;
132
- if (!this.launchCommando)
133
- return;
134
- this.logWarning(`Killing unit - ${this.config.label}`);
135
- await ((_a = this.launchCommando) === null || _a === void 0 ? void 0 : _a.gracefullyKill(this.hostingPid));
136
- this.logWarning(`Unit killed - ${this.config.label}`);
120
+ .append('npm run start');
121
+ return this.executeAsyncCommando(commando);
137
122
  }
138
123
  //######################### Deploy Logic #########################
139
124
  async deployImpl() {
140
- await nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic)
125
+ const commando = this.allocateCommando(nvm_1.Commando_NVM).applyNVM()
141
126
  .cd(this.runtime.pathTo.pkg)
142
- .append(`firebase --debug deploy --only hosting`)
143
- .execute();
127
+ .append(`firebase --debug deploy --only hosting`);
128
+ return this.executeAsyncCommando(commando);
144
129
  }
145
130
  }
146
131
  exports.Unit_FirebaseHostingApp = Unit_FirebaseHostingApp;
@@ -0,0 +1,2 @@
1
+ import { PackageJson } from '../../../core/types';
2
+ export declare function convertPackageJSONTemplateToPackJSON_Value(template: PackageJson, value: (value: string, key?: string) => string): PackageJson;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertPackageJSONTemplateToPackJSON_Value = void 0;
4
+ const ts_common_1 = require("@nu-art/ts-common");
5
+ function convertPackageJSONTemplateToPackJSON_Value(template, value) {
6
+ let workspacePackageJsonAsString = (0, ts_common_1.__stringify)(template, true);
7
+ let match = null;
8
+ do {
9
+ match = workspacePackageJsonAsString.match(/"(.*?)": ?"\$([A-Z_]+?)"/);
10
+ if (match === null || match === void 0 ? void 0 : match[0])
11
+ workspacePackageJsonAsString = workspacePackageJsonAsString.replace(new RegExp(`\\$${match[2]}`), value(match[2], match[1]));
12
+ } while (match);
13
+ const packageJson = JSON.parse(workspacePackageJsonAsString);
14
+ return packageJson;
15
+ }
16
+ exports.convertPackageJSONTemplateToPackJSON_Value = convertPackageJSONTemplateToPackJSON_Value;
@@ -1,49 +0,0 @@
1
- import { RuntimePackage, RuntimePackage_WithOutput } from '../core/types';
2
- import { Logger } from '@nu-art/ts-common';
3
- import { RunningStatus } from '../defaults/consts';
4
- export declare const PackageBuildPhaseType_Package: "package";
5
- export declare const PackageBuildPhaseType_PackageWithOutput: "package-with-output";
6
- export declare const PackageBuildPhaseType_Project: "project";
7
- type BuildPhase_Base = {
8
- name: string;
9
- terminatingPhase?: boolean;
10
- breakAfterPhase?: boolean;
11
- mandatoryPhases?: BuildPhase[];
12
- isMandatory?: boolean;
13
- };
14
- type BuildPhase_Package = BuildPhase_Base & {
15
- type: typeof PackageBuildPhaseType_Package;
16
- action: (pkg: RuntimePackage) => Promise<any>;
17
- filter?: (pkg: RuntimePackage) => Promise<boolean>;
18
- };
19
- type BuildPhase_PackageWithOutput = BuildPhase_Base & {
20
- type: typeof PackageBuildPhaseType_PackageWithOutput;
21
- action: (pkg: RuntimePackage_WithOutput) => Promise<any>;
22
- filter?: (pkg: RuntimePackage_WithOutput) => Promise<boolean>;
23
- };
24
- type BuildPhase_Project = BuildPhase_Base & {
25
- type: 'project';
26
- action: () => Promise<any>;
27
- filter?: () => Promise<boolean>;
28
- };
29
- export type BuildPhase = BuildPhase_Package | BuildPhase_PackageWithOutput | BuildPhase_Project;
30
- export declare class ProjectManager extends Logger {
31
- private phases;
32
- private dryRun;
33
- private terminate;
34
- private prevRunningStatus?;
35
- private readonly projectScreen;
36
- private logger?;
37
- constructor();
38
- clearLogger(): void;
39
- showAllLogs(): void;
40
- showPrettyLogs(): void;
41
- private loadPackage;
42
- registerPhase(phase: BuildPhase): void;
43
- updateRunningStatus: (runningStatus?: RunningStatus) => Promise<void>;
44
- prepare(phases?: BuildPhase[], index?: number): Promise<(() => Promise<void>) | undefined>;
45
- private static isAborted;
46
- execute(phases?: BuildPhase[], prevRunningStatus?: RunningStatus, signal?: AbortSignal): Promise<void>;
47
- executePhase(phaseKey: string, prevRunningStatus?: RunningStatus, signal?: AbortSignal): Promise<void>;
48
- }
49
- export {};
@@ -1,271 +0,0 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.ProjectManager = exports.PackageBuildPhaseType_Project = exports.PackageBuildPhaseType_PackageWithOutput = exports.PackageBuildPhaseType_Package = void 0;
27
- const ts_common_1 = require("@nu-art/ts-common");
28
- const params_1 = require("../core/params/params");
29
- const tools_1 = require("@nu-art/commando/shell/tools");
30
- const map_project_packages_1 = require("./map-project-packages");
31
- const consts_1 = require("../core/consts");
32
- const fs = __importStar(require("fs"));
33
- const fs_1 = require("fs");
34
- const consts_2 = require("../defaults/consts");
35
- const MemStorage_1 = require("@nu-art/ts-common/mem-storage/MemStorage");
36
- const project_manager_1 = require("../project-manager");
37
- const ProjectScreen_1 = require("../screen/ProjectScreen");
38
- exports.PackageBuildPhaseType_Package = 'package';
39
- exports.PackageBuildPhaseType_PackageWithOutput = 'package-with-output';
40
- exports.PackageBuildPhaseType_Project = 'project';
41
- const mapToName = (item) => item.name;
42
- function resolveAllMandatoryPhases(phase) {
43
- let result = [phase];
44
- if (phase.mandatoryPhases) {
45
- for (const childPhase of phase.mandatoryPhases) {
46
- result = result.concat(resolveAllMandatoryPhases(childPhase));
47
- }
48
- }
49
- return (0, ts_common_1.filterDuplicates)(result, result => result.name);
50
- }
51
- ts_common_1.DebugFlag.DefaultLogLevel = ts_common_1.LogLevel.Verbose;
52
- class ProjectManager extends ts_common_1.Logger {
53
- constructor() {
54
- super();
55
- this.phases = [];
56
- this.dryRun = params_1.RuntimeParams.dryRun;
57
- this.terminate = false;
58
- this.updateRunningStatus = async (runningStatus = consts_2.MemKey_RunningStatus.get(undefined)) => {
59
- if (!runningStatus)
60
- return;
61
- if (!fs.existsSync(consts_2.Default_OutputFiles.output))
62
- await fs_1.promises.mkdir(consts_2.Default_OutputFiles.output, { recursive: true });
63
- await fs_1.promises.writeFile(consts_2.Default_OutputFiles.runningStatus, (0, ts_common_1.__stringify)(runningStatus, true));
64
- };
65
- this.projectScreen = new ProjectScreen_1.ProjectScreen([]);
66
- params_1.RuntimeParams.allLogs ? this.showAllLogs() : this.showPrettyLogs();
67
- this.setMinLevel(ts_common_1.LogLevel.Verbose);
68
- this.logInfo('Runtime params:', params_1.RuntimeParams);
69
- }
70
- clearLogger() {
71
- if (this.logger)
72
- ts_common_1.BeLogged.removeConsole(this.logger);
73
- }
74
- showAllLogs() {
75
- var _a;
76
- this.clearLogger();
77
- (_a = this.projectScreen) === null || _a === void 0 ? void 0 : _a.dispose();
78
- ts_common_1.BeLogged.addClient(this.logger = ts_common_1.LogClient_Terminal);
79
- }
80
- showPrettyLogs() {
81
- this.clearLogger();
82
- this.projectScreen.create();
83
- ts_common_1.BeLogged.addClient(this.logger = this.projectScreen.logClient);
84
- }
85
- loadPackage() {
86
- const pathToConfig = (0, tools_1.convertToFullPath)('./.config/project-config.ts');
87
- if (!fs.existsSync(pathToConfig))
88
- throw new ts_common_1.ImplementationMissingException(`Missing ./.config/project-config.ts file, could not find in path: ${pathToConfig}`);
89
- const projectConfig = require(pathToConfig).default;
90
- const packages = (0, map_project_packages_1.mapProjectPackages)(projectConfig);
91
- consts_1.MemKey_Packages.set(packages);
92
- }
93
- registerPhase(phase) {
94
- this.phases.push(phase);
95
- }
96
- async prepare(phases = this.phases, index = 0) {
97
- var _a;
98
- const phasesToRun = [];
99
- let i = index;
100
- for (; i < phases.length; i++) {
101
- const phase = phases[i];
102
- const isNotSamePackageType = phasesToRun[0] && phase.type !== phasesToRun[0].type;
103
- const isNextPhaseANoneValidProjectPackage = phase.type === 'project' && (phase.filter && !(await phase.filter()));
104
- if (isNotSamePackageType) {
105
- if (isNextPhaseANoneValidProjectPackage)
106
- continue;
107
- else
108
- break;
109
- }
110
- if (phase.type !== 'project' || (!phase.filter || await ((_a = phase.filter) === null || _a === void 0 ? void 0 : _a.call(phase))))
111
- phasesToRun.push(phase);
112
- if ((phasesToRun.length > 0 && phase.terminatingPhase) || phase.breakAfterPhase) {
113
- i++;
114
- break;
115
- }
116
- }
117
- if (!phasesToRun.length)
118
- return;
119
- const nextAction = await this.prepare(phases, i);
120
- this.logDebug('Scheduling phases: ', phasesToRun.map(mapToName));
121
- if (phasesToRun[0].type === 'project')
122
- return async () => {
123
- var _a;
124
- if (this.terminate)
125
- return this.logInfo(`Skipping project phases:`, phasesToRun.map(mapToName));
126
- let didRun = false;
127
- for (const phase of phasesToRun) {
128
- if (ProjectManager.isAborted())
129
- return;
130
- // if there's a previous running status and the current phase is the one to continue from clean
131
- if (this.prevRunningStatus && this.prevRunningStatus.phaseKey === phase.name)
132
- delete this.prevRunningStatus;
133
- // keep the current running status updated
134
- if (!this.prevRunningStatus && !phase.terminatingPhase)
135
- consts_2.MemKey_RunningStatus.set({ phaseKey: phase.name });
136
- this.logInfo(`Running project phase: ${phase.name}`);
137
- // if prev running status still exists skip execution
138
- if (this.prevRunningStatus && !phase.isMandatory) {
139
- this.logVerbose('Skipping duo continue');
140
- continue;
141
- }
142
- //Update project screen
143
- (_a = this.projectScreen) === null || _a === void 0 ? void 0 : _a.updateRunningPhase(phase.name);
144
- if (this.dryRun) {
145
- await (0, ts_common_1.sleep)(200);
146
- }
147
- else
148
- await phase.action();
149
- didRun = true;
150
- }
151
- if (didRun && (0, ts_common_1.lastElement)(phasesToRun).terminatingPhase)
152
- this.terminate = true;
153
- await (nextAction === null || nextAction === void 0 ? void 0 : nextAction());
154
- };
155
- return async () => {
156
- let didRun = false;
157
- let didPrintPhase = false;
158
- const phasesRan = [];
159
- const toRunPackages = consts_1.MemKey_Packages.get().packagesDependency.map((packages, i) => {
160
- return async () => {
161
- var _a;
162
- // if there's a previous running status and the current phase is the one to continue from clean
163
- if (phasesToRun.find(phase => { var _a; return phase.name === ((_a = this.prevRunningStatus) === null || _a === void 0 ? void 0 : _a.phaseKey); }) && i === ((_a = this.prevRunningStatus) === null || _a === void 0 ? void 0 : _a.packageDependencyIndex))
164
- delete this.prevRunningStatus;
165
- let didPrintPackages = false;
166
- const values = (0, ts_common_1.flatArray)(packages.map(async (pkg) => {
167
- var _a;
168
- for (const phase of phasesToRun) {
169
- if (ProjectManager.isAborted())
170
- return;
171
- if (!(!phase.filter || await phase.filter(pkg)))
172
- continue;
173
- // keep the current running status updated
174
- if (!this.prevRunningStatus && !phase.terminatingPhase)
175
- consts_2.MemKey_RunningStatus.set({ phaseKey: phase.name, packageDependencyIndex: i });
176
- if (!didPrintPhase) {
177
- // will only be called once per phase
178
- phasesRan.push(phase);
179
- this.logInfo(`Running package phase: ${(0, ts_common_1.__stringify)(phasesToRun.map(mapToName))}`);
180
- didPrintPhase = true;
181
- }
182
- if (!didPrintPackages) {
183
- this.logDebug(` - on packages: ${(0, ts_common_1.__stringify)(packages.map(mapToName))}`);
184
- didPrintPackages = true;
185
- }
186
- didRun = true;
187
- this.logDebug(` - ${pkg.name}:${phase.name}`);
188
- //Update project screen
189
- (_a = this.projectScreen) === null || _a === void 0 ? void 0 : _a.updateRunningPhase(phase.name);
190
- // if prev running status still exists skip execution
191
- if (this.prevRunningStatus && !phase.isMandatory) {
192
- this.logVerbose('Skipping duo continue');
193
- continue;
194
- }
195
- if (this.dryRun) {
196
- await (0, ts_common_1.sleep)(200);
197
- }
198
- else
199
- await phase.action(pkg);
200
- }
201
- }));
202
- await Promise.all(values);
203
- };
204
- });
205
- if (this.terminate)
206
- return this.logInfo(`Skipping packages phases:`, phasesToRun.map(mapToName));
207
- for (const toRunPackage of toRunPackages) {
208
- await toRunPackage();
209
- }
210
- if (didRun && (0, ts_common_1.lastElement)(phasesRan).terminatingPhase)
211
- this.terminate = true;
212
- await (nextAction === null || nextAction === void 0 ? void 0 : nextAction());
213
- };
214
- }
215
- static isAborted() {
216
- try {
217
- return project_manager_1.MemKey_AbortSignal.get().aborted;
218
- }
219
- catch (e) {
220
- return false;
221
- }
222
- }
223
- async execute(phases = this.phases, prevRunningStatus, signal) {
224
- return new MemStorage_1.MemStorage().init(async () => {
225
- //Update the project manager mem key to be used elsewhere in the project
226
- project_manager_1.MemKey_ProjectManager.set(this);
227
- consts_2.MemKey_DefaultFiles.set(consts_2.Default_Files);
228
- // Set default value to memKey
229
- consts_2.MemKey_RunningStatus.set({ phaseKey: '' });
230
- //Set project screen
231
- ProjectScreen_1.MemKey_ProjectScreen.set(this.projectScreen);
232
- const listener = async (status) => {
233
- this.logDebug('SIGINT - running status:', status);
234
- await this.updateRunningStatus();
235
- process.exit(0);
236
- };
237
- process.on('SIGINT', listener);
238
- try {
239
- if (params_1.RuntimeParams.continue)
240
- this.prevRunningStatus = JSON.parse(await fs_1.promises.readFile(consts_2.Default_OutputFiles.runningStatus, { encoding: 'utf-8' }));
241
- }
242
- catch (e) {
243
- this.logError('Failed reading running status', e);
244
- }
245
- this.loadPackage();
246
- if (signal)
247
- project_manager_1.MemKey_AbortSignal.set(signal);
248
- // update prev running status if passed
249
- if (prevRunningStatus) {
250
- this.logWarning('Setting prev running status: ', prevRunningStatus);
251
- this.prevRunningStatus = prevRunningStatus;
252
- }
253
- try {
254
- await (await this.prepare(phases))();
255
- }
256
- catch (e) {
257
- this.logError(e);
258
- }
259
- process.off('SIGINT', listener);
260
- await this.updateRunningStatus();
261
- });
262
- }
263
- async executePhase(phaseKey, prevRunningStatus, signal) {
264
- const phase = this.phases.find(phase => phase.name === phaseKey);
265
- if (!phase)
266
- throw new ts_common_1.BadImplementationException(`No Such Phase: ${phaseKey}`);
267
- const finalPhasesToRun = resolveAllMandatoryPhases(phase).reverse();
268
- return this.execute(finalPhasesToRun, prevRunningStatus, signal);
269
- }
270
- }
271
- exports.ProjectManager = ProjectManager;
@@ -1,21 +0,0 @@
1
- import { Package_FirebaseFunctionsApp } from '../../core/types';
2
- type OnReadyCallback = (pkg: Package_FirebaseFunctionsApp) => Promise<void>;
3
- export declare class CommandExecutor_FirebaseFunction {
4
- static staggerCount: number;
5
- private readonly PROXY_PID_LOG;
6
- private readonly PROXY_KILL_LOG;
7
- private readonly EMULATOR_PID_LOG;
8
- private readonly EMULATOR_KILL_LOG;
9
- private readonly pkg;
10
- private readonly commandos;
11
- private onReadyCallbacks;
12
- constructor(pkg: Package_FirebaseFunctionsApp);
13
- private initListeners;
14
- private clearPorts;
15
- private runProxy;
16
- private runEmulator;
17
- execute(): Promise<this>;
18
- kill(): Promise<void>;
19
- addOnReadyCallback(cb: OnReadyCallback): void;
20
- }
21
- export {};
@@ -1,71 +0,0 @@
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 ts_common_1 = require("@nu-art/ts-common");
7
- const params_1 = require("../../core/params/params");
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.onReadyCallbacks = [];
15
- this.pkg = pkg;
16
- this.commandos = {
17
- emulator: nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic),
18
- proxy: nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic),
19
- };
20
- this.initListeners();
21
- }
22
- //######################### Inner Logic #########################
23
- initListeners() {
24
- }
25
- async clearPorts() {
26
- const allPorts = Array.from({ length: 10 }, (_, i) => `${this.pkg.envConfig.basePort + i}`);
27
- await nvm_1.NVM.createCommando(basic_1.Cli_Basic)
28
- .setUID(this.pkg.name)
29
- .append(`array=($(lsof -ti:${allPorts.join(',')}))`)
30
- .append(`((\${#array[@]} > 0)) && kill -9 "\${array[@]}"`)
31
- .append('echo ')
32
- .execute();
33
- }
34
- async runProxy() {
35
- await this.commandos.proxy
36
- .setUID(this.pkg.name)
37
- .cd(this.pkg.path)
38
- .append('ts-node src/main/proxy.ts &')
39
- .append('pid=$!')
40
- .append(`echo "${this.PROXY_PID_LOG}=\${pid}"`)
41
- .append(`wait \$pid`)
42
- .append(`echo "${this.PROXY_KILL_LOG} \${pid}"`)
43
- .execute();
44
- }
45
- async runEmulator() {
46
- await this.commandos.emulator
47
- .setUID(this.pkg.name)
48
- .cd(this.pkg.path)
49
- .append(`firebase emulators:start --export-on-exit --import=.trash/data ${params_1.RuntimeParams.debugBackend ? `--inspect-functions ${this.pkg.envConfig.debugPort}` : ''} &`)
50
- .append('pid=$!')
51
- .append(`echo "${this.EMULATOR_PID_LOG}=\${pid}"`)
52
- .append(`wait \$pid`)
53
- .append(`echo "${this.EMULATOR_KILL_LOG} \${pid}"`)
54
- .execute();
55
- }
56
- //######################### Functions #########################
57
- async execute() {
58
- await (0, ts_common_1.sleep)(2 * ts_common_1.Second * CommandExecutor_FirebaseFunction.staggerCount++);
59
- await this.clearPorts();
60
- await this.runProxy();
61
- await this.runEmulator();
62
- return this;
63
- }
64
- async kill() {
65
- }
66
- addOnReadyCallback(cb) {
67
- this.onReadyCallbacks.push(cb);
68
- }
69
- }
70
- CommandExecutor_FirebaseFunction.staggerCount = 0;
71
- exports.CommandExecutor_FirebaseFunction = CommandExecutor_FirebaseFunction;
@@ -1,13 +0,0 @@
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
- constructor(pkg: Package_FirebaseHostingApp);
8
- private initListeners;
9
- private clearPorts;
10
- private runApp;
11
- execute(): Promise<this>;
12
- kill(): Promise<void>;
13
- }
@@ -1,48 +0,0 @@
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
- class CommandExecutor_FirebaseHosting {
8
- constructor(pkg) {
9
- this.APP_PID_LOG = '_APP_PID_';
10
- this.APP_KILL_LOG = '_APP_KILLED_';
11
- if (!pkg.envConfig.hostingPort)
12
- throw new ts_common_1.BadImplementationException(`Package ${pkg.name} missing hosting port in envConfig`);
13
- this.pkg = pkg;
14
- this.commando = nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic);
15
- this.initListeners();
16
- }
17
- //######################### Inner Logic #########################
18
- initListeners() {
19
- }
20
- async clearPorts() {
21
- await nvm_1.NVM.createCommando(basic_1.Cli_Basic)
22
- .setUID(this.pkg.name)
23
- .append(`array=($(lsof -ti:${[this.pkg.envConfig.hostingPort].join(',')}))`)
24
- .append(`((\${#array[@]} > 0)) && kill -9 "\${array[@]}"`)
25
- .append('echo ')
26
- .execute();
27
- }
28
- async runApp() {
29
- await this.commando
30
- .setUID(this.pkg.name)
31
- .cd(this.pkg.path)
32
- .append(`npm run start &`)
33
- .append('pid=$!')
34
- .append(`echo "${this.APP_PID_LOG}=\${pid}"`)
35
- .append(`wait \$pid`)
36
- .append(`echo "${this.APP_KILL_LOG} \${pid}"`)
37
- .execute();
38
- }
39
- //######################### Functions #########################
40
- async execute() {
41
- await this.clearPorts();
42
- await this.runApp();
43
- return this;
44
- }
45
- async kill() {
46
- }
47
- }
48
- exports.CommandExecutor_FirebaseHosting = CommandExecutor_FirebaseHosting;
@@ -1,15 +0,0 @@
1
- import { Package_Python } from '../../core/types';
2
- export declare class CommandExecutor_Python {
3
- private readonly APP_PID_LOG;
4
- private readonly APP_KILL_LOG;
5
- private readonly pkg;
6
- private readonly commando;
7
- constructor(pkg: Package_Python);
8
- private initListeners;
9
- private enterVenv;
10
- private setPythonPath;
11
- private runApp;
12
- private clearPorts;
13
- execute(): Promise<void>;
14
- kill(): Promise<void>;
15
- }