44// https://opensource.org/licenses/MIT
55import { flags } from '@oclif/command' ;
66import { IConfig } from '@oclif/config' ;
7- import { execSync } from 'child_process' ;
8- import * as fs from 'fs' ;
9- import * as path from 'path' ;
7+ import { execSync } from 'node: child_process' ;
8+ import * as fs from 'node: fs' ;
9+ import * as path from 'node: path' ;
1010import Base from '../../command-base' ;
1111import { AnyObject , PromptFunction } from '../../types' ;
1212import { FileGenerator } from '../../utilities/file-generator' ;
@@ -98,15 +98,33 @@ export class AngularInfo extends Base<{}> {
9898 const { detailed} = inputs ;
9999 const projectRoot = this . fileGenerator [ 'getProjectRoot' ] ( ) ;
100100
101- // Read package.json
101+ const packageJson = this . loadPackageJson ( projectRoot ) ;
102+ let info = this . buildBasicInfo ( packageJson ) ;
103+
104+ info += this . getEnvironmentInfo ( ) ;
105+ info += this . getKeyDependencies ( packageJson ) ;
106+ info += this . getScripts ( packageJson ) ;
107+
108+ if ( detailed ) {
109+ info += this . getDetailedStatistics ( projectRoot ) ;
110+ }
111+
112+ info += this . getConfigurationFiles ( projectRoot ) ;
113+ info += this . getMcpConfiguration ( projectRoot ) ;
114+
115+ return info ;
116+ }
117+
118+ private loadPackageJson ( projectRoot : string ) : AnyObject {
102119 const packageJsonPath = path . join ( projectRoot , 'package.json' ) ;
103120 if ( ! fs . existsSync ( packageJsonPath ) ) {
104121 throw new Error ( 'package.json not found. Is this an Angular project?' ) ;
105122 }
123+ return JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf-8' ) ) ;
124+ }
106125
107- const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf-8' ) ) ;
108-
109- let info = `
126+ private buildBasicInfo ( packageJson : AnyObject ) : string {
127+ return `
110128📦 Angular Project Information
111129═══════════════════════════════
112130
@@ -115,23 +133,26 @@ Version: ${packageJson.version || 'N/A'}
115133Description: ${ packageJson . description || 'N/A' }
116134
117135` ;
136+ }
118137
119- // Node/NPM versions
138+ private getEnvironmentInfo ( ) : string {
120139 try {
121140 const nodeVersion = execSync ( 'node --version' , { encoding : 'utf-8' } ) . trim ( ) ;
122141 const npmVersion = execSync ( 'npm --version' , { encoding : 'utf-8' } ) . trim ( ) ;
123- info += `🔧 Environment
142+ return `🔧 Environment
124143───────────────
125144Node: ${ nodeVersion }
126145NPM: ${ npmVersion }
127146
128147` ;
129148 } catch ( err ) {
130- // Ignore if node/npm not available
149+ // Node/NPM not available - return empty string
150+ return '' ;
131151 }
152+ }
132153
133- // Key dependencies
134- info + = `📚 Key Dependencies
154+ private getKeyDependencies ( packageJson : AnyObject ) : string {
155+ let info = `📚 Key Dependencies
135156───────────────────
136157` ;
137158 const deps = packageJson . dependencies || { } ;
@@ -146,57 +167,68 @@ NPM: ${npmVersion}
146167 'rxjs' ,
147168 ] ;
148169
149- keyDeps . forEach ( dep => {
170+ for ( const dep of keyDeps ) {
150171 if ( allDeps [ dep ] ) {
151172 info += `${ dep } : ${ allDeps [ dep ] } \n` ;
152173 }
153- } ) ;
174+ }
175+
176+ return info ;
177+ }
178+
179+ private getScripts ( packageJson : AnyObject ) : string {
180+ if ( ! packageJson . scripts ) {
181+ return '' ;
182+ }
154183
155- // Scripts
156- if ( packageJson . scripts ) {
157- info += `\n⚡ Available Scripts
184+ let info = `\n⚡ Available Scripts
158185──────────────────
159186` ;
160- Object . keys ( packageJson . scripts )
161- . slice ( 0 , 10 )
162- . forEach ( script => {
163- info += `${ script } : ${ packageJson . scripts [ script ] } \n` ;
164- } ) ;
187+ const scripts = Object . keys ( packageJson . scripts ) . slice ( 0 , 10 ) ;
188+ for ( const script of scripts ) {
189+ info += `${ script } : ${ packageJson . scripts [ script ] } \n` ;
165190 }
166191
167- // Project statistics (if detailed)
168- if ( detailed ) {
169- const stats = this . getProjectStatistics ( projectRoot ) ;
170- info += `\n📊 Project Statistics
192+ return info ;
193+ }
194+
195+ private getDetailedStatistics ( projectRoot : string ) : string {
196+ const stats = this . getProjectStatistics ( projectRoot ) ;
197+ return `\n📊 Project Statistics
171198────────────────────
172199${ stats }
173200` ;
174- }
201+ }
175202
176- // Configuration files
203+ private getConfigurationFiles ( projectRoot : string ) : string {
177204 const configFiles = [
178205 'angular.json' ,
179206 'tsconfig.json' ,
180207 'karma.conf.js' ,
181208 '.eslintrc.json' ,
182209 ] ;
183210
184- info + = `\n📄 Configuration Files
211+ let info = `\n📄 Configuration Files
185212──────────────────────
186213` ;
187- configFiles . forEach ( file => {
214+ for ( const file of configFiles ) {
188215 const filePath = path . join ( projectRoot , file ) ;
189216 info += `${ file } : ${ fs . existsSync ( filePath ) ? '✅' : '❌' } \n` ;
190- } ) ;
217+ }
191218
192- // MCP Configuration
219+ return info ;
220+ }
221+
222+ private getMcpConfiguration ( projectRoot : string ) : string {
193223 const mcpConfigPath = path . join ( projectRoot , '.claude' , 'mcp.json' ) ;
194- info += `\n🤖 MCP Configuration
224+ const isConfigured = fs . existsSync ( mcpConfigPath ) ;
225+
226+ let info = `\n🤖 MCP Configuration
195227───────────────────
196- Status: ${ fs . existsSync ( mcpConfigPath ) ? '✅ Configured' : '❌ Not configured' }
228+ Status: ${ isConfigured ? '✅ Configured' : '❌ Not configured' }
197229` ;
198230
199- if ( fs . existsSync ( mcpConfigPath ) ) {
231+ if ( isConfigured ) {
200232 info += `Location: .claude/mcp.json
201233` ;
202234 }
@@ -241,7 +273,7 @@ Status: ${fs.existsSync(mcpConfigPath) ? '✅ Configured' : '❌ Not configured'
241273 const walk = ( directory : string ) => {
242274 try {
243275 const files = fs . readdirSync ( directory ) ;
244- files . forEach ( file => {
276+ for ( const file of files ) {
245277 const filePath = path . join ( directory , file ) ;
246278 const stats = fs . statSync ( filePath ) ;
247279
@@ -250,9 +282,9 @@ Status: ${fs.existsSync(mcpConfigPath) ? '✅ Configured' : '❌ Not configured'
250282 } else if ( file . endsWith ( extension ) ) {
251283 count ++ ;
252284 }
253- } ) ;
285+ }
254286 } catch ( err ) {
255- // Ignore errors
287+ // Directory not accessible - skip it
256288 }
257289 } ;
258290
0 commit comments