@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,153 @@
1
+ import fs, { promises as _fs } from 'fs';
2
+ import { __stringify, Logger } from '@nu-art/ts-common';
3
+ /**
4
+ * Manages execution state persistence for resume support.
5
+ *
6
+ * **Purpose**: Enables `--continue` flag to resume from last completed step.
7
+ *
8
+ * **State Management**:
9
+ * - **startIndex**: Current step index (0-based)
10
+ * - **completedUnits**: Units completed in current step
11
+ * - **runtimeParams**: Runtime parameters (for state validation)
12
+ *
13
+ * **Persistence**:
14
+ * - Saves state to `.trash/output/running-status.json` after each step/unit
15
+ * - Loads state on init if `--continue` flag is set
16
+ * - State includes: index, runtimeParams, completedUnits
17
+ *
18
+ * **Isolation Mode**: When isolated, skips saving state (useful for tests).
19
+ *
20
+ * **Usage Flow**:
21
+ * 1. `init()` - Loads state if `--continue`
22
+ * 2. `onStepStarted()` - Saves current step index
23
+ * 3. `onUnitCompleted()` - Marks unit as completed, saves state
24
+ * 4. `onStepEnded()` - Clears completed units for next step
25
+ * 5. `isCompleted()` - Checks if unit already completed (for resume)
26
+ */
27
+ export class RunningStatusHandler extends Logger {
28
+ isolated = false;
29
+ outputFolder;
30
+ // The completed units in the phase.. when running -con, these can be skipped
31
+ completedUnits = [];
32
+ runtimeParams;
33
+ startIndex = 0;
34
+ constructor(outputFolder, runtimeParams) {
35
+ super();
36
+ this.outputFolder = outputFolder;
37
+ this.runtimeParams = runtimeParams;
38
+ }
39
+ /**
40
+ * Initializes the status handler.
41
+ *
42
+ * **Actions**:
43
+ * - Creates output folder if missing
44
+ * - Loads saved state if `--continue` flag is set
45
+ * - Merges loaded runtime params with current params (loaded params take precedence)
46
+ */
47
+ async init() {
48
+ if (!fs.existsSync(this.outputFolder))
49
+ await _fs.mkdir(this.outputFolder, { recursive: true });
50
+ if (this.runtimeParams.continue) {
51
+ const currentParams = this.runtimeParams;
52
+ this.startIndex = await this.load();
53
+ this.runtimeParams = Object.assign(currentParams, this.runtimeParams);
54
+ }
55
+ }
56
+ /**
57
+ * Enables isolation mode (skips saving state).
58
+ *
59
+ * Useful for tests or when state persistence is not desired.
60
+ *
61
+ * @returns This instance for chaining
62
+ */
63
+ isolate() {
64
+ this.isolated = true;
65
+ return this;
66
+ }
67
+ /**
68
+ * Checks if a unit has already been completed (for resume).
69
+ *
70
+ * @param unitKey - Unit key to check
71
+ * @returns True if unit is marked as completed
72
+ */
73
+ isCompleted(unitKey) {
74
+ return this.completedUnits.includes(unitKey);
75
+ }
76
+ /**
77
+ * Marks a unit as completed and saves state.
78
+ *
79
+ * Called after a unit successfully completes all its phases.
80
+ *
81
+ * @param unitKey - Unit key that completed
82
+ */
83
+ async onUnitCompleted(unitKey) {
84
+ this.logDebug(`On unit completed: ${unitKey}`);
85
+ this.completedUnits.push(unitKey);
86
+ await this.saveStatus();
87
+ }
88
+ /**
89
+ * Called when a step completes successfully.
90
+ *
91
+ * Clears completed units list for the next step.
92
+ */
93
+ async onStepEnded() {
94
+ this.logDebug(`On step ended successfully #${this.startIndex}`);
95
+ this.completedUnits = [];
96
+ }
97
+ /**
98
+ * Called when a step starts.
99
+ *
100
+ * Updates start index and saves state (unless isolated).
101
+ *
102
+ * @param index - Step index (0-based)
103
+ */
104
+ async onStepStarted(index) {
105
+ this.startIndex = index;
106
+ this.logDebug(`Setting execution index to #${this.startIndex}`);
107
+ await this.saveStatus();
108
+ }
109
+ /**
110
+ * Saves current state to disk.
111
+ *
112
+ * Writes to `.trash/output/running-status.json` with:
113
+ * - Current step index
114
+ * - Runtime params (for validation)
115
+ * - Completed units in current step
116
+ *
117
+ * Called after each step start and unit completion.
118
+ */
119
+ async saveStatus() {
120
+ if (this.isolated)
121
+ return;
122
+ await _fs.writeFile(`${this.outputFolder}/running-status.json`, __stringify({
123
+ index: this.startIndex,
124
+ runtimeParams: this.runtimeParams,
125
+ completedUnits: this.completedUnits
126
+ }, true));
127
+ }
128
+ /**
129
+ * Loads saved state from disk.
130
+ *
131
+ * **Behavior**:
132
+ * - Reads from `.trash/output/running-status.json`
133
+ * - Restores step index, completed units, and runtime params
134
+ * - Returns undefined if file doesn't exist or parse fails (logs error)
135
+ *
136
+ * **Note**: Runtime params from file override current params (for consistency).
137
+ *
138
+ * @returns Promise resolving to step index, or undefined if load fails
139
+ */
140
+ async load() {
141
+ try {
142
+ const data = JSON.parse(await _fs.readFile(`${this.outputFolder}/running-status.json`, { encoding: 'utf-8' }));
143
+ this.startIndex = data.index;
144
+ this.completedUnits = data.completedUnits ?? [];
145
+ this.runtimeParams = data.runtimeParams;
146
+ return data.index;
147
+ }
148
+ catch (e) {
149
+ this.logError('Failed reading running status, using initial status', e);
150
+ return;
151
+ }
152
+ }
153
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ // Runtime types will be defined here if needed
2
+ export {};
@@ -11,6 +11,15 @@ export declare const Const_FirebaseDefaultsKeyToFile: {
11
11
  [k in typeof Const_FirebaseConfigKeys[number]]: string;
12
12
  };
13
13
  export declare const Default_Files: ProjectConfig_DefaultFileRoutes;
14
+ /**
15
+ * Template file paths for Firebase Functions container builds.
16
+ * These are used when no custom templates are specified in baiConfig.
17
+ */
18
+ export declare const FunctionBuildTemplateFiles: {
19
+ dockerfile: string;
20
+ cloudbuildYaml: string;
21
+ serviceYaml: string;
22
+ };
14
23
  export declare const Default_OutputFiles: {
15
24
  output: string;
16
25
  outputLogs: string;
@@ -3,8 +3,9 @@ import { dirname } from 'node:path';
3
3
  // ESM-safe replacements for __filename/__dirname
4
4
  const __filename = fileURLToPath(import.meta.url);
5
5
  const __dirname = dirname(__filename);
6
- const CONST_FirebaseConfig = `${__dirname}/.firebase_config`;
7
- const CONST_BackendProxy = `${__dirname}/backend-proxy`;
6
+ const CONST_FirebaseConfig = `${__dirname}/firebase/config`;
7
+ const CONST_FirebaseFunctions = `${__dirname}/firebase/functions`;
8
+ const CONST_BackendProxy = `${__dirname}/backend/proxy`;
8
9
  export const Const_FirebaseConfigKeys = [
9
10
  'databaseRules',
10
11
  'firestoreIndexesRules',
@@ -28,6 +29,15 @@ export const Default_Files = {
28
29
  proxy: `${CONST_BackendProxy}/proxy._ts`
29
30
  }
30
31
  };
32
+ /**
33
+ * Template file paths for Firebase Functions container builds.
34
+ * These are used when no custom templates are specified in baiConfig.
35
+ */
36
+ export const FunctionBuildTemplateFiles = {
37
+ dockerfile: `${CONST_FirebaseFunctions}/dockerfile`,
38
+ cloudbuildYaml: `${CONST_FirebaseFunctions}/cloudbuild.yaml`,
39
+ serviceYaml: `${CONST_FirebaseFunctions}/service.yaml`,
40
+ };
31
41
  const Default_OutputPath = './.trash';
32
42
  export const Default_OutputFiles = {
33
43
  output: Default_OutputPath,
@@ -0,0 +1,17 @@
1
+ steps:
2
+ - name: 'gcr.io/cloud-builders/docker'
3
+ args:
4
+ - 'build'
5
+ - '--platform=linux/amd64'
6
+ - '-t'
7
+ - '{{IMAGE_REFERENCE}}'
8
+ - '-t'
9
+ - '{{IMAGE_REFERENCE_LATEST}}'
10
+ - '-f'
11
+ - '{{DOCKERFILE_PATH}}'
12
+ {{LABELS}}
13
+ - '.'
14
+ images:
15
+ - '{{IMAGE_REFERENCE}}'
16
+ - '{{IMAGE_REFERENCE_LATEST}}'
17
+
@@ -0,0 +1,19 @@
1
+ FROM node:22
2
+ WORKDIR /workspace/dist
3
+
4
+ # Copy dist folder (which contains package.json and all compiled code)
5
+ COPY dist/ ./
6
+
7
+ # Install dependencies including functions-framework
8
+ RUN npm install --production && \
9
+ npm install -g @google-cloud/functions-framework
10
+
11
+ # Expose the port that Cloud Run will use
12
+ EXPOSE 8080
13
+
14
+ # Use functions-framework to run the function
15
+ # FUNCTION_TARGET environment variable (set by deployment) specifies which exported function to invoke
16
+ # PORT is automatically set by Cloud Run (default 8080)
17
+ # The framework will load index.js (since we're already in the dist directory)
18
+ CMD ["functions-framework", "--source=index.js"]
19
+
@@ -0,0 +1,49 @@
1
+ HttpSeapiVersion: serving.knative.dev/v1
2
+ kind: Service
3
+ metadata:
4
+ name: {{SERVICE_NAME}}
5
+ labels:
6
+ goog-cloudfunctions-runtime: nodejs22
7
+ cloud.googleapis.com/location: {{REGION}}
8
+ goog-managed-by: cloudfunctions
9
+ annotations:
10
+ serving.knative.dev/creator: service-{{RUNTIME_PROJECT_ID}}@gcf-admin-robot.iam.gserviceaccount.com
11
+ run.googleapis.com/client-name: cli-firebase
12
+ cloudfunctions.googleapis.com/function-id: {{FUNCTION_NAME}}
13
+ run.googleapis.com/ingress: all
14
+ run.googleapis.com/ingress-status: all
15
+ spec:
16
+ template:
17
+ metadata:
18
+ labels: {}
19
+ annotations:
20
+ autoscaling.knative.dev/maxScale: '{{MAX_INSTANCES}}'
21
+ autoscaling.knative.dev/minScale: '{{MIN_INSTANCES}}'
22
+ run.googleapis.com/startup-cpu-boost: 'true'
23
+ cloudfunctions.googleapis.com/trigger-type: {{TRIGGER_TYPE}}
24
+ spec:
25
+ containerConcurrency: {{CONCURRENCY}}
26
+ timeoutSeconds: {{TIMEOUT}}
27
+ {{SERVICE_ACCOUNT}}
28
+ containers:
29
+ - name: worker
30
+ image: {{IMAGE_REFERENCE}}
31
+ ports:
32
+ - name: http1
33
+ containerPort: 8080
34
+ env:
35
+ {{ENV_VARS}}
36
+ resources:
37
+ limits:
38
+ cpu: '{{CPU}}'
39
+ memory: {{MEMORY}}
40
+ startupProbe:
41
+ timeoutSeconds: 240
42
+ periodSeconds: 240
43
+ failureThreshold: 1
44
+ tcpSocket:
45
+ port: 8080
46
+ traffic:
47
+ - percent: 100
48
+ latestRevision: true
49
+
@@ -3,14 +3,23 @@ import { CommandoInteractive } from '@nu-art/commando/shell/index';
3
3
  import { BaseCommando } from '@nu-art/commando/shell/core/BaseCommando';
4
4
  import { MergeTypes } from '@nu-art/commando/shell/core/class-merger';
5
5
  import { Commando_Basic } from '@nu-art/commando/shell/plugins/basic';
6
- import { BAI_Config } from '../../core/types/index.js';
7
- import { UnitsDependencyMapper } from '../UnitsDependencyMapper/UnitsDependencyMapper.js';
8
- import { BaiParams } from '../../core/params/params.js';
6
+ import { BAI_Config } from '../../config/types/index.js';
7
+ import { UnitsDependencyMapper } from '../../dependencies/UnitsDependencyMapper.js';
8
+ import { BaiParams } from '../../core/params.js';
9
+ import { Workspace } from '../../workspace/Workspace.js';
10
+ /**
11
+ * Base configuration for all units.
12
+ */
9
13
  export type BaseUnit_Config = {
10
14
  key: string;
11
15
  label: string;
12
16
  isTopLevelApp?: boolean;
13
17
  };
18
+ /**
19
+ * Runtime context provided to all units during execution.
20
+ *
21
+ * Contains version, config, dependency mapper, runtime params, and workspace reference.
22
+ */
14
23
  export type UnitRuntimeContext = {
15
24
  version: string;
16
25
  baiConfig: Readonly<BAI_Config>;
@@ -18,7 +27,30 @@ export type UnitRuntimeContext = {
18
27
  unitsResolver: <Class extends BaseUnit>(keys: string[], className: Constructor<Class>) => Class[];
19
28
  runtimeParams: BaiParams;
20
29
  globalOutputFolder: string;
30
+ workspace?: Workspace;
21
31
  };
32
+ /**
33
+ * Base class for all units in the build system.
34
+ *
35
+ * **Unit Lifecycle**:
36
+ * 1. **Discovery**: Units are discovered by UnitsMapper from file system
37
+ * 2. **Initialization**: Constructor sets up config and logging
38
+ * 3. **Context Setup**: `setupRuntimeContext()` provides runtime information
39
+ * 4. **Phase Execution**: Phases call unit methods (e.g., `compile()`, `test()`)
40
+ * 5. **Termination**: `kill()` stops all running processes
41
+ *
42
+ * **Key Features**:
43
+ * - **Commando Integration**: Allocates Commando instances for shell commands
44
+ * - **Process Management**: Tracks and kills subprocesses on termination
45
+ * - **Logging**: Buffered logging with status tracking
46
+ * - **Time Tracking**: Measures operation duration
47
+ *
48
+ * **Phase Methods**: Units implement phase methods (e.g., `prepare()`, `compile()`, `test()`)
49
+ * that are called by PhaseManager. Methods are discovered via reflection.
50
+ *
51
+ * **Status Tracking**: Units track their status ('Pending Initialization', 'Running', etc.)
52
+ * for monitoring and debugging.
53
+ */
22
54
  export declare abstract class BaseUnit<C extends BaseUnit_Config = BaseUnit_Config, RT_Context extends UnitRuntimeContext = UnitRuntimeContext> extends Logger {
23
55
  readonly config: Readonly<C>;
24
56
  private unitStatus;
@@ -1,6 +1,27 @@
1
1
  import { _logger_finalDate, _logger_getPrefix, _logger_timezoneOffset, BeLogged, exists, lastElement, LogClient_MemBuffer, Logger, LogLevel, removeItemFromArray, timeCounter } from '@nu-art/ts-common';
2
- import { dispatcher_UnitStatusChange } from '../../old/PhaseRunnerDispatcher.js';
3
2
  import { CommandoPool } from '@nu-art/commando/shell/core/CommandoPool';
3
+ /**
4
+ * Base class for all units in the build system.
5
+ *
6
+ * **Unit Lifecycle**:
7
+ * 1. **Discovery**: Units are discovered by UnitsMapper from file system
8
+ * 2. **Initialization**: Constructor sets up config and logging
9
+ * 3. **Context Setup**: `setupRuntimeContext()` provides runtime information
10
+ * 4. **Phase Execution**: Phases call unit methods (e.g., `compile()`, `test()`)
11
+ * 5. **Termination**: `kill()` stops all running processes
12
+ *
13
+ * **Key Features**:
14
+ * - **Commando Integration**: Allocates Commando instances for shell commands
15
+ * - **Process Management**: Tracks and kills subprocesses on termination
16
+ * - **Logging**: Buffered logging with status tracking
17
+ * - **Time Tracking**: Measures operation duration
18
+ *
19
+ * **Phase Methods**: Units implement phase methods (e.g., `prepare()`, `compile()`, `test()`)
20
+ * that are called by PhaseManager. Methods are discovered via reflection.
21
+ *
22
+ * **Status Tracking**: Units track their status ('Pending Initialization', 'Running', etc.)
23
+ * for monitoring and debugging.
24
+ */
4
25
  export class BaseUnit extends Logger {
5
26
  config;
6
27
  unitStatus = 'Pending Initialization';
@@ -86,7 +107,6 @@ export class BaseUnit extends Logger {
86
107
  }
87
108
  this.log(logLevel, false, [`Unit status update: ${this.unitStatus} => ${status}${operationDuration}`]);
88
109
  this.unitStatus = `${status}${operationDuration}`;
89
- dispatcher_UnitStatusChange.dispatch(this);
90
110
  }
91
111
  addToClassStack = (cls) => {
92
112
  this.classStack.push(cls.name);
@@ -0,0 +1,32 @@
1
+ import { StringMap } from '@nu-art/ts-common';
2
+ import { BaseUnit, BaseUnit_Config, UnitRuntimeContext } from './BaseUnit.js';
3
+ export type Config_ProjectUnit = BaseUnit_Config & {
4
+ relativePath: string;
5
+ fullPath: string;
6
+ dependencies: StringMap;
7
+ };
8
+ export type ProjectUnit_RuntimeContext = UnitRuntimeContext & {
9
+ parentUnit: ProjectUnit<any>;
10
+ childUnits: ProjectUnit[];
11
+ };
12
+ /**
13
+ * Abstract base class for project units (packages/apps in the workspace).
14
+ *
15
+ * **Project Units vs Base Units**:
16
+ * - **Project Units**: Have file paths, dependencies, and participate in dependency resolution
17
+ * - **Base Units**: Generic units without file system context
18
+ *
19
+ * **Key Properties**:
20
+ * - `relativePath`: Path relative to project root
21
+ * - `fullPath`: Absolute path to unit directory
22
+ * - `dependencies`: Map of dependency keys (for dependency resolution)
23
+ *
24
+ * **Runtime Context**: ProjectUnits receive `ProjectUnit_RuntimeContext` which includes:
25
+ * - `parentUnit`: Root NodeProject unit
26
+ * - `childUnits`: All project units in workspace
27
+ *
28
+ * **Examples**: Unit_NodeProject, Unit_TypescriptLib, Unit_FirebaseHostingApp
29
+ */
30
+ export declare abstract class ProjectUnit<C extends Config_ProjectUnit = Config_ProjectUnit> extends BaseUnit<C, ProjectUnit_RuntimeContext> {
31
+ constructor(config: C);
32
+ }
@@ -0,0 +1,25 @@
1
+ import { BaseUnit } from './BaseUnit.js';
2
+ /**
3
+ * Abstract base class for project units (packages/apps in the workspace).
4
+ *
5
+ * **Project Units vs Base Units**:
6
+ * - **Project Units**: Have file paths, dependencies, and participate in dependency resolution
7
+ * - **Base Units**: Generic units without file system context
8
+ *
9
+ * **Key Properties**:
10
+ * - `relativePath`: Path relative to project root
11
+ * - `fullPath`: Absolute path to unit directory
12
+ * - `dependencies`: Map of dependency keys (for dependency resolution)
13
+ *
14
+ * **Runtime Context**: ProjectUnits receive `ProjectUnit_RuntimeContext` which includes:
15
+ * - `parentUnit`: Root NodeProject unit
16
+ * - `childUnits`: All project units in workspace
17
+ *
18
+ * **Examples**: Unit_NodeProject, Unit_TypescriptLib, Unit_FirebaseHostingApp
19
+ */
20
+ export class ProjectUnit extends BaseUnit {
21
+ constructor(config) {
22
+ super(config);
23
+ this.addToClassStack(ProjectUnit);
24
+ }
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,69 @@
1
+ import { BaseUnit, ProjectUnit } from '../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.js';
5
+ /**
6
+ * Recursively scans workspace and discovers units using resolution rules.
7
+ *
8
+ * **Discovery Process**:
9
+ * 1. Starts at project root path
10
+ * 2. Applies resolution rules in order (first match wins)
11
+ * 3. If unit found and not root, stops recursion (unit is a leaf)
12
+ * 4. If unit is root, continues scanning subdirectories
13
+ * 5. Skips `node_modules` and hidden directories (`.git`, `.vscode`, etc.)
14
+ *
15
+ * **Resolution Rules**:
16
+ * - Rules are added via `addRules()` (e.g., UnitMapper_NodeLib, UnitMapper_FirebaseFunction)
17
+ * - Each rule checks if a path matches its criteria (package.json, firebase.json, etc.)
18
+ * - Rules can be configured with runtime params
19
+ *
20
+ * **Unit Types**:
21
+ * - **Root Units**: Continue scanning subdirectories (e.g., monorepo root)
22
+ * - **Leaf Units**: Stop recursion (e.g., individual packages)
23
+ *
24
+ * **Filtering**: Automatically skips:
25
+ * - `node_modules` directories
26
+ * - Hidden directories (starting with `.`)
27
+ *
28
+ * **Usage**: Called by `Workspace.scanUnits()` to discover all units in workspace.
29
+ */
30
+ export declare class UnitsMapper extends Logger {
31
+ private rules;
32
+ /**
33
+ * @param path - will always be a directory
34
+ * @param projectRoot - The path to the project root
35
+ * @param units - The project units derived from the file system
36
+ */
37
+ resolveUnits(path: string, projectRoot?: string, units?: BaseUnit<any>[]): Promise<BaseUnit<any, import("../index.js").UnitRuntimeContext>[]>;
38
+ /**
39
+ * Adds unit resolution rules.
40
+ *
41
+ * Rules are tried in order (first match wins). Common rules:
42
+ * - `UnitMapper_NodeProject`: Root project unit
43
+ * - `UnitMapper_NodeLib`: TypeScript libraries
44
+ * - `UnitMapper_FirebaseHosting`: Firebase hosting apps
45
+ * - `UnitMapper_FirebaseFunction`: Firebase functions
46
+ *
47
+ * @param rules - Unit mapper rules to add
48
+ * @returns This instance for chaining
49
+ */
50
+ addRules<T extends BaseUnit<any>>(...rules: UnitMapper_Base<T>[]): this;
51
+ /**
52
+ * Sets runtime params on all rules.
53
+ *
54
+ * Rules can use runtime params to filter or configure resolution behavior.
55
+ *
56
+ * @param runtimeParams - Runtime parameters
57
+ * @returns This instance for chaining
58
+ */
59
+ setRuntimeParams(runtimeParams: BaiParams): this;
60
+ /**
61
+ * Validates that all units have unique keys.
62
+ *
63
+ * Throws `BadImplementationException` if duplicate keys found.
64
+ *
65
+ * @param units - Units to validate
66
+ * @throws BadImplementationException if duplicate keys found
67
+ */
68
+ assertUniqueKeys(units: ProjectUnit[]): void;
69
+ }
@@ -1,9 +1,29 @@
1
1
  import { promises as fs } from 'fs';
2
2
  import { BadImplementationException, Logger } from '@nu-art/ts-common';
3
3
  /**
4
- * This class will receive a path and will map the workspace packages and libs
4
+ * Recursively scans workspace and discovers units using resolution rules.
5
5
  *
6
- * 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
6
+ * **Discovery Process**:
7
+ * 1. Starts at project root path
8
+ * 2. Applies resolution rules in order (first match wins)
9
+ * 3. If unit found and not root, stops recursion (unit is a leaf)
10
+ * 4. If unit is root, continues scanning subdirectories
11
+ * 5. Skips `node_modules` and hidden directories (`.git`, `.vscode`, etc.)
12
+ *
13
+ * **Resolution Rules**:
14
+ * - Rules are added via `addRules()` (e.g., UnitMapper_NodeLib, UnitMapper_FirebaseFunction)
15
+ * - Each rule checks if a path matches its criteria (package.json, firebase.json, etc.)
16
+ * - Rules can be configured with runtime params
17
+ *
18
+ * **Unit Types**:
19
+ * - **Root Units**: Continue scanning subdirectories (e.g., monorepo root)
20
+ * - **Leaf Units**: Stop recursion (e.g., individual packages)
21
+ *
22
+ * **Filtering**: Automatically skips:
23
+ * - `node_modules` directories
24
+ * - Hidden directories (starting with `.`)
25
+ *
26
+ * **Usage**: Called by `Workspace.scanUnits()` to discover all units in workspace.
7
27
  */
8
28
  export class UnitsMapper extends Logger {
9
29
  rules = [];
@@ -20,7 +40,7 @@ export class UnitsMapper extends Logger {
20
40
  unit = await rule.resolveUnit(path, projectRoot);
21
41
  if (!unit)
22
42
  continue;
23
- this.logDebug(`Found unit ${unit.config.key} at path ${path}`);
43
+ this.logVerbose(`Found unit ${unit.config.key} at path ${path}`);
24
44
  units.push(unit);
25
45
  if (!unit.config.isRoot)
26
46
  return units;
@@ -38,14 +58,42 @@ export class UnitsMapper extends Logger {
38
58
  }
39
59
  return units;
40
60
  }
61
+ /**
62
+ * Adds unit resolution rules.
63
+ *
64
+ * Rules are tried in order (first match wins). Common rules:
65
+ * - `UnitMapper_NodeProject`: Root project unit
66
+ * - `UnitMapper_NodeLib`: TypeScript libraries
67
+ * - `UnitMapper_FirebaseHosting`: Firebase hosting apps
68
+ * - `UnitMapper_FirebaseFunction`: Firebase functions
69
+ *
70
+ * @param rules - Unit mapper rules to add
71
+ * @returns This instance for chaining
72
+ */
41
73
  addRules(...rules) {
42
74
  this.rules.push(...rules);
43
75
  return this;
44
76
  }
77
+ /**
78
+ * Sets runtime params on all rules.
79
+ *
80
+ * Rules can use runtime params to filter or configure resolution behavior.
81
+ *
82
+ * @param runtimeParams - Runtime parameters
83
+ * @returns This instance for chaining
84
+ */
45
85
  setRuntimeParams(runtimeParams) {
46
86
  this.rules.forEach(rule => rule.setRuntimeParams(runtimeParams));
47
87
  return this;
48
88
  }
89
+ /**
90
+ * Validates that all units have unique keys.
91
+ *
92
+ * Throws `BadImplementationException` if duplicate keys found.
93
+ *
94
+ * @param units - Units to validate
95
+ * @throws BadImplementationException if duplicate keys found
96
+ */
49
97
  assertUniqueKeys(units) {
50
98
  const keyToUnit = {};
51
99
  for (const unit of units) {
@@ -0,0 +1,65 @@
1
+ import { AbsolutePath, Logger, RelativePath, StringMap, TypeValidator } from '@nu-art/ts-common';
2
+ import { BaseUnit } from '../../index.js';
3
+ import { BAI_Config } from '../../../config/types/index.js';
4
+ import { BaiParams } from '../../../core/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
+ /**
16
+ * Base class for unit mapper resolvers.
17
+ *
18
+ * **Purpose**: Each mapper resolver checks if a directory path matches its unit type
19
+ * and creates the appropriate unit instance if it matches.
20
+ *
21
+ * **Resolution Process**:
22
+ * 1. `resolveUnit()` is called for each directory during workspace scan
23
+ * 2. Mapper checks if path matches its criteria (package.json type, file presence, etc.)
24
+ * 3. If match, creates and returns unit instance
25
+ * 4. If no match, returns undefined (next mapper tries)
26
+ *
27
+ * **Configuration**:
28
+ * - `validator`: Validates unit config JSON (e.g., package.json.unitConfig.type)
29
+ * - `baiConfig`: BAI configuration (set by UnitsMapper)
30
+ * - `runtimeParams`: Runtime parameters (set by UnitsMapper)
31
+ *
32
+ * **Usage**: Extended by specific mappers (UnitMapper_NodeLib, UnitMapper_FirebaseFunction, etc.)
33
+ * to implement unit-specific discovery logic.
34
+ */
35
+ export declare abstract class UnitMapper_Base<T extends BaseUnit<any>, ConfigJSON extends UnitConfigJSON_Base = UnitConfigJSON_Base> extends Logger {
36
+ protected validator: TypeValidator<ConfigJSON>;
37
+ protected baiConfig: BAI_Config;
38
+ protected runtimeParams: BaiParams;
39
+ protected constructor(validator: TypeValidator<ConfigJSON>);
40
+ /**
41
+ * Sets runtime parameters for the mapper.
42
+ *
43
+ * Called by UnitsMapper to provide runtime context.
44
+ */
45
+ setRuntimeParams(runtimeParams: BaiParams): void;
46
+ /**
47
+ * Sets BAI configuration for the mapper.
48
+ *
49
+ * Called by UnitsMapper to provide configuration context.
50
+ */
51
+ setConfig(config: BAI_Config): void;
52
+ /**
53
+ * Resolves a unit from a directory path.
54
+ *
55
+ * **Behavior**:
56
+ * - Checks if path matches this mapper's criteria
57
+ * - If match, creates and returns unit instance
58
+ * - If no match, returns undefined
59
+ *
60
+ * @param path - Directory path to check
61
+ * @param root - Project root path
62
+ * @returns Promise resolving to unit instance or undefined
63
+ */
64
+ abstract resolveUnit(path: string, root: string): Promise<T | undefined>;
65
+ }