diff --git a/lib/cli/build.js b/lib/cli/build.js index 37f73ba..1795af9 100644 --- a/lib/cli/build.js +++ b/lib/cli/build.js @@ -2,7 +2,7 @@ import log from '../log'; import Reptar from '../index'; export default async function build(options) { - const id = log.startActivity('building\t\t\t'); + const id = log.startActivity('building\t\t\t\t'); process.stdout.write('\n'); const reptar = new Reptar(options); diff --git a/lib/cli/watch.js b/lib/cli/watch.js index 2053fd4..42a9b45 100644 --- a/lib/cli/watch.js +++ b/lib/cli/watch.js @@ -158,7 +158,7 @@ class Server { } export default async function watch(options = {}) { - const startActivity = activity.start('Starting watch.\t\t\t'); + const startActivity = activity.start('Starting watch.\t\t\t\t'); const reptar = new Reptar({ // Turn off caching of templates. diff --git a/lib/index.js b/lib/index.js index a58c387..ccbd8fe 100644 --- a/lib/index.js +++ b/lib/index.js @@ -118,12 +118,26 @@ export default class Reptar { this.destination = Object.create(null); } + async _processMiddlewares({ middlewaresKey }) { + const middlewares = this.config.get(middlewaresKey); + + if (middlewares.length === 0) { + return; + } + + const tabs = middlewaresKey.length > 11 ? '\t\t' : '\t\t'; + + await this._wrapCommand( + `Running "${middlewaresKey}".${tabs}`, + () => processMiddlewares({ middlewares, reptar: this }) + ); + } + async update({ skipFiles = false } = {}) { this.config.update(); - await processMiddlewares({ - middlewares: this.config.get('lifecycle.willUpdate'), - reptar: this, + await this._processMiddlewares({ + middlewaresKey: 'lifecycle.willUpdate', }); const { base, dir } = path.parse(this.config.root); @@ -149,7 +163,7 @@ export default class Reptar { if (!skipFiles) { await this._wrapCommand( - 'Reading files.\t\t', + 'Reading files.\t\t\t', this.fileSystem.loadIntoMemory.bind(this.fileSystem) ); } @@ -163,14 +177,12 @@ export default class Reptar { addCollections(this); addDataFiles(this); - await processMiddlewares({ - middlewares: this.config.get('lifecycle.didUpdate'), - reptar: this, + await this._processMiddlewares({ + middlewaresKey: 'lifecycle.didUpdate', }); - await processMiddlewares({ - middlewares: this.config.get('middlewares'), - reptar: this, + await this._processMiddlewares({ + middlewaresKey: 'middlewares', }); } @@ -180,7 +192,7 @@ export default class Reptar { */ cleanDestination() { return this._wrapCommand( - 'Cleaning destination.\t\t', + 'Cleaning destination.\t\t\t', async () => { await Promise.fromCallback((cb) => { rimraf(this.config.get('path.destination'), cb); @@ -196,9 +208,8 @@ export default class Reptar { * Builds the Reptar site in its entirety. */ async build() { - await processMiddlewares({ - middlewares: this.config.get('lifecycle.willBuild'), - reptar: this, + await this._processMiddlewares({ + middlewaresKey: 'lifecycle.willBuild', }); if (this.config.get('cleanDestination') || this.options.clean) { @@ -208,16 +219,15 @@ export default class Reptar { const metadata = this.metadata.get(); await this._wrapCommand( - 'Writing destination.\t\t', + 'Writing destination.\t\t\t', () => Promise.all( _.map(this.destination, file => file.write(metadata)) ) ); - await processMiddlewares({ - middlewares: this.config.get('lifecycle.didBuild'), - reptar: this, + await this._processMiddlewares({ + middlewaresKey: 'lifecycle.didBuild', }); }