@nu-art/build-and-install 0.300.8 → 0.400.1

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 (195) hide show
  1. package/build-and-install-v3.d.ts +29 -0
  2. package/build-and-install-v3.js +132 -0
  3. package/build-and-install-v3.js.map +1 -0
  4. package/build-and-install.js +18 -24
  5. package/build-and-install.js.map +1 -0
  6. package/core/consts.d.ts +7 -2
  7. package/core/consts.js +12 -9
  8. package/core/consts.js.map +1 -0
  9. package/core/exceptions/PhaseAggregatedException.d.ts +5 -0
  10. package/core/exceptions/PhaseAggregatedException.js +9 -0
  11. package/core/exceptions/PhaseAggregatedException.js.map +1 -0
  12. package/core/package/consts.d.ts +1 -1
  13. package/core/package/consts.js +7 -9
  14. package/core/package/consts.js.map +1 -0
  15. package/core/params/params.d.ts +18 -19
  16. package/core/params/params.js +142 -178
  17. package/core/params/params.js.map +1 -0
  18. package/core/types/configs/firebasejson.js +2 -2
  19. package/core/types/configs/firebasejson.js.map +1 -0
  20. package/core/types/configs/firebaserc.js +2 -2
  21. package/core/types/configs/firebaserc.js.map +1 -0
  22. package/core/types/configs/index.d.ts +3 -3
  23. package/core/types/configs/index.js +4 -19
  24. package/core/types/configs/index.js.map +1 -0
  25. package/core/types/configs/package-json.d.ts +2 -1
  26. package/core/types/configs/package-json.js +2 -2
  27. package/core/types/configs/package-json.js.map +1 -0
  28. package/core/types/core.js +2 -2
  29. package/core/types/core.js.map +1 -0
  30. package/core/types/index.d.ts +4 -4
  31. package/core/types/index.js +5 -20
  32. package/core/types/index.js.map +1 -0
  33. package/core/types/package/index.d.ts +2 -2
  34. package/core/types/package/index.js +3 -18
  35. package/core/types/package/index.js.map +1 -0
  36. package/core/types/package/package.d.ts +10 -14
  37. package/core/types/package/package.js +15 -12
  38. package/core/types/package/package.js.map +1 -0
  39. package/core/types/package/runtime-package.d.ts +2 -2
  40. package/core/types/package/runtime-package.js +2 -2
  41. package/core/types/package/runtime-package.js.map +1 -0
  42. package/core/types/project-config.d.ts +31 -2
  43. package/core/types/project-config.js +2 -2
  44. package/core/types/project-config.js.map +1 -0
  45. package/defaults/backend-proxy/proxy._ts +3 -1
  46. package/defaults/consts.d.ts +0 -7
  47. package/defaults/consts.js +10 -10
  48. package/defaults/consts.js.map +1 -0
  49. package/{v2/phase-runner → old}/PhaseRunnerDispatcher.d.ts +4 -4
  50. package/old/PhaseRunnerDispatcher.js +33 -0
  51. package/old/PhaseRunnerDispatcher.js.map +1 -0
  52. package/{v2/unit → old}/runner-dispatchers.d.ts +3 -3
  53. package/old/runner-dispatchers.js +4 -0
  54. package/old/runner-dispatchers.js.map +1 -0
  55. package/package.json +20 -15
  56. package/v3/PhaseManager.d.ts +26 -0
  57. package/v3/PhaseManager.js +144 -0
  58. package/v3/PhaseManager.js.map +1 -0
  59. package/v3/RunningStatusHandler.d.ts +16 -0
  60. package/v3/RunningStatusHandler.js +57 -0
  61. package/v3/RunningStatusHandler.js.map +1 -0
  62. package/v3/UnitsDependencyMapper/UnitsDependencyMapper.d.ts +52 -0
  63. package/v3/UnitsDependencyMapper/UnitsDependencyMapper.js +287 -0
  64. package/v3/UnitsDependencyMapper/UnitsDependencyMapper.js.map +1 -0
  65. package/v3/UnitsMapper/UnitsMapper.d.ts +21 -0
  66. package/v3/UnitsMapper/UnitsMapper.js +60 -0
  67. package/v3/UnitsMapper/UnitsMapper.js.map +1 -0
  68. package/v3/UnitsMapper/resolvers/UnitMapper_Base.d.ts +23 -0
  69. package/v3/UnitsMapper/resolvers/UnitMapper_Base.js +17 -0
  70. package/v3/UnitsMapper/resolvers/UnitMapper_Base.js.map +1 -0
  71. package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseFunction.d.ts +62 -0
  72. package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseFunction.js +56 -0
  73. package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseFunction.js.map +1 -0
  74. package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseHosting.d.ts +38 -0
  75. package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseHosting.js +49 -0
  76. package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseHosting.js.map +1 -0
  77. package/v3/UnitsMapper/resolvers/UnitMapper_Node.d.ts +30 -0
  78. package/v3/UnitsMapper/resolvers/UnitMapper_Node.js +59 -0
  79. package/v3/UnitsMapper/resolvers/UnitMapper_Node.js.map +1 -0
  80. package/v3/UnitsMapper/resolvers/UnitMapper_NodeLib.d.ts +25 -0
  81. package/v3/UnitsMapper/resolvers/UnitMapper_NodeLib.js +29 -0
  82. package/v3/UnitsMapper/resolvers/UnitMapper_NodeLib.js.map +1 -0
  83. package/v3/UnitsMapper/resolvers/UnitMapper_NodeProject.d.ts +24 -0
  84. package/v3/UnitsMapper/resolvers/UnitMapper_NodeProject.js +23 -0
  85. package/v3/UnitsMapper/resolvers/UnitMapper_NodeProject.js.map +1 -0
  86. package/v3/UnitsMapper/resolvers/index.d.ts +4 -0
  87. package/v3/UnitsMapper/resolvers/index.js +5 -0
  88. package/v3/UnitsMapper/resolvers/index.js.map +1 -0
  89. package/v3/UnitsMapper/types.d.ts +25 -0
  90. package/v3/UnitsMapper/types.js +2 -0
  91. package/v3/UnitsMapper/types.js.map +1 -0
  92. package/v3/core/FileSystemUtils.d.ts +34 -0
  93. package/v3/core/FileSystemUtils.js +152 -0
  94. package/v3/core/FileSystemUtils.js.map +1 -0
  95. package/v3/core/FilesCache.d.ts +7 -0
  96. package/v3/core/FilesCache.js +34 -0
  97. package/v3/core/FilesCache.js.map +1 -0
  98. package/v3/core/Unit_HelpPrinter.d.ts +16 -0
  99. package/v3/core/Unit_HelpPrinter.js +48 -0
  100. package/v3/core/Unit_HelpPrinter.js.map +1 -0
  101. package/v3/core/types.d.ts +17 -0
  102. package/v3/core/types.js +6 -0
  103. package/v3/core/types.js.map +1 -0
  104. package/v3/phase/consts.d.ts +52 -0
  105. package/v3/phase/consts.js +127 -0
  106. package/v3/phase/consts.js.map +1 -0
  107. package/v3/phase/index.d.ts +2 -0
  108. package/v3/phase/index.js +3 -0
  109. package/v3/phase/index.js.map +1 -0
  110. package/v3/phase/types.d.ts +9 -0
  111. package/v3/phase/types.js +2 -0
  112. package/v3/phase/types.js.map +1 -0
  113. package/v3/units/BaseUnit.d.ts +46 -0
  114. package/v3/units/BaseUnit.js +120 -0
  115. package/v3/units/BaseUnit.js.map +1 -0
  116. package/v3/units/ProjectUnit.d.ts +18 -0
  117. package/v3/units/ProjectUnit.js +12 -0
  118. package/v3/units/ProjectUnit.js.map +1 -0
  119. package/v3/units/Unit_NodeProject.d.ts +30 -0
  120. package/v3/units/Unit_NodeProject.js +244 -0
  121. package/v3/units/Unit_NodeProject.js.map +1 -0
  122. package/v3/units/Unit_PackageJson.d.ts +18 -0
  123. package/v3/units/Unit_PackageJson.js +51 -0
  124. package/v3/units/Unit_PackageJson.js.map +1 -0
  125. package/v3/units/Unit_TypescriptLib.d.ts +45 -0
  126. package/v3/units/Unit_TypescriptLib.js +377 -0
  127. package/v3/units/Unit_TypescriptLib.js.map +1 -0
  128. package/v3/units/firebase/Unit_FirebaseFunctionsApp.d.ts +60 -0
  129. package/v3/units/firebase/Unit_FirebaseFunctionsApp.js +281 -0
  130. package/v3/units/firebase/Unit_FirebaseFunctionsApp.js.map +1 -0
  131. package/v3/units/firebase/Unit_FirebaseHostingApp.d.ts +49 -0
  132. package/v3/units/firebase/Unit_FirebaseHostingApp.js +100 -0
  133. package/v3/units/firebase/Unit_FirebaseHostingApp.js.map +1 -0
  134. package/v3/units/index.d.ts +5 -0
  135. package/v3/units/index.js +6 -0
  136. package/v3/units/index.js.map +1 -0
  137. package/core/params/types.d.ts +0 -51
  138. package/core/params/types.js +0 -2
  139. package/tsconfig.json +0 -23
  140. package/v2/phase/consts.d.ts +0 -53
  141. package/v2/phase/consts.js +0 -151
  142. package/v2/phase/index.d.ts +0 -2
  143. package/v2/phase/index.js +0 -18
  144. package/v2/phase/types.d.ts +0 -12
  145. package/v2/phase/types.js +0 -2
  146. package/v2/phase-runner/PhaseRunner.d.ts +0 -69
  147. package/v2/phase-runner/PhaseRunner.js +0 -472
  148. package/v2/phase-runner/PhaseRunnerDispatcher.js +0 -37
  149. package/v2/phase-runner/RunnerParams.d.ts +0 -12
  150. package/v2/phase-runner/RunnerParams.js +0 -9
  151. package/v2/phase-runner/consts.d.ts +0 -7
  152. package/v2/phase-runner/consts.js +0 -9
  153. package/v2/phase-runner/kaki.d.ts +0 -0
  154. package/v2/phase-runner/kaki.js +0 -1
  155. package/v2/phase-runner/types.d.ts +0 -13
  156. package/v2/phase-runner/types.js +0 -6
  157. package/v2/project/types.d.ts +0 -8
  158. package/v2/project/types.js +0 -2
  159. package/v2/screens/BAIScreen.d.ts +0 -22
  160. package/v2/screens/BAIScreen.js +0 -82
  161. package/v2/screens/BAIScreenManager.d.ts +0 -28
  162. package/v2/screens/BAIScreenManager.js +0 -77
  163. package/v2/screens/BAIScreen_Launch.d.ts +0 -28
  164. package/v2/screens/BAIScreen_Launch.js +0 -173
  165. package/v2/screens/BAIScreen_UnitList.d.ts +0 -36
  166. package/v2/screens/BAIScreen_UnitList.js +0 -203
  167. package/v2/unit/consts.d.ts +0 -6
  168. package/v2/unit/consts.js +0 -8
  169. package/v2/unit/core/BaseUnit.d.ts +0 -39
  170. package/v2/unit/core/BaseUnit.js +0 -138
  171. package/v2/unit/core/Unit_Python.d.ts +0 -16
  172. package/v2/unit/core/Unit_Python.js +0 -26
  173. package/v2/unit/core/Unit_Typescript.d.ts +0 -49
  174. package/v2/unit/core/Unit_Typescript.js +0 -143
  175. package/v2/unit/core/Unit_TypescriptLib.d.ts +0 -48
  176. package/v2/unit/core/Unit_TypescriptLib.js +0 -226
  177. package/v2/unit/core/Unit_TypescriptProject.d.ts +0 -31
  178. package/v2/unit/core/Unit_TypescriptProject.js +0 -194
  179. package/v2/unit/core/index.d.ts +0 -5
  180. package/v2/unit/core/index.js +0 -21
  181. package/v2/unit/firebase-units/Unit_FirebaseFunctionsApp.d.ts +0 -35
  182. package/v2/unit/firebase-units/Unit_FirebaseFunctionsApp.js +0 -309
  183. package/v2/unit/firebase-units/Unit_FirebaseHostingApp.d.ts +0 -24
  184. package/v2/unit/firebase-units/Unit_FirebaseHostingApp.js +0 -138
  185. package/v2/unit/firebase-units/consts.d.ts +0 -2
  186. package/v2/unit/firebase-units/consts.js +0 -9
  187. package/v2/unit/firebase-units/index.d.ts +0 -2
  188. package/v2/unit/firebase-units/index.js +0 -18
  189. package/v2/unit/runner-dispatchers.js +0 -6
  190. package/v2/unit/thunderstorm.d.ts +0 -171
  191. package/v2/unit/thunderstorm.js +0 -199
  192. package/v2/unit/tools/tools.d.ts +0 -2
  193. package/v2/unit/tools/tools.js +0 -15
  194. package/v2/unit/types.d.ts +0 -8
  195. package/v2/unit/types.js +0 -2
