@nu-art/build-and-install 0.204.98 → 0.204.99

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/build-and-install",
3
- "version": "0.204.98",
3
+ "version": "0.204.99",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -1,6 +1,6 @@
1
- import { ConsoleContainer } from '@nu-art/commando/console/ConsoleContainer';
2
1
  import { AsyncVoidFunction } from '@nu-art/ts-common';
3
- export declare abstract class BAIScreen<State extends {} = {}> extends ConsoleContainer<'screen', State> {
2
+ import { ConsoleScreen } from '@nu-art/commando/console/ConsoleScreen';
3
+ export declare abstract class BAIScreen<State extends {} = {}> extends ConsoleScreen<State> {
4
4
  private onKillCallback?;
5
5
  private logClient;
6
6
  /**
@@ -11,6 +11,7 @@ export declare abstract class BAIScreen<State extends {} = {}> extends ConsoleCo
11
11
  */
12
12
  constructor(logClientKey: string);
13
13
  private createLogClient;
14
+ protected abstract scrollLog(direction: number): void;
14
15
  protected abstract onLogUpdated: () => void;
15
16
  protected getLogs: () => string;
16
17
  startScreen: () => void;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BAIScreen = void 0;
4
- const ConsoleContainer_1 = require("@nu-art/commando/console/ConsoleContainer");
5
4
  const ts_common_1 = require("@nu-art/ts-common");
6
5
  const PhaseRunnerDispatcher_1 = require("../phase-runner/PhaseRunnerDispatcher");
7
- class BAIScreen extends ConsoleContainer_1.ConsoleContainer {
6
+ const ConsoleScreen_1 = require("@nu-art/commando/console/ConsoleScreen");
7
+ class BAIScreen extends ConsoleScreen_1.ConsoleScreen {
8
8
  //######################### Initialization #########################
9
9
  /**
10
10
  * Creates an instance of ConsoleScreen.
@@ -13,10 +13,24 @@ class BAIScreen extends ConsoleContainer_1.ConsoleContainer {
13
13
  * @param {ScreenKeyBinding[]} [keyBinding] - An array of key bindings for the screen widget.
14
14
  */
15
15
  constructor(logClientKey) {
16
- super('screen', { smartCSR: true, title: 'Build and Install' }, [{
16
+ super({ smartCSR: true, title: 'Build and Install' }, [
17
+ {
17
18
  keys: ['escape', 'q', 'C-c'],
18
19
  callback: async () => await this.onKill(),
19
- }]);
20
+ },
21
+ {
22
+ keys: ['up'],
23
+ callback: () => {
24
+ this.scrollLog(-1);
25
+ },
26
+ },
27
+ {
28
+ keys: ['down'],
29
+ callback: () => {
30
+ this.scrollLog(1);
31
+ },
32
+ },
33
+ ]);
20
34
  this.getLogs = () => this.logClient.buffers[0];
21
35
  this.startScreen = () => {
22
36
  //Start listening on dispatchers
@@ -38,6 +52,7 @@ class BAIScreen extends ConsoleContainer_1.ConsoleContainer {
38
52
  this.container.destroy();
39
53
  };
40
54
  this.setOnKillCallback = (cb) => this.onKillCallback = cb;
55
+ this.scrollLog.bind(this);
41
56
  this.createLogClient(logClientKey);
42
57
  }
43
58
  createLogClient(logClientKey) {
@@ -2,16 +2,20 @@ import { BAIScreen } from './BAIScreen';
2
2
  import { BaseUnit } from '../unit/core';
3
3
  import { PhaseRunner_OnUnitsChange } from '../phase-runner/PhaseRunnerDispatcher';
4
4
  export declare class BAIScreen_Launch extends BAIScreen implements PhaseRunner_OnUnitsChange {
5
- private units;
5
+ private allUnits;
6
+ private focusUnits;
6
7
  private gridDimensions;
7
8
  private withRunningLogs;
8
9
  private gridCellWidgets;
9
10
  constructor();
10
11
  __onUnitsChange: (data: BaseUnit[]) => void;
12
+ private rebuildScreens;
11
13
  protected onLogUpdated: () => void;
12
14
  private updateUnits;
13
15
  protected createContent(): void;
16
+ protected scrollLog(direction: number): void;
14
17
  private createGridWidgets;
18
+ private toggleFullScreenMode;
15
19
  private calculateGridDimensions;
16
20
  private getGridWidgetLabel;
17
21
  protected destroyContent(): void;
@@ -4,30 +4,32 @@ exports.BAIScreen_Launch = void 0;
4
4
  const BAIScreen_1 = require("./BAIScreen");
5
5
  const consts_1 = require("../phase-runner/consts");
6
6
  const firebase_units_1 = require("../unit/firebase-units");
7
+ const ts_common_1 = require("@nu-art/ts-common");
7
8
  class BAIScreen_Launch extends BAIScreen_1.BAIScreen {
8
9
  //######################### Lifecycle #########################
9
10
  constructor() {
10
11
  super('bai-launch');
11
12
  //######################### Properties #########################
12
- this.units = [];
13
+ this.allUnits = [];
14
+ this.focusUnits = [];
13
15
  this.gridDimensions = [[{ width: 1, height: 1 }]];
14
16
  this.withRunningLogs = false;
15
17
  //Widgets
16
18
  this.gridCellWidgets = [];
17
19
  this.__onUnitsChange = (data) => {
18
20
  this.updateUnits();
19
- this.createGridWidgets();
20
- this.renderGridWidgets();
21
- this.container.screen.render();
21
+ this.rebuildScreens();
22
22
  };
23
23
  this.onLogUpdated = () => {
24
24
  this.renderGridWidgets();
25
25
  };
26
26
  this.updateUnits = () => {
27
27
  const runner = consts_1.MemKey_PhaseRunner.get();
28
- this.units = runner.getUnits().filter(unit => {
28
+ this.allUnits = runner.getUnits().filter(unit => {
29
29
  return unit.isInstanceOf(firebase_units_1.Unit_FirebaseHostingApp) || unit.isInstanceOf(firebase_units_1.Unit_FirebaseFunctionsApp);
30
30
  });
31
+ if (!this.focusUnits.length)
32
+ this.focusUnits = this.allUnits;
31
33
  };
32
34
  this.createGridWidgets = () => {
33
35
  this.destroyGridWidgets();
@@ -47,27 +49,50 @@ class BAIScreen_Launch extends BAIScreen_1.BAIScreen {
47
49
  label: this.getGridWidgetLabel(widgetIndex),
48
50
  border: { type: 'line' },
49
51
  style: {
50
- border: { fg: 'blue' },
52
+ hover: { border: { fg: 'blue' } },
53
+ border: { fg: 'gray' },
54
+ focus: { border: { fg: 'green' } }
51
55
  },
52
56
  valign: 'top',
53
57
  align: 'left',
54
- mouse: true,
58
+ interactive: true,
59
+ focusable: true,
55
60
  };
56
- this.gridCellWidgets.push(this.createWidget('log', props));
61
+ const logWidget = this.createWidget('log', props);
62
+ let doubleClickTimestamp = 0;
63
+ const unitIndex = widgetIndex;
64
+ logWidget.on('mouse', (event) => {
65
+ if (!(event.button === 'middle' && event.action === 'mouseup'))
66
+ return;
67
+ if ((0, ts_common_1.currentTimeMillis)() - doubleClickTimestamp < 500) {
68
+ try {
69
+ this.toggleFullScreenMode(unitIndex);
70
+ }
71
+ catch (e) {
72
+ console.log(e);
73
+ console.log(e);
74
+ console.log(e);
75
+ console.log(e);
76
+ console.log(e);
77
+ }
78
+ return;
79
+ }
80
+ doubleClickTimestamp = (0, ts_common_1.currentTimeMillis)();
81
+ });
82
+ this.gridCellWidgets.push(logWidget);
57
83
  yPos += height; //Assuming all cells in a column have the same height
58
84
  widgetIndex++;
59
85
  });
60
86
  xPos += col[0].width * 100; //Assuming all Cells have the same width
61
87
  });
62
88
  };
63
- this.calculateGridDimensions = () => {
64
- let n = this.units.length;
89
+ this.calculateGridDimensions = (count = this.focusUnits.length) => {
65
90
  //Add 1 more window for running logs
66
91
  if (this.withRunningLogs)
67
- n++;
92
+ count++;
68
93
  const grid = [];
69
- const columns = Math.ceil(Math.sqrt(n)); // Calculate number of columns
70
- let remainingItems = n;
94
+ const columns = Math.ceil(Math.sqrt(count)); // Calculate number of columns
95
+ let remainingItems = count;
71
96
  for (let col = 0; col < columns; col++) {
72
97
  const column = [];
73
98
  const itemsInThisColumn = Math.ceil(remainingItems / (columns - col));
@@ -82,22 +107,25 @@ class BAIScreen_Launch extends BAIScreen_1.BAIScreen {
82
107
  };
83
108
  this.getGridWidgetLabel = (index) => {
84
109
  if (!this.withRunningLogs)
85
- return this.units[index].config.label;
86
- return index === this.units.length ? 'Running Logs' : this.units[index].config.label;
110
+ return this.focusUnits[index].config.label;
111
+ return index === this.focusUnits.length ? 'Running Logs' : this.focusUnits[index].config.label;
87
112
  };
88
113
  this.destroyGridWidgets = () => {
89
114
  this.gridCellWidgets.forEach(widget => widget.destroy());
115
+ this.gridCellWidgets.length = 0;
90
116
  };
91
117
  this.getContentForWidget = (widgetIndex) => {
92
118
  var _a, _b;
93
119
  if (!this.withRunningLogs) {
94
- const unit = this.units[widgetIndex];
120
+ const unit = this.focusUnits[widgetIndex];
121
+ if (!unit)
122
+ throw new ts_common_1.WhoCallThisException(`focusedUnits: ${this.focusUnits.length}[${widgetIndex}]`);
95
123
  return (_a = unit.getLogs()) !== null && _a !== void 0 ? _a : `No logs for unit ${unit.config.label}`;
96
124
  }
97
125
  //With running logs, last index should return the running logs
98
- if (widgetIndex === this.units.length)
126
+ if (widgetIndex === this.focusUnits.length)
99
127
  return this.getLogs();
100
- const unit = this.units[widgetIndex];
128
+ const unit = this.focusUnits[widgetIndex];
101
129
  return (_b = unit.getLogs()) !== null && _b !== void 0 ? _b : `No logs for unit ${unit.config.label}`;
102
130
  };
103
131
  this.renderGridWidgets = () => {
@@ -111,11 +139,29 @@ class BAIScreen_Launch extends BAIScreen_1.BAIScreen {
111
139
  //######################### Options #########################
112
140
  this.setWithRunningLogs = (val) => this.withRunningLogs = val;
113
141
  }
142
+ rebuildScreens() {
143
+ this.createGridWidgets();
144
+ this.renderGridWidgets();
145
+ this.container.screen.render();
146
+ }
114
147
  //######################### Content Creation #########################
115
148
  createContent() {
116
149
  this.updateUnits();
117
150
  this.createGridWidgets();
118
151
  }
152
+ scrollLog(direction) {
153
+ var _a;
154
+ const focusedWidget = this.getFocusedWidget();
155
+ // @ts-ignore
156
+ (_a = this.gridCellWidgets.find(log => log._label.content === focusedWidget._label.content)) === null || _a === void 0 ? void 0 : _a.scroll(direction);
157
+ }
158
+ toggleFullScreenMode(unitIndex) {
159
+ if (this.focusUnits.length !== this.allUnits.length)
160
+ this.focusUnits = this.allUnits;
161
+ else
162
+ this.focusUnits = [this.allUnits[unitIndex]];
163
+ this.rebuildScreens();
164
+ }
119
165
  //######################### Content Destruction #########################
120
166
  destroyContent() {
121
167
  this.destroyGridWidgets();
@@ -124,7 +170,7 @@ class BAIScreen_Launch extends BAIScreen_1.BAIScreen {
124
170
  render() {
125
171
  this.renderGridWidgets();
126
172
  this.logInfo('GRID DIMENSIONS', this.gridDimensions);
127
- this.logInfo('UNITS', this.units.map(unit => unit.config.label));
173
+ this.logInfo('UNITS', this.focusUnits.map(unit => unit.config.label));
128
174
  this.logInfo('RUNNER UNITS', consts_1.MemKey_PhaseRunner.get().getUnits().map(unit => unit.config.label));
129
175
  }
130
176
  }
@@ -17,6 +17,7 @@ export declare class BAIScreen_UnitList extends BAIScreen<State> implements Phas
17
17
  __onUnitStatusChange(unit: BaseUnit): void;
18
18
  __onUnitsChange(data: BaseUnit[]): void;
19
19
  protected onLogUpdated: () => void;
20
+ protected scrollLog(direction: number): void;
20
21
  protected destroyContent(): void;
21
22
  private destroyPhaseWidget;
22
23
  private destroyUnitListWidget;
@@ -28,6 +28,14 @@ class BAIScreen_UnitList extends BAIScreen_1.BAIScreen {
28
28
  this.createUnitListWidget();
29
29
  this.renderUnitList();
30
30
  }
31
+ scrollLog(direction) {
32
+ // const focusedWidget = this.getFocusedWidget();
33
+ // @ts-ignore
34
+ // console.log(`ZEVEL ${focusedWidget.type}`);
35
+ // if (focusedWidget !== this.logWidget)
36
+ // return;
37
+ this.logWidget.scroll(direction);
38
+ }
31
39
  //######################### Content Destruction #########################
32
40
  destroyContent() {
33
41
  this.destroyPhaseWidget();
@@ -69,7 +77,6 @@ class BAIScreen_UnitList extends BAIScreen_1.BAIScreen {
69
77
  },
70
78
  align: 'center',
71
79
  label: 'phase',
72
- mouse: true
73
80
  };
74
81
  this.phaseWidget = this.createWidget('text', props);
75
82
  this.phaseWidget.on('mouse', (event) => {
@@ -142,9 +149,16 @@ class BAIScreen_UnitList extends BAIScreen_1.BAIScreen {
142
149
  style: {
143
150
  border: { fg: 'blue' }
144
151
  },
145
- valign: 'top',
146
- align: 'left',
147
- mouse: true,
152
+ scrollbar: {
153
+ ch: ' ',
154
+ track: {
155
+ bg: 'grey',
156
+ },
157
+ style: {
158
+ inverse: true,
159
+ },
160
+ },
161
+ interactive: true // This is typically required for focus management
148
162
  };
149
163
  this.logWidget = this.createWidget('log', props);
150
164
  }
@@ -172,10 +186,10 @@ class BAIScreen_UnitList extends BAIScreen_1.BAIScreen {
172
186
  });
173
187
  }
174
188
  renderLogs() {
175
- const scrollPosition = this.logWidget.getScroll();
189
+ var _a, _b;
176
190
  const content = this.state.selectedUnit ? this.state.selectedUnit.getLogs() : this.getLogs();
191
+ this.logWidget.setLabel(` ${(_b = (_a = this.state.selectedUnit) === null || _a === void 0 ? void 0 : _a.config.label) !== null && _b !== void 0 ? _b : 'All Logs'} `);
177
192
  this.logWidget.setContent(content);
178
- this.logWidget.setScroll(scrollPosition);
179
193
  }
180
194
  //######################### Events #########################
181
195
  onUnitSelect(unit, index) {
@@ -186,3 +200,4 @@ class BAIScreen_UnitList extends BAIScreen_1.BAIScreen {
186
200
  }
187
201
  }
188
202
  exports.BAIScreen_UnitList = BAIScreen_UnitList;
203
+ // /Users/tacb0ss/.nvm/versions/node/v18.15.0/bin/ts-node -P /Users/tacb0ss/dev/quai/test/quai-web/_thunderstorm/commando/src/test/tsconfig.json /Users/tacb0ss/dev/quai/test/quai-web/_thunderstorm/commando/src/test/console/controlled-scroll/run.ts
@@ -100,9 +100,11 @@ class BaseUnit extends ts_common_1.Logger {
100
100
  async kill() {
101
101
  if (!this.processTerminator.length)
102
102
  return this.setStatus('Killed');
103
+ const processTerminator = [...this.processTerminator];
104
+ this.processTerminator.length = 0;
103
105
  this.setStatus('Killing');
104
106
  try {
105
- await Promise.all(this.processTerminator.map(toTerminate => toTerminate()));
107
+ await Promise.all(processTerminator.map(toTerminate => toTerminate()));
106
108
  }
107
109
  finally {
108
110
  this.setStatus('Killed');
@@ -60,7 +60,12 @@ class Unit_Typescript extends BaseUnit_1.BaseUnit {
60
60
  const templatePath = `${unitRootPath}/${consts_1.CONST_PackageJSONTemplate}`;
61
61
  if (!fs.existsSync(templatePath))
62
62
  throw new ts_common_1.BadImplementationException(`Missing __package.json file in root for unit ${this.config.label}`);
63
- this.packageJson.template = JSON.parse(await fs_1.promises.readFile(templatePath, 'utf-8'));
63
+ try {
64
+ this.packageJson.template = JSON.parse(await fs_1.promises.readFile(templatePath, 'utf-8'));
65
+ }
66
+ catch (e) {
67
+ throw new ts_common_1.BadImplementationException(`There is an issue in the __package.json file in root for unit ${this.config.label}`);
68
+ }
64
69
  }
65
70
  /**
66
71
  * Create a packageJson object for each target key