-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88c956b
commit 14443b4
Showing
5 changed files
with
59 additions
and
55 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,41 @@ | ||
import fs from 'fs-extra' | ||
import path from 'path' | ||
import FileCache from './cache/file' | ||
import MemoryCache from './cache/memory' | ||
|
||
/** | ||
* @param {string|object} config | ||
* @return {*} | ||
*/ | ||
export function makeConfig (config) { | ||
// By convention, look in the root directory for | ||
// a torchlight.config.js file. | ||
if (config === undefined || config === '') { | ||
config = 'torchlight.config.js' | ||
} | ||
|
||
if (typeof config === 'string') { | ||
config = fs.pathExistsSync(path.resolve(config)) ? require(path.resolve(config)) : {} | ||
} | ||
|
||
return config || {} | ||
} | ||
|
||
/** | ||
* Make a cache to hold highlighted blocks. | ||
* | ||
* @return {Cache} | ||
*/ | ||
export function makeCache (config) { | ||
const cache = config?.cache | ||
|
||
// Make a file cache if we're given a directory. | ||
if (cache && typeof cache === 'string') { | ||
return new FileCache({ | ||
directory: cache | ||
}) | ||
} | ||
|
||
// Use the cache they have provided, or default to an in-memory cache. | ||
return cache || new MemoryCache() | ||
} |
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