@nu-art/build-and-install 0.204.67 → 0.204.69

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 (59) hide show
  1. package/build-and-install.js +11 -26
  2. package/core/package/generate.js +5 -3
  3. package/core/params/params.d.ts +3 -2
  4. package/core/params/params.js +16 -4
  5. package/defaults/consts.d.ts +11 -23
  6. package/defaults/consts.js +7 -7
  7. package/package.json +1 -1
  8. package/phases/phases.js +7 -3
  9. package/screen/ProjectScreen.js +0 -1
  10. package/v2/phase/consts.d.ts +53 -0
  11. package/v2/phase/consts.js +146 -0
  12. package/v2/phase/index.d.ts +2 -0
  13. package/v2/phase/index.js +18 -0
  14. package/v2/phase/types.d.ts +9 -0
  15. package/v2/phase/types.js +2 -0
  16. package/v2/phase-runner/PhaseRunner.d.ts +69 -13
  17. package/v2/phase-runner/PhaseRunner.js +392 -32
  18. package/v2/phase-runner/PhaseRunnerDispatcher.d.ts +25 -0
  19. package/v2/phase-runner/PhaseRunnerDispatcher.js +26 -0
  20. package/v2/phase-runner/RunnerParams.d.ts +12 -0
  21. package/v2/phase-runner/RunnerParams.js +9 -0
  22. package/v2/phase-runner/consts.d.ts +7 -0
  23. package/v2/phase-runner/consts.js +9 -0
  24. package/v2/phase-runner/types.d.ts +6 -9
  25. package/v2/phase-runner/types.js +4 -0
  26. package/v2/project/types.d.ts +8 -0
  27. package/v2/project/types.js +2 -0
  28. package/v2/screens/list-screen.d.ts +47 -0
  29. package/v2/screens/list-screen.js +196 -0
  30. package/v2/unit/core/BaseUnit.d.ts +18 -7
  31. package/v2/unit/core/BaseUnit.js +35 -10
  32. package/v2/unit/core/Unit_Python.d.ts +18 -2
  33. package/v2/unit/core/Unit_Python.js +30 -1
  34. package/v2/unit/core/Unit_Typescript.d.ts +15 -13
  35. package/v2/unit/core/Unit_Typescript.js +40 -36
  36. package/v2/unit/core/Unit_TypescriptLib.d.ts +27 -3
  37. package/v2/unit/core/Unit_TypescriptLib.js +98 -4
  38. package/v2/unit/core/Unit_TypescriptProject.d.ts +11 -2
  39. package/v2/unit/core/Unit_TypescriptProject.js +29 -0
  40. package/v2/unit/core/index.d.ts +2 -1
  41. package/v2/unit/core/index.js +2 -1
  42. package/v2/unit/firebase-units/Unit_FirebaseFunctionsApp.d.ts +40 -0
  43. package/v2/unit/firebase-units/Unit_FirebaseFunctionsApp.js +312 -0
  44. package/v2/unit/firebase-units/Unit_FirebaseHostingApp.d.ts +32 -0
  45. package/v2/unit/firebase-units/Unit_FirebaseHostingApp.js +159 -0
  46. package/v2/unit/firebase-units/index.d.ts +2 -0
  47. package/v2/unit/firebase-units/index.js +18 -0
  48. package/v2/unit/thunderstorm.d.ts +291 -0
  49. package/v2/unit/thunderstorm.js +199 -0
  50. package/v2/unit/types.d.ts +7 -0
  51. package/v2/unit/types.js +2 -0
  52. package/v2/BasePackage.d.ts +0 -4
  53. package/v2/BasePackage.js +0 -9
  54. package/v2/ProjectManagerV2.d.ts +0 -8
  55. package/v2/ProjectManagerV2.js +0 -23
  56. package/v2/test/test.d.ts +0 -14
  57. package/v2/test/test.js +0 -85
  58. package/v2/unit/core/types.d.ts +0 -13
  59. package/v2/unit/core/types.js +0 -23
@@ -1,57 +1,417 @@
1
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.PhaseRunner = void 0;
4
27
  const ts_common_1 = require("@nu-art/ts-common");
