@nu-art/build-and-install 0.401.0 → 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 (155) hide show
  1. package/BuildAndInstall.d.ts +40 -0
  2. package/BuildAndInstall.js +155 -0
  3. package/build-and-install-v3.d.ts +1 -44
  4. package/build-and-install-v3.js +1 -157
  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 -332
  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/{v3 → phases}/PhaseManager.js +99 -2
  37. package/{v3/phase → phases/definitions}/consts.d.ts +36 -0
  38. package/{v3/phase → phases/definitions}/consts.js +44 -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 +34 -4
  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 +50 -2
  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 +65 -5
  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/{v3 → workspace}/Workspace.d.ts +30 -15
  89. package/{v3 → workspace}/Workspace.js +48 -35
  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 -27
  100. package/v3/RunningStatusHandler.d.ts +0 -18
  101. package/v3/RunningStatusHandler.js +0 -67
  102. package/v3/UnitsMapper/UnitsMapper.d.ts +0 -21
  103. package/v3/UnitsMapper/resolvers/UnitMapper_Base.d.ts +0 -23
  104. package/v3/UnitsMapper/resolvers/UnitMapper_Base.js +0 -16
  105. package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseFunction.js +0 -66
  106. package/v3/core/FilesCache.d.ts +0 -7
  107. package/v3/core/FilesCache.js +0 -33
  108. package/v3/phase/types.d.ts +0 -10
  109. package/v3/units/ProjectUnit.d.ts +0 -18
  110. package/v3/units/ProjectUnit.js +0 -11
  111. package/v3/units/Unit_NodeProject.d.ts +0 -30
  112. package/v3/units/Unit_PackageJson.d.ts +0 -17
  113. package/v3/units/firebase/Unit_FirebaseFunctionsApp.d.ts +0 -64
  114. package/v3/units/firebase/Unit_FirebaseFunctionsApp.js +0 -306
  115. package/v3/units/firebase/Unit_FirebaseHostingApp.d.ts +0 -49
  116. package/v3/units/firebase/Unit_FirebaseHostingApp.js +0 -118
  117. package/v3/units/firebase/common.d.ts +0 -3
  118. package/v3/units/firebase/common.js +0 -13
  119. package/v3/units/index.d.ts +0 -6
  120. package/v3/units/index.js +0 -6
  121. /package/{core → config}/package/consts.js +0 -0
  122. /package/{core → config}/types/configs/firebasejson.d.ts +0 -0
  123. /package/{core → config}/types/configs/firebasejson.js +0 -0
  124. /package/{core → config}/types/configs/firebaserc.d.ts +0 -0
  125. /package/{core → config}/types/configs/firebaserc.js +0 -0
  126. /package/{core → config}/types/configs/index.d.ts +0 -0
  127. /package/{core → config}/types/configs/index.js +0 -0
  128. /package/{core → config}/types/configs/package-json.d.ts +0 -0
  129. /package/{core → config}/types/configs/package-json.js +0 -0
  130. /package/{core → config}/types/core.d.ts +0 -0
  131. /package/{core → config}/types/core.js +0 -0
  132. /package/{core → config}/types/index.d.ts +0 -0
  133. /package/{core → config}/types/index.js +0 -0
  134. /package/{core → config}/types/package/index.d.ts +0 -0
  135. /package/{core → config}/types/package/index.js +0 -0
  136. /package/{core → config}/types/package/package.d.ts +0 -0
  137. /package/{core → config}/types/package/package.js +0 -0
  138. /package/{core → config}/types/package/runtime-package.d.ts +0 -0
  139. /package/{core → config}/types/package/runtime-package.js +0 -0
  140. /package/{core → config}/types/project-config.js +0 -0
  141. /package/{v3/core → core}/types.js +0 -0
  142. /package/{v3/UnitsMapper/types.js → exports/types.d.ts} +0 -0
  143. /package/{v3/phase → phases/definitions}/index.d.ts +0 -0
  144. /package/{v3/phase → phases/definitions}/index.js +0 -0
  145. /package/{v3/phase → phases/definitions}/types.js +0 -0
  146. /package/{v3/units/types.js → run.d.ts} +0 -0
  147. /package/{defaults/backend-proxy → templates/backend/proxy}/proxy._ts +0 -0
  148. /package/{defaults/.firebase_config → templates/firebase/config}/database.rules.json +0 -0
  149. /package/{defaults/.firebase_config → templates/firebase/config}/firestore.indexes.json +0 -0
  150. /package/{defaults/.firebase_config → templates/firebase/config}/firestore.rules +0 -0
  151. /package/{defaults/.firebase_config → templates/firebase/config}/storage.rules +0 -0
  152. /package/{v3/units → units/base}/types.d.ts +0 -0
  153. /package/{v3/UnitsMapper → units/discovery}/resolvers/index.d.ts +0 -0
  154. /package/{v3/UnitsMapper → units/discovery}/resolvers/index.js +0 -0
  155. /package/{v3/UnitsMapper → units/discovery}/types.d.ts +0 -0