@@ -1,472 +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.PhaseRunner = void 0;
27
- const ts_common_1 = require("@nu-art/ts-common");
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 thunderstorm_1 = require("../unit/thunderstorm");
34
- const consts_1 = require("../../defaults/consts");
35
- const PhaseRunnerDispatcher_1 = require("./PhaseRunnerDispatcher");
36
- const tools_1 = require("@nu-art/commando/shell/tools");
37
- const types_1 = require("./types");
38
- const BAIScreenManager_1 = require("../screens/BAIScreenManager");
39
- const consts_2 = require("./consts");
40
- const basic_1 = require("@nu-art/commando/shell/plugins/basic");
41
- const CONST_ThunderstormVersionKey = 'THUNDERSTORM_SDK_VERSION';
42
- const CONST_ThunderstormDependencyKey = 'THUNDERSTORM_DEPENDENCY_VERSION';
43
- const CONST_ProjectVersionKey = 'APP_VERSION';
44
- const CONST_ProjectDependencyKey = 'APP_VERSION_DEPENDENCY';
45
- class PhaseRunner extends core_1.BaseUnit {
46
- constructor(projectPath) {
47
- super({ label: 'Phase Runner', key: 'phase-runner' });
48
- /**
49
- * kill counter that will intercept the kill event and if the threshold will be met the main process will be killed as well
50
- * @private
51
- */
52
- this.killCounter = 0;
53
- this.phaseFilters = {
54
- [types_1.PhaseRunnerMode_Normal]: async (phase) => {
55
- return !(0, ts_common_1.exists)(phase.filter) || (await phase.filter());
56
- },
57
- [types_1.PhaseRunnerMode_Continue]: async (phase) => {
58
- const currentPhaseIndex = this.phases.findIndex(phase => phase.key === this.runningStatus.phaseKey);
59
- const phaseIndex = this.phases.indexOf(phase);
60
- //True if the phase index is larger equals the index of the first phase that will run in continue
61
- if (phaseIndex >= currentPhaseIndex)
62
- return true;
63
- //Check if phase should run as a dependency
64
- const allPhasesThatWillRun = [];
65
- for (const phase of this.phases) {
66
- const index = this.phases.indexOf(phase);
67
- if (index >= currentPhaseIndex && await this.phaseFilters[types_1.PhaseRunnerMode_Normal](phase))
68
- allPhasesThatWillRun.push(phase);
69
- }
70
- const dependencyKeys = (0, ts_common_1.flatArray)(allPhasesThatWillRun.map(phase => { var _a; return (_a = phase.dependencyPhaseKeys) !== null && _a !== void 0 ? _a : []; }));
71
- return dependencyKeys.includes(phase.key);
72
- }
73
- };
74
- this.willUnitRunForPhase = async (phase, unit) => {
75
- var _a, _b;
76
- // Unit doesn't implement the phase method
77
- if (!(0, ts_common_1.exists)(unit[phase.method]))
78
- return false;
79
- // If phase implements unit filter whether unit doesn't pass
80
- if ((0, ts_common_1.exists)(phase.unitFilter))
81
- return (await phase.unitFilter(unit));
82
- // Runtime input is stronger than the unit default filter
83
- if (params_1.RuntimeParams.usePackage)
84
- return (((_a = params_1.RuntimeParams.usePackage) === null || _a === void 0 ? void 0 : _a.includes(unit.config.key)) || ((_b = params_1.RuntimeParams.usePackage) === null || _b === void 0 ? void 0 : _b.includes(unit.config.label)));
85
- // Unit filter itself
86
- if ((0, ts_common_1.exists)(unit.config.filter) && !await unit.config.filter())
87
- return false;
88
- return true;
89
- };
90
- this.getPhases = () => [...this.phases];
91
- if ((0, ts_common_1.exists)(PhaseRunner.instance))
92
- throw new ts_common_1.MUSTNeverHappenException('phase runner instance must be unique');
93
- Error.stackTraceLimit = 50;
94
- this.addToClassStack(PhaseRunner);
95
- this.screenManager = new BAIScreenManager_1.BAIScreenManager();
96
- this.phases = [];
97
- this.units = [this];
98
- this.projectPath = (0, tools_1.convertToFullPath)(projectPath);
99
- this.phaseFilter = this.phaseFilters[types_1.PhaseRunnerMode_Normal];
100
- this.setMinLevel(ts_common_1.LogLevel.Info);
101
- console.log('RuntimeParams.debug', params_1.RuntimeParams.debug);
102
- if (params_1.RuntimeParams.debug)
103
- this.setMinLevel(ts_common_1.LogLevel.Debug);
104
- if (params_1.RuntimeParams.verbose)
105
- this.setMinLevel(ts_common_1.LogLevel.Debug);
106
- }
107
- //######################### Initialization #########################
108
- async init() {
109
- var _a;
110
- consts_2.MemKey_PhaseRunner.set(this);
111
- BAIScreenManager_1.MemKey_BAIScreenManager.set(this.screenManager);
112
- const runnerParams = {
113
- rootPath: process.cwd(),
114
- configPath: process.cwd() + '/.config',
115
- };
116
- RunnerParams_1.MemKey_RunnerParams.set(runnerParams);
117
- if (this.projectConfig) {
118
- const projectParams = this.prepareProjectParams();
119
- RunnerParams_1.MemKey_ProjectConfig.set(Object.assign(Object.assign({}, this.projectConfig), { params: projectParams }));
120
- }
121
- if (this.defaultFileRoutes)
122
- consts_1.MemKey_DefaultFiles.set(this.defaultFileRoutes);
123
- if (PhaseRunner.instance) {
124
- return;
125
- }
126
- PhaseRunner.instance = this;
127
- //Load project for use in the phase runner
128
- (_a = this.projectConfig) !== null && _a !== void 0 ? _a : (this.projectConfig = await this.loadProject());
129
- //Filter specific units
130
- // this.filterUnits();
131
- this.logDebug('Runtime params:', params_1.RuntimeParams);
132
- //Set runner params
133
- //Set Project Params
134
- const projectParams = this.prepareProjectParams();
135
- RunnerParams_1.MemKey_ProjectConfig.set(Object.assign(Object.assign({}, this.projectConfig), { params: projectParams }));
136
- //Set Default File Routes
137
- this.defaultFileRoutes = this.prepareDefaultFileRouts();
138
- consts_1.MemKey_DefaultFiles.set(this.defaultFileRoutes);
139
- //Load running status
140
- await this.loadRunningStatus();
141
- //Print init results
142
- this.setStatus('Initialized');
143
- const units = this.units.filter(unit => unit !== this);
144
- await Promise.all(units.map(unit => {
145
- // @ts-ignore
146
- return unit.init();
147
- }));
148
- }
149
- // private filterUnits() {
150
- // const useUnits = RuntimeParams.usePackage;
151
- // if (!useUnits || !useUnits.length)
152
- // return;
153
- //
154
- // const unitsToRemove: BaseUnit[] = [];
155
- // for (const unit of this.units) {
156
- // if (unit === this)
157
- // continue;
158
- //
159
- // if (!useUnits.includes(unit.config.key))
160
- // unitsToRemove.push(unit);
161
- // }
162
- //
163
- // if (!unitsToRemove.length)
164
- // return;
165
- //
166
- // unitsToRemove.forEach(unit => removeItemFromArray(this.units, unit));
167
- // }
168
- async loadProject() {
169
- if (!fs_1.default.existsSync(this.projectPath))
170
- throw new ts_common_1.ImplementationMissingException(`Missing project config file, could not find in path: ${this.projectPath}`);
171
- const projectConfigCB = require(this.projectPath).default;
172
- if (typeof projectConfigCB !== 'function')
173
- throw new ts_common_1.BadImplementationException('Config file must be an asynchronous function returning a ProjectConfigV2 object');
174
- return projectConfigCB();
175
- }
176
- prepareProjectParams() {
177
- var _a;
178
- const params = (_a = this.projectConfig.params) !== null && _a !== void 0 ? _a : {};
179
- params[CONST_ThunderstormVersionKey] = this.projectConfig.thunderstormVersion;
180
- params[CONST_ThunderstormDependencyKey] = this.projectConfig.thunderstormVersion;
181
- params[CONST_ProjectVersionKey] = this.projectConfig.projectVersion;
182
- params[CONST_ProjectDependencyKey] = this.projectConfig.projectVersion;
183
- return params;
184
- }
185
- prepareDefaultFileRouts() {
186
- const defaultFileRoutes = (0, ts_common_1.deepClone)(consts_1.Default_Files);
187
- const projectDefaultFileRoutes = RunnerParams_1.MemKey_ProjectConfig.get().defaultFileRoutes;
188
- return (0, ts_common_1.merge)(defaultFileRoutes, projectDefaultFileRoutes);
189
- }
190
- async buildUnitDependencyTree() {
191
- const units = [...this.units];
192
- // Filter out units by their filter
193
- for (const unit of units) {
194
- if ((0, ts_common_1.exists)(unit.config.filter) && !(await unit.config.filter())) {
195
- (0, ts_common_1.removeItemFromArray)(units, unit);
196
- // @ts-ignore
197
- unit.setStatus('Will not run');
198
- unit.logInfo('unit will not run, did not pass unit filter');
199
- }
200
- }
201
- const allDependencies = units.map(unit => unit.runtime.dependencyName);
202
- const resolvedUnitNames = [];
203
- const dependencyTree = [];
204
- while (units.length) {
205
- if (!resolvedUnitNames.length) {
206
- //First run - get all units that don't have other units as dependencies
207
- const nonDependantUnits = units.filter(unit => {
208
- return !(0, ts_common_1.arrayIncludesAny)(unit.runtime.unitDependencyNames, allDependencies);
209
- });
210
- //Remove gathered units from the list of units to resolve
211
- nonDependantUnits.forEach(unit => (0, ts_common_1.removeItemFromArray)(units, unit));
212
- //Add resolved unit names to the array
213
- resolvedUnitNames.push(...nonDependantUnits.map(unit => unit.runtime.dependencyName));
214
- //Add resolved units as a layer in the dependency tree
215
- dependencyTree.push(nonDependantUnits);
216
- continue;
217
- }
218
- //Not first run - get all units where their dependencies are already resolved.
219
- const resolvingUnits = units.filter(unit => {
220
- const dependencyUnitPackageNames = unit.runtime.unitDependencyNames.filter(dependency => allDependencies.includes(dependency));
221
- return dependencyUnitPackageNames.every(dependency => resolvedUnitNames.includes(dependency));
222
- });
223
- //Remove gathered units from the list of units to resolve
224
- resolvingUnits.forEach(unit => (0, ts_common_1.removeItemFromArray)(units, unit));
225
- //Add resolved unit names to the array
226
- resolvedUnitNames.push(...resolvingUnits.map(unit => unit.runtime.dependencyName));
227
- //Add resolved units as a layer in the dependency tree
228
- dependencyTree.push(resolvingUnits);
229
- }
230
- this.unitDependencyTree = dependencyTree;
231
- }
232
- async executeImpl() {
233
- var _a;
234
- const phasesBlocks = [];
235
- let phasesBlock = [];
236
- let lastPhase;
237
- const reversedPhases = [...this.phases].reverse();
238
- for (const phase of this.phases) {
239
- if (lastPhase === null || lastPhase === void 0 ? void 0 : lastPhase.terminateAfterPhase)
240
- continue;
241
- try {
242
- let willExecutePhase = await this.phaseFilter(phase);
243
- for (const _phase of reversedPhases) {
244
- if (await this.phaseFilter(_phase) && ((_a = _phase.dependencyPhaseKeys) === null || _a === void 0 ? void 0 : _a.includes(phase.key))) {
245
- willExecutePhase = true;
246
- }
247
- }
248
- if (!willExecutePhase) {
249
- this.logDebug(`Will not execute phase: ${phase.name}, did not pass filter`);
250
- lastPhase = undefined;
251
- continue;
252
- }
253
- lastPhase = phase;
254
- this.logVerbose(`Will execute phase: ${phase.name}`);
255
- if (phase.breakPhases) {
256
- phasesBlocks.push(phasesBlock);
257
- phasesBlocks.push([phase]);
258
- phasesBlock = [];
259
- continue;
260
- }
261
- phasesBlock.push(phase);
262
- // await this.executePhase(phase);
263
- }
264
- catch (e) {
265
- this.logError(`Error running phase: ${phase.name}`, e);
266
- }
267
- }
268
- if (phasesBlock.length)
269
- phasesBlocks.push(phasesBlock);
270
- if (params_1.RuntimeParams.debug)
271
- this.logDebug('phasesBlock: ', phasesBlock);
272
- const executionQueue = phasesBlocks.map((_phasesBlock, index) => {
273
- this.logDebug(`Executing phases #${index}: ${_phasesBlock.map(p => p.name).join(', ')}`);
274
- return async () => {
275
- return (0, ts_common_1.Promise_all_sequentially)(this.unitDependencyTree.map(unitGroup => () => {
276
- return Promise.all(unitGroup.map(unit => (0, ts_common_1.Promise_all_sequentially)(_phasesBlock.map(phase => () => this.executePhase(phase, unit, index)))));
277
- }));
278
- };
279
- });
280
- await (0, ts_common_1.Promise_all_sequentially)(executionQueue);
281
- this.killed = false;
282
- }
283
- async executePhase(phase, unit, index) {
284
- if (!params_1.RuntimeParams.dryRun)
285
- return this.executePhaseImpl(phase, unit, index);
286
- return this.executePhaseDryRun(phase, unit, index);
287
- }
288
- async executePhaseImpl(phase, unit, index) {
289
- var _a, _b;
290
- if (!await this.willUnitRunForPhase(phase, unit))
291
- return;
292
- unit.logDebug(`Running phase #${index}: ${phase.name}`);
293
- return (_b = (_a = unit)[phase.method]) === null || _b === void 0 ? void 0 : _b.call(_a);
294
- }
295
- async executePhaseDryRun(phase, unit, index) {
296
- if (!(await this.willUnitRunForPhase(phase, unit)))
297
- unit.logWarning(`will NOT run phase #${index}: ${phase.name}`);
298
- else
299
- unit.logWarning(`Running phase #${index}: ${phase.name}`);
300
- }
301
- //######################### Unit Logic #########################
302
- registerUnits(units) {
303
- this.units.push(...(0, ts_common_1.asArray)(units));
304
- (0, ts_common_1.sortArray)(this.units, unit => {
305
- //Phase runner is first
306
- if (unit === this)
307
- return 0;
308
- //Second priority for project units
309
- if (unit instanceof core_1.Unit_TypescriptProject)
310
- return 1;
311
- //TS units after project units, but before the rest
312
- return thunderstorm_1.allTSUnits.includes(unit) ? 2 : 3;
313
- });
314
- PhaseRunnerDispatcher_1.dispatcher_UnitChange.dispatch(this.units);
315
- }
316
- getUnits() {
317
- return this.units;
318
- }
319
- prependPhase(phase, beforePhase) {
320
- if (!beforePhase) {
321
- this.phases.unshift(phase);
322
- return;
323
- }
324
- const index = this.phases.indexOf(beforePhase);
325
- //If the beforePhase isn't in this.phases or is the first item
326
- if (index === -1 || index === 0)
327
- return this.prependPhase(phase);
328
- (0, ts_common_1.addItemToArrayAtIndex)(this.phases, phase, index - 1);
329
- }
330
- appendPhase(phase, afterPhase) {
331
- if (!afterPhase) {
332
- this.phases.push(phase);
333
- return;
334
- }
335
- const index = this.phases.indexOf(afterPhase);
336
- //If the afterPhase isn't in this.phases or is the last item
337
- if (index === -1 || index === this.phases.length - 1)
338
- return this.appendPhase(phase);
339
- (0, ts_common_1.addItemToArrayAtIndex)(this.phases, phase, index + 1);
340
- }
341
- //######################### Running Status #########################
342
- async setRunningStatus() {
343
- this.logVerbose('Setting Running Status', this.runningStatus);
344
- if (!fs_1.default.existsSync(consts_1.Default_OutputFiles.output))
345
- await fs_1.promises.mkdir(consts_1.Default_OutputFiles.output, { recursive: true });
346
- await fs_1.promises.writeFile(consts_1.Default_OutputFiles.runningStatus, (0, ts_common_1.__stringify)(this.runningStatus, true));
347
- }
348
- async loadRunningStatus() {
349
- const setDefaultRunningStatus = () => {
350
- this.runningStatus = {
351
- phaseKey: this.phases[0].key,
352
- packageDependencyIndex: 0,
353
- };
354
- this.phaseFilter = this.phaseFilters[types_1.PhaseRunnerMode_Normal];
355
- };
356
- if (!params_1.RuntimeParams.continue) {
357
- setDefaultRunningStatus();
358
- return;
359
- }
360
- //If the dir exists, try to read the file
361
- if (fs_1.default.existsSync(consts_1.Default_OutputFiles.output)) {
362
- try {
363
- this.runningStatus = JSON.parse(await fs_1.promises.readFile(consts_1.Default_OutputFiles.runningStatus, { encoding: 'utf-8' }));
364
- this.phaseFilter = this.phaseFilters[types_1.PhaseRunnerMode_Continue];
365
- }
366
- catch (e) {
367
- this.logError('Failed reading running status');
368
- setDefaultRunningStatus();
369
- return;
370
- }
371
- }
372
- else
373
- setDefaultRunningStatus();
374
- }
375
- //######################### Public Functions #########################
376
- async execute() {
377
- return new MemStorage_1.MemStorage().init(async () => {
378
- process.on('SIGINT', () => {
379
- this.killRunner();
380
- });
381
- try {
382
- try {
383
- await this.init();
384
- }
385
- catch (e) {
386
- this.logError('Error initializing Runner', e);
387
- throw e;
388
- }
389
- try {
390
- await this.buildUnitDependencyTree();
391
- }
392
- catch (e) {
393
- this.logError('Error building execution Tree', e);
394
- throw e;
395
- }
396
- await this.executeImpl();
397
- this.killed = true;
398
- this.logInfo('Completed successfully');
399
- ts_common_1.StaticLogger.logInfo('-----------', '---------------------------------- Process Completed successfully ----------------------------------');
400
- if (params_1.RuntimeParams.closeOnExit)
401
- process.exit(0);
402
- }
403
- catch (e) {
404
- if (params_1.RuntimeParams.closeOnExit)
405
- process.exit(1);
406
- }
407
- });
408
- }
409
- async killRunner() {
410
- this.killCounter++;
411
- if (this.killCounter === PhaseRunner.KILL_THRESHOLD)
412
- process.exit(1);
413
- if (this.killed)
414
- process.exit(1);
415
- await this.setRunningStatus();
416
- this.logDebug('Killing units');
417
- await Promise.all(this.units.map(async (unit) => {
418
- try {
419
- await unit.kill();
420
- }
421
- catch (e) {
422
- unit.logError(`Error killing unit`, e);
423
- }
424
- }));
425
- this.logDebug('Units killed');
426
- this.killed = true;
427
- if (params_1.RuntimeParams.closeOnExit)
428
- process.exit(1);
429
- }
430
- //######################### Phase Implementation #########################
431
- async printHelp() {
432
- this.logInfo('Build and install parameters:');
433
- const noGroupConst = 'No Group';
434
- //Resolve all params by group
435
- 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) => {
436
- var _a, _b, _c, _d;
437
- 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];
438
- return mapper[(_d = item.group) !== null && _d !== void 0 ? _d : noGroupConst];
439
- });
440
- (0, ts_common_1._keys)(paramsByGroup).map(paramGroup => {
441
- this.logWarningBold(`${paramGroup}: \n`);
442
- // commando.append(`echo "${paramGroup}:" \n`);
443
- paramsByGroup[paramGroup].map(param => {
444
- const paramKeys = param.keys.join(' | ');
445
- const paramDescription = param.description.trim().split('\n').join('\n\t\t');
446
- this.logInfo(`${paramKeys} \n\t\t ${paramDescription} \n`);
447
- // commando.append(`echo "\n ${param.keys.join(' | ')} \n \t\t${param.description.trim().split('\n').join('\n\t\t')} \n"`);
448
- });
449
- });
450
- }
451
- async printEnv() {
452
- await this.allocateCommando(basic_1.Commando_Basic)
453
- .append('npm -g list typescript eslint firebase-tools sort-package-json --depth=0')
454
- .append('echo "npm version:"; npm -v')
455
- .append('echo "node version:"; node -v')
456
- .append('echo "base version:"; bash --version')
457
- .execute();
458
- }
459
- async printDebug() {
460
- this.logDebug('Runner Params:', RunnerParams_1.MemKey_RunnerParams.get());
461
- this.logDebug('Project Config:', RunnerParams_1.MemKey_ProjectConfig.get());
462
- this.logDebug('Default File Routes:', consts_1.MemKey_DefaultFiles.get());
463
- this.logDebug('All Phases:', this.phases.map(phase => phase.name));
464
- this.logDebug('Filtered Units:', this.units.map(unit => unit.config.label));
465
- const dependencyTree = this.unitDependencyTree.map(row => row.map(unit => unit.config.label));
466
- this.logInfo('Unit Dependencies Tree:', dependencyTree);
467
- if (params_1.RuntimeParams.debugLifecycle)
468
- process.exit(0);
469
- }
470
- }
471
- exports.PhaseRunner = PhaseRunner;
472
- PhaseRunner.KILL_THRESHOLD = 5;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dispatcher_UnitChange = exports.dispatcher_UnitStatusChange = exports.dispatcher_PhaseChange = exports.PhaseRunnerDispatcher = 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
- if (this.listeners.includes(listener))
13
- return;
14
- this.listeners.push(listener);
15
- }
16
- removeListener(listener) {
17
- (0, ts_common_1.removeItemFromArray)(this.listeners, listener);
18
- }
19
- dispatch(...data) {
20
- this.listeners.forEach(listener => {
21
- var _a;
22
- // @ts-ignore
23
- (_a = listener[this.method]) === null || _a === void 0 ? void 0 : _a.call(listener, ...data);
24
- });
25
- }
26
- async dispatchAsync(...data) {
27
- await Promise.all(this.listeners.map(async (listener) => {
28
- var _a;
29
- // @ts-ignore
30
- return (_a = listener[this.method]) === null || _a === void 0 ? void 0 : _a.call(listener, ...data);
31
- }));
32
- }
33
- }
34
- exports.PhaseRunnerDispatcher = PhaseRunnerDispatcher;
35
- exports.dispatcher_PhaseChange = new PhaseRunnerDispatcher('__onPhaseChange');
36
- exports.dispatcher_UnitStatusChange = new PhaseRunnerDispatcher('__onUnitStatusChange');
37
- exports.dispatcher_UnitChange = new PhaseRunnerDispatcher('__onUnitsChange');
@@ -1,12 +0,0 @@
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 {};
@@ -1,9 +0,0 @@
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];
@@ -1,7 +0,0 @@
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>;
@@ -1,9 +0,0 @@
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');
File without changes
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,13 +0,0 @@
1
- import { AsyncVoidFunction } from '@nu-art/ts-common';
2
- import { Phase } from '../phase/types';
3
- export type PhaseImplementor<P extends Phase<string>[]> = {
4
- [K in P[number]['method']]: AsyncVoidFunction;
5
- };
6
- export type PhasesImplementor<Phases extends Phase<string>[]> = {
7
- [K in Phases[number]['method']]?: AsyncVoidFunction;
8
- };
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,6 +0,0 @@
1
- "use strict";
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];
@@ -1,8 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,22 +0,0 @@
1
- import { AsyncVoidFunction } from '@nu-art/ts-common';
2
- import { ConsoleScreen } from '@nu-art/commando/console/ConsoleScreen';
3
- export declare abstract class BAIScreen<State extends {} = {}> extends ConsoleScreen<State> {
4
- private onKillCallback?;
5
- private logClient;
6
- /**
7
- * Creates an instance of ConsoleScreen.
8
- *
9
- * @param {Widgets.IScreenOptions} [props] - The properties to apply to the screen widget.
10
- * @param {ScreenKeyBinding[]} [keyBinding] - An array of key bindings for the screen widget.
11
- */
12
- constructor(logClientKey: string);
13
- private createLogClient;
14
- protected abstract scrollLog(direction: number): void;
15
- protected abstract onLogUpdated: () => void;
16
- protected getLogs: () => string;
17
- startScreen: () => void;
18
- stopScreen: () => void;
19
- protected abstract destroyContent(): void;
20
- protected onKill(): Promise<void>;
21
- setOnKillCallback: (cb: AsyncVoidFunction) => AsyncVoidFunction;
22
- }