5
- const BaseUnit_1 = require("../unit/core/BaseUnit");
6
- class PhaseRunner extends BaseUnit_1.BaseUnit {
7
- constructor(phases) {
28
+ const RunnerParams_1 = require("./RunnerParams");
29
+ const core_1 = require("../unit/core");
30
+ const params_1 = require("../../core/params/params");
31
+ const MemStorage_1 = require("@nu-art/ts-common/mem-storage/MemStorage");
32
+ const fs_1 = __importStar(require("fs"));
33
+ const tools_1 = require("@nu-art/commando/core/tools");
34
+ const thunderstorm_1 = require("../unit/thunderstorm");
35
+ const consts_1 = require("../../defaults/consts");
36
+ const nvm_1 = require("@nu-art/commando/cli/nvm");
37
+ const basic_1 = require("@nu-art/commando/cli/basic");
38
+ const PhaseRunnerDispatcher_1 = require("./PhaseRunnerDispatcher");
39
+ const consts_2 = require("./consts");
40
+ const types_1 = require("./types");
41
+ class PhaseRunner extends core_1.BaseUnit {
42
+ constructor(projectPath) {
8
43
  super({ label: 'Phase Runner', key: 'phase-runner' });
9
- this.units = [];
10
- this.runnerParams = {};
11
- this._getRunnerParam = (runnerParamKey) => this.runnerParams[runnerParamKey];
12
- this.phases = phases;
44
+ //######################### Internal Logic #########################
45
+ this.phaseFilters = {
46
+ [types_1.PhaseRunnerMode_Normal]: async (phase) => {
47
+ return !(0, ts_common_1.exists)(phase.filter) || (await phase.filter());
48
+ },
49
+ [types_1.PhaseRunnerMode_Continue]: async (phase) => {
50
+ const currentPhaseIndex = this.phases.findIndex(phase => phase.key === this.runningStatus.phaseKey);
51
+ const phaseIndex = this.phases.indexOf(phase);
52
+ //True if the phase index is larger equals the index of the first phase that will run in continue
53
+ if (phaseIndex >= currentPhaseIndex)
54
+ return true;
55
+ //Check if phase should run as a dependency
56
+ const allPhasesThatWillRun = [];
57
+ for (const phase of this.phases) {
58
+ const index = this.phases.indexOf(phase);
59
+ if (index >= currentPhaseIndex && await this.phaseFilters[types_1.PhaseRunnerMode_Normal](phase))
60
+ allPhasesThatWillRun.push(phase);
61
+ }
62
+ const dependencyKeys = (0, ts_common_1.flatArray)(allPhasesThatWillRun.map(phase => { var _a; return (_a = phase.dependencyPhaseKeys) !== null && _a !== void 0 ? _a : []; }));
63
+ return dependencyKeys.includes(phase.key);
64
+ }
65
+ };
66
+ this.phases = [];
67
+ this.units = [this];
68
+ this.project = { path: (0, tools_1.convertToFullPath)(projectPath), config: {} };
69
+ this.phaseFilter = this.phaseFilters[types_1.PhaseRunnerMode_Normal];
70
+ this.showAllLogs();
71
+ this.setMinLevel(ts_common_1.LogLevel.Verbose);
13
72
  }
73
+ //######################### Initialization #########################
14
74
  async init() {
15
- this.runnerParams['rootPath'] = process.cwd();
16
- this.runnerParams['configPath'] = this.runnerParams['rootPath'] + '/.config';
75
+ // await super.init(false);
76
+ //Set phase runner to MemKey, so it can be referenced in the runtime
77
+ consts_2.MemKey_PhaseRunner.set(this);
78
+ //Load project for use in the phase runner
79
+ await this.loadProject();
80
+ //Filter specific units
81
+ this.filterUnits();
82
+ //Set Logger if one is not already set, or if the allLogs flag is set
83
+ if (!this.screen || params_1.RuntimeParams.allLogs) {
84
+ this.showAllLogs();
85
+ }
86
+ else {
87
+ this.showScreenLogs();
88
+ }
89
+ this.logDebug('Runtime params:', params_1.RuntimeParams);
90
+ //Set runner params
91
+ const runnerParams = {
92
+ rootPath: process.cwd(),
93
+ configPath: process.cwd() + '/.config',
94
+ };
95
+ RunnerParams_1.MemKey_RunnerParams.set(runnerParams);
96
+ //Set Project Params
97
+ const projectParams = this.prepareProjectParams();
98
+ RunnerParams_1.MemKey_ProjectConfig.set(Object.assign(Object.assign({}, this.project.config), { params: projectParams }));
99
+ //Set Default File Routes
100
+ const defaultFileRoutes = this.prepareDefaultFileRouts();
101
+ consts_1.MemKey_DefaultFiles.set(defaultFileRoutes);
102
+ //Load running status
103
+ await this.loadRunningStatus();
104
+ //Print init results
105
+ this.printInit();
106
+ this.setStatus('Initialized');
107
+ const units = this.units.filter(unit => unit !== this);
108
+ await Promise.all(units.map(unit => {
109
+ // @ts-ignore
110
+ return unit.init();
111
+ }));
112
+ }
113
+ filterUnits() {
114
+ const useUnits = params_1.RuntimeParams.usePackage;
115
+ if (!useUnits || !useUnits.length)
116
+ return;
117
+ const unitsToRemove = [];
118
+ for (const unit of this.units) {
119
+ if (unit === this)
120
+ continue;
121
+ if (!useUnits.includes(unit.config.key))
122
+ unitsToRemove.push(unit);
123
+ }
124
+ unitsToRemove.forEach(unit => (0, ts_common_1.removeItemFromArray)(this.units, unit));
125
+ }
126
+ async loadProject() {
127
+ if (!fs_1.default.existsSync(this.project.path))
128
+ throw new ts_common_1.ImplementationMissingException(`Missing project config file, could not find in path: ${this.project.path}`);
129
+ const projectConfigCB = require(this.project.path).default;
130
+ if (typeof projectConfigCB !== 'function')
131
+ throw new ts_common_1.BadImplementationException('Config file must be an asynchronous function returning a ProjectConfigV2 object');
132
+ this.project.config = await projectConfigCB();
133
+ }
134
+ showAllLogs() {
135
+ if (this.screen)
136
+ // @ts-ignore
137
+ ts_common_1.BeLogged.removeClient(this.screen.logClient);
138
+ ts_common_1.BeLogged.addClient(ts_common_1.LogClient_Terminal);
139
+ //If no screen is set, PhaseRunner should be responsible to listening to kill command
140
+ //Listen on kill signal
141
+ process.on('SIGINT', async () => {
142
+ this.logInfo('Kill command received, killing units!');
143
+ await this.killRunner();
144
+ this.logInfo('Killed');
145
+ process.exit(0);
146
+ });
147
+ }
148
+ showScreenLogs() {
149
+ if (!this.screen)
150
+ throw new ts_common_1.ThisShouldNotHappenException('Calling showScreenLogs without a screen set!');
151
+ this.screen.create();
152
+ }
153
+ prepareProjectParams() {
154
+ var _a;
155
+ const params = (_a = this.project.config.params) !== null && _a !== void 0 ? _a : {};
156
+ params[consts_2.CONST_ThunderstormVersionKey] = this.project.config.thunderstormVersion;
157
+ params[consts_2.CONST_ThunderstormDependencyKey] = this.project.config.thunderstormVersion;
158
+ params[consts_2.CONST_ProjectVersionKey] = this.project.config.projectVersion;
159
+ params[consts_2.CONST_ProjectDependencyKey] = this.project.config.projectVersion;
160
+ return params;
161
+ }
162
+ prepareDefaultFileRouts() {
163
+ const defaultFileRoutes = (0, ts_common_1.deepClone)(consts_1.Default_Files);
164
+ const projectDefaultFileRoutes = RunnerParams_1.MemKey_ProjectConfig.get().defaultFileRoutes;
165
+ return (0, ts_common_1.merge)(defaultFileRoutes, projectDefaultFileRoutes);
166
+ }
167
+ buildUnitDependencyTree() {
168
+ const units = [...this.units];
169
+ const allDependencies = units.map(unit => unit.runtime.dependencyName);
170
+ const resolvedUnitNames = [];
171
+ const dependencyTree = [];
172
+ while (units.length) {
173
+ if (!resolvedUnitNames.length) {
174
+ //First run - get all units that don't have other units as dependencies
175
+ const nonDependantUnits = units.filter(unit => {
176
+ return !(0, ts_common_1.arrayIncludesAny)(unit.runtime.unitDependencyNames, allDependencies);
177
+ });
178
+ //Remove gathered units from the list of units to resolve
179
+ nonDependantUnits.forEach(unit => (0, ts_common_1.removeItemFromArray)(units, unit));
180
+ //Add resolved unit names to the array
181
+ resolvedUnitNames.push(...nonDependantUnits.map(unit => unit.runtime.dependencyName));
182
+ //Add resolved units as a layer in the dependency tree
183
+ dependencyTree.push(nonDependantUnits);
184
+ continue;
185
+ }
186
+ //Not first run - get all units where their dependencies are already resolved.
187
+ const resolvingUnits = units.filter(unit => {
188
+ const dependencyUnitPackageNames = unit.runtime.unitDependencyNames.filter(dependency => allDependencies.includes(dependency));
189
+ return dependencyUnitPackageNames.every(dependency => resolvedUnitNames.includes(dependency));
190
+ });
191
+ //Remove gathered units from the list of units to resolve
192
+ resolvingUnits.forEach(unit => (0, ts_common_1.removeItemFromArray)(units, unit));
193
+ //Add resolved unit names to the array
194
+ resolvedUnitNames.push(...resolvingUnits.map(unit => unit.runtime.dependencyName));
195
+ //Add resolved units as a layer in the dependency tree
196
+ dependencyTree.push(resolvingUnits);
197
+ }
198
+ this.unitDependencyTree = dependencyTree;
199
+ const toPrint = dependencyTree.map(row => row.map(unit => unit.config.label));
200
+ this.logDebug('Unit Dependency Tree:', toPrint);
201
+ }
202
+ printInit() {
203
+ this.logDebug('Runner Params:', RunnerParams_1.MemKey_RunnerParams.get());
204
+ this.logDebug('Project Config:', RunnerParams_1.MemKey_ProjectConfig.get());
205
+ this.logDebug('Default File Routes:', consts_1.MemKey_DefaultFiles.get());
206
+ }
207
+ async executeImpl() {
208
+ for (const phase of this.phases) {
209
+ const phaseDidRun = await this.executePhase(phase);
210
+ //If phase is terminating
211
+ if (phaseDidRun && phase.terminateAfterPhase)
212
+ break;
213
+ }
17
214
  }
18
215
  //######################### Unit Logic #########################
19
216
  registerUnits(units) {
20
- (0, ts_common_1.asArray)(units).forEach(unit => this.units.push(unit));
217
+ this.units.push(...(0, ts_common_1.asArray)(units));
218
+ (0, ts_common_1.sortArray)(this.units, unit => {
219
+ //Phase runner is first
220
+ if (unit === this)
221
+ return 0;
222
+ //Second priority for project units
223
+ if (unit instanceof core_1.Unit_TypescriptProject)
224
+ return 1;
225
+ //TS units after project units, but before the rest
226
+ return thunderstorm_1.allTSUnits.includes(unit) ? 2 : 3;
227
+ });
21
228
  }
22
229
  getUnitsForPhase(phase) {
23
- return this.units.filter(unit => (0, ts_common_1.exists)(unit[phase.method]));
24
- }
25
- async initUnits() {
26
- return Promise.all(this.units.map(unit => {
27
- unit.setGetRunnerParamCaller(this._getRunnerParam);
28
- // @ts-ignore
29
- unit.init();
230
+ return (0, ts_common_1.filterInstances)(this.unitDependencyTree.map(row => {
231
+ const filteredRow = row.filter(unit => {
232
+ if ((0, ts_common_1.exists)(unit.config.filter) && !unit.config.filter())
233
+ return false;
234
+ return (0, ts_common_1.exists)(unit[phase.method]);
235
+ });
236
+ return filteredRow.length ? filteredRow : undefined;
30
237
  }));
31
238
  }
239
+ getUnits() {
240
+ return this.units;
241
+ }
32
242
  //######################### Phase Logic #########################
243
+ /**
244
+ * Determines whether to run the phase.</br>
245
+ * returns true if phase ran, false otherwise
246
+ * @param phase
247
+ * @private
248
+ */
33
249
  async executePhase(phase) {
34
- const willExecutePhase = (0, ts_common_1.exists)(phase.filter) && !phase.filter();
35
- if (!willExecutePhase)
36
- return this.logInfo(`Will not execute phase: ${phase.name}, did not pass filter`);
250
+ var _a;
251
+ const willExecutePhase = await this.phaseFilter(phase);
252
+ if (!willExecutePhase) {
253
+ this.logDebug(`Will not execute phase: ${phase.name}, did not pass filter`);
254
+ return false;
255
+ }
37
256
  const units = this.getUnitsForPhase(phase);
38
- if (!units.length)
39
- return this.logInfo(`Will not execute phase: ${phase.name}, no units to execute`);
40
- this.logInfo(`Executing phase: ${phase.name} for ${units.length} units`);
41
- for (const unit of units) {
42
- await unit[phase.method]();
257
+ if (!units.length) {
258
+ this.logDebug(`Will not execute phase: ${phase.name}, no units to execute`);
259
+ return false;
260
+ }
261
+ this.logDebug(`Executing phase: ${phase.name}`);
262
+ PhaseRunnerDispatcher_1.dispatcher_PhaseChange.dispatch(phase);
263
+ const phaseIndex = this.phases.indexOf(phase);
264
+ let runningPhaseIndex = this.phases.findIndex(phase => phase.key === this.runningStatus.phaseKey);
265
+ const inContinueMode = this.phaseFilter === this.phaseFilters[types_1.PhaseRunnerMode_Continue];
266
+ //Run all units at the same time
267
+ if (!phase.runUnitsInDependency) {
268
+ //The current phase is (or is after) the running status phase
269
+ if (phaseIndex >= runningPhaseIndex) {
270
+ this.runningStatus = { phaseKey: phase.key, packageDependencyIndex: 0 };
271
+ await this.setRunningStatus();
272
+ //Return to normal mode, if in continue
273
+ if (inContinueMode)
274
+ this.phaseFilter = this.phaseFilters[types_1.PhaseRunnerMode_Normal];
275
+ }
276
+ const unitsToRun = (0, ts_common_1.flatArray)(units);
277
+ await Promise.all(unitsToRun.map(unit => unit[phase.method]()));
278
+ return true;
279
+ }
280
+ //Run units according to dependency tree
281
+ for (const row of units) {
282
+ const index = units.indexOf(row);
283
+ const runningStatusRowIndex = (_a = this.runningStatus.packageDependencyIndex) !== null && _a !== void 0 ? _a : 0;
284
+ //Skip running status holds a larger index for the same phase
285
+ if ((phaseIndex === runningPhaseIndex) && index < runningStatusRowIndex)
286
+ continue;
287
+ this.logWarning(`Phase Index ${phaseIndex}, Row Index ${index}`);
288
+ this.logWarning(`RunningStatus Phase Index: ${runningPhaseIndex}, RunningStatus Row Index: ${runningStatusRowIndex}`);
289
+ if (phaseIndex > runningPhaseIndex) {
290
+ //Index of the current phase is larger, update the running status
291
+ this.runningStatus = { phaseKey: phase.key, packageDependencyIndex: 0 };
292
+ runningPhaseIndex = phaseIndex;
293
+ await this.setRunningStatus();
294
+ //Return to normal mode, if in continue
295
+ if (inContinueMode)
296
+ this.phaseFilter = this.phaseFilters[types_1.PhaseRunnerMode_Normal];
297
+ }
298
+ else if (phaseIndex === runningPhaseIndex && index >= runningStatusRowIndex) {
299
+ //Index of the row is larger for the same phase, update running status
300
+ this.runningStatus = { phaseKey: phase.key, packageDependencyIndex: index };
301
+ await this.setRunningStatus();
302
+ //Return to normal mode, if in continue
303
+ if (inContinueMode)
304
+ this.phaseFilter = this.phaseFilters[types_1.PhaseRunnerMode_Normal];
305
+ }
306
+ await Promise.all(row.map(unit => unit[phase.method]()));
307
+ }
308
+ return true;
309
+ }
310
+ prependPhase(phase, beforePhase) {
311
+ if (!beforePhase) {
312
+ this.phases.unshift(phase);
313
+ return;
314
+ }
315
+ const index = this.phases.indexOf(beforePhase);
316
+ //If the beforePhase isn't in this.phases or is the first item
317
+ if (index === -1 || index === 0)
318
+ return this.prependPhase(phase);
319
+ (0, ts_common_1.addItemToArrayAtIndex)(this.phases, phase, index - 1);
320
+ }
321
+ appendPhase(phase, afterPhase) {
322
+ if (!afterPhase) {
323
+ this.phases.push(phase);
324
+ return;
325
+ }
326
+ const index = this.phases.indexOf(afterPhase);
327
+ //If the afterPhase isn't in this.phases or is the last item
328
+ if (index === -1 || index === this.phases.length - 1)
329
+ return this.appendPhase(phase);
330
+ (0, ts_common_1.addItemToArrayAtIndex)(this.phases, phase, index + 1);
331
+ }
332
+ //######################### Running Status #########################
333
+ async setRunningStatus() {
334
+ this.logDebug('Setting Running Status', this.runningStatus);
335
+ if (!fs_1.default.existsSync(consts_1.Default_OutputFiles.output))
336
+ await fs_1.promises.mkdir(consts_1.Default_OutputFiles.output, { recursive: true });
337
+ await fs_1.promises.writeFile(consts_1.Default_OutputFiles.runningStatus, (0, ts_common_1.__stringify)(this.runningStatus, true));
338
+ }
339
+ async loadRunningStatus() {
340
+ const setDefaultRunningStatus = () => {
341
+ this.runningStatus = {
342
+ phaseKey: this.phases[0].key,
343
+ packageDependencyIndex: 0,
344
+ };
345
+ this.phaseFilter = this.phaseFilters[types_1.PhaseRunnerMode_Normal];
346
+ };
347
+ if (!params_1.RuntimeParams.continue) {
348
+ setDefaultRunningStatus();
349
+ return;
350
+ }
351
+ //If the dir exists, try to read the file
352
+ if (fs_1.default.existsSync(consts_1.Default_OutputFiles.output)) {
353
+ try {
354
+ this.runningStatus = JSON.parse(await fs_1.promises.readFile(consts_1.Default_OutputFiles.runningStatus, { encoding: 'utf-8' }));
355
+ this.phaseFilter = this.phaseFilters[types_1.PhaseRunnerMode_Continue];
356
+ }
357
+ catch (e) {
358
+ this.logError('Failed reading running status');
359
+ setDefaultRunningStatus();
360
+ return;
361
+ }
43
362
  }
363
+ else
364
+ setDefaultRunningStatus();
44
365
  }
45
366
  //######################### Public Functions #########################
46
367
  async execute() {
47
- await this.init();
48
- await this.initUnits();
49
- await this.executeImpl();
368
+ return new MemStorage_1.MemStorage().init(async () => {
369
+ await this.init();
370
+ this.buildUnitDependencyTree();
371
+ await this.executeImpl();
372
+ });
50
373
  }
51
- async executeImpl() {
52
- for (const phase of this.phases) {
53
- await this.executePhase(phase);
54
- }
374
+ async killRunner() {
375
+ await Promise.all(this.units.map(unit => unit.kill()));
376
+ await this.setRunningStatus();
377
+ }
378
+ setScreen(screen) {
379
+ this.screen = screen;
380
+ }
381
+ //######################### Phase Implementation #########################
382
+ async printHelp() {
383
+ this.logInfo('Build and install parameters:');
384
+ const noGroupConst = 'No Group';
385
+ //Resolve all params by group
386
+ const paramsByGroup = (0, ts_common_1.reduceToMap)(params_1.AllBaiParams, param => { var _a; return (_a = param.group) !== null && _a !== void 0 ? _a : noGroupConst; }, (item, index, mapper) => {
387
+ var _a, _b, _c, _d;
388
+ mapper[(_a = item.group) !== null && _a !== void 0 ? _a : noGroupConst] = [...(_c = mapper[(_b = item.group) !== null && _b !== void 0 ? _b : noGroupConst]) !== null && _c !== void 0 ? _c : [], item];
389
+ return mapper[(_d = item.group) !== null && _d !== void 0 ? _d : noGroupConst];
390
+ });
391
+ (0, ts_common_1._keys)(paramsByGroup).map(paramGroup => {
392
+ this.logWarningBold(`${paramGroup}: \n`);
393
+ // commando.append(`echo "${paramGroup}:" \n`);
394
+ paramsByGroup[paramGroup].map(param => {
395
+ const paramKeys = param.keys.join(' | ');
396
+ const paramDescription = param.description.trim().split('\n').join('\n\t\t');
397
+ this.logInfo(`${paramKeys} \n\t\t ${paramDescription} \n`);
398
+ // commando.append(`echo "\n ${param.keys.join(' | ')} \n \t\t${param.description.trim().split('\n').join('\n\t\t')} \n"`);
399
+ });
400
+ });
401
+ }
402
+ async printEnv() {
403
+ await nvm_1.NVM.createCommando(basic_1.Cli_Basic)
404
+ .append('npm -g list typescript eslint firebase-tools sort-package-json --depth=0')
405
+ .append('echo "npm version:"; npm -v')
406
+ .append('echo "node version:"; node -v')
407
+ .append('echo "base version:"; bash --version')
408
+ .execute();
409
+ }
410
+ async debug() {
411
+ // const configs = this.units.map(unit => unit.config);
412
+ // this.logInfo(JSON.stringify(configs, null, 2));
413
+ const dependencyTree = this.unitDependencyTree.map(row => row.map(unit => unit.config.label));
414
+ this.logInfo(dependencyTree);
55
415
  }
56
416
  }
57
417
  exports.PhaseRunner = PhaseRunner;
@@ -0,0 +1,25 @@
1
+ import { FunctionKeys, ParamResolver } from '@nu-art/ts-common';
2
+ import { Phase } from '../phase/types';
3
+ import { BaseUnit } from '../unit/core';
4
+ export interface PhaseRunnerEventListener {
5
+ __onPhaseChange: (data: Phase<string>) => void;
6
+ __onUnitStatusChange: (data: BaseUnit) => void;
7
+ }
8
+ declare class PhaseRunnerDispatcher<K extends FunctionKeys<PhaseRunnerEventListener>, P extends ParamResolver<PhaseRunnerEventListener, K> = ParamResolver<PhaseRunnerEventListener, K>> {
9
+ private readonly method;
10
+ constructor(method: K);
11
+ private listeners;
12
+ addListener(listener: any): void;
13
+ removeListener(listener: any): void;
14
+ dispatch(...data: P): void;
15
+ }
16
+ export declare const dispatcher_PhaseChange: PhaseRunnerDispatcher<"__onPhaseChange", [data: Phase<string>]>;
17
+ export declare const dispatcher_UnitStatusChange: PhaseRunnerDispatcher<"__onUnitStatusChange", [data: BaseUnit<{}, {}, {
18
+ key: string;
19
+ label: string;
20
+ filter?: (() => boolean | Promise<boolean>) | undefined;
21
+ }, {
22
+ dependencyName: string;
23
+ unitDependencyNames: string[];
24
+ }>]>;
25
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dispatcher_UnitStatusChange = exports.dispatcher_PhaseChange = void 0;
4
+ const ts_common_1 = require("@nu-art/ts-common");
5
+ class PhaseRunnerDispatcher {
6
+ constructor(method) {
7
+ this.listeners = [];
8
+ this.method = method;
9
+ }
10
+ //######################### Listeners Logic #########################
11
+ addListener(listener) {
12
+ this.listeners.push(listener);
13
+ }
14
+ removeListener(listener) {
15
+ (0, ts_common_1.removeItemFromArray)(this.listeners, listener);
16
+ }
17
+ dispatch(...data) {
18
+ this.listeners.forEach(listener => {
19
+ var _a;
20
+ // @ts-ignore
21
+ (_a = listener[this.method]) === null || _a === void 0 ? void 0 : _a.call(listener, ...data);
22
+ });
23
+ }
24
+ }
25
+ exports.dispatcher_PhaseChange = new PhaseRunnerDispatcher('__onPhaseChange');
26
+ exports.dispatcher_UnitStatusChange = new PhaseRunnerDispatcher('__onUnitStatusChange');
@@ -0,0 +1,12 @@
1
+ import { MemKey } from '@nu-art/ts-common/mem-storage/MemStorage';
2
+ import { ProjectConfigV2 } from '../project/types';
3
+ export declare const MemKey_ProjectConfig: MemKey<ProjectConfigV2>;
4
+ export type RunnerParamKey = typeof RunnerParamKeys[number];
5
+ export type RunnerParams = {
6
+ [K in RunnerParamKey]?: string;
7
+ };
8
+ export declare const MemKey_RunnerParams: MemKey<RunnerParams>;
9
+ export declare const RunnerParamKey_RootPath: "rootPath";
10
+ export declare const RunnerParamKey_ConfigPath: "configPath";
11
+ declare const RunnerParamKeys: readonly ["rootPath", "configPath"];
12
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RunnerParamKey_ConfigPath = exports.RunnerParamKey_RootPath = exports.MemKey_RunnerParams = exports.MemKey_ProjectConfig = void 0;
4
+ const MemStorage_1 = require("@nu-art/ts-common/mem-storage/MemStorage");
5
+ exports.MemKey_ProjectConfig = new MemStorage_1.MemKey('project-config');
6
+ exports.MemKey_RunnerParams = new MemStorage_1.MemKey('runner-params');
7
+ exports.RunnerParamKey_RootPath = 'rootPath';
8
+ exports.RunnerParamKey_ConfigPath = 'configPath';
9
+ const RunnerParamKeys = [exports.RunnerParamKey_RootPath, exports.RunnerParamKey_ConfigPath];
@@ -0,0 +1,7 @@
1
+ import { MemKey } from '@nu-art/ts-common/mem-storage/MemStorage';
2
+ import { PhaseRunner } from './PhaseRunner';
3
+ export declare const CONST_ThunderstormVersionKey = "THUNDERSTORM_SDK_VERSION";
4
+ export declare const CONST_ThunderstormDependencyKey = "THUNDERSTORM_DEPENDENCY_VERSION";
5
+ export declare const CONST_ProjectVersionKey = "APP_VERSION";
6
+ export declare const CONST_ProjectDependencyKey = "APP_VERSION_DEPENDENCY";
7
+ export declare const MemKey_PhaseRunner: MemKey<PhaseRunner>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemKey_PhaseRunner = exports.CONST_ProjectDependencyKey = exports.CONST_ProjectVersionKey = exports.CONST_ThunderstormDependencyKey = exports.CONST_ThunderstormVersionKey = void 0;
4
+ const MemStorage_1 = require("@nu-art/ts-common/mem-storage/MemStorage");
5
+ exports.CONST_ThunderstormVersionKey = 'THUNDERSTORM_SDK_VERSION';
6
+ exports.CONST_ThunderstormDependencyKey = 'THUNDERSTORM_DEPENDENCY_VERSION';
7
+ exports.CONST_ProjectVersionKey = 'APP_VERSION';
8
+ exports.CONST_ProjectDependencyKey = 'APP_VERSION_DEPENDENCY';
9
+ exports.MemKey_PhaseRunner = new MemStorage_1.MemKey('phase-runner');
@@ -1,16 +1,13 @@
1
1
  import { AsyncVoidFunction } from '@nu-art/ts-common';
2
- export type Phase<PhaseMethod extends string> = {
3
- name: string;
4
- method: PhaseMethod;
5
- filter?: () => (Promise<boolean> | boolean);
6
- };
2
+ import { Phase } from '../phase/types';
7
3
  export type PhaseImplementor<P extends Phase<string>[]> = {
8
4
  [K in P[number]['method']]: AsyncVoidFunction;
9
5
  };
10
6
  export type PhasesImplementor<Phases extends Phase<string>[]> = {
11
7
  [K in Phases[number]['method']]?: AsyncVoidFunction;
12
8
  };
13
- export type RunnerParamKeys = 'rootPath' | 'configPath';
14
- export type RunnerParams = {
15
- [K in RunnerParamKeys]: string;
16
- };
9
+ export declare const PhaseRunnerMode_Normal = "normal";
10
+ export declare const PhaseRunnerMode_Continue = "continue";
11
+ declare const PhaseRunnerModes: readonly ["normal", "continue"];
12
+ export type PhaseRunnerMode = typeof PhaseRunnerModes[number];
13
+ export {};
@@ -1,2 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PhaseRunnerMode_Continue = exports.PhaseRunnerMode_Normal = void 0;
4
+ exports.PhaseRunnerMode_Normal = 'normal';
5
+ exports.PhaseRunnerMode_Continue = 'continue';
6
+ const PhaseRunnerModes = [exports.PhaseRunnerMode_Normal, exports.PhaseRunnerMode_Continue];
@@ -0,0 +1,8 @@
1
+ import { StringMap } from '@nu-art/ts-common';
2
+ import { ProjectConfig_DefaultFileRoutes } from '../../defaults/consts';
3
+ export type ProjectConfigV2 = {
4
+ params: StringMap;
5
+ defaultFileRoutes?: ProjectConfig_DefaultFileRoutes;
6
+ projectVersion: string;
7
+ thunderstormVersion: string;
8
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,47 @@
1
+ import { ConsoleContainer } from '@nu-art/commando/console/ConsoleContainer';
2
+ import { Widgets } from 'blessed';
3
+ import { PhaseRunnerEventListener } from '../phase-runner/PhaseRunnerDispatcher';
4
+ import { Phase } from '../phase';
5
+ import { BaseUnit } from '../unit/core';
6
+ import { AsyncVoidFunction } from '@nu-art/ts-common';
7
+ type ScreenKeyBinding = {
8
+ keys: string[];
9
+ callback: VoidFunction;
10
+ };
11
+ type State = {
12
+ currentPhaseName?: string;
13
+ selectedUnit?: BaseUnit;
14
+ };
15
+ export declare class BAI_ListScreen extends ConsoleContainer<'screen', State> implements PhaseRunnerEventListener {
16
+ private units;
17
+ private logClient;
18
+ private onKillCB?;
19
+ private unitWrapperWidget;
20
+ private unitWidgets;
21
+ private logWidget;
22
+ private phaseWidget;
23
+ __onPhaseChange(phase: Phase<string>): void;
24
+ __onUnitStatusChange(unit: BaseUnit): void;
25
+ /**
26
+ * Creates an instance of ConsoleScreen.
27
+ *
28
+ * @param units - The units this screen should keep track of
29
+ * @param {Widgets.IScreenOptions} [props] - The properties to apply to the screen widget.
30
+ * @param {ScreenKeyBinding[]} [keyBinding] - An array of key bindings for the screen widget.
31
+ */
32
+ constructor(units: BaseUnit[], props?: Widgets.IScreenOptions, keyBinding?: ScreenKeyBinding[]);
33
+ private initLogger;
34
+ create(): this;
35
+ protected createContent(): void;
36
+ private createPhaseWidget;
37
+ private createUnitListWidget;
38
+ private createUnitItemWidget;
39
+ private createLogWidget;
40
+ protected render(): void;
41
+ private renderPhase;
42
+ private renderUnitList;
43
+ private renderLogs;
44
+ setKillCB(cb: AsyncVoidFunction): void;
45
+ private onUnitSelect;
46
+ }
47
+ export {};