Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(hexo/index): async/await #3952

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions lib/hexo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Hexo {
});
}

init() {
async init() {
this.log.debug('Hexo version: %s', chalk.magenta(this.version));
this.log.debug('Working directory: %s', chalk.magenta(tildify(this.base_dir)));

Expand All @@ -224,14 +224,16 @@ class Hexo {
require('../plugins/tag')(this);

// Load config
return Promise.each([
await Promise.each([
'update_package', // Update package.json
'load_config', // Load config
'load_plugins' // Load external plugins & scripts
], name => require(`./${name}`)(this)).then(() => this.execFilter('after_init', null, {context: this})).then(() => {
// Ready to go!
this.emit('ready');
});
], name => require(`./${name}`)(this));

await this.execFilter('after_init', null, { context: this });

// Ready to go!
return await this.emit('ready');
}

call(name, args, callback) {
Expand Down Expand Up @@ -438,7 +440,7 @@ class Hexo {
});
}

exit(err) {
async exit(err) {
if (err) {
this.log.fatal(
{err},
Expand All @@ -447,9 +449,8 @@ class Hexo {
);
}

return this.execFilter('before_exit', null, {context: this}).then(() => {
this.emit('exit', err);
});
await this.execFilter('before_exit', null, { context: this });
return await this.emit('exit', err);
}

execFilter(type, data, options) {
Expand Down