@@ -1,25 +1,38 @@
1
- import { Constructor, Logger } from '@nu-art/ts-common';
2
- import { BaiParams } from '../core/params/params.js';
3
- import { UnitsMapper } from './UnitsMapper/UnitsMapper.js';
4
- import { UnitsDependencyMapper } from './UnitsDependencyMapper/UnitsDependencyMapper.js';
5
- import { BaseUnit, ProjectUnit, Unit_NodeProject } from './units/index.js';
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
6
  /**
7
- * Manages all units in the workspace, including:
8
- * - Scanned Units: All units discovered from workspace scan
9
- * - Active Units: Units selected for execution (compile/test/lint)
10
- * - Project Units: Active units + their transitive dependencies
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
11
29
  */
12
30
  export declare class Workspace extends Logger {
13
- private _scannedUnits;
14
31
  private _projectUnits;
15
32
  private _activeUnits;
16
33
  private _projectUnitKeys;
17
34
  private unitsDependencyMapper?;
18
35
  private unitKeyToUnitMap;
19
- /**
20
- * All units discovered from the workspace scan
21
- */
22
- get scannedUnits(): ReadonlyArray<BaseUnit<any>>;
23
36
  /**
24
37
  * All project units (subset of scanned units that are ProjectUnits)
25
38
  */
@@ -38,6 +51,7 @@ export declare class Workspace extends Logger {
38
51
  scanUnits(path: string, unitsMapper: UnitsMapper): Promise<void>;
39
52
  /**
40
53
  * Add additional project units (e.g., from applicative configuration)
54
+ * can only be called before scanUnits()
41
55
  */
42
56
  addProjectUnits(projectUnits: ProjectUnit[]): void;
43
57
  /**
@@ -56,10 +70,11 @@ export declare class Workspace extends Logger {
56
70
  * Get a unit by its key
57
71
  */
58
72
  getUnitByKey<T extends BaseUnit>(key: string): T | undefined;
73
+ getUnitByKey<T extends BaseUnit>(key: string, className: AnyConstructor<T>): T;
59
74
  /**
60
75
  * Get multiple units by their keys, optionally filtered by class type
61
76
  */
62
- getUnitsByKeys<T extends BaseUnit>(keys: string[], className?: Constructor<T>): T[];
77
+ getUnitsByKeys<T extends BaseUnit>(keys: string[], className?: AnyConstructor<T>): T[];
63
78
  /**
64
79
  * Get the root NodeProject unit
65
80
  */
@@ -1,25 +1,36 @@
1
- import { _keys, arrayToMap, flatArray, Logger } from '@nu-art/ts-common';
2
- import { UnitsDependencyMapper } from './UnitsDependencyMapper/UnitsDependencyMapper.js';
3
- import { ProjectUnit, Unit_NodeProject } from './units/index.js';
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
4
  /**
5
- * Manages all units in the workspace, including:
6
- * - Scanned Units: All units discovered from workspace scan
7
- * - Active Units: Units selected for execution (compile/test/lint)
8
- * - Project Units: Active units + their transitive dependencies
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
9
27
  */
10
28
  export class Workspace extends Logger {
11
- _scannedUnits = [];
12
29
  _projectUnits = [];
13
30
  _activeUnits = [];
14
31
  _projectUnitKeys = [];
15
32
  unitsDependencyMapper;
16
33
  unitKeyToUnitMap = {};
17
- /**
18
- * All units discovered from the workspace scan
19
- */
20
- get scannedUnits() {
21
- return this._scannedUnits;
22
- }
23
34
  /**
24
35
  * All project units (subset of scanned units that are ProjectUnits)
25
36
  */
@@ -43,26 +54,25 @@ export class Workspace extends Logger {
43
54
  */
44
55
  async scanUnits(path, unitsMapper) {
45
56
  this.logDebug(`Resolving units from: ${path}`);
46
- this._scannedUnits = await unitsMapper.resolveUnits(path);
47
- Object.freeze(this._scannedUnits);
48
- this.unitKeyToUnitMap = arrayToMap(this._scannedUnits, unit => unit.config.key);
49
- this._projectUnits = this._scannedUnits.filter(unit => unit.isInstanceOf(ProjectUnit));
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)));
50
61
  Object.freeze(this._projectUnits);
51
62
  }
52
63
  /**
53
64
  * Add additional project units (e.g., from applicative configuration)
65
+ * can only be called before scanUnits()
54
66
  */
55
67
  addProjectUnits(projectUnits) {
56
68
  // Check for duplicates
57
- const existingKeys = new Set(this._projectUnits.map(u => u.config.key));
58
- const newUnits = projectUnits.filter(unit => !existingKeys.has(unit.config.key));
59
- if (newUnits.length > 0) {
60
- // Unfreeze, add, then refreeze
61
- const current = [...this._projectUnits, ...newUnits];
62
- this._projectUnits = current;
63
- Object.freeze(this._projectUnits);
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);
64
73
  // Update lookup map
65
- for (const unit of newUnits) {
74
+ for (const unit of projectUnits) {
75
+ this.logDebug(`Adding project unit: ${unit.config.key}`);
66
76
  this.unitKeyToUnitMap[unit.config.key] = unit;
67
77
  }
68
78
  }
@@ -83,11 +93,11 @@ export class Workspace extends Logger {
83
93
  */
84
94
  deriveActiveAndProjectUnits(runtimeParams) {
85
95
  if (!this.unitsDependencyMapper) {
86
- throw new Error('Dependency mapper must be initialized before deriving units. Call initializeDependencyMapper() first.');
96
+ throw new BadImplementationException('Dependency mapper must be initialized before deriving units. Call initializeDependencyMapper() first.');
87
97
  }
88
98
  const unitKeySet = new Set();
89
99
  const allUnits = [];
90
- for (const unit of flatArray(this._scannedUnits)) {
100
+ for (const unit of flatArray(this._projectUnits)) {
91
101
  if (unitKeySet.has(unit.config.key))
92
102
  throw new Error(`Multiple units with same key: ${unit.config.key}`);
93
103
  unitKeySet.add(unit.config.key);
@@ -106,6 +116,8 @@ export class Workspace extends Logger {
106
116
  const transitive = this.unitsDependencyMapper.getTransitiveDependencies(matched);
107
117
  activeUnits.push(...matched);
108
118
  projectUnits.push(...matched, ...transitive);
119
+ if (!activeUnits.length)
120
+ throw new ImplementationMissingException('No unit found matching these filters: ' + usePackageKeys.join(', '));
109
121
  // If buildTree flag is set, make transitive dependencies active too
110
122
  if (runtimeParams.buildTree) {
111
123
  activeUnits.push(...transitive);
@@ -125,20 +137,21 @@ export class Workspace extends Logger {
125
137
  projectUnits: this._projectUnitKeys
126
138
  };
127
139
  }
128
- /**
129
- * Get a unit by its key
130
- */
131
- getUnitByKey(key) {
132
- return this.unitKeyToUnitMap[key];
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;
133
147
  }
134
148
  /**
135
149
  * Get multiple units by their keys, optionally filtered by class type
136
150
  */
137
151
  getUnitsByKeys(keys, className) {
138
152
  const units = keys.map(key => this.unitKeyToUnitMap[key]).filter(Boolean);
139
- if (className) {
153
+ if (className)
140
154
  return units.filter(unit => unit.isInstanceOf(className));
141
- }
142
155
  return units;
143
156
  }
144
157
  /**
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,27 +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 projectUnitKeys;
21
- private readonly keyToPhaseMap;
22
- constructor(runningStatus: RunningStatusHandler, phases: Phase<any>[][], units: BaseUnit[][], activeUnits: string[], projectUnitKeys: string[]);
23
- calculateExecutionSteps(): Promise<ScheduledStep[]>;
24
- execute(_steps: ScheduledStep[]): Promise<void>;
25
- break(): Promise<void[]>;
26
- private mapStep;
27
- }
@@ -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
- }
@@ -1,67 +0,0 @@
1
- import fs, { promises as _fs } from 'fs';
2
- import { __stringify, Logger } from '@nu-art/ts-common';
3
- export class RunningStatusHandler extends Logger {
4
- isolated = false;
5
- outputFolder;
6
- // The completed units in the phase.. when running -con, these can be skipped
7
- completedUnits = [];
8
- runtimeParams;
9
- startIndex = 0;
10
- constructor(outputFolder, runtimeParams) {
11
- super();
12
- this.outputFolder = outputFolder;
13
- this.runtimeParams = runtimeParams;
14
- }
15
- async init() {
16
- if (!fs.existsSync(this.outputFolder))
17
- await _fs.mkdir(this.outputFolder, { recursive: true });
18
- if (this.runtimeParams.continue) {
19
- const currentParams = this.runtimeParams;
20
- this.startIndex = await this.load();
21
- this.runtimeParams = Object.assign(currentParams, this.runtimeParams);
22
- }
23
- }
24
- isolate() {
25
- this.isolated = true;
26
- return this;
27
- }
28
- isCompleted(unitKey) {
29
- return this.completedUnits.includes(unitKey);
30
- }
31
- async onUnitCompleted(unitKey) {
32
- this.logDebug(`On unit completed: ${unitKey}`);
33
- this.completedUnits.push(unitKey);
34
- await this.saveStatus();
35
- }
36
- async onStepEnded() {
37
- this.logDebug(`On step ended successfully #${this.startIndex}`);
38
- this.completedUnits = [];
39
- }
40
- async onStepStarted(index) {
41
- this.startIndex = index;
42
- this.logDebug(`Setting execution index to #${this.startIndex}`);
43
- if (this.isolated)
44
- return;
45
- await this.saveStatus();
46
- }
47
- async saveStatus() {
48
- await _fs.writeFile(`${this.outputFolder}/running-status.json`, __stringify({
49
- index: this.startIndex,
50
- runtimeParams: this.runtimeParams,
51
- completedUnits: this.completedUnits
52
- }, true));
53
- }
54
- async load() {
55
- try {
56
- const data = JSON.parse(await _fs.readFile(`${this.outputFolder}/running-status.json`, { encoding: 'utf-8' }));
57
- this.startIndex = data.index;
58
- this.completedUnits = data.completedUnits ?? [];
59
- this.runtimeParams = data.runtimeParams;
60
- return data.index;
61
- }
62
- catch (e) {
63
- this.logError('Failed reading running status, using initial status', e);
64
- return;
65
- }
66
- }
67
- }
@@ -1,21 +0,0 @@
1
- import { BaseUnit, ProjectUnit } from '../units/index.js';
2
- import { Logger } from '@nu-art/ts-common';
3
- import { UnitMapper_Base } from './resolvers/UnitMapper_Base.js';
4
- import { BaiParams } from '../../core/params/params.js';
5
- /**
6
- * This class will receive a path and will map the workspace packages and libs
7
- *
8
- * A lib will have rules to infer it, mainly from the package.json but also from existing files in the context of the node lib
9
- */
10
- export declare class UnitsMapper extends Logger {
11
- private rules;
12
- /**
13
- * @param path - will always be a directory
14
- * @param projectRoot - The path to the project root
15
- * @param units - The project units derived from the file system
16
- */
17
- resolveUnits(path: string, projectRoot?: string, units?: BaseUnit<any>[]): Promise<BaseUnit<any, import("../units/BaseUnit.js").UnitRuntimeContext>[]>;
18
- addRules<T extends BaseUnit<any>>(...rules: UnitMapper_Base<T>[]): this;
19
- setRuntimeParams(runtimeParams: BaiParams): this;
20
- assertUniqueKeys(units: ProjectUnit[]): void;
21
- }
@@ -1,23 +0,0 @@
1
- import { AbsolutePath, Logger, RelativePath, StringMap, TypeValidator } from '@nu-art/ts-common';
2
- import { BaseUnit } from '../../units/index.js';
3
- import { BAI_Config } from '../../../core/types/index.js';
4
- import { BaiParams } from '../../../core/params/params.js';
5
- export type BaseUnitConfig = {
6
- fullPath: AbsolutePath;
7
- relativePath: RelativePath;
8
- label: string;
9
- key: string;
10
- dependencies: StringMap;
11
- };
12
- export type UnitConfigJSON_Base = {
13
- type: string;
14
- };
15
- export declare abstract class UnitMapper_Base<T extends BaseUnit<any>, ConfigJSON extends UnitConfigJSON_Base = UnitConfigJSON_Base> extends Logger {
16
- protected validator: TypeValidator<ConfigJSON>;
17
- protected baiConfig: BAI_Config;
18
- protected runtimeParams: BaiParams;
19
- protected constructor(validator: TypeValidator<ConfigJSON>);
20
- setRuntimeParams(runtimeParams: BaiParams): void;
21
- setConfig(config: BAI_Config): void;
22
- abstract resolveUnit(path: string, root: string): Promise<T | undefined>;
23
- }
@@ -1,16 +0,0 @@
1
- import { Logger } from '@nu-art/ts-common';
2
- export class UnitMapper_Base extends Logger {
3
- validator;
4
- baiConfig;
5
- runtimeParams;
6
- constructor(validator) {
7
- super();
8
- this.validator = validator;
9
- }
10
- setRuntimeParams(runtimeParams) {
11
- this.runtimeParams = runtimeParams;
12
- }
13
- setConfig(config) {
14
- this.baiConfig = config;
15
- }
16
- }
@@ -1,66 +0,0 @@
1
- import { tsValidate_OptionalArray, tsValidateAnyString, tsValidateBoolean, tsValidateDynamicObject, tsValidateOptionalAnyNumber, tsValidateOptionalAnyString, tsValidateValue } from '@nu-art/ts-common';
2
- import { UnitMapper_Node } from './UnitMapper_Node.js';
3
- import { Unit_FirebaseFunctionsApp } from '../../units/firebase/Unit_FirebaseFunctionsApp.js';
4
- import { resolve } from 'path';
5
- import { BaiParam_SetEnv } from '../../../core/params/params.js';
6
- const valuesValidator = {
7
- defaultConfig: tsValidateOptionalAnyString,
8
- envConfig: tsValidateOptionalAnyString,
9
- identityAccount: tsValidateOptionalAnyString,
10
- projectId: tsValidateAnyString,
11
- isLocal: tsValidateBoolean(false),
12
- };
13
- export class UnitMapper_FirebaseFunction_Class extends UnitMapper_Node {
14
- static tsValidator_FirebaseFunction = {
15
- type: tsValidateValue(['firebase-function']),
16
- ignore: tsValidate_OptionalArray(tsValidateOptionalAnyString),
17
- envs: tsValidateDynamicObject(valuesValidator, tsValidateAnyString),
18
- debugPort: tsValidateOptionalAnyNumber,
19
- basePort: tsValidateOptionalAnyNumber,
20
- sslKey: tsValidateOptionalAnyString,
21
- sslCert: tsValidateOptionalAnyString,
22
- ...UnitMapper_Node.tsValidator_Node,
23
- };
24
- constructor() {
25
- super(UnitMapper_FirebaseFunction_Class.tsValidator_FirebaseFunction);
26
- }
27
- async resolveNodeUnit(context) {
28
- const outputDir = context.packageJson.publishConfig?.directory;
29
- const env = this.runtimeParams[BaiParam_SetEnv.keyName];
30
- let envUnitConfig = context.packageJson.unitConfig.envs[env];
31
- if (!envUnitConfig) {
32
- this.logWarning(`Missing EnvConfig in unit ${context.baseConfig.key}`);
33
- envUnitConfig = {
34
- identityAccount: '',
35
- defaultConfig: '',
36
- envConfig: '',
37
- projectId: '',
38
- isLocal: true
39
- };
40
- // throw new ImplementationMissingException(`Missing configuration for env: ${env}`);
41
- }
42
- const envConfig = {
43
- identityAccount: envUnitConfig.identityAccount,
44
- defaultConfig: envUnitConfig.defaultConfig,
45
- envConfig: envUnitConfig.envConfig,
46
- projectId: envUnitConfig.projectId,
47
- isLocal: envUnitConfig.isLocal ?? env === 'local'
48
- };
49
- const { type, ...unitConfig } = context.packageJson.unitConfig;
50
- return new Unit_FirebaseFunctionsApp({
51
- ...context.baseConfig,
52
- ...Unit_FirebaseFunctionsApp.DefaultConfig_FirebaseFunction,
53
- ...unitConfig,
54
- envConfig,
55
- isTopLevelApp: true,
56
- hasSelfHotReload: unitConfig.hasSelfHotReload ?? false,
57
- packageJson: context.packageJson,
58
- customESLintConfig: context.customESLintConfig,
59
- customTSConfig: context.customTSConfig,
60
- output: resolve(context.baseConfig.fullPath, outputDir ?? Unit_FirebaseFunctionsApp.DefaultConfig_FirebaseFunction.output),
61
- sslCert: resolve(context.baseConfig.fullPath, unitConfig.sslCert ?? Unit_FirebaseFunctionsApp.DefaultConfig_FirebaseFunction.sslCert),
62
- sslKey: resolve(context.baseConfig.fullPath, unitConfig.sslKey ?? Unit_FirebaseFunctionsApp.DefaultConfig_FirebaseFunction.sslKey),
63
- });
64
- }
65
- }
66
- export const UnitMapper_FirebaseFunction = new UnitMapper_FirebaseFunction_Class();
@@ -1,7 +0,0 @@
1
- export declare const FilesCache: {
2
- clear: () => {};
3
- load: {
4
- json: <T>(pathToFile: string) => Promise<T>;
5
- text: (pathToFile: string) => Promise<string>;
6
- };
7
- };
@@ -1,33 +0,0 @@
1
- import { ImplementationMissingException } from '@nu-art/ts-common';
2
- import { promises as fs } from 'fs';
3
- let cachedFiles = {};
4
- const readFile = async (path) => {
5
- try {
6
- const fileStat = await fs.stat(path);
7
- if (fileStat.isFile())
8
- return await fs.readFile(path, 'utf-8');
9
- }
10
- catch (error) {
11
- if (error.code === 'ENOENT')
12
- throw new ImplementationMissingException(`file does not exist: ${path}`);
13
- throw error; // rethrow other errors
14
- }
15
- throw new ImplementationMissingException(`expected a file at: ${path}`);
16
- };
17
- export const FilesCache = {
18
- clear: () => cachedFiles = {},
19
- load: {
20
- json: async (pathToFile) => {
21
- const json = cachedFiles[pathToFile];
22
- if (!json)
23
- cachedFiles[pathToFile] = Object.freeze(JSON.parse(await readFile(pathToFile)));
24
- return cachedFiles[pathToFile];
25
- },
26
- text: async (pathToFile) => {
27
- const fileContent = cachedFiles[pathToFile];
28
- if (!fileContent)
29
- cachedFiles[pathToFile] = await readFile(pathToFile);
30
- return cachedFiles[pathToFile];
31
- }
32
- }
33
- };
@@ -1,10 +0,0 @@
1
- import { BaiParams } from '../../core/params/params.js';
2
- export type Phase<PhaseMethod extends string> = {
3
- key: string;
4
- name: string;
5
- method: PhaseMethod;
6
- filter?: (params: BaiParams) => boolean;
7
- terminateAfterPhase?: boolean;
8
- dependencyPhase?: Phase<string>[];
9
- unitCategory?: "project" | "active";
10
- };