@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.
- package/BuildAndInstall.d.ts +40 -0
- package/BuildAndInstall.js +155 -0
- package/build-and-install-v3.d.ts +1 -44
- package/build-and-install-v3.js +1 -157
- package/build-and-install.js +11 -11
- package/config/consts.d.ts +43 -0
- package/config/consts.js +42 -0
- package/{core → config}/package/consts.d.ts +1 -1
- package/{core → config}/types/project-config.d.ts +3 -0
- package/core/FilesCache.d.ts +50 -0
- package/core/FilesCache.js +76 -0
- package/core/Unit_HelpPrinter.d.ts +16 -0
- package/core/Unit_HelpPrinter.js +47 -0
- package/core/params/params.d.ts +1 -41
- package/core/params/params.js +1 -332
- package/core/params.d.ts +50 -0
- package/core/params.js +441 -0
- package/{v3/core → core}/types.d.ts +1 -1
- package/{v3/UnitsDependencyMapper → dependencies}/UnitsDependencyMapper.d.ts +21 -1
- package/{v3/UnitsDependencyMapper → dependencies}/UnitsDependencyMapper.js +26 -3
- package/dependencies/types.d.ts +1 -0
- package/dependencies/types.js +1 -0
- package/exceptions/PhaseAggregatedException.d.ts +34 -0
- package/{core/exceptions → exceptions}/PhaseAggregatedException.js +26 -0
- package/exceptions/UnitPhaseException.d.ts +20 -0
- package/exceptions/UnitPhaseException.js +21 -0
- package/exports/ExportIndexCache.d.ts +25 -0
- package/exports/ExportIndexCache.js +115 -0
- package/exports/ExportMapper.d.ts +43 -0
- package/exports/ExportMapper.js +519 -0
- package/exports/IndicesMcpServer.d.ts +22 -0
- package/exports/IndicesMcpServer.js +220 -0
- package/exports/types.js +3 -0
- package/package.json +20 -9
- package/phases/PhaseManager.d.ts +130 -0
- package/{v3 → phases}/PhaseManager.js +99 -2
- package/{v3/phase → phases/definitions}/consts.d.ts +36 -0
- package/{v3/phase → phases/definitions}/consts.js +44 -2
- package/phases/definitions/types.d.ts +40 -0
- package/phases/index.d.ts +2 -0
- package/phases/index.js +2 -0
- package/run.js +10 -0
- package/runtime/RunningStatusHandler.d.ts +104 -0
- package/runtime/RunningStatusHandler.js +153 -0
- package/runtime/types.d.ts +1 -0
- package/runtime/types.js +2 -0
- package/{defaults → templates}/consts.d.ts +9 -0
- package/{defaults → templates}/consts.js +12 -2
- package/templates/firebase/functions/cloudbuild.yaml +17 -0
- package/templates/firebase/functions/dockerfile +19 -0
- package/templates/firebase/functions/service.yaml +49 -0
- package/{v3/units → units/base}/BaseUnit.d.ts +34 -4
- package/{v3/units → units/base}/BaseUnit.js +22 -2
- package/units/base/ProjectUnit.d.ts +32 -0
- package/units/base/ProjectUnit.js +25 -0
- package/units/base/types.js +1 -0
- package/units/discovery/UnitsMapper.d.ts +69 -0
- package/{v3/UnitsMapper → units/discovery}/UnitsMapper.js +50 -2
- package/units/discovery/resolvers/UnitMapper_Base.d.ts +65 -0
- package/units/discovery/resolvers/UnitMapper_Base.js +46 -0
- package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_FirebaseFunction.d.ts +5 -3
- package/units/discovery/resolvers/UnitMapper_FirebaseFunction.js +105 -0
- package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_FirebaseHosting.d.ts +3 -2
- package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_FirebaseHosting.js +14 -10
- package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_Node.d.ts +1 -1
- package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_Node.js +2 -2
- package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_NodeLib.d.ts +24 -1
- package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_NodeLib.js +24 -1
- package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_NodeProject.d.ts +22 -1
- package/{v3/UnitsMapper → units/discovery}/resolvers/UnitMapper_NodeProject.js +22 -1
- package/units/discovery/types.js +1 -0
- package/units/implementations/Unit_NodeProject.d.ts +59 -0
- package/{v3/units → units/implementations}/Unit_NodeProject.js +65 -5
- package/units/implementations/Unit_PackageJson.d.ts +56 -0
- package/{v3/units → units/implementations}/Unit_PackageJson.js +39 -3
- package/{v3/units → units/implementations}/Unit_TypescriptLib.d.ts +40 -4
- package/{v3/units → units/implementations}/Unit_TypescriptLib.js +167 -17
- package/units/implementations/firebase/Unit_FirebaseFunctionsApp.d.ts +233 -0
- package/units/implementations/firebase/Unit_FirebaseFunctionsApp.js +804 -0
- package/units/implementations/firebase/Unit_FirebaseHostingApp.d.ts +113 -0
- package/units/implementations/firebase/Unit_FirebaseHostingApp.js +320 -0
- package/units/implementations/firebase/common.d.ts +26 -0
- package/units/implementations/firebase/common.js +65 -0
- package/units/index.d.ts +6 -0
- package/units/index.js +6 -0
- package/v3/core/Unit_HelpPrinter.d.ts +1 -16
- package/v3/core/Unit_HelpPrinter.js +1 -47
- package/{v3 → workspace}/Workspace.d.ts +30 -15
- package/{v3 → workspace}/Workspace.js +48 -35
- package/core/consts.d.ts +0 -13
- package/core/consts.js +0 -12
- package/core/exceptions/PhaseAggregatedException.d.ts +0 -8
- package/core/exceptions/UnitPhaseException.d.ts +0 -5
- package/core/exceptions/UnitPhaseException.js +0 -6
- package/old/PhaseRunnerDispatcher.d.ts +0 -24
- package/old/PhaseRunnerDispatcher.js +0 -32
- package/old/runner-dispatchers.d.ts +0 -10
- package/old/runner-dispatchers.js +0 -3
- package/v3/PhaseManager.d.ts +0 -27
- package/v3/RunningStatusHandler.d.ts +0 -18
- package/v3/RunningStatusHandler.js +0 -67
- package/v3/UnitsMapper/UnitsMapper.d.ts +0 -21
- package/v3/UnitsMapper/resolvers/UnitMapper_Base.d.ts +0 -23
- package/v3/UnitsMapper/resolvers/UnitMapper_Base.js +0 -16
- package/v3/UnitsMapper/resolvers/UnitMapper_FirebaseFunction.js +0 -66
- package/v3/core/FilesCache.d.ts +0 -7
- package/v3/core/FilesCache.js +0 -33
- package/v3/phase/types.d.ts +0 -10
- package/v3/units/ProjectUnit.d.ts +0 -18
- package/v3/units/ProjectUnit.js +0 -11
- package/v3/units/Unit_NodeProject.d.ts +0 -30
- package/v3/units/Unit_PackageJson.d.ts +0 -17
- package/v3/units/firebase/Unit_FirebaseFunctionsApp.d.ts +0 -64
- package/v3/units/firebase/Unit_FirebaseFunctionsApp.js +0 -306
- package/v3/units/firebase/Unit_FirebaseHostingApp.d.ts +0 -49
- package/v3/units/firebase/Unit_FirebaseHostingApp.js +0 -118
- package/v3/units/firebase/common.d.ts +0 -3
- package/v3/units/firebase/common.js +0 -13
- package/v3/units/index.d.ts +0 -6
- package/v3/units/index.js +0 -6
- /package/{core → config}/package/consts.js +0 -0
- /package/{core → config}/types/configs/firebasejson.d.ts +0 -0
- /package/{core → config}/types/configs/firebasejson.js +0 -0
- /package/{core → config}/types/configs/firebaserc.d.ts +0 -0
- /package/{core → config}/types/configs/firebaserc.js +0 -0
- /package/{core → config}/types/configs/index.d.ts +0 -0
- /package/{core → config}/types/configs/index.js +0 -0
- /package/{core → config}/types/configs/package-json.d.ts +0 -0
- /package/{core → config}/types/configs/package-json.js +0 -0
- /package/{core → config}/types/core.d.ts +0 -0
- /package/{core → config}/types/core.js +0 -0
- /package/{core → config}/types/index.d.ts +0 -0
- /package/{core → config}/types/index.js +0 -0
- /package/{core → config}/types/package/index.d.ts +0 -0
- /package/{core → config}/types/package/index.js +0 -0
- /package/{core → config}/types/package/package.d.ts +0 -0
- /package/{core → config}/types/package/package.js +0 -0
- /package/{core → config}/types/package/runtime-package.d.ts +0 -0
- /package/{core → config}/types/package/runtime-package.js +0 -0
- /package/{core → config}/types/project-config.js +0 -0
- /package/{v3/core → core}/types.js +0 -0
- /package/{v3/UnitsMapper/types.js → exports/types.d.ts} +0 -0
- /package/{v3/phase → phases/definitions}/index.d.ts +0 -0
- /package/{v3/phase → phases/definitions}/index.js +0 -0
- /package/{v3/phase → phases/definitions}/types.js +0 -0
- /package/{v3/units/types.js → run.d.ts} +0 -0
- /package/{defaults/backend-proxy → templates/backend/proxy}/proxy._ts +0 -0
- /package/{defaults/.firebase_config → templates/firebase/config}/database.rules.json +0 -0
- /package/{defaults/.firebase_config → templates/firebase/config}/firestore.indexes.json +0 -0
- /package/{defaults/.firebase_config → templates/firebase/config}/firestore.rules +0 -0
- /package/{defaults/.firebase_config → templates/firebase/config}/storage.rules +0 -0
- /package/{v3/units → units/base}/types.d.ts +0 -0
- /package/{v3/UnitsMapper → units/discovery}/resolvers/index.d.ts +0 -0
- /package/{v3/UnitsMapper → units/discovery}/resolvers/index.js +0 -0
- /package/{v3/UnitsMapper → units/discovery}/types.d.ts +0 -0
|
@@ -62,6 +62,20 @@ export const phase_PreCompile = {
|
|
|
62
62
|
method: 'preCompile',
|
|
63
63
|
filter: (baiParams) => !baiParams.noBuild,
|
|
64
64
|
};
|
|
65
|
+
export const phaseKey_ExtractDynamicDeps = 'extract-dynamic-deps';
|
|
66
|
+
export const phase_ExtractDynamicDeps = {
|
|
67
|
+
key: phaseKey_ExtractDynamicDeps,
|
|
68
|
+
name: 'Extract Dynamic Dependencies',
|
|
69
|
+
method: 'extractDynamicDeps',
|
|
70
|
+
filter: (baiParams) => baiParams.extractDynamicDeps,
|
|
71
|
+
};
|
|
72
|
+
export const phaseKey_MapExports = 'map-exports';
|
|
73
|
+
export const phase_MapExports = {
|
|
74
|
+
key: phaseKey_MapExports,
|
|
75
|
+
name: 'Map Exports',
|
|
76
|
+
method: 'mapExports',
|
|
77
|
+
filter: (baiParams) => baiParams.mapExports,
|
|
78
|
+
};
|
|
65
79
|
export const phaseKey_Compile = 'compile';
|
|
66
80
|
export const phase_Compile = {
|
|
67
81
|
key: phaseKey_Compile,
|
|
@@ -95,7 +109,7 @@ export const phases_Build = [
|
|
|
95
109
|
[phase_Purge, phase_Prepare],
|
|
96
110
|
[phase_ToESM],
|
|
97
111
|
[phase_Install],
|
|
98
|
-
[phase_Lint, phase_PreCompile, phase_Compile, phase_Test,],
|
|
112
|
+
[phase_Lint, phase_PreCompile, phase_ExtractDynamicDeps, phase_MapExports, phase_Compile, phase_Test,],
|
|
99
113
|
[phase_Watch]
|
|
100
114
|
];
|
|
101
115
|
export const phaseKey_Launch = 'launch';
|
|
@@ -105,8 +119,16 @@ export const phase_Launch = {
|
|
|
105
119
|
method: 'launch',
|
|
106
120
|
filter: (baiParams) => !!baiParams.launch,
|
|
107
121
|
};
|
|
122
|
+
export const phaseKey_IndicesMcpServer = 'indices-mcp-server';
|
|
123
|
+
export const phase_IndicesMcpServer = {
|
|
124
|
+
key: phaseKey_IndicesMcpServer,
|
|
125
|
+
name: 'Export Indices MCP Server',
|
|
126
|
+
method: 'indicesMcpServer',
|
|
127
|
+
filter: (baiParams) => baiParams.indicesMcpServer,
|
|
128
|
+
};
|
|
108
129
|
export const phases_Launch = [[
|
|
109
130
|
phase_Launch,
|
|
131
|
+
phase_IndicesMcpServer,
|
|
110
132
|
]];
|
|
111
133
|
export const phaseKey_Publish = 'publish';
|
|
112
134
|
export const phase_Publish = {
|
|
@@ -129,4 +151,24 @@ export const phase_Deploy = {
|
|
|
129
151
|
method: 'deploy',
|
|
130
152
|
filter: (baiParams) => !!baiParams.deploy,
|
|
131
153
|
};
|
|
132
|
-
export const
|
|
154
|
+
export const phaseKey_BuildPushImage = 'build-push-image';
|
|
155
|
+
export const phase_BuildPushImage = {
|
|
156
|
+
key: phaseKey_BuildPushImage,
|
|
157
|
+
name: 'Build & Push Container Image',
|
|
158
|
+
method: 'buildPushImage',
|
|
159
|
+
filter: (baiParams) => !!baiParams.buildPushImage,
|
|
160
|
+
};
|
|
161
|
+
export const phaseKey_DeployImage = 'deploy-image';
|
|
162
|
+
export const phase_DeployImage = {
|
|
163
|
+
key: phaseKey_DeployImage,
|
|
164
|
+
name: 'Deploy Container Image',
|
|
165
|
+
method: 'deployImage',
|
|
166
|
+
filter: (baiParams) => !!baiParams.deployImage,
|
|
167
|
+
dependencyPhase: [phase_BuildPushImage],
|
|
168
|
+
};
|
|
169
|
+
export const phases_Deploy = [
|
|
170
|
+
[phase_BuildPushImage],
|
|
171
|
+
[phase_DeployImage],
|
|
172
|
+
[phase_Publish, phase_Deploy],
|
|
173
|
+
[phase_PostPublish]
|
|
174
|
+
];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BaiParams } from '../../core/params.js';
|
|
2
|
+
/**
|
|
3
|
+
* Phase definition for build system execution.
|
|
4
|
+
*
|
|
5
|
+
* **Phase Structure**:
|
|
6
|
+
* - Phases are grouped into phase groups (arrays of phases)
|
|
7
|
+
* - Phases in a group can run in parallel
|
|
8
|
+
* - Phase groups run sequentially
|
|
9
|
+
*
|
|
10
|
+
* **Key Properties**:
|
|
11
|
+
* - `key`: Unique identifier for the phase
|
|
12
|
+
* - `method`: Method name that units must implement (e.g., 'compile', 'test')
|
|
13
|
+
* - `filter`: Optional function to determine if phase should run based on runtime params
|
|
14
|
+
* - `unitCategory`: Which units participate ('active' or 'project')
|
|
15
|
+
* - `dependencyPhase`: Phases that must complete before this phase runs
|
|
16
|
+
* - `terminateAfterPhase`: If true, stops execution after this phase completes
|
|
17
|
+
*
|
|
18
|
+
* **Unit Participation**:
|
|
19
|
+
* - Units must implement the phase method to participate
|
|
20
|
+
* - Units must be in the correct category (active/project)
|
|
21
|
+
* - Phase filter must pass (if present)
|
|
22
|
+
*
|
|
23
|
+
* **Examples**: See `phase/consts.ts` for all phase definitions.
|
|
24
|
+
*/
|
|
25
|
+
export type Phase<PhaseMethod extends string> = {
|
|
26
|
+
/** Unique identifier for the phase */
|
|
27
|
+
key: string;
|
|
28
|
+
/** Display name for the phase */
|
|
29
|
+
name: string;
|
|
30
|
+
/** Method name that units must implement */
|
|
31
|
+
method: PhaseMethod;
|
|
32
|
+
/** Optional filter to determine if phase should run based on runtime params */
|
|
33
|
+
filter?: (params: BaiParams) => boolean;
|
|
34
|
+
/** If true, terminates execution after this phase completes */
|
|
35
|
+
terminateAfterPhase?: boolean;
|
|
36
|
+
/** Phases that must complete before this phase runs */
|
|
37
|
+
dependencyPhase?: Phase<string>[];
|
|
38
|
+
/** Unit category: 'project' = all project units (active + dependencies), 'active' = only active units (default) */
|
|
39
|
+
unitCategory?: "project" | "active";
|
|
40
|
+
};
|
package/phases/index.js
ADDED
package/run.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BuildAndInstall } from './BuildAndInstall.js';
|
|
2
|
+
(async () => {
|
|
3
|
+
const buildAndInstall = new BuildAndInstall();
|
|
4
|
+
await buildAndInstall.build();
|
|
5
|
+
await buildAndInstall.run();
|
|
6
|
+
})()
|
|
7
|
+
.catch((err) => {
|
|
8
|
+
process.exit(2);
|
|
9
|
+
})
|
|
10
|
+
.then(() => process.exit(0));
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Logger } from '@nu-art/ts-common';
|
|
2
|
+
import { BaiParams } from '../core/params.js';
|
|
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 declare class RunningStatusHandler extends Logger {
|
|
28
|
+
private isolated;
|
|
29
|
+
private readonly outputFolder;
|
|
30
|
+
private completedUnits;
|
|
31
|
+
runtimeParams: BaiParams;
|
|
32
|
+
startIndex: number;
|
|
33
|
+
constructor(outputFolder: string, runtimeParams: BaiParams);
|
|
34
|
+
/**
|
|
35
|
+
* Initializes the status handler.
|
|
36
|
+
*
|
|
37
|
+
* **Actions**:
|
|
38
|
+
* - Creates output folder if missing
|
|
39
|
+
* - Loads saved state if `--continue` flag is set
|
|
40
|
+
* - Merges loaded runtime params with current params (loaded params take precedence)
|
|
41
|
+
*/
|
|
42
|
+
init(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Enables isolation mode (skips saving state).
|
|
45
|
+
*
|
|
46
|
+
* Useful for tests or when state persistence is not desired.
|
|
47
|
+
*
|
|
48
|
+
* @returns This instance for chaining
|
|
49
|
+
*/
|
|
50
|
+
isolate(): RunningStatusHandler;
|
|
51
|
+
/**
|
|
52
|
+
* Checks if a unit has already been completed (for resume).
|
|
53
|
+
*
|
|
54
|
+
* @param unitKey - Unit key to check
|
|
55
|
+
* @returns True if unit is marked as completed
|
|
56
|
+
*/
|
|
57
|
+
isCompleted(unitKey: string): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Marks a unit as completed and saves state.
|
|
60
|
+
*
|
|
61
|
+
* Called after a unit successfully completes all its phases.
|
|
62
|
+
*
|
|
63
|
+
* @param unitKey - Unit key that completed
|
|
64
|
+
*/
|
|
65
|
+
onUnitCompleted(unitKey: string): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Called when a step completes successfully.
|
|
68
|
+
*
|
|
69
|
+
* Clears completed units list for the next step.
|
|
70
|
+
*/
|
|
71
|
+
onStepEnded(): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Called when a step starts.
|
|
74
|
+
*
|
|
75
|
+
* Updates start index and saves state (unless isolated).
|
|
76
|
+
*
|
|
77
|
+
* @param index - Step index (0-based)
|
|
78
|
+
*/
|
|
79
|
+
onStepStarted(index: number): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Saves current state to disk.
|
|
82
|
+
*
|
|
83
|
+
* Writes to `.trash/output/running-status.json` with:
|
|
84
|
+
* - Current step index
|
|
85
|
+
* - Runtime params (for validation)
|
|
86
|
+
* - Completed units in current step
|
|
87
|
+
*
|
|
88
|
+
* Called after each step start and unit completion.
|
|
89
|
+
*/
|
|
90
|
+
private saveStatus;
|
|
91
|
+
/**
|
|
92
|
+
* Loads saved state from disk.
|
|
93
|
+
*
|
|
94
|
+
* **Behavior**:
|
|
95
|
+
* - Reads from `.trash/output/running-status.json`
|
|
96
|
+
* - Restores step index, completed units, and runtime params
|
|
97
|
+
* - Returns undefined if file doesn't exist or parse fails (logs error)
|
|
98
|
+
*
|
|
99
|
+
* **Note**: Runtime params from file override current params (for consistency).
|
|
100
|
+
*
|
|
101
|
+
* @returns Promise resolving to step index, or undefined if load fails
|
|
102
|
+
*/
|
|
103
|
+
load(): Promise<any>;
|
|
104
|
+
}
|
|
@@ -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 {};
|
package/runtime/types.js
ADDED
|
@@ -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}
|
|
7
|
-
const
|
|
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,15 +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 '../../
|
|
7
|
-
import { UnitsDependencyMapper } from '
|
|
8
|
-
import { BaiParams } from '../../core/params
|
|
9
|
-
import { Workspace } from '
|
|
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
|
+
*/
|
|
10
13
|
export type BaseUnit_Config = {
|
|
11
14
|
key: string;
|
|
12
15
|
label: string;
|
|
13
16
|
isTopLevelApp?: boolean;
|
|
14
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Runtime context provided to all units during execution.
|
|
20
|
+
*
|
|
21
|
+
* Contains version, config, dependency mapper, runtime params, and workspace reference.
|
|
22
|
+
*/
|
|
15
23
|
export type UnitRuntimeContext = {
|
|
16
24
|
version: string;
|
|
17
25
|
baiConfig: Readonly<BAI_Config>;
|
|
@@ -21,6 +29,28 @@ export type UnitRuntimeContext = {
|
|
|
21
29
|
globalOutputFolder: string;
|
|
22
30
|
workspace?: Workspace;
|
|
23
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
|
+
*/
|
|
24
54
|
export declare abstract class BaseUnit<C extends BaseUnit_Config = BaseUnit_Config, RT_Context extends UnitRuntimeContext = UnitRuntimeContext> extends Logger {
|
|
25
55
|
readonly config: Readonly<C>;
|
|
26
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
|
+
}
|