Skip to content

Commit

Permalink
feat: Show output of middlewares when running them.
Browse files Browse the repository at this point in the history
  • Loading branch information
hswolff committed Mar 25, 2017
1 parent be87c40 commit 189bf7b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/cli/build.js
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/watch.js
Expand Up @@ -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.
Expand Down
46 changes: 28 additions & 18 deletions lib/index.js
Expand Up @@ -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);
Expand All @@ -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)
);
}
Expand All @@ -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',
});
}

Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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',
});
}

Expand Down

0 comments on commit 189bf7b

Please sign in to comment.