@nu-art/build-and-install 0.400.14 → 0.401.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 (156) hide show
  1. package/BuildAndInstall.d.ts +40 -0
  2. package/BuildAndInstall.js +155 -0
  3. package/build-and-install-v3.d.ts +1 -32
  4. package/build-and-install-v3.js +1 -154
  5. package/build-and-install.js +11 -11
  6. package/config/consts.d.ts +43 -0
  7. package/config/consts.js +42 -0
  8. package/{core → config}/package/consts.d.ts +1 -1
  9. package/{core → config}/types/project-config.d.ts +3 -0
  10. package/core/FilesCache.d.ts +50 -0
  11. package/core/FilesCache.js +76 -0
  12. package/core/Unit_HelpPrinter.d.ts +16 -0
  13. package/core/Unit_HelpPrinter.js +47 -0
  14. package/core/params/params.d.ts +1 -41
  15. package/core/params/params.js +1 -334
  16. package/core/params.d.ts +50 -0
  17. package/core/params.js +441 -0
  18. package/{v3/core → core}/types.d.ts +1 -1
  19. package/{v3/UnitsDependencyMapper → dependencies}/UnitsDependencyMapper.d.ts +21 -1
  20. package/{v3/UnitsDependencyMapper → dependencies}/UnitsDependencyMapper.js +26 -3
  21. package/dependencies/types.d.ts +1 -0
  22. package/dependencies/types.js +1 -0
  23. package/exceptions/PhaseAggregatedException.d.ts +34 -0
  24. package/{core/exceptions → exceptions}/PhaseAggregatedException.js +26 -0
  25. package/exceptions/UnitPhaseException.d.ts +20 -0
  26. package/exceptions/UnitPhaseException.js +21 -0
  27. package/exports/ExportIndexCache.d.ts +25 -0
  28. package/exports/ExportIndexCache.js +115 -0
  29. package/exports/ExportMapper.d.ts +43 -0
  30. package/exports/ExportMapper.js +519 -0
  31. package/exports/IndicesMcpServer.d.ts +22 -0
  32. package/exports/IndicesMcpServer.js +220 -0
  33. package/exports/types.js +3 -0
  34. package/package.json +20 -9
  35. package/phases/PhaseManager.d.ts +130 -0
  36. package/phases/PhaseManager.js +267 -0
  37. package/{v3/phase → phases/definitions}/consts.d.ts +36 -0
  38. package/{v3/phase → phases/definitions}/consts.js +45 -2
  39. package/phases/definitions/types.d.ts +40 -0
  40. package/phases/index.d.ts +2 -0
  41. package/phases/index.js +2 -0
  42. package/run.js +10 -0
  43. package/runtime/RunningStatusHandler.d.ts +104 -0
  44. package/runtime/RunningStatusHandler.js +153 -0
  45. package/runtime/types.d.ts +1 -0
  46. package/runtime/types.js +2 -0
  47. package/{defaults → templates}/consts.d.ts +9 -0
  48. package/{defaults → templates}/consts.js +12 -2
  49. package/templates/firebase/functions/cloudbuild.yaml +17 -0
  50. package/templates/firebase/functions/dockerfile +19 -0
  51. package/templates/firebase/functions/service.yaml +49 -0
  52. package/{v3/units → units/base}/BaseUnit.d.ts +35 -3
  53. package/{v3/units → units/base}/BaseUnit.js +22 -2
  54. package/units/base/ProjectUnit.d.ts +32 -0
  55. package/units/base/ProjectUnit.js +25 -0
  56. package/units/base/types.js +1 -0
  57. package/units/discovery/UnitsMapper.d.ts +69 -0
  58. package/{v3/UnitsMapper → units/discovery}/UnitsMapper.js +51 -3
  59. package/units/discovery/resolvers/UnitMapper_Base.d.ts +65 -0
  60. package/units/discovery/resolvers/UnitMapper_Base.js +46 -0
  61. package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_FirebaseFunction.d.ts +5 -3
  62. package/units/discovery/resolvers/UnitMapper_FirebaseFunction.js +105 -0
  63. package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_FirebaseHosting.d.ts +3 -2
  64. package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_FirebaseHosting.js +14 -10
  65. package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_Node.d.ts +1 -1
  66. package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_Node.js +2 -2
  67. package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_NodeLib.d.ts +24 -1
  68. package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_NodeLib.js +24 -1
  69. package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_NodeProject.d.ts +22 -1
  70. package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_NodeProject.js +22 -1
  71. package/units/discovery/types.js +1 -0
  72. package/units/implementations/Unit_NodeProject.d.ts +59 -0
  73. package/{v3/units → units/implementations}/Unit_NodeProject.js +67 -6
  74. package/units/implementations/Unit_PackageJson.d.ts +56 -0
  75. package/{v3/units → units/implementations}/Unit_PackageJson.js +39 -3
  76. package/{v3/units → units/implementations}/Unit_TypescriptLib.d.ts +40 -4
  77. package/{v3/units → units/implementations}/Unit_TypescriptLib.js +167 -17
  78. package/units/implementations/firebase/Unit_FirebaseFunctionsApp.d.ts +233 -0
  79. package/units/implementations/firebase/Unit_FirebaseFunctionsApp.js +804 -0
  80. package/units/implementations/firebase/Unit_FirebaseHostingApp.d.ts +113 -0
  81. package/units/implementations/firebase/Unit_FirebaseHostingApp.js +320 -0
  82. package/units/implementations/firebase/common.d.ts +26 -0
  83. package/units/implementations/firebase/common.js +65 -0
  84. package/units/index.d.ts +6 -0
  85. package/units/index.js +6 -0
  86. package/v3/core/Unit_HelpPrinter.d.ts +1 -16
  87. package/v3/core/Unit_HelpPrinter.js +1 -47
  88. package/workspace/Workspace.d.ts +95 -0
  89. package/workspace/Workspace.js +192 -0
  90. package/core/consts.d.ts +0 -13
  91. package/core/consts.js +0 -12
  92. package/core/exceptions/PhaseAggregatedException.d.ts +0 -8
  93. package/core/exceptions/UnitPhaseException.d.ts +0 -5
  94. package/core/exceptions/UnitPhaseException.js +0 -6
  95. package/old/PhaseRunnerDispatcher.d.ts +0 -24
  96. package/old/PhaseRunnerDispatcher.js +0 -32
  97. package/old/runner-dispatchers.d.ts +0 -10
  98. package/old/runner-dispatchers.js +0 -3
  99. package/v3/PhaseManager.d.ts +0 -26
  100. package/v3/PhaseManager.js +0 -158
  101. package/v3/RunningStatusHandler.d.ts +0 -18
  102. package/v3/RunningStatusHandler.js +0 -67
  103. package/v3/UnitsMapper/UnitsMapper.d.ts +0 -21
  104. package/v3/UnitsMapper/resolvers/UnitMapper_Base.d.ts +0 -23
  105. package/v3/UnitsMapper/resolvers/UnitMapper_Base.js +0 -16
  106. package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseFunction.js +0 -66
  107. package/v3/core/FilesCache.d.ts +0 -7
  108. package/v3/core/FilesCache.js +0 -33
  109. package/v3/phase/types.d.ts +0 -9
  110. package/v3/units/ProjectUnit.d.ts +0 -18
  111. package/v3/units/ProjectUnit.js +0 -11
  112. package/v3/units/Unit_NodeProject.d.ts +0 -30
  113. package/v3/units/Unit_PackageJson.d.ts +0 -17
  114. package/v3/units/firebase/Unit_FirebaseFunctionsApp.d.ts +0 -64
  115. package/v3/units/firebase/Unit_FirebaseFunctionsApp.js +0 -306
  116. package/v3/units/firebase/Unit_FirebaseHostingApp.d.ts +0 -49
  117. package/v3/units/firebase/Unit_FirebaseHostingApp.js +0 -114
  118. package/v3/units/firebase/common.d.ts +0 -3
  119. package/v3/units/firebase/common.js +0 -13
  120. package/v3/units/index.d.ts +0 -6
  121. package/v3/units/index.js +0 -6
  122. /package/{core → config}/package/consts.js +0 -0
  123. /package/{core → config}/types/configs/firebasejson.d.ts +0 -0
  124. /package/{core → config}/types/configs/firebasejson.js +0 -0
  125. /package/{core → config}/types/configs/firebaserc.d.ts +0 -0
  126. /package/{core → config}/types/configs/firebaserc.js +0 -0
  127. /package/{core → config}/types/configs/index.d.ts +0 -0
  128. /package/{core → config}/types/configs/index.js +0 -0
  129. /package/{core → config}/types/configs/package-json.d.ts +0 -0
  130. /package/{core → config}/types/configs/package-json.js +0 -0
  131. /package/{core → config}/types/core.d.ts +0 -0
  132. /package/{core → config}/types/core.js +0 -0
  133. /package/{core → config}/types/index.d.ts +0 -0
  134. /package/{core → config}/types/index.js +0 -0
  135. /package/{core → config}/types/package/index.d.ts +0 -0
  136. /package/{core → config}/types/package/index.js +0 -0
  137. /package/{core → config}/types/package/package.d.ts +0 -0
  138. /package/{core → config}/types/package/package.js +0 -0
  139. /package/{core → config}/types/package/runtime-package.d.ts +0 -0
  140. /package/{core → config}/types/package/runtime-package.js +0 -0
  141. /package/{core → config}/types/project-config.js +0 -0
  142. /package/{v3/core → core}/types.js +0 -0
  143. /package/{v3/UnitsMapper/types.js → exports/types.d.ts} +0 -0
  144. /package/{v3/phase → phases/definitions}/index.d.ts +0 -0
  145. /package/{v3/phase → phases/definitions}/index.js +0 -0
  146. /package/{v3/phase → phases/definitions}/types.js +0 -0
  147. /package/{v3/units/types.js → run.d.ts} +0 -0
  148. /package/{defaults/backend-proxy → templates/backend/proxy}/proxy._ts +0 -0
  149. /package/{defaults/.firebase_config → templates/firebase/config}/database.rules.json +0 -0
  150. /package/{defaults/.firebase_config → templates/firebase/config}/firestore.indexes.json +0 -0
  151. /package/{defaults/.firebase_config → templates/firebase/config}/firestore.rules +0 -0
  152. /package/{defaults/.firebase_config → templates/firebase/config}/storage.rules +0 -0
  153. /package/{v3/units → units/base}/types.d.ts +0 -0
  154. /package/{v3/UnitsMapper → units/discovery}/resolvers/index.d.ts +0 -0
  155. /package/{v3/UnitsMapper → units/discovery}/resolvers/index.js +0 -0
  156. /package/{v3/UnitsMapper → units/discovery}/types.d.ts +0 -0
@@ -0,0 +1,95 @@
1
+ import { AnyConstructor, Logger } from '@nu-art/ts-common';
2
+ import { BaiParams } from '../core/params.js';
3
+ import { UnitsMapper } from '../units/discovery/UnitsMapper.js';
4
+ import { UnitsDependencyMapper } from '../dependencies/UnitsDependencyMapper.js';
5
+ import { BaseUnit, ProjectUnit, Unit_NodeProject } from '../units/index.js';
6
+ /**
7
+ * Central workspace manager for all units in the build system.
8
+ *
9
+ * **Unit Categories**:
10
+ * - **Scanned Units**: All units discovered from workspace file system scan
11
+ * - **Active Units**: Units selected for execution (compile/test/lint) based on runtime params
12
+ * - **Project Units**: Active units + their transitive dependencies (needed for prepare/install)
13
+ *
14
+ * **Key Responsibilities**:
15
+ * - Unit discovery and storage
16
+ * - Dependency resolution and tree building
17
+ * - Unit lookup by key/type
18
+ * - Active/project unit derivation based on runtime params
19
+ *
20
+ * **Dependency Management**:
21
+ * - Uses `UnitsDependencyMapper` to resolve transitive dependencies
22
+ * - Builds dependency tree in layers (dependencies first, dependents last)
23
+ * - Filters dependencies to only include units that exist in workspace
24
+ *
25
+ * **Runtime Params Impact**:
26
+ * - `--use-package`: Filters active units to match regex patterns
27
+ * - `--build-tree`: Includes transitive dependencies in active units
28
+ * - Without flags: All units are active and project units
29
+ */
30
+ export declare class Workspace extends Logger {
31
+ private _projectUnits;
32
+ private _activeUnits;
33
+ private _projectUnitKeys;
34
+ private unitsDependencyMapper?;
35
+ private unitKeyToUnitMap;
36
+ /**
37
+ * All project units (subset of scanned units that are ProjectUnits)
38
+ */
39
+ get projectUnits(): ReadonlyArray<ProjectUnit>;
40
+ /**
41
+ * Keys of units selected for execution
42
+ */
43
+ get activeUnits(): ReadonlyArray<string>;
44
+ /**
45
+ * Keys of project units (active units + their transitive dependencies)
46
+ */
47
+ get projectUnitKeys(): ReadonlyArray<string>;
48
+ /**
49
+ * Scan units from the workspace using the provided UnitsMapper
50
+ */
51
+ scanUnits(path: string, unitsMapper: UnitsMapper): Promise<void>;
52
+ /**
53
+ * Add additional project units (e.g., from applicative configuration)
54
+ * can only be called before scanUnits()
55
+ */
56
+ addProjectUnits(projectUnits: ProjectUnit[]): void;
57
+ /**
58
+ * Initialize the dependency mapper with project units
59
+ */
60
+ initializeDependencyMapper(globalOutputFolder: string): void;
61
+ /**
62
+ * Derive active and project units based on runtime parameters
63
+ * This must be called after initializeDependencyMapper()
64
+ */
65
+ deriveActiveAndProjectUnits(runtimeParams: BaiParams): {
66
+ activeUnits: string[];
67
+ projectUnits: string[];
68
+ };
69
+ /**
70
+ * Get a unit by its key
71
+ */
72
+ getUnitByKey<T extends BaseUnit>(key: string): T | undefined;
73
+ getUnitByKey<T extends BaseUnit>(key: string, className: AnyConstructor<T>): T;
74
+ /**
75
+ * Get multiple units by their keys, optionally filtered by class type
76
+ */
77
+ getUnitsByKeys<T extends BaseUnit>(keys: string[], className?: AnyConstructor<T>): T[];
78
+ /**
79
+ * Get the root NodeProject unit
80
+ */
81
+ getNodeProjectUnit(): Unit_NodeProject | undefined;
82
+ /**
83
+ * Build dependency tree for the given project unit keys
84
+ * Returns layers of units ordered from bottom (no dependencies) to top
85
+ */
86
+ buildDependencyTree(projectUnitKeys: string[]): Promise<ProjectUnit[][]>;
87
+ /**
88
+ * Get transitive dependencies for given unit keys
89
+ */
90
+ getTransitiveDependencies(keys: string[]): string[];
91
+ /**
92
+ * Get the dependency mapper (for runtime context)
93
+ */
94
+ getDependencyMapper(): UnitsDependencyMapper;
95
+ }
@@ -0,0 +1,192 @@
1
+ import { _keys, arrayToMap, BadImplementationException, flatArray, ImplementationMissingException, Logger } from '@nu-art/ts-common';
2
+ import { UnitsDependencyMapper } from '../dependencies/UnitsDependencyMapper.js';
3
+ import { ProjectUnit, Unit_NodeProject } from '../units/index.js';
4
+ /**
5
+ * Central workspace manager for all units in the build system.
6
+ *
7
+ * **Unit Categories**:
8
+ * - **Scanned Units**: All units discovered from workspace file system scan
9
+ * - **Active Units**: Units selected for execution (compile/test/lint) based on runtime params
10
+ * - **Project Units**: Active units + their transitive dependencies (needed for prepare/install)
11
+ *
12
+ * **Key Responsibilities**:
13
+ * - Unit discovery and storage
14
+ * - Dependency resolution and tree building
15
+ * - Unit lookup by key/type
16
+ * - Active/project unit derivation based on runtime params
17
+ *
18
+ * **Dependency Management**:
19
+ * - Uses `UnitsDependencyMapper` to resolve transitive dependencies
20
+ * - Builds dependency tree in layers (dependencies first, dependents last)
21
+ * - Filters dependencies to only include units that exist in workspace
22
+ *
23
+ * **Runtime Params Impact**:
24
+ * - `--use-package`: Filters active units to match regex patterns
25
+ * - `--build-tree`: Includes transitive dependencies in active units
26
+ * - Without flags: All units are active and project units
27
+ */
28
+ export class Workspace extends Logger {
29
+ _projectUnits = [];
30
+ _activeUnits = [];
31
+ _projectUnitKeys = [];
32
+ unitsDependencyMapper;
33
+ unitKeyToUnitMap = {};
34
+ /**
35
+ * All project units (subset of scanned units that are ProjectUnits)
36
+ */
37
+ get projectUnits() {
38
+ return this._projectUnits;
39
+ }
40
+ /**
41
+ * Keys of units selected for execution
42
+ */
43
+ get activeUnits() {
44
+ return this._activeUnits;
45
+ }
46
+ /**
47
+ * Keys of project units (active units + their transitive dependencies)
48
+ */
49
+ get projectUnitKeys() {
50
+ return this._projectUnitKeys;
51
+ }
52
+ /**
53
+ * Scan units from the workspace using the provided UnitsMapper
54
+ */
55
+ async scanUnits(path, unitsMapper) {
56
+ this.logDebug(`Resolving units from: ${path}`);
57
+ const scannedUnits = await unitsMapper.resolveUnits(path);
58
+ Object.freeze(scannedUnits);
59
+ this.unitKeyToUnitMap = arrayToMap(scannedUnits, unit => unit.config.key, this.unitKeyToUnitMap);
60
+ this._projectUnits.push(...scannedUnits.filter(unit => unit.isInstanceOf(ProjectUnit)));
61
+ Object.freeze(this._projectUnits);
62
+ }
63
+ /**
64
+ * Add additional project units (e.g., from applicative configuration)
65
+ * can only be called before scanUnits()
66
+ */
67
+ addProjectUnits(projectUnits) {
68
+ // Check for duplicates
69
+ const unitKeysToAdd = projectUnits.map(u => u.config.key);
70
+ this.logVerbose(`Adding units:`, unitKeysToAdd);
71
+ if (projectUnits.length > 0) {
72
+ this._projectUnits.push(...projectUnits);
73
+ // Update lookup map
74
+ for (const unit of projectUnits) {
75
+ this.logDebug(`Adding project unit: ${unit.config.key}`);
76
+ this.unitKeyToUnitMap[unit.config.key] = unit;
77
+ }
78
+ }
79
+ }
80
+ /**
81
+ * Initialize the dependency mapper with project units
82
+ */
83
+ initializeDependencyMapper(globalOutputFolder) {
84
+ const unitsDependencies = this._projectUnits.map(unit => ({
85
+ key: unit.config.key,
86
+ dependsOn: _keys(unit.config.dependencies).filter(key => !!this.unitKeyToUnitMap[key])
87
+ }));
88
+ this.unitsDependencyMapper = new UnitsDependencyMapper(unitsDependencies, globalOutputFolder);
89
+ }
90
+ /**
91
+ * Derive active and project units based on runtime parameters
92
+ * This must be called after initializeDependencyMapper()
93
+ */
94
+ deriveActiveAndProjectUnits(runtimeParams) {
95
+ if (!this.unitsDependencyMapper) {
96
+ throw new BadImplementationException('Dependency mapper must be initialized before deriving units. Call initializeDependencyMapper() first.');
97
+ }
98
+ const unitKeySet = new Set();
99
+ const allUnits = [];
100
+ for (const unit of flatArray(this._projectUnits)) {
101
+ if (unitKeySet.has(unit.config.key))
102
+ throw new Error(`Multiple units with same key: ${unit.config.key}`);
103
+ unitKeySet.add(unit.config.key);
104
+ allUnits.push(unit);
105
+ }
106
+ let activeUnits = [];
107
+ let projectUnits = [];
108
+ // 1. Handle usePackage: "Work on these units only" (Option A)
109
+ // - Matched units → active (compile/test/lint these)
110
+ // - Matched + transitive → project (prepare dependencies, but don't compile them)
111
+ // - If buildTree flag is set, transitive dependencies also become active
112
+ const usePackageKeys = runtimeParams.usePackage;
113
+ if (usePackageKeys?.length) {
114
+ const regexMatchers = usePackageKeys.map(filter => new RegExp(`.*?${filter}.*?`, 'i'));
115
+ const matched = allUnits.filter(unit => regexMatchers.some(matcher => matcher.test(unit.config.key))).map(unit => unit.config.key);
116
+ const transitive = this.unitsDependencyMapper.getTransitiveDependencies(matched);
117
+ activeUnits.push(...matched);
118
+ projectUnits.push(...matched, ...transitive);
119
+ if (!activeUnits.length)
120
+ throw new ImplementationMissingException('No unit found matching these filters: ' + usePackageKeys.join(', '));
121
+ // If buildTree flag is set, make transitive dependencies active too
122
+ if (runtimeParams.buildTree) {
123
+ activeUnits.push(...transitive);
124
+ }
125
+ }
126
+ else {
127
+ const allKeys = allUnits.map(unit => unit.config.key);
128
+ activeUnits = allKeys;
129
+ projectUnits = allKeys;
130
+ }
131
+ this._activeUnits = [...new Set(activeUnits)];
132
+ this._projectUnitKeys = [...new Set(projectUnits)];
133
+ this.logDebug(`Active units: ${this._activeUnits.join(', ')}`);
134
+ this.logDebug(`Project units: ${this._projectUnitKeys.join(', ')}`);
135
+ return {
136
+ activeUnits: this._activeUnits,
137
+ projectUnits: this._projectUnitKeys
138
+ };
139
+ }
140
+ getUnitByKey(key, className) {
141
+ const unit = this.unitKeyToUnitMap[key];
142
+ if (!unit)
143
+ throw new BadImplementationException(`Unit with key '${key}' not found.`);
144
+ if (className && !unit.isInstanceOf(className))
145
+ throw new BadImplementationException(`Unit with key '${key}' is not of type: ${className.name}`);
146
+ return unit;
147
+ }
148
+ /**
149
+ * Get multiple units by their keys, optionally filtered by class type
150
+ */
151
+ getUnitsByKeys(keys, className) {
152
+ const units = keys.map(key => this.unitKeyToUnitMap[key]).filter(Boolean);
153
+ if (className)
154
+ return units.filter(unit => unit.isInstanceOf(className));
155
+ return units;
156
+ }
157
+ /**
158
+ * Get the root NodeProject unit
159
+ */
160
+ getNodeProjectUnit() {
161
+ return this._projectUnits.find(unit => unit.isInstanceOf(Unit_NodeProject));
162
+ }
163
+ /**
164
+ * Build dependency tree for the given project unit keys
165
+ * Returns layers of units ordered from bottom (no dependencies) to top
166
+ */
167
+ async buildDependencyTree(projectUnitKeys) {
168
+ if (!this.unitsDependencyMapper) {
169
+ throw new Error('Dependency mapper must be initialized. Call initializeDependencyMapper() first.');
170
+ }
171
+ const unitKeyLayers = await this.unitsDependencyMapper.buildDependencyTree(projectUnitKeys);
172
+ return unitKeyLayers.map(keys => keys.map(key => this.getUnitByKey(key)).filter(Boolean));
173
+ }
174
+ /**
175
+ * Get transitive dependencies for given unit keys
176
+ */
177
+ getTransitiveDependencies(keys) {
178
+ if (!this.unitsDependencyMapper) {
179
+ throw new Error('Dependency mapper must be initialized. Call initializeDependencyMapper() first.');
180
+ }
181
+ return this.unitsDependencyMapper.getTransitiveDependencies(keys);
182
+ }
183
+ /**
184
+ * Get the dependency mapper (for runtime context)
185
+ */
186
+ getDependencyMapper() {
187
+ if (!this.unitsDependencyMapper) {
188
+ throw new Error('Dependency mapper must be initialized. Call initializeDependencyMapper() first.');
189
+ }
190
+ return this.unitsDependencyMapper;
191
+ }
192
+ }
package/core/consts.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import { MemKey } from '@nu-art/ts-common/mem-storage/index';
2
- import { RuntimeProjectConfig } from './types/index.js';
3
- export declare const CONST_VersionApp = "version-app.json";
4
- export declare const CONST_PackageJSONTemplate = "__package.json";
5
- export declare const CONST_PackageJSON = "package.json";
6
- export declare const CONST_NodeModules = "node_modules";
7
- export declare const CONST_BaiConfig = "bai-config.json";
8
- export declare const CONST_FirebaseRC = ".firebaserc";
9
- export declare const CONST_FirebaseJSON = "firebase.json";
10
- export declare const CONST_TS_CONFIG = "tsconfig.json";
11
- export declare const CONST_PNPM_WORKSPACE = "pnpm-workspace.yaml";
12
- export declare const CONST_PNPM_LOCK = "pnpm-lock.yaml";
13
- export declare const MemKey_Packages: MemKey<RuntimeProjectConfig>;
package/core/consts.js DELETED
@@ -1,12 +0,0 @@
1
- import { MemKey } from '@nu-art/ts-common/mem-storage/index';
2
- export const CONST_VersionApp = 'version-app.json';
3
- export const CONST_PackageJSONTemplate = '__package.json';
4
- export const CONST_PackageJSON = 'package.json';
5
- export const CONST_NodeModules = 'node_modules';
6
- export const CONST_BaiConfig = 'bai-config.json';
7
- export const CONST_FirebaseRC = '.firebaserc';
8
- export const CONST_FirebaseJSON = 'firebase.json';
9
- export const CONST_TS_CONFIG = 'tsconfig.json';
10
- export const CONST_PNPM_WORKSPACE = 'pnpm-workspace.yaml';
11
- export const CONST_PNPM_LOCK = 'pnpm-lock.yaml';
12
- export const MemKey_Packages = new MemKey('bai-packages', true);
@@ -1,8 +0,0 @@
1
- import { CustomException, Logger } from '@nu-art/ts-common';
2
- import { ScheduledStep } from '../../v3/PhaseManager.js';
3
- import { UnitPhaseException } from './UnitPhaseException.js';
4
- export declare class PhaseAggregatedException extends CustomException {
5
- errors: UnitPhaseException[];
6
- constructor(errors: UnitPhaseException[], step: ScheduledStep);
7
- print(logger: Logger): void;
8
- }
@@ -1,5 +0,0 @@
1
- import { CustomException } from '@nu-art/ts-common';
2
- import { BaseUnit } from '../../v3/units/index.js';
3
- export declare class UnitPhaseException extends CustomException {
4
- constructor(cause: Error, unit: BaseUnit, phase: string);
5
- }
@@ -1,6 +0,0 @@
1
- import { CustomException } from '@nu-art/ts-common';
2
- export class UnitPhaseException extends CustomException {
3
- constructor(cause, unit, phase) {
4
- super(UnitPhaseException, `Error in ${unit.config.key} (${phase})`, cause);
5
- }
6
- }
@@ -1,24 +0,0 @@
1
- import { FunctionKeys, ParamResolver } from '@nu-art/ts-common';
2
- import { BaseUnit } from '../v3/units/index.js';
3
- import { Phase } from '../v3/phase/index.js';
4
- export declare class PhaseRunnerDispatcher<T, K extends FunctionKeys<T> = FunctionKeys<T>, P extends ParamResolver<T, K> = ParamResolver<T, K>> {
5
- private readonly method;
6
- constructor(method: K);
7
- private listeners;
8
- addListener(listener: any): void;
9
- removeListener(listener: any): void;
10
- dispatch(...data: P): void;
11
- dispatchAsync(...data: P): Promise<void>;
12
- }
13
- export interface PhaseRunner_OnPhaseChange {
14
- __onPhaseChange: (data: Phase<string>) => void;
15
- }
16
- export declare const dispatcher_PhaseChange: PhaseRunnerDispatcher<PhaseRunner_OnPhaseChange, "__onPhaseChange", [data: Phase<string>]>;
17
- export interface PhaseRunner_OnUnitStatusChange {
18
- __onUnitStatusChange: (data: BaseUnit) => void;
19
- }
20
- export declare const dispatcher_UnitStatusChange: PhaseRunnerDispatcher<PhaseRunner_OnUnitStatusChange, "__onUnitStatusChange", [data: BaseUnit<import("../v3/units/BaseUnit.js").BaseUnit_Config, import("../v3/units/BaseUnit.js").UnitRuntimeContext>]>;
21
- export interface PhaseRunner_OnUnitsChange {
22
- __onUnitsChange: (data: BaseUnit[]) => void;
23
- }
24
- export declare const dispatcher_UnitChange: PhaseRunnerDispatcher<PhaseRunner_OnUnitsChange, "__onUnitsChange", [data: BaseUnit<import("../v3/units/BaseUnit.js").BaseUnit_Config, import("../v3/units/BaseUnit.js").UnitRuntimeContext>[]]>;
@@ -1,32 +0,0 @@
1
- import { removeItemFromArray } from '@nu-art/ts-common';
2
- export class PhaseRunnerDispatcher {
3
- method;
4
- constructor(method) {
5
- this.method = method;
6
- }
7
- listeners = [];
8
- //######################### Listeners Logic #########################
9
- addListener(listener) {
10
- if (this.listeners.includes(listener))
11
- return;
12
- this.listeners.push(listener);
13
- }
14
- removeListener(listener) {
15
- removeItemFromArray(this.listeners, listener);
16
- }
17
- dispatch(...data) {
18
- this.listeners.forEach(listener => {
19
- // @ts-ignore
20
- listener[this.method]?.(...data);
21
- });
22
- }
23
- async dispatchAsync(...data) {
24
- await Promise.all(this.listeners.map(async (listener) => {
25
- // @ts-ignore
26
- return listener[this.method]?.(...data);
27
- }));
28
- }
29
- }
30
- export const dispatcher_PhaseChange = new PhaseRunnerDispatcher('__onPhaseChange');
31
- export const dispatcher_UnitStatusChange = new PhaseRunnerDispatcher('__onUnitStatusChange');
32
- export const dispatcher_UnitChange = new PhaseRunnerDispatcher('__onUnitsChange');
@@ -1,10 +0,0 @@
1
- import { PhaseRunnerDispatcher } from './PhaseRunnerDispatcher.js';
2
- import { BaseUnit } from '../v3/units/index.js';
3
- export interface OnWatchReady {
4
- __onWatchReady: () => void;
5
- }
6
- export declare const dispatcher_WatchReady: PhaseRunnerDispatcher<OnWatchReady, "__onWatchReady", []>;
7
- export interface OnUnitWatchCompiled {
8
- __onUnitWatchCompiled: (units: BaseUnit[]) => void;
9
- }
10
- export declare const dispatcher_UnitWatchCompile: PhaseRunnerDispatcher<OnUnitWatchCompiled, "__onUnitWatchCompiled", [units: BaseUnit<import("../v3/units/BaseUnit.js").BaseUnit_Config, import("../v3/units/BaseUnit.js").UnitRuntimeContext>[]]>;
@@ -1,3 +0,0 @@
1
- import { PhaseRunnerDispatcher } from './PhaseRunnerDispatcher.js';
2
- export const dispatcher_WatchReady = new PhaseRunnerDispatcher('__onWatchReady');
3
- export const dispatcher_UnitWatchCompile = new PhaseRunnerDispatcher('__onUnitWatchCompiled');
@@ -1,26 +0,0 @@
1
- import { Logger } from '@nu-art/ts-common';
2
- import { RunningStatusHandler } from './RunningStatusHandler.js';
3
- import { Phase } from './phase/index.js';
4
- import { BaseUnit } from './units/index.js';
5
- export type ScheduledStep = {
6
- phases: string[];
7
- units: string[];
8
- };
9
- export type ExecutionStep = {
10
- phases: Phase<any>[];
11
- units: BaseUnit<any>[];
12
- };
13
- export declare class PhaseManager extends Logger {
14
- private readonly phases;
15
- private readonly units;
16
- private runningUnits;
17
- private killed;
18
- private runningStatus;
19
- private activeUnits;
20
- private readonly keyToPhaseMap;
21
- constructor(runningStatus: RunningStatusHandler, phases: Phase<any>[][], units: BaseUnit[][]);
22
- calculateExecutionSteps(): Promise<ScheduledStep[]>;
23
- execute(_steps: ScheduledStep[]): Promise<void>;
24
- break(): Promise<void[]>;
25
- private mapStep;
26
- }
@@ -1,158 +0,0 @@
1
- import { addItemToArray, asArray, exists, flatArray, Logger, removeItemFromArray, timeCounter } from '@nu-art/ts-common';
2
- import { PhaseAggregatedException } from '../core/exceptions/PhaseAggregatedException.js';
3
- import { UnitPhaseException } from '../core/exceptions/UnitPhaseException.js';
4
- export class PhaseManager extends Logger {
5
- phases;
6
- units;
7
- runningUnits = [];
8
- killed = false;
9
- runningStatus;
10
- activeUnits;
11
- keyToPhaseMap;
12
- constructor(runningStatus, phases, units) {
13
- super();
14
- this.phases = phases;
15
- this.units = units;
16
- this.runningStatus = runningStatus;
17
- const unitKeySet = new Set();
18
- const allUnits = [];
19
- for (const unit of flatArray(units)) {
20
- if (unitKeySet.has(unit.config.key))
21
- throw new Error(`Multiple units with same key: ${unit.config.key}`);
22
- unitKeySet.add(unit.config.key);
23
- allUnits.push(unit);
24
- }
25
- const usePackageKeys = this.runningStatus.runtimeParams.usePackage;
26
- if (!usePackageKeys?.length)
27
- this.activeUnits = allUnits.map(unit => unit.config.key);
28
- else {
29
- const regexMatchers = usePackageKeys.map(filter => new RegExp(`.*?${filter}.*?`, 'i'));
30
- this.activeUnits = allUnits.filter(unit => regexMatchers.some(matcher => matcher.test(unit.config.key))).map(unit => unit.config.key);
31
- }
32
- const packagesToInclude = this.runningStatus.runtimeParams.includePackage;
33
- if (packagesToInclude?.length) {
34
- const regexMatchers = asArray(packagesToInclude).map(filter => new RegExp(`.*?${filter}.*?`, 'i'));
35
- this.activeUnits.push(...allUnits.filter(unit => regexMatchers.some(matcher => matcher.test(unit.config.key))).map(unit => unit.config.key));
36
- this.activeUnits = [...new Set(this.activeUnits)];
37
- }
38
- this.keyToPhaseMap = flatArray(phases).reduce((acc, phase) => {
39
- acc[phase.key] = phase;
40
- return acc;
41
- }, {});
42
- }
43
- //######################### Initialization #########################
44
- async calculateExecutionSteps() {
45
- const steps = [];
46
- this.logDebug('Calculating execution steps for phases: ', this.phases.map(phases => phases.map(phase => phase.key)));
47
- this.logDebug('Active Units: ', this.activeUnits);
48
- for (let phaseGroup of this.phases) {
49
- phaseGroup = phaseGroup.filter(phase => !exists(phase.filter) || phase.filter(this.runningStatus.runtimeParams));
50
- for (const layer of this.units) {
51
- const layerUnits = layer.filter(u => this.activeUnits.includes(u.config.key));
52
- if (layerUnits.length === 0)
53
- continue;
54
- const phaseMap = new Map();
55
- for (const unit of layerUnits) {
56
- const supportedPhases = phaseGroup.filter(phase => phase.method in unit && typeof unit[phase.method] === 'function');
57
- if (supportedPhases.length === 0)
58
- continue;
59
- const key = phaseGroup
60
- .filter(phase => supportedPhases.find(p => p.key === phase.key))
61
- .map(p => p.key)
62
- .join('|');
63
- if (!phaseMap.has(key))
64
- phaseMap.set(key, []);
65
- phaseMap.get(key).push(unit);
66
- }
67
- for (const [phaseKeyCombo, groupedUnits] of phaseMap.entries()) {
68
- steps.push({
69
- phases: phaseKeyCombo.split('|'),
70
- units: groupedUnits.map(u => u.config.key),
71
- });
72
- }
73
- }
74
- }
75
- this.logVerbose('Calculated execution steps: ', steps);
76
- return steps;
77
- }
78
- async execute(_steps) {
79
- this.runningUnits = [];
80
- for (let i = this.runningStatus.startIndex; i < _steps.length; i++) {
81
- if (this.killed)
82
- break;
83
- const scheduledStep = _steps[i];
84
- const step = this.mapStep(scheduledStep);
85
- await this.runningStatus.onStepStarted(i);
86
- this.logDebug(`Executing step #${i + 1}/${_steps.length}`);
87
- this.logVerbose(scheduledStep);
88
- const errors = [];
89
- let failedStep;
90
- await Promise.all(step.units.map(async (unit) => {
91
- if (this.runningStatus.isCompleted(unit.config.key))
92
- return;
93
- let failed = false;
94
- for (const phase of step.phases) {
95
- if (this.killed)
96
- break;
97
- if (this.runningStatus.runtimeParams.dryRun) {
98
- this.logInfo(`[${phase.key}] - ${unit.config.key}`);
99
- continue;
100
- }
101
- addItemToArray(this.runningUnits, unit);
102
- const dtCounter = timeCounter();
103
- try {
104
- this.logInfo(`Phase(${phase.name}) - Running - ${unit.config.key}`);
105
- if (typeof unit[phase.method] === 'function')
106
- await unit[phase.method].call(unit);
107
- let operationDuration = '';
108
- if (dtCounter.dt() > 1500)
109
- operationDuration = ` (${dtCounter.format('mm:ss')})`;
110
- this.logInfo(`Phase(${phase.name}) - Completed${operationDuration} - ${unit.config.key}`);
111
- }
112
- catch (error) {
113
- this.logError(`Phase(${phase.name}) - Error - ${unit.config.key}`, error);
114
- errors.push(new UnitPhaseException(error, unit, phase.key));
115
- failedStep = scheduledStep;
116
- this.killed = true;
117
- failed = true;
118
- break;
119
- }
120
- finally {
121
- removeItemFromArray(this.runningUnits, unit);
122
- }
123
- }
124
- if (!failed)
125
- await this.runningStatus.onUnitCompleted(unit.config.key);
126
- }));
127
- if (failedStep && errors.length) {
128
- throw new PhaseAggregatedException(errors, failedStep);
129
- }
130
- await this.runningStatus.onStepEnded();
131
- }
132
- this.logInfo('All steps completed.');
133
- }
134
- break() {
135
- this.killed = true;
136
- return Promise.all(this.runningUnits.map(unit => unit.kill()));
137
- }
138
- mapStep(scheduledStep) {
139
- const mappedPhases = scheduledStep.phases.map(phaseKey => {
140
- const phase = this.keyToPhaseMap[phaseKey];
141
- if (!phase)
142
- throw new Error(`Phase '${phaseKey}' not found in PhaseManager.phases`);
143
- return phase;
144
- });
145
- const mappedUnits = scheduledStep.units.map(unitKey => {
146
- for (const layer of this.units) {
147
- const unit = layer.find(u => u.config.key === unitKey);
148
- if (unit)
149
- return unit;
150
- }
151
- throw new Error(`Unit '${unitKey}' not found in PhaseManager.units`);
152
- });
153
- return {
154
- phases: mappedPhases,
155
- units: mappedUnits
156
- };
157
- }
158
- }
@@ -1,18 +0,0 @@
1
- import { Logger } from '@nu-art/ts-common';
2
- import { BaiParams } from '../core/params/params.js';
3
- export declare class RunningStatusHandler extends Logger {
4
- private isolated;
5
- private readonly outputFolder;
6
- private completedUnits;
7
- runtimeParams: BaiParams;
8
- startIndex: number;
9
- constructor(outputFolder: string, runtimeParams: BaiParams);
10
- init(): Promise<void>;
11
- isolate(): RunningStatusHandler;
12
- isCompleted(unitKey: string): boolean;
13
- onUnitCompleted(unitKey: string): Promise<void>;
14
- onStepEnded(): Promise<void>;
15
- onStepStarted(index: number): Promise<void>;
16
- private saveStatus;
17
- load(): Promise<any>;
18
- }