33// This software is released under the MIT License.
44// https://opensource.org/licenses/MIT
55import { flags } from '@oclif/command' ;
6+ import { IConfig } from '@oclif/config' ;
67import * as path from 'path' ;
78import Base from '../../command-base' ;
8- import { AnyObject } from '../../types' ;
9+ import { AnyObject , PromptFunction } from '../../types' ;
910import { FileGenerator } from '../../utilities/file-generator' ;
1011import { McpConfigInjector } from '../../utilities/mcp-injector' ;
1112import { TemplateFetcher } from '../../utilities/template-fetcher' ;
@@ -135,7 +136,7 @@ export class AngularScaffold extends Base<{}> {
135136 }
136137
137138 try {
138- const scaffolder = new AngularScaffold ( [ ] , { } as any , { } as any ) ;
139+ const scaffolder = new AngularScaffold ( [ ] , { } as unknown as IConfig , { } as unknown as PromptFunction ) ;
139140 const result = await scaffolder . scaffoldProject ( inputs ) ;
140141 process . chdir ( originalCwd ) ;
141142 return {
@@ -155,71 +156,46 @@ export class AngularScaffold extends Base<{}> {
155156 }
156157 }
157158
158- private async scaffoldProject ( inputs : AnyObject ) : Promise < string > {
159- const {
160- name,
161- withAuth,
162- withThemes,
163- withBreadcrumbs,
164- withI18n,
165- templateRepo,
166- templateVersion,
167- installDeps,
168- localPath,
169- } = inputs ;
170-
171- const targetDir = path . join ( process . cwd ( ) , name ) ;
172-
173- // Step 1: Fetch template
174- console . log ( `\n📦 Scaffolding Angular project '${ name } '...` ) ;
175- await this . templateFetcher . smartFetch ( {
176- repo : templateRepo ,
177- targetDir,
178- branch : templateVersion ,
179- localPath,
180- } ) ;
181-
182- // Step 2: Configure modular features
159+ private configureModules (
160+ targetDir : string ,
161+ inputs : AnyObject ,
162+ ) : { includedModules : string [ ] ; removedModules : string [ ] } {
183163 const includedModules : string [ ] = [ ] ;
184164 const removedModules : string [ ] = [ ] ;
185165
186- if ( ! withAuth ) {
187- this . fileGenerator . removeModule ( targetDir , 'auth' ) ;
188- removedModules . push ( 'Authentication' ) ;
189- } else {
190- includedModules . push ( 'Authentication' ) ;
191- }
192-
193- if ( ! withThemes ) {
194- this . fileGenerator . removeModule ( targetDir , 'themes' ) ;
195- removedModules . push ( 'Themes' ) ;
196- } else {
197- includedModules . push ( 'Themes' ) ;
198- }
199-
200- if ( ! withBreadcrumbs ) {
201- this . fileGenerator . removeModule ( targetDir , 'breadcrumbs' ) ;
202- removedModules . push ( 'Breadcrumbs' ) ;
203- } else {
204- includedModules . push ( 'Breadcrumbs' ) ;
205- }
166+ const moduleConfigs = [
167+ { flag : inputs . withAuth , name : 'Authentication' , module : 'auth' } ,
168+ { flag : inputs . withThemes , name : 'Themes' , module : 'themes' } ,
169+ {
170+ flag : inputs . withBreadcrumbs ,
171+ name : 'Breadcrumbs' ,
172+ module : 'breadcrumbs' ,
173+ } ,
174+ ] ;
175+
176+ moduleConfigs . forEach ( ( { flag, name, module} ) => {
177+ if ( flag === false ) {
178+ this . fileGenerator . removeModule ( targetDir , module ) ;
179+ removedModules . push ( name ) ;
180+ } else {
181+ includedModules . push ( name ) ;
182+ }
183+ } ) ;
206184
207- if ( withI18n ) {
185+ if ( inputs . withI18n ) {
208186 includedModules . push ( 'Internationalization' ) ;
209187 }
210188
211- // Step 3: Inject MCP configuration
212- this . mcpInjector . injectConfig ( targetDir , 'angular' ) ;
213-
214- // Step 4: Update package.json
215- this . fileGenerator . updatePackageJson ( targetDir , name ) ;
216-
217- // Step 5: Install dependencies
218- if ( installDeps ) {
219- this . fileGenerator . installDependencies ( targetDir ) ;
220- }
189+ return { includedModules, removedModules} ;
190+ }
221191
222- // Build success message
192+ private buildSuccessMessage (
193+ name : string ,
194+ targetDir : string ,
195+ includedModules : string [ ] ,
196+ removedModules : string [ ] ,
197+ installDeps : boolean ,
198+ ) : string {
223199 let result = `
224200✅ Angular project '${ name } ' scaffolded successfully!
225201
@@ -245,4 +221,46 @@ Next steps:
245221
246222 return result ;
247223 }
224+
225+ private async scaffoldProject ( inputs : AnyObject ) : Promise < string > {
226+ const { name, templateRepo, templateVersion, installDeps, localPath} =
227+ inputs ;
228+
229+ const targetDir = path . join ( process . cwd ( ) , name ) ;
230+
231+ // Step 1: Fetch template
232+ console . log ( `\n📦 Scaffolding Angular project '${ name } '...` ) ;
233+ await this . templateFetcher . smartFetch ( {
234+ repo : templateRepo ,
235+ targetDir,
236+ branch : templateVersion ,
237+ localPath,
238+ } ) ;
239+
240+ // Step 2: Configure modular features
241+ const { includedModules, removedModules} = this . configureModules (
242+ targetDir ,
243+ inputs ,
244+ ) ;
245+
246+ // Step 3: Inject MCP configuration
247+ this . mcpInjector . injectConfig ( targetDir , 'angular' ) ;
248+
249+ // Step 4: Update package.json
250+ this . fileGenerator . updatePackageJson ( targetDir , name ) ;
251+
252+ // Step 5: Install dependencies
253+ if ( installDeps ) {
254+ this . fileGenerator . installDependencies ( targetDir ) ;
255+ }
256+
257+ // Build success message
258+ return this . buildSuccessMessage (
259+ name ,
260+ targetDir ,
261+ includedModules ,
262+ removedModules ,
263+ installDeps ,
264+ ) ;
265+ }
248266}
0 commit comments