-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): expose util for standard cache directory per config
- Loading branch information
1 parent
ab8dab6
commit cab8bae
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/practices/config/best-practice/src/utils/config/getCacheDirectory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { DirectoryToPersistTo } from 'simple-on-disk-cache'; | ||
import { isPresent } from 'type-fns'; | ||
|
||
import { getConfig } from './getConfig'; | ||
|
||
/** | ||
* .what = gets the project's default s3 bucket, based on config | ||
*/ | ||
export const getProjectBucket = async (): Promise<string> => { | ||
const config = await getConfig(); | ||
const bucket = [ | ||
config.project, | ||
config.aws.namespace, | ||
config.environment.access, | ||
].join('-'); | ||
return bucket; | ||
}; | ||
|
||
/** | ||
* .what = gets the project's default cache directory, based on config | ||
*/ | ||
export const getCacheDirectory = async ( | ||
input: { | ||
scope?: string; | ||
} = {}, | ||
): Promise<DirectoryToPersistTo> => ({ | ||
s3: { | ||
bucket: await getProjectBucket(), | ||
prefix: ['purpose=cache', input.scope ? `scope=${input.scope}` : undefined] | ||
.filter(isPresent) | ||
.join('/'), | ||
}, | ||
}); |