File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed
Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,16 @@ export class Asset extends cdk.Construct {
6565 */
6666 public readonly assetPath : string ;
6767
68- private readonly bucket : s3 . BucketRef ;
68+ /**
69+ * The S3 bucket in which this asset resides.
70+ */
71+ public readonly bucket : s3 . BucketRef ;
72+
73+ /**
74+ * Indicates if this asset is a zip archive. Allows constructs to ensure that the
75+ * correct file type was used.
76+ */
77+ public readonly isZipArchive : boolean ;
6978
7079 /**
7180 * The S3 prefix where all different versions of this asset are stored
@@ -78,6 +87,11 @@ export class Asset extends cdk.Construct {
7887 // resolve full path
7988 this . assetPath = path . resolve ( props . path ) ;
8089
90+ // sets isZipArchive based on the type of packaging and file extension
91+ this . isZipArchive = props . packaging === AssetPackaging . ZipDirectory
92+ ? true
93+ : this . assetPath . toLowerCase ( ) . endsWith ( '.zip' ) ;
94+
8195 validateAssetOnDisk ( this . assetPath , props . packaging ) ;
8296
8397 // add parameters for s3 bucket and s3 key. those will be set by
Original file line number Diff line number Diff line change @@ -112,4 +112,28 @@ export = {
112112
113113 test . done ( ) ;
114114 } ,
115+
116+ 'isZipArchive indicates if the asset represents a .zip file (either explicitly or via ZipDirectory packaging)' ( test : Test ) {
117+ // GIVEN
118+ const stack = new cdk . Stack ( ) ;
119+
120+ // WHEN
121+ const nonZipAsset = new FileAsset ( stack , 'NonZipAsset' , {
122+ path : path . join ( __dirname , 'sample-asset-directory' , 'sample-asset-file.txt' )
123+ } ) ;
124+
125+ const zipDirectoryAsset = new ZipDirectoryAsset ( stack , 'ZipDirectoryAsset' , {
126+ path : path . join ( __dirname , 'sample-asset-directory' )
127+ } ) ;
128+
129+ const zipFileAsset = new FileAsset ( stack , 'ZipFileAsset' , {
130+ path : path . join ( __dirname , 'sample-asset-directory' , 'sample-zip-asset.zip' )
131+ } ) ;
132+
133+ // THEN
134+ test . equal ( nonZipAsset . isZipArchive , false ) ;
135+ test . equal ( zipDirectoryAsset . isZipArchive , true ) ;
136+ test . equal ( zipFileAsset . isZipArchive , true ) ;
137+ test . done ( ) ;
138+ }
115139} ;
You can’t perform that action at this time.
0 commit comments