2021-08-21 03:01:43 +08:00
|
|
|
import path from 'path'
|
|
|
|
import fs from 'fs'
|
2021-10-30 21:15:20 +08:00
|
|
|
import {AbstractCache} from './cache-base'
|
2021-08-21 03:01:43 +08:00
|
|
|
|
2021-09-14 01:47:59 +08:00
|
|
|
// TODO: Maybe allow the user to override / tweak this set
|
2021-08-21 03:01:43 +08:00
|
|
|
const PATHS_TO_CACHE = [
|
|
|
|
'configuration-cache' // Only configuration-cache is stored at present
|
|
|
|
]
|
|
|
|
|
2021-11-29 01:19:56 +08:00
|
|
|
/**
|
|
|
|
* A simple cache that saves and restores the '.gradle/configuration-cache' directory in the project root.
|
|
|
|
*/
|
2021-09-07 01:16:08 +08:00
|
|
|
export class ProjectDotGradleCache extends AbstractCache {
|
|
|
|
private rootDir: string
|
|
|
|
constructor(rootDir: string) {
|
2021-10-30 21:39:21 +08:00
|
|
|
super('project', 'Project configuration cache')
|
2021-09-07 01:16:08 +08:00
|
|
|
this.rootDir = rootDir
|
2021-08-21 03:01:43 +08:00
|
|
|
}
|
|
|
|
|
2021-09-07 01:16:08 +08:00
|
|
|
protected cacheOutputExists(): boolean {
|
|
|
|
const dir = this.getProjectDotGradleDir()
|
|
|
|
return fs.existsSync(dir)
|
2021-08-21 03:01:43 +08:00
|
|
|
}
|
|
|
|
|
2021-09-07 01:16:08 +08:00
|
|
|
protected getCachePath(): string[] {
|
|
|
|
const dir = this.getProjectDotGradleDir()
|
|
|
|
return PATHS_TO_CACHE.map(x => path.resolve(dir, x))
|
2021-08-21 03:01:43 +08:00
|
|
|
}
|
|
|
|
|
2021-09-07 01:16:08 +08:00
|
|
|
private getProjectDotGradleDir(): string {
|
|
|
|
return path.resolve(this.rootDir, '.gradle')
|
2021-08-21 03:01:43 +08:00
|
|
|
}
|
|
|
|
}
|