-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/rework-go-cts
- Loading branch information
Showing
5 changed files
with
91 additions
and
95 deletions.
There are no files selected for viewing
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
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
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,56 @@ | ||
import fsp from 'fs/promises'; | ||
|
||
import { hashElement } from 'folder-hash'; | ||
|
||
import { exists } from './common'; | ||
|
||
export class Cache { | ||
folder: string; | ||
generatedFiles: string[]; | ||
filesToCache: string[]; | ||
cacheFile: string; | ||
|
||
constructor({ | ||
folder, | ||
generatedFiles, | ||
filesToCache, | ||
cacheFile, | ||
}: { | ||
folder: string; | ||
generatedFiles: string[]; | ||
filesToCache: string[]; | ||
cacheFile: string; | ||
}) { | ||
this.folder = folder; | ||
this.generatedFiles = generatedFiles; | ||
this.filesToCache = filesToCache; | ||
this.cacheFile = cacheFile; | ||
} | ||
|
||
async computeHash(): Promise<string> { | ||
let hash = ''; | ||
|
||
for (const generatedFile of this.generatedFiles) { | ||
hash += (await hashElement(`${this.folder}/${generatedFile}`)).hash; | ||
} | ||
|
||
for (const fileToCache of this.filesToCache) { | ||
hash += (await hashElement(`${this.folder}/${fileToCache}`)).hash; | ||
} | ||
|
||
return hash; | ||
} | ||
|
||
async isValid(): Promise<boolean> { | ||
if (!(await exists(this.cacheFile))) { | ||
return false; | ||
} | ||
|
||
const storedHash = (await fsp.readFile(this.cacheFile)).toString(); | ||
return storedHash === (await this.computeHash()); | ||
} | ||
|
||
async store(): Promise<void> { | ||
await fsp.writeFile(this.cacheFile, await this.computeHash()); | ||
} | ||
} |
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
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