@@ -39,6 +39,9 @@ export interface IMessageRouterOptions {
3939}
4040
4141export class MessageRouter {
42+ public static readonly DIAGNOSTICS_HEADER : string = '==[DIAGNOSTICS]===================================' ;
43+ public static readonly DIAGNOSTICS_FOOTER : string = '==================================================\n' ;
44+
4245 private readonly _workingPackageFolder : string | undefined ;
4346 private readonly _messageCallback : ( ( message : ExtractorMessage ) => void ) | undefined ;
4447
@@ -240,6 +243,54 @@ export class MessageRouter {
240243 }
241244 }
242245
246+ /**
247+ * Recursively collects the primitive members (numbers, strings, arrays, etc) into an object that
248+ * is JSON serializable. This is used by the "--diagnostics" feature to dump the state of configuration objects.
249+ */
250+ // tslint:disable-next-line:no-any
251+ public static buildJsonDumpObject ( input : any ) : any {
252+ if ( input === null || input === undefined ) {
253+ // tslint:disable-next-line:no-null-keyword
254+ return null ; // JSON uses null instead of undefined
255+ }
256+
257+ switch ( typeof input ) {
258+ case 'boolean' :
259+ case 'number' :
260+ case 'string' :
261+ return input ;
262+ case 'object' :
263+ if ( Array . isArray ( input ) ) {
264+ // tslint:disable-next-line:no-any
265+ const outputArray : any [ ] = [ ] ;
266+ for ( const element of input ) {
267+ // tslint:disable-next-line:no-any
268+ const serializedElement : any = MessageRouter . buildJsonDumpObject ( element ) ;
269+ if ( serializedElement !== undefined ) {
270+ outputArray . push ( serializedElement ) ;
271+ }
272+ }
273+ return outputArray ;
274+ }
275+
276+ const outputObject : object = { } ;
277+ for ( const key of Object . getOwnPropertyNames ( input ) ) {
278+ // tslint:disable-next-line:no-any
279+ const value : any = input [ key ] ;
280+
281+ // tslint:disable-next-line:no-any
282+ const serializedValue : any = MessageRouter . buildJsonDumpObject ( value ) ;
283+
284+ if ( serializedValue !== undefined ) {
285+ outputObject [ key ] = serializedValue ;
286+ }
287+ }
288+ return outputObject ;
289+ }
290+
291+ return undefined ;
292+ }
293+
243294 /**
244295 * Record this message in _associatedMessagesForAstDeclaration
245296 */
0 commit comments