1+ import { Logger } from '@launchql/logger' ;
2+ import {
3+ ConfigManager ,
4+ ModuleManager ,
5+ ExtensionManager ,
6+ PackageManager ,
7+ PlanGenerator
8+ } from '../managers' ;
9+
10+ export enum ProjectContext {
11+ Workspace = 'workspace' ,
12+ Module = 'module' ,
13+ Unknown = 'unknown'
14+ }
15+
16+ /**
17+ * Refactored LaunchQL class using manager pattern
18+ * This class serves as a facade to the various managers
19+ */
20+ export class LaunchQL {
21+ private logger = new Logger ( 'launchql' ) ;
22+ private configManager : ConfigManager ;
23+ private moduleManager : ModuleManager ;
24+ private extensionManager : ExtensionManager ;
25+ private packageManager : PackageManager ;
26+ private planGenerator : PlanGenerator ;
27+
28+ constructor ( cwd : string = process . cwd ( ) ) {
29+ // Initialize managers
30+ this . configManager = new ConfigManager ( cwd ) ;
31+ this . moduleManager = new ModuleManager ( this . configManager ) ;
32+ this . extensionManager = new ExtensionManager ( this . configManager , this . moduleManager ) ;
33+ this . packageManager = new PackageManager (
34+ this . configManager ,
35+ this . moduleManager ,
36+ this . extensionManager
37+ ) ;
38+ this . planGenerator = new PlanGenerator (
39+ this . configManager ,
40+ this . moduleManager ,
41+ this . extensionManager
42+ ) ;
43+ }
44+
45+ // Delegate to ConfigManager
46+ resetCwd ( cwd : string ) : void {
47+ this . configManager . resetCwd ( cwd ) ;
48+ }
49+
50+ isInsideAllowedDirs ( cwd : string ) : boolean {
51+ return this . configManager . isInsideAllowedDirs ( cwd ) ;
52+ }
53+
54+ ensureModule ( ) : void {
55+ this . configManager . ensureModule ( ) ;
56+ }
57+
58+ ensureWorkspace ( ) : void {
59+ this . configManager . ensureWorkspace ( ) ;
60+ }
61+
62+ getContext ( ) : ProjectContext {
63+ if ( this . configManager . isInModule ( ) && this . configManager . isInWorkspace ( ) ) {
64+ return ProjectContext . Module ;
65+ }
66+ if ( this . configManager . isInWorkspace ( ) ) return ProjectContext . Workspace ;
67+ return ProjectContext . Unknown ;
68+ }
69+
70+ isInWorkspace ( ) : boolean {
71+ return this . configManager . isInWorkspace ( ) ;
72+ }
73+
74+ isInModule ( ) : boolean {
75+ return this . configManager . isInModule ( ) ;
76+ }
77+
78+ getWorkspacePath ( ) : string | undefined {
79+ return this . configManager . getWorkspacePath ( ) ;
80+ }
81+
82+ getModulePath ( ) : string | undefined {
83+ return this . configManager . getModulePath ( ) ;
84+ }
85+
86+ get cwd ( ) : string {
87+ return this . configManager . getCwd ( ) ;
88+ }
89+
90+ get workspacePath ( ) : string | undefined {
91+ return this . configManager . getWorkspacePath ( ) ;
92+ }
93+
94+ get modulePath ( ) : string | undefined {
95+ return this . configManager . getModulePath ( ) ;
96+ }
97+
98+ get config ( ) : any {
99+ return this . configManager . getConfig ( ) ;
100+ }
101+
102+ get allowedDirs ( ) : string [ ] {
103+ return this . configManager . getAllowedDirs ( ) ;
104+ }
105+
106+ // Delegate to ModuleManager
107+ clearCache ( ) : void {
108+ this . moduleManager . clearCache ( ) ;
109+ this . extensionManager . clearCache ( ) ;
110+ }
111+
112+ getAvailableModules ( ) : LaunchQL [ ] {
113+ return this . moduleManager . getAvailableModules ( ) ;
114+ }
115+
116+ getModuleMap ( ) : any {
117+ return this . moduleManager . getModuleMap ( ) ;
118+ }
119+
120+ getModuleName ( ) : string {
121+ return this . moduleManager . getModuleName ( ) ;
122+ }
123+
124+ getModuleDependencies ( ) : string [ ] {
125+ return this . moduleManager . getModuleDependencies ( ) ;
126+ }
127+
128+ getModuleDependencyChanges ( ) : string [ ] {
129+ return this . moduleManager . getModuleDependencyChanges ( ) ;
130+ }
131+
132+ getLatestChange ( ) : string | undefined {
133+ return this . moduleManager . getLatestChange ( ) ;
134+ }
135+
136+ getLatestChangeAndVersion ( ) : any {
137+ return this . moduleManager . getLatestChangeAndVersion ( ) ;
138+ }
139+
140+ getModulePlan ( ) : string {
141+ return this . moduleManager . getModulePlan ( ) ;
142+ }
143+
144+ getModuleSQL ( ) : string [ ] {
145+ return this . moduleManager . getModuleSQL ( ) ;
146+ }
147+
148+ getModuleControlFile ( ) : any {
149+ return this . moduleManager . getModuleControlFile ( ) ;
150+ }
151+
152+ getModuleMakefile ( ) : string | null {
153+ return this . moduleManager . getModuleMakefile ( ) ;
154+ }
155+
156+ normalizeChangeName ( name : string ) : string {
157+ return this . moduleManager . normalizeChangeName ( name ) ;
158+ }
159+
160+ async initModule ( name : string ) : Promise < string > {
161+ return this . moduleManager . initModule ( name ) ;
162+ }
163+
164+ // Delegate to ExtensionManager
165+ getModuleInfo ( ) : any {
166+ return this . extensionManager . getModuleInfo ( ) ;
167+ }
168+
169+ getModuleExtensions ( ) : string [ ] {
170+ return this . extensionManager . getModuleExtensions ( ) ;
171+ }
172+
173+ getAvailableExtensions ( ) : string [ ] {
174+ return this . extensionManager . getAvailableExtensions ( ) ;
175+ }
176+
177+ getInstalledExtensions ( ) : string [ ] {
178+ return this . extensionManager . getInstalledExtensions ( ) ;
179+ }
180+
181+ async installExtension ( packageSpec : string ) : Promise < void > {
182+ return this . extensionManager . installExtension ( packageSpec ) ;
183+ }
184+
185+ async writeExtensions ( ) : Promise < void > {
186+ return this . extensionManager . writeExtensions ( ) ;
187+ }
188+
189+ // Delegate to PackageManager
190+ async publishToDist ( ) : Promise < void > {
191+ return this . packageManager . publishToDist ( ) ;
192+ }
193+
194+ setModuleDependencies ( dependencies : string [ ] ) : void {
195+ this . packageManager . setModuleDependencies ( dependencies ) ;
196+ }
197+
198+ getRequiredModules ( ) : string [ ] {
199+ return this . packageManager . getRequiredModules ( ) ;
200+ }
201+
202+ // Delegate to PlanGenerator
203+ generatePlanFromFiles ( ) : string {
204+ return this . planGenerator . generatePlanFromFiles ( ) ;
205+ }
206+
207+ writeModulePlan ( ) : void {
208+ this . planGenerator . writeModulePlan ( ) ;
209+ }
210+
211+ addChangeToProject ( name : string , dependencies ?: string [ ] ) : void {
212+ this . planGenerator . addChangeToProject ( name , dependencies ) ;
213+ }
214+
215+ validatePlanConsistency ( ) : { valid : boolean ; errors : string [ ] } {
216+ return this . planGenerator . validatePlanConsistency ( ) ;
217+ }
218+
219+ // Convenience methods that combine multiple managers
220+ async install ( packages : string [ ] ) : Promise < void > {
221+ for ( const pkg of packages ) {
222+ await this . installExtension ( pkg ) ;
223+ }
224+ }
225+
226+ async deploy ( ) : Promise < void > {
227+ // Validate plan first
228+ const validation = this . validatePlanConsistency ( ) ;
229+ if ( ! validation . valid ) {
230+ throw new Error ( `Invalid plan: ${ validation . errors . join ( ', ' ) } ` ) ;
231+ }
232+
233+ // Deploy logic would go here
234+ this . logger . info ( 'Deploy functionality to be implemented' ) ;
235+ }
236+
237+ async revert ( target ?: string ) : Promise < void > {
238+ // Revert logic would go here
239+ this . logger . info ( 'Revert functionality to be implemented' ) ;
240+ }
241+
242+ async verify ( ) : Promise < void > {
243+ // Verify logic would go here
244+ this . logger . info ( 'Verify functionality to be implemented' ) ;
245+ }
246+
247+ async status ( ) : Promise < any > {
248+ // Status logic would go here
249+ return {
250+ workspace : this . getWorkspacePath ( ) ,
251+ module : this . getModulePath ( ) ,
252+ context : this . getContext ( ) ,
253+ modules : this . getAvailableModules ( ) . map ( m => m . getModuleName ( ) ) ,
254+ extensions : this . getInstalledExtensions ( )
255+ } ;
256+ }
257+ }
0 commit comments