File tree 3 files changed +39
-1
lines changed
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 {
65
65
*/
66
66
public readonly assetPath : string ;
67
67
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 ;
69
78
70
79
/**
71
80
* The S3 prefix where all different versions of this asset are stored
@@ -78,6 +87,11 @@ export class Asset extends cdk.Construct {
78
87
// resolve full path
79
88
this . assetPath = path . resolve ( props . path ) ;
80
89
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
+
81
95
validateAssetOnDisk ( this . assetPath , props . packaging ) ;
82
96
83
97
// 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 = {
112
112
113
113
test . done ( ) ;
114
114
} ,
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
+ }
115
139
} ;
You can’t perform that action at this time.
0 commit comments