Skip to content

Commit

Permalink
Docs driven dev
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondfrancis committed Aug 19, 2021
1 parent e99fb1c commit 0dd32ea
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const {program} = require('commander')
const torchlight = require('./src/torchlight');

command('_default_')
.alias('highlight')
.description('Highlight code blocks in source files')
.option('-i, --input <directory>', 'Input directory. Defaults to current directory.')
.option('-o, --output <directory>', 'Output directory. Defaults to current directory.')
Expand Down
8 changes: 4 additions & 4 deletions src/commands/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const log = require('../support/log')

module.exports = function (torchlight, options) {
options = {
input: torchlight.config('files.input', ''),
output: torchlight.config('files.output', ''),
include: torchlight.config('files.includeGlobs', ['**/*.htm', '**/*.html']),
exclude: torchlight.config('files.excludePatterns', ['/node_modules/', '/vendor/']),
input: torchlight.config('highlight.input', ''),
output: torchlight.config('highlight.output', ''),
include: torchlight.config('highlight.includeGlobs', ['**/*.htm', '**/*.html']),
exclude: torchlight.config('highlight.excludePatterns', ['/node_modules/', '/vendor/']),
watch: false,
...options
}
Expand Down
9 changes: 6 additions & 3 deletions src/stubs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ module.exports = {

// The Torchlight client caches highlighted code blocks. Here you
// can define which directory you'd like to use. You'll likely
// want to add this directory to your .gitignore.
cacheDirectory: 'cache',
// want to add this directory to your .gitignore. Set to
// `false` to use an in-memory cache. You may also
// provide a full cache implementation.
cache: 'cache',

// Which theme you want to use. You can find all of the themes at
// https://torchlight.dev/docs/themes.
Expand Down Expand Up @@ -35,7 +37,8 @@ module.exports = {
// summaryCollapsedIndicator: '...',
},

files: {
// Options for the highlight command.
highlight: {
// Directory where your un-highlighted source files live. If
// left blank, Torchlight will use the current directory.
input: '',
Expand Down
8 changes: 5 additions & 3 deletions src/torchlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ Torchlight.prototype.normalizeConfiguration = function (config) {
* @return {Cache}
*/
Torchlight.prototype.makeCache = function () {
let cache = this.config('cache', false);

// Make a file cache if we're given a directory.
if (this.config('cacheDirectory')) {
if (cache && typeof cache === 'string') {
return new FileCache({
directory: this.config('cacheDirectory')
directory: cache
});
}

// Use the cache they have provided, or default to an in-memory cache.
return this.config('cache') ? this.config('cache') : new MemoryCache();
return cache ? cache : new MemoryCache();
}

/**
Expand Down

0 comments on commit 0dd32ea

Please sign in to comment.