mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Move Incremental Cache into class
This commit is contained in:
parent
aa960903de
commit
12326c5b74
2 changed files with 124 additions and 42 deletions
|
|
@ -26,37 +26,65 @@ export async function getNetlifyConfig () {
|
|||
}
|
||||
|
||||
|
||||
export async function getPublishDirectoryName () {
|
||||
const netlifyConfig = await getNetlifyConfig()
|
||||
|
||||
return netlifyConfig.build.publish
|
||||
}
|
||||
|
||||
|
||||
export async function getPublishDirectoryPath () {
|
||||
const publishDirectoryPath = await getPublishDirectoryName()
|
||||
|
||||
return path.resolve( rootDir, publishDirectoryPath )
|
||||
}
|
||||
|
||||
|
||||
export async function hasCachedPublishFolder () {
|
||||
const homePageFile = `${ CACHE_PATH }/index.html`
|
||||
|
||||
// https://github.com/jprichardson/node-fs-extra/blob/master/docs/pathExists.md
|
||||
return await fs.pathExists( homePageFile )
|
||||
}
|
||||
|
||||
|
||||
export async function cachePublishFolder () {
|
||||
|
||||
const publishDirectoryPath = await getPublishDirectoryPath()
|
||||
|
||||
// console.log('publishDirectoryPath', publishDirectoryPath)
|
||||
|
||||
// Make sure cache folder exists
|
||||
await fs.ensureDir( CACHE_PATH )
|
||||
|
||||
await fs.copy( publishDirectoryPath, CACHE_PATH )
|
||||
export class IncrementalCache {
|
||||
|
||||
constructor( options = {} ) {
|
||||
this.cachePath = options.cachePath || CACHE_PATH
|
||||
this.publishDirectoryName = options.publishDirectoryName || null
|
||||
this.publishDirectoryPath = options.publishDirectoryPath || null
|
||||
|
||||
}
|
||||
|
||||
// export async function
|
||||
|
||||
async hasCachedPublishFolder () {
|
||||
const homePageFile = `${ this.cachePath }/index.html`
|
||||
|
||||
// https://github.com/jprichardson/node-fs-extra/blob/master/docs/pathExists.md
|
||||
return await fs.pathExists( homePageFile )
|
||||
}
|
||||
|
||||
async getPublishDirectoryName () {
|
||||
const netlifyConfig = await getNetlifyConfig()
|
||||
|
||||
return netlifyConfig.build.publish
|
||||
}
|
||||
|
||||
async getPublishDirectoryPath () {
|
||||
// const publishDirectoryPath = await this.getPublishDirectoryName()
|
||||
|
||||
return path.resolve( rootDir, this.publishDirectoryName )
|
||||
}
|
||||
|
||||
async cachePublishFolder () {
|
||||
|
||||
// const publishDirectoryPath = await this.getPublishDirectoryPath()
|
||||
|
||||
// console.log('publishDirectoryPath', publishDirectoryPath)
|
||||
|
||||
// Make sure cache folder exists
|
||||
await fs.ensureDir( this.cachePath )
|
||||
|
||||
await fs.copy( this.publishDirectoryPath, this.cachePath )
|
||||
|
||||
}
|
||||
|
||||
async emptyPublishDirectory () {
|
||||
// const publishDirectoryPath = await this.getPublishDirectoryName()
|
||||
|
||||
return await fs.emptyDir( this.publishDirectoryPath, 'utf-8' )
|
||||
}
|
||||
|
||||
|
||||
async init () {
|
||||
|
||||
if ( this.publishDirectoryName === null ) {
|
||||
this.publishDirectoryName = await this.getPublishDirectoryName()
|
||||
}
|
||||
|
||||
if ( this.publishDirectoryPath === null ) {
|
||||
this.publishDirectoryPath = await this.getPublishDirectoryPath()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue