aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 1.7 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.TreeMetadata=void 0;const fs=require("fs"),path=require("path"),cloud_assembly_schema_1=require("../../../cloud-assembly-schema"),constructs_1=require("constructs"),runtime_info_1=require("./runtime-info"),annotations_1=require("../annotations"),stack_1=require("../stack"),tree_1=require("../tree"),FILE_PATH="tree.json";class TreeMetadata extends constructs_1.Construct{constructor(scope){super(scope,"Tree")}_synthesizeTree(session){const lookup={},visit=construct=>{const childrenMap=construct.node.children.map(c=>{try{return visit(c)}catch(e){annotations_1.Annotations.of(this).addWarning(`Failed to render tree metadata for node [${c.node.id}]. Reason: ${e}`);return}}).filter(child=>child!==void 0).reduce((map,child)=>Object.assign(map,{[child.id]:child}),{}),node={id:construct.node.id||"App",path:construct.node.path,children:Object.keys(childrenMap).length===0?void 0:childrenMap,attributes:this.synthAttributes(construct),constructInfo:runtime_info_1.constructInfoFromConstruct(construct)};return lookup[node.path]=node,node},tree={version:"tree-0.1",tree:visit(this.node.root)},builder=session.assembly;fs.writeFileSync(path.join(builder.outdir,FILE_PATH),JSON.stringify(tree,void 0,2),{encoding:"utf-8"}),builder.addArtifact("Tree",{type:cloud_assembly_schema_1.ArtifactType.CDK_TREE,properties:{file:FILE_PATH}})}synthAttributes(construct){function canInspect(inspectable){return inspectable.inspect!==void 0}const inspector=new tree_1.TreeInspector;if(canInspect(construct))return construct.inspect(inspector),stack_1.Stack.of(construct).resolve(inspector.attributes)}}exports.TreeMetadata=TreeMetadata;