Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(assets): isZipArchive indicates if this is a zip asset #944

Merged
merged 4 commits into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/@aws-cdk/assets/lib/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@ export class Asset extends cdk.Construct {
*/
public readonly assetPath: string;

private readonly bucket: s3.BucketRef;
/**
* The S3 bucket in which this asset resides.
*/
public readonly bucket: s3.BucketRef;

/**
* Indicates if this asset is a zip archive. Allows constructs to ensure that the
* correct file type was used.
*/
public readonly isZipArchive: boolean;

/**
* The S3 prefix where all different versions of this asset are stored
Expand All @@ -78,6 +87,11 @@ export class Asset extends cdk.Construct {
// resolve full path
this.assetPath = path.resolve(props.path);

// sets isZipArchive based on the type of packaging and file extension
this.isZipArchive = props.packaging === AssetPackaging.ZipDirectory
? true
: this.assetPath.toLowerCase().endsWith('.zip');

validateAssetOnDisk(this.assetPath, props.packaging);

// add parameters for s3 bucket and s3 key. those will be set by
Expand Down
Binary file not shown.
24 changes: 24 additions & 0 deletions packages/@aws-cdk/assets/test/test.asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,28 @@ export = {

test.done();
},

'isZipArchive indicates if the asset represents a .zip file (either explicitly or via ZipDirectory packaging)'(test: Test) {
// GIVEN
const stack = new cdk.Stack();

// WHEN
const nonZipAsset = new FileAsset(stack, 'NonZipAsset', {
path: path.join(__dirname, 'sample-asset-directory', 'sample-asset-file.txt')
});

const zipDirectoryAsset = new ZipDirectoryAsset(stack, 'ZipDirectoryAsset', {
path: path.join(__dirname, 'sample-asset-directory')
});

const zipFileAsset = new FileAsset(stack, 'ZipFileAsset', {
path: path.join(__dirname, 'sample-asset-directory', 'sample-zip-asset.zip')
});

// THEN
test.equal(nonZipAsset.isZipArchive, false);
test.equal(zipDirectoryAsset.isZipArchive, true);
test.equal(zipFileAsset.isZipArchive, true);
test.done();
}